[racket] beginner question about macros

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Mon Dec 5 10:24:34 EST 2011

Precisely. Hygiene guarantees that identifiers that are neither explicitly passed to a macro nor in the lexical scope of the macro definition will not be in the output of said macro. This is often too restrictive for macro writers, since we have naming conventions that we want to programmatically produce (consider struct). Thus we have datum->syntax. 

You have to be careful about abusing this capability, since unintuitive collisions can happen when you have two macros using one another that depend on unhygienic naming conventions.
You should try to restrict your use of unhygienic macros to function definitions and not macro definitions.

-Ian
----- Original Message -----
From: "Răzvan Rotaru" <razvan.rotaru at gmail.com>
To: "J. Ian Johnson" <ianj at ccs.neu.edu>
Cc: users at racket-lang.org
Sent: Monday, December 5, 2011 9:46:07 AM GMT -05:00 US/Canada Eastern
Subject: Re: [racket] beginner question about macros

On 5 December 2011 16:39, J. Ian Johnson <ianj at ccs.neu.edu> wrote:
> Your textual manipulation of identifiers is unhygienic. You will need to do the following
>
> (with-syntax ([newX (datum->syntax #'x (translate-symbol (syntax-e #'x)))])
>  ...use-of-newX...)
>

Why it is unhygienic? Because newX doesn't exist in the macro
environment, but only in the caller environment?

Razvan



Posted on the users mailing list.