bug-kawa
[Top][All Lists]
Advanced

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

[Bug-kawa] [bug #37051] define-syntax does not work when included


From: Per Bothner
Subject: [Bug-kawa] [bug #37051] define-syntax does not work when included
Date: Fri, 17 Aug 2012 02:06:12 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1

Update of bug #37051 (project kawa):

                  Status:                    None => Invalid                

    _______________________________________________________

Follow-up Comment #4:

Thanks for the test-case.  I believe the compiler is correct.
The call to bar should *not* match the define, because of macros hygiene:

http://en.wikipedia.org/wiki/Hygienic_macro
http://www.randomhacks.net/articles/2002/09/13/hygienic-macros

The reason it "works" when you remove the begin is because then things happen
at the "top-level" which has special rules.

One solution is to explicitly pass bar as a macro argument:

(begin
(define-syntax foo
  (syntax-rules ()
    ((_ e bname) (define (bname) (display e)(newline)))))
(foo 123 bar)
(bar)
)

Another is to use define-syntax-case, and a "literal" 'bar is the expansion:

(begin
(define-syntax-case foo ()
  ((_ e) #`(define (#,'bar) (display e)(newline))))
(foo 123)
(bar)
)

Even better would be to use datum->syntax:

(begin
(define-syntax-case foo ()
  ((foo e) #`(define (#,(datum->syntax #'foo 'bar)) (display e)(newline))))
(foo 123)
(bar)
)

The datum->syntax means to take the symbol 'bar and convert it to a syntax
object in the same lexical scope as foo.  (For this to work you need to use
(foo e) in the pattern.)




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?37051>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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