Hi,

On Tue 15 Jun 2010 22:48, l...@gnu.org (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