3 ms·
The code page now includes some simple instructions for doing a quick download and test. I also made a very nice but simple enhancement to the grammar. Now wh
by fexl 15y ago
The code page now includes some simple instructions for doing a quick
download and test.
I also made a very nice but simple enhancement to the grammar. Now when
you want to do a recursive definition, you must use "==" instead of the
normal "=". That might sound like a pain, but bear with me, it's
really great. In short, the "==" syntax
announces to the parser that you intend to apply the
fixpoint operator (Y combinator) to the definition, explicitly making it recursive.
For example, here is the function which sums the numbers in a list:
\sum == (\list list 0.0 \head\tail double_add head; sum tail)
Of course, if you don't like saying double_add everywhere, you can
easily abbreviate as follows:
\add=double_add
\sum == (\list list 0.0 \head\tail add head; sum tail)
Now here's the great thing about requiring "==" for recursive
definitions. It enables us to do ordinary "procedural" looking code,
like in this snippet from test_procedural in test/try.fxl:
\show=(\name\value print name; print " = "; print value; nl;)
\x=3.0
\y=4.0
\x=(add x x)
\y=(mul y x)
show "x" x; show "y" y;
\x=(div x; mul y 4.0)
show "x" x; show "y" y;
\z=(mul x; mul y; add 1.0 y)
show "x" x; show "y" y; show "z" z;
\z=(div z 5.0)
show "z" z;
In other words, you can do incremental calculations which look like
destructive assignment, but really aren't.
In the old version "a2", a definition like this would have yielded
infinite recursion:
\x=(add x x)
Now it actually means something useful.