Menu

#21 Variable capture within hygienic and legacy macro

General
open
General (24)
4
2002-05-01
2002-04-20
Shiro Kawai
No

String interpolation doesn't work with
hyginic macro, in the sense that
the embedded expression can't "see"
the bindings introduced by the hygienic
macro.

<pre>
(define-syntax foo
(syntax-rules
((_)
(let ((x (hoge)))
#`",x"))))
</pre>

In the above example, interpolated "x"
doesn't refer to the "x" in the syntax-rules.

Discussion

  • Shiro Kawai

    Shiro Kawai - 2002-05-01

    Logged In: YES
    user_id=126450

    I found it is more general problem. Generally, when a
    legacy macro is used within hygienic macro, the internal
    legacy macro can't bind a variable in the original body
    since it is effectively renamed.

    (define-syntax foo
    (syntax-rules ()
    ((_) (bar x))))

    (define-macro (bar var)
    (let ((x 2)) var))

    Then, (foo) expands to

    (let ((x 2)) x_RENAMED)

    This is hygienic. The problem is that we need explicit
    contamination here.

     
  • Shiro Kawai

    Shiro Kawai - 2002-05-01
    • summary: string interpolation and hygienic macro --> Variable capture within hygienic and legacy macro
     

Log in to post a comment.