unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Hans Aberg <haberg-1@telia.com>
To: guile-user <guile-user@gnu.org>
Subject: Macro expansion
Date: Tue, 11 Jan 2011 14:34:15 +0100	[thread overview]
Message-ID: <13B7D376-7BFD-4236-B6EF-5BF70FE248B7@telia.com> (raw)

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	other threads:[~2011-01-11 13:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-11 13:34 Hans Aberg [this message]
2011-01-15 20:39 ` Macro expansion Neil Jerram
2011-01-15 23:11   ` Hans Aberg
2011-01-16 14:43   ` Hans Aberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13B7D376-7BFD-4236-B6EF-5BF70FE248B7@telia.com \
    --to=haberg-1@telia.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).