[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug with macros in SCM and Guile
From: |
Aubrey Jaffer |
Subject: |
Re: Bug with macros in SCM and Guile |
Date: |
Sat, 6 Jan 2007 23:12:00 -0500 (EST) |
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?
- Re: Bug with macros in SCM and Guile,
Aubrey Jaffer <=