factor/contrib/algebra
Daniel Ehrenberg 54ad3394a7 adding unittest for infix-word.see 2005-03-06 01:01:51 +00:00
..
README.TXT changes to algebra 2005-03-04 01:35:33 +00:00
algebra.factor s/word-property/word-prop/ 2005-03-05 23:55:31 +00:00
infix.factor s/word-property/word-prop/ 2005-03-05 23:55:31 +00:00
repl.factor updates on infix & infix repl 2005-02-25 05:06:30 +00:00
tests.factor adding unittest for infix-word.see 2005-03-06 01:01:51 +00:00

README.TXT

This is the infix minilanguage created by Daniel Ehrenberg, allowing you to do infix math in Factor. The syntax is simple: all operators are right-associative, and square brackets ('[' and ']') are used for paretheses. The syntax for creating an infix expression is ([ infix code goes here ]). That will leave the expression in the internal s-expression format which is easier to process by the evaluator and the CAS. The CAS subsystem of the infix minilanguage does algebra. Currently, it doesn't do very much, only modular arithmetic, though there may be more by the time you read this. There is also constant folding. The way to evaluate an infix expression is to make a seperate word to evaluate it in. The syntax for this is :| name | args |: body ; . Args are one or more variables that you use in the expression. Their values come from the stack. Variables are effectively substituted in to the expression. To make a new variable, use the syntax VARIABLE: variablename in top level code. The variables included by default are x, y, z, a, b, and c. To make a new operator, just set its arith-1 and/or arith-2 word properties, which should link to a word that is the unary or binary arithmetic version, respectively. To make a new constant, like pi, just set the constant? word property of a word that pushes it to t. When opening the files in this package, open first infix.factor, then algebra.factor, then repl.factor. To close, here's an implementation of the quadratic formula using infix math. This is included in the module.
:| quadratic-formula a b c |:
    [ [ - b ] / 2 * a ] +- [ sqrt [ sq b ] - 4 * a * c ] / 2 * a ;

If you find any bugs in this or have any questions, please contact me at microdan @ gmail . com, ask LittleDan@irc.freenode.net, or ask irc.freenode.net/#concatenative