[plt-scheme] syntax/cx+loc

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Mar 28 11:42:12 EST 2005

At Sat, 26 Mar 2005 21:26:34 -0500, Doug Orleans wrote:
>  What I'm actually doing is taking
> application expressions apart and putting parts of them back together--
> I'm not introducing any new symbols.  Then `syntax/cx+loc' seems to work:
> > (module h mzscheme
>   (define-syntax syntax/cx+loc
>     (syntax-rules ()
>       ((_ source-stx-expr template-expr)
>        (let ((source-stx source-stx-expr))
> 	 (datum->syntax-object
> 	  source-stx (syntax-e #'template-expr) source-stx)))))
>   (define (helper stx)
>     (syntax-case stx ()
>       ((a b c . d)
>        (syntax/cx+loc stx (b . d)))))
>   (provide helper))
> > (require-for-syntax h)
> > (define-syntax (macro stx) (helper stx))
> > (macro + 1 2 3)
> 5
> Is this still non-hygienic? 

In a sense, yes. The meaning of the implicit `#%app' comes from the use
of the macro, not the template site. Arguably, though, you're just
copying the `#%app' that was implicitly supplied. (In other words, you
wouldn't need `syntax/cx+loc' if `#%app' were part of the pattern.)

> It seems like requiring mzscheme for
> templates is non-hygienic, since this would ignore any local
> definition for #%app.  Is that right?

No, I wouldn't call that non-hygienic. It's obeying lexical scope: the
implicitly introduced `#%app' is bound by the environment of the
template that introduces it.

I think the confusion here is that `#%app' isn't explicit, and so it's
difficult to pin down whether it's being introduced or recycled from
the input.


Posted on the users mailing list.