[plt-scheme] identifier macros in application position

From: Dave Herman (dherman at ccs.neu.edu)
Date: Fri Jul 9 03:08:23 EDT 2004

> It matches in operator position too, but in that case the value of
> `stx' is the entire expression, not just the identifier:

Ah. Of course.

> There's no such thing as an "identifier macro"-- all macros are just
> identifiers bound to syntax transformers.  Maybe you're being confused
> by the difference between `syntax-rules' and `syntax-id-rules'?
> (which is irrelevant if you're using `syntax-case')

No, my mistake was thinking that since the transformer didn't define a 
case for `(identifier ...)', the macro expansion algorithm could just 
ignore the entire expression (and then when it went inside the 
expression and examined the identifier alone, it would run the 
transformer again and the match would succeed). But when syntax-case 
fails to match the entire expression, it can't just ignore it and 
continue, because falling off the end of a syntax-case causes a syntax 
error.

BTW, the helpdesk does provide three links for the phrase "identifier 
macro" although it doesn't define the phrase. I'd always taken it to 
mean "a macro that also has a case that can recognize just an identifier 
in any position," but now I'm thinking it really means something more 
like "a macro that also has a case that can recognize an identifier in 
expression position," since when a macro identifier occurs in 
application position, the entire application expression is always passed 
to the transformer.

> This works already: <snip>
> 
> Or am I misunderstanding your question?

I was showing an example for an "alternate universe" in which 
identifiers could be recognized *on their own* in any position (i.e., 
without the rest of the expression), and -- because I was forgetting how 
syntax-case works -- syntax-case transformers silently do nothing (i.e., 
return the original syntax object unmodified) when they fail to match.

In that universe, a macro that didn't care about the entire application 
expression could just omit a case to recognize them. The expansion 
algorithm would (magically) skip past the entire expression and then go 
inside and apply the transformer to just the identifier. An identifier 
macro that wanted to distinguish between application and expression 
positions would work like the pseudomacro I gave.

But that's all bogus because a transformer can't just "leave the code 
the way it is" -- the expansion would repeatedly replace the code with 
itself and loop infinitely.

To sum up: I was being meat-headed.

Thanks,
Dave



Posted on the users mailing list.