[racket] Introduction to syntax-parse

From: Greg Hendershott (greghendershott at gmail.com)
Date: Wed Sep 25 17:42:54 EDT 2013

Without actually `require`-ing syntax-parse, could syntax-rules and
syntax-case simply report this one special case differently?  If the
specific not-expression is the exact syntax `_`, then report
not-an-expression (as usual) but also add the p.s. "Are you trying to
use syntax-parse? ...."

Maybe bonus points for doing this only if `_` is nested inside a
syntax-rule or syntax-case form. But just bonus points. Even simply,
whenever the syntax is `_`. After all, the main error message is still
"not an expression". It's just adding a p.s. suggestion.

Maybe this is excessively practical (to borrow a phrase I think I
heard Jay use at lunch today) but this is a really common mistake. Not
only have I forgotten to (require (for-syntax syntax/parse)).  I've
even managed to remember it... but get it wrong as (require
(for-syntax syntax-parse)) [hyphen not slash].

p.s. I'm amused that `_` is also a good emoticon for how I look when
I've made this mistake and stare at the error message:  `_`

On Wed, Sep 25, 2013 at 7:59 AM, Sam Tobin-Hochstadt
<samth at cs.indiana.edu> wrote:
> On Wed, Sep 25, 2013 at 2:14 AM, Konrad Hinsen
> <konrad.hinsen at fastmail.net> wrote:
>>  > Maybe making the error message more specific like "Did you forget to (require
>>  > (for-syntax syntax/parse)) ?" ? Or is it too specific?
>> It would already help a lot if the error message said something about
>> syntax-parse being undefined. But it complains about the pattern,
>> which is kind of strange. It looks like syntax-parse is already there
>> but incomplete.
> The reason it complains about the pattern is that `_` is already bound
> -- `syntax-rules` and `syntax-case` both work at phase 0 without any
> new requires. So Racket interprets everything as function application
> until it gets to the `_`, which it tries to expand and gives an error
> because it's not supposed to be used as an expression.  Of course, you
> didn't mean it as an expression, but as part of a `syntax-parse`
> pattern, but because `syntax-parse` wasn't bound, it didn't get
> recognized as a pattern.
> I think the error message could be better about making this clearer,
> but I can't think of a good way that doesn't build-in `syntax/parse`.
> Sam
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.