[racket] Introduction to syntax-parse

From: Nick Sivo (nicksivo at gmail.com)
Date: Tue Sep 24 15:20:30 EDT 2013

Why doesn't syntax/parse just provide everything at phases 0 and 1
like the module 'sp below:

(module sp racket/base
  (require syntax/parse
           (for-syntax syntax/parse))
  (provide (all-from-out syntax/parse)
           (for-syntax (all-from-out syntax/parse))))

(require 'sp)

(define-syntax (mylet stx)
  (syntax-parse stx
                [(_ ([var-id rhs-expr] ...) body ...+)
                 #'((lambda (var-id ...) body ...) rhs-expr ...)]))

I've not done as much Racket programming as many of you, but I've yet
to want syntax/parse in only phase 0.

-Nick

On Tue, Sep 24, 2013 at 10:21 AM, Laurent <laurent.orseau at gmail.com> wrote:
> This is a quite common pitfall into which I have myself fallen a few times,
> and I guess it's not the last time.
>
> How much work would be required to prevent people from falling into it ever
> again?
> Maybe saying so in the docs at the right place wouldn't hurt, but people may
> still miss it.
> Maybe making the error message more specific like "Did you forget to
> (require (for-syntax syntax/parse)) ?" ? Or is it too specific?
> Or pushing the idea further (and requiring more work, obviously), Racket's
> errors could propose a list of packages where the unknown identifier can be
> found, along with the require phase? Is xref able to do that currently?
>
> Laurent
>
>
>
> On Tue, Sep 24, 2013 at 6:20 PM, Stephen Chang <stchang at ccs.neu.edu> wrote:
>>
>> You need (require (for-syntax syntax/parse)) because you are using it
>> inside a define-syntax.
>>
>> On Sep 24, 2013 11:56 AM, "Konrad Hinsen" <konrad.hinsen at fastmail.net>
>> wrote:
>>>
>>> Hi everyone,
>>>
>>> I am trying to learn about syntax-parse, starting with the introduction
>>> of the "Syntax" documentation.
>>>
>>> Unfortunately, the very first example given for the use of syntax-parse
>>> doesn't work in my Racket installation:
>>>
>>>    Welcome to Racket v5.90.0.9.
>>>    racket@> (require syntax/parse)
>>>    racket@> (define-syntax (mylet stx)
>>>                 (syntax-parse stx
>>>                   [(_ ([var-id rhs-expr] ...) body ...+)
>>>                    #'((lambda (var-id ...) body ...) rhs-expr ...)]))
>>>    stdin::277: _: wildcard not allowed as an expression
>>>      in: (_ ((var-id rhs-expr) ...) body ...+)
>>>      errortrace...:
>>>      context...:
>>>       try-next
>>>
>>> /Users/hinsen/Development/racket/pkgs/errortrace-pkgs/errortrace-lib/errortrace/errortrace-lib.rkt:480:4
>>>
>>> /Users/hinsen/Applications/Racket/collects/racket/private/misc.rkt:87:7
>>>
>>> I tried replacing the wildcard by "mylet", but that only leads to another
>>> error
>>> message:
>>>
>>>    racket@> (define-syntax (mylet stx)
>>>                 (syntax-parse stx
>>>                   [(mylet ([var-id rhs-expr] ...) body ...+)
>>>                    #'((lambda (var-id ...) body ...) rhs-expr ...)]))
>>>    stdin::842: ...: ellipses not allowed as an expression
>>>      in: ...
>>>      errortrace...:
>>>      context...:
>>>       try-next
>>>
>>> /Users/hinsen/Development/racket/pkgs/errortrace-pkgs/errortrace-lib/errortrace/errortrace-lib.rkt:480:4
>>>
>>> /Users/hinsen/Applications/Racket/collects/racket/private/misc.rkt:87:7
>>>
>>> Am I doing something wrong here? Or are the examples obsolete?
>>>
>>> Konrad.
>>> ____________________
>>>   Racket Users list:
>>>   http://lists.racket-lang.org/users
>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

Posted on the users mailing list.