davidedc / Algebrite

Computer Algebra System in Javascript (Typescript)
http://algebrite.org
MIT License
957 stars 59 forks source link

docs to include explanation of how to add (i.e. define, implement) own functions #55

Open CesMak opened 7 years ago

CesMak commented 7 years ago

Hey there I just want to ask how to write an own function?

What I did is: I wrote my own coffeescript: string2array.coffee: string2array = (hal)-> console.log hal console.log JSON.parse(hal) JSON.parse(hal)

In the runtime/defs.coffee: (I added:) string2array = counter++

In the runtime/init.coffee: (I added:) std_symbol("size", string2array)

In the runtime/zombocom.coffee (I added:) builtin_fns = ["string2array"]

Now I tried to build it (npm run build):

algebrite@1.0.2 build /home/markus/Desktop/Algebrite-master cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/count.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee runtime/lrucache.coffee runtime/freeze.coffee | coffee -sc > dist/algebrite.js

[stdin]:23406:17: error: unexpected Substitute new expr for old expr in expr.

Input: push expr

  push    old expr

  push    new expr

Output: Result on stack

JSON.parse(hal)### ^^^ npm ERR! code ELIFECYCLE npm ERR! errno 1 [...]

Getting the above error.

Any ideas how to solve this?

I would use the Algebrite libray and understand more of it. Would appreciate if sb could explain how to add new coffee scripts

davidedc commented 7 years ago

yes you are right, a better explanation is in order. However, really, in the meantime the best way is the following: 1) pick the most similar existing function to the one you want to implement (in terms of number of arguments, type of operation, etc.). 2) Do a "search all" for that keyword in the whole project. 3) Add analogous definitions in all the places where the existing one is defined.