Permalink
Browse files

* example/recursive.pn: an (old?) shootout example testing recursion…

…. need to do floats.
  • Loading branch information...
1 parent 93e82de commit 0d3641bfdb58742e6ff07f28d7cad1cf96fb9d01 _why committed Jul 9, 2009
Showing with 24 additions and 0 deletions.
  1. +1 −0 core/pn-scan.rl
  2. +23 −0 example/recursive.pn
View
@@ -139,6 +139,7 @@
utf8 => { SCHAR(ts, te - ts); };
*|;
+ # TODO: this is lousy stuff, will need to wait until i move to peg/leg.
lick := |*
comma => { TOKEN1(SEP); fgoto main; };
newline+ => { if (last != PN_NIL) TOKEN1(SEP); fgoto main; };
View
@@ -0,0 +1,23 @@
+n = 11
+
+ack = (m, n):
+ if (m == 0): n + 1
+ . elsif (n == 0): ack(m - 1, 1)
+ . else: ack(m - 1, ack(m, n - 1)).
+.
+
+fib = (n):
+ if (n <= 1): 1. else: fib (n - 1) + fib (n - 2).
+.
+
+tak = (x, y, z):
+ if (y >= x): z
+ . else: tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y)).
+.
+
+n--
+("Ack(3,", n + 1, "): ", ack(3, n + 1), "\n") join print
+("Fib(", n + 28, "): ", fib(n + 28), "\n") join print
+("Tak(", (3 * n, 2 * n, n) join (","), "): ", tak(3 * n, 2 * n, n), "\n") join print
+("Fib(3): ", fib(3), "\n") join print
+("Tak(3,2,1): ", tak(3, 2, 1), "\n") join print

0 comments on commit 0d3641b

Please sign in to comment.