unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Aubrey Jaffer <agj@alum.mit.edu>
Cc: bug-guile@gnu.org, Radey Shouman <shouman@comcast.net>
Subject: Re: Bug with macros in SCM and Guile
Date: Sat,  6 Jan 2007 23:12:00 -0500 (EST)	[thread overview]
Message-ID: <20070107041200.1DF7F51D737@home.voluntocracy.org> (raw)
In-Reply-To: <5D389A9F-1903-4B48-970C-6D704EA11764@iro.umontreal.ca> (message from Marc Feeley on Wed, 29 Nov 2006 15:58:57 -0500)

If we take the first DEFMACRO out of the begin, then macro expansion
works correctly in both SCM and Guile:

  bash-3.1$ slib guile
  guile> (require 'defmacroexpand)
  guile> (require 'pretty-print)
  guile> (defmacro foo (x)
     (display "expanding-foo-version1\n")
     `(list 'foo-v1 ',x))
  guile> (pretty-print (defmacro:expand* '(begin
  (define (bar1)    (foo in-bar1))
  (define (bar2) #f (foo in-bar2))
  (define (bar3)    (foo in-bar3))
  (write (bar1)) (newline)
  (defmacro foo (x)
     (display "expanding-foo-version2\n")
     `(list 'foo-v2 ',x))
  (write (bar2)) (newline)
  (write (bar3)) (newline)
  )))

Guile prints:

  expanding-foo-version1
  expanding-foo-version1
  expanding-foo-version1

  (begin
    (define (bar1) (list 'foo-v1 'in-bar1))
    (define (bar2) #f (list 'foo-v1 'in-bar2))
    (define (bar3) (list 'foo-v1 'in-bar3))
    (write (bar1))
    (newline)
    (eval-case
      ((load-toplevel)
       (define foo
	 (defmacro:transformer
	   (lambda (x)
	     (display "expanding-foo-version2
  ")
	     `(list 'foo-v2 ',x)))))
      (else (error "defmacro can only be used at the top level")))
    (write (bar2))
    (newline)
    (write (bar3))
    (newline))

SCM prints:

  expanding-foo-version1
  expanding-foo-version1
  expanding-foo-version1

  (begin
    (define (bar1) (list 'foo-v1 'in-bar1))
    (define (bar2) #f (list 'foo-v1 'in-bar2))
    (define (bar3) (list 'foo-v1 'in-bar3))
    (write (bar1))
    (newline)
    (defmacro:simple-defmacro
      foo
      scm:G21
      (let ((scm:G22 scm:G21))
	(let ((x (car scm:G22)))
	  (display "expanding-foo-version2
  ")
	  `(list 'foo-v2 ',x))))
    (write (bar2))
    (newline)
    (write (bar3))
    (newline))

In both cases, the definintions of the bar routines are expanded; so
subsequent DEFMACROs will have no effect on them.

It is disturbing that "expanding-foo-version1" is printed out when
DEFMACRO:EXPAND is expanding the code (both in SCM and Guile).  There
is no call to eval in "defmacex.scm".  How does this happen?


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-guile


      parent reply	other threads:[~2007-01-07  4:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5D389A9F-1903-4B48-970C-6D704EA11764@iro.umontreal.ca>
2007-01-07  3:42 ` Bug with macros in SCM and Guile Aubrey Jaffer
2007-01-15 22:35   ` Kevin Ryde
2007-01-16  2:26     ` Aubrey Jaffer
2007-01-07  4:12 ` Aubrey Jaffer [this message]

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=20070107041200.1DF7F51D737@home.voluntocracy.org \
    --to=agj@alum.mit.edu \
    --cc=bug-guile@gnu.org \
    --cc=shouman@comcast.net \
    /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).