On Friday, August 18, 2017 at 9:31:33 AM UTC-4, Matthias Felleisen wrote:
> > On Aug 18, 2017, at 5:28 AM, Sam Waxman <samwax...@gmail.com> wrote:
> > 
> > If I have code like this,
> > 
> > (define-syntax-rule (identity x)
> >   x)
> > 
> > ((identity identity) 1)
> > 
> > At phase 1, the (identity identity) will get transformed into identity. As 
> > macros expand outside in, however, this won't turn into (identity 1) like a 
> > function would, it will try expanding the identity macro all by itself 
> > without any "arguments" and give a bad syntax error.
> > 
> > Is there a simple way to change this so that ((identity identity) 1) 
> > actually does expand into (identity 1) which expands into 1? I'm guessing 
> > not, but it would certainly be a nice trick if there were.
> 
> 
> The explanation of the error is wrong. Run it in DrRacket and see which 
> identity it highlights for the error message. [I’d rather have you come up 
> with a proper explanation yourself. That way you will remember.]

It highlights the second. I don't think I misspoke above, but please correct me 
if I'm wrong.

((identity identity) 1) first starts by receiving the entire s-expression. Then 
it tries expanding the first thing in that s-expression which is (identity 
identity)

To do this, it goes to the identity rule, which states that identity is allowed 
to expand if it has exactly one argument. In this case it does, so #'(identity 
identity) becomes #'identity. Then instead of moving back to the first 
s-expression and moving onto 1, because macro-expansion goes outside-in (and 
more importantly, I suppose, depth first), the macro expander then tries to 
expand #'identity. This is where the bad syntax error comes from because the 
rule for identity says it must have an argument, but this identity is getting 
expanded with no arguments.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to