Re: hygiene when using multiple instances of a macro..? Andre van Tonder (08 Aug 2005 14:55 UTC)
Re: hygiene when using multiple instances of a macro..? Keith Wright (09 Aug 2005 02:28 UTC)
Re: hygiene when using multiple instances of a macro..? Andre van Tonder (09 Aug 2005 11:49 UTC)
Re: hygiene when using multiple instances of a macro..? Panu A. Kalliokoski (09 Aug 2005 07:00 UTC)
Re: hygiene when using multiple instances of a macro..? Andre van Tonder (09 Aug 2005 13:53 UTC)

Re: hygiene when using multiple instances of a macro..? Andre van Tonder 08 Aug 2005 14:55 UTC

On Mon, 8 Aug 2005, Panu wrote:

> I'll try to write a macro definition to show the situation I was talking
> about:
>
> (define-syntax (can-we-stand-duplicates a-macro)
>  (quasisyntax
>    (if ,a-macro
>      (let ((x 3)) (,a-macro #f))
>      x)))
>
> (define-syntax (test)
>  (quasisyntax (can-we-stand-duplicates can-we-stand-duplicates)))
>
> (test)

Thank you for the example, but shouldn't that be instead:

   (define-syntax (can-we-stand-duplicates a-macro)
     (quasisyntax
      (if ',a-macro                     ; note quote
          (let ((x 3)) (,a-macro #f))
          x)))

   (define-syntax (test)
     (quasisyntax (can-we-stand-duplicates can-we-stand-duplicates)))

   (test)    ;==> reference to unidentified identifier: x#top

> ... if it works wrong, it expands to (something that evaluates to) 3.
> If it works right, it expands to something that has an unbound
> identifier.
> The reason I suspected the wrong behavior is that in some rewrite-based
> systems, the fact the both x's are created in the same context (here, in
> the same quasisyntax) suffices to make them identical, even though they
> should not be identical across different invocations of the macro.

We do get the right behaviour, since the two x's are created in different
/evaluations/ of the quasisyntax form, which suffices to make them different:

   (expand (syntax (test))

  ==> (if 'can-we-stand-duplicates
          ((lambda (@x8165) (if '#f
                                ((lambda (@x8168) (#f #f)) 3)
                                x#top))
           3)
          x#top)

Cheers
Andre