Page 1 of 1

loop

Posted: Wed Mar 03, 2004 6:15 pm
by newdep
Hello Lutz,

Im seeking for a solution ;-)
A 'While 'Unit 'dotree etc..are all loop based and im now trying to create
a simple loop myself that must loop the function but somehow im overseeing
something i think?

>(define (loop _func) ( while true _func))

but this does not work... you have a hint ?

Norman.

Posted: Wed Mar 03, 2004 6:36 pm
by Lutz
This one will work:

(define-macro (loop _func) (while true (eval _func)))

now try:

(loop (println "."))


What happens in your function is the following: When the function argument (println ".") passes into your function it gets evaluated and evaluates to ".". Now inside your function you are doing a (while true "."), which will just sit there and loop without any output.

Using 'define-macro' leaves (println ".") un-evaluated and you get a

(while true (eval '(println ".")))

which will work

Lutz

Posted: Wed Mar 03, 2004 6:52 pm
by newdep
Great...
...thanks for the explanation...

Norman.