loop

For the Compleat Fan
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

loop

Post 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Great...
...thanks for the explanation...

Norman.

Locked