[racket] Introduction to syntax-parse
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
>
What I don't understand is why the implicit `#%app` added in front of
`syntax-parse` doesn't blow up when it tries to expand its first argument
-- the name `syntax-parse` -- and a use of `#%top` shows up. I thought
`#%top` was supposed to blow up inside a module. If it blew up here, we'd
see an error about the name `syntax-parse` before `#%app` ever got around
to expanding the clauses with `_` in them. Somehow that error is being
delayed, and the clauses are being treated as expressions as if the name
`syntax-parse` had successfully expanded into an expression that might
produce a function. If we can just make `#%top` cause a syntax error
sooner here, we'll get intelligent error messages.
--Carl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130926/fd21a157/attachment.html>