[racket] Expander vs Reader layer and general Macro advice

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Mon Sep 9 12:38:22 EDT 2013

On 09/09/2013 10:06 AM, Eli Barzilay wrote:
> An hour ago, Jay McCarthy wrote:
>> You can do this a complicated way and an easy way. The complicated
>> way would have to deal with stuff like (f 1):5 and the easy way
>> would just work on stuff like x:1. I see "string":e as being part of
>> the complicated way. In my mind, the complicated way would have to
>> be done with a reader that produced some syntax that the expander
>> dealt with the rest of. The easy way would just be a #%top macro
>> like you have.
>
> There's a much easier way: use the built-in reader, then scan the
> resulting syntax tree and tweak occurrences of `? : ?'.  This of
> course requires spaces around all `:'s -- but dealing with that should
> be simple now: change the default reader table to make `:' a
> terminating reader macro, and make it consume just the colon and
> produce itself as an identifier for the previous hack to continue
> working.

What does

   (a b #; c:d e)

read as? Adding an infix S-expression syntax means that you now have to 
worry about its precedence relative to all of the prefix syntaxes.

(Maybe that's what you meant to point out below, but the example should 
be 'x:y, not '(x:y), I believe.)

Ryan

> But the real problem with any of these is still the same: you need to
> decide what to do with things like '(x:y) and a naive reader tweaker
> would add confusions like (define (x : y) ...) (which quote etc
> already are doing).


Posted on the users mailing list.