In the code below the 'loop' and 'begin' examples will execute the
'while' loop, but if put into the body of a function, 'while' will not
run. So why, and how to fix it?
Just copy and paste the examples below into guile. For the two first,
I get
0123456789
0123456789done!3
but for the third, the thunk, only
done!3
So the macro 'while' is not expanded as expected.
Hans
(use-syntax (ice-9 syncase))
(define-syntax loop
(syntax-rules ()
((loop (j ...) p (r ...) (x ...))
(begin j ... (while p x ... r ...)))
))
(loop ((define i 0))
(< i 10)
((set! i (+ i 1)))
((display i)))
(begin
(loop ((define i 0))
(< i 10)
((set! i (+ i 1)))
((display i)))
(display "done!")
(+ 1 2)
)
((lambda
()
(begin
(loop ((define i 0))
(< i 10)
((set! i (+ i 1)))
((display i)))
(display "done!")
(+ 1 2)
)
))