guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Macro expansion


From: Hans Aberg
Subject: Macro expansion
Date: Tue, 11 Jan 2011 14:34:15 +0100

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]