unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Macro expansion
@ 2011-01-11 13:34 Hans Aberg
  2011-01-15 20:39 ` Neil Jerram
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Aberg @ 2011-01-11 13:34 UTC (permalink / raw)
  To: guile-user

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)
   )
))





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-16 14:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-11 13:34 Macro expansion Hans Aberg
2011-01-15 20:39 ` Neil Jerram
2011-01-15 23:11   ` Hans Aberg
2011-01-16 14:43   ` Hans Aberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).