Code: Select all
(eval (setf code '(when (< counter 40)
(inc counter)
(println counter)
(eval code))))
or even better, "crawler-tractor"
Code: Select all
(set 'f (lambda()
(if (< counter2 50)
(begin (println "Hi for the " (inc counter2) ". time. ")
(push (last f) f -1)
(if (> (length f) 3) (pop f 1))))))
(f)
This last is particularly charmy because it doesn't use recursion and Lutz actually made some change so it doesn't result in stack overflow at all.
I tried to do same with map,
Code: Select all
(setf L '(1 2))
(map (lambda(x)(when (< x 10)
(push (+ x 2) L -1))
(println L))
L)
but it doesn't work, i.e. original version of L is used, not modified version, perhaps some optimization. I guess that other functions are optimized on the same way. One can always use (sequence 1 50), but it looks too trivial, I think.
Finally, Lutz implemented Y-combinator from lambda-calculus in Newlisp:
http://www.newlisp.org/index.cgi?Y_Function