guile-devel
[Top][All Lists]
Advanced

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

Re: define-syntax


From: Andy Wingo
Subject: Re: define-syntax
Date: Wed, 16 Jun 2010 00:06:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hi,

On Tue 15 Jun 2010 22:48, address@hidden (Ludovic Courtès) writes:

> From R6RS Section 10:
>
>   define-syntax form  The expander expands and evaluates the
>     right-hand-side expression and binds the keyword to the resulting
>     transformer.
>
> Thus I think the following should work:
>

An interesting issue, and an interesting example. The problem boils down
to eval-when.

$ cat > foo.scm
(define-syntax +
  (let ((plus +))  ;; `+' should resolve to whatever `+' is bound to
                   ;; before this definition
    (lambda (stx)
      (syntax-case stx ()
        ((_ args ...)
         (apply plus (map syntax->datum #'(args ...))))))))
^D
$ guile -l foo.scm -c '(begin (display (+ 1 2 3)) (newline))'
6

Indeed + does resolve to whatever + was bound to before the definition;
it's just that when you define the + macro it usually defines at
compile-time too! By compiling ahead of time and exiting we leave + in
its pristine state. See also the discussion of
eval-syntax-expanders-when in psyntax.scm or in
http://www.scheme.com/csug8/system.html#./system:s78.

Cheers,

Andy
-- 
http://wingolog.org/



reply via email to

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