Diff
Not logged in

Differences From Artifact [5b2c3c452aca5b18]:

To Artifact [4438bc82733dcb16]:


1 +# Standard Fibonacci function 1 2 def fib(x) 2 3 { 3 4 if x<2 then 1 else fib(x-1) + fib(x-2) 4 5 }; 5 6 6 7 let upto = fun(n, f){ 7 8 if n > 0: upto(n-1,f); 8 9 f(n) 9 10 }; 10 11 11 12 var compose = fun(f,g){ fun(x){f(g(x))} }; 12 13 var "<<" = compose; 13 14 14 -upto(16, print<<fib); 15 +upto(18, print<<fib); 16 + 17 + 18 +###################################### 19 +# Omake. Feel the automatic memoization! 20 + 21 +# Set up a mirror layer (do-the-same-thing layer) of @value 22 +@@m(x){x}; 23 +@m "+" (x,y) { @value(@m(x)+@m(y)) }; 24 +@m "-" (x,y) { @value(@m(x)-@m(y)) }; 25 +@m "<" (x,y) { @value(@m(x)<@m(y)) }; 26 +@m "if" (c,t,e) { @value(if @m(c) then @m(t()) else @m(e())) }; 27 + 28 +# Helper function to call fib in layer @m 29 +def fibm(x @value) { @m(fib(@value(x))) }; 30 + 31 +# User defined layers are automatically memoized. 32 +# So this is much faster. 33 +upto(18, print<<fibm);