[racket-dev] [plt] Push #21491: master branch updated

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Tue Nov 9 19:31:51 EST 2010

It occured to me while making this small patch that the name of the
macro shown in the error message might not be the same as the one the
user called. Namely, if the user renames or prefixes the macro when
requiring it then they will get a mismatch. This seems to be consistent
with how `raise-syntax-error' already works though so is it a big deal?

On 11/09/2010 05:26 PM, rafkind at racket-lang.org wrote:
> rafkind has updated `master' from 3936a40717 to 81eac261dc.
>   http://git.racket-lang.org/plt/3936a40717..81eac261dc
>
> =====[ 1 Commits ]======================================================
>
> Directory summary:
>  100.0% collects/racket/private/
>
> ~~~~~~~~~~
>
> 81eac26 Jon Rafkind <rafkind at racket-lang.org> 2010-11-09 17:23
> :
> | better error message for define-syntax-rule
> :
>   M collects/racket/private/misc.rkt |   22 ++++++++++++----------
>
> =====[ Overall Diff ]===================================================
>
> collects/racket/private/misc.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/racket/private/misc.rkt
> +++ NEW/collects/racket/private/misc.rkt
> @@ -12,18 +12,20 @@
>    (define-syntax define-syntax-rule
>      (lambda (stx)
>        (syntax-case stx ()
> -        [(dr (foo . pattern) template)
> -         (identifier? #'foo)
> +        [(dr (name . pattern) template)
> +         (identifier? #'name)
>           (syntax/loc stx
> -           (define-syntax foo
> -             (lambda (x)
> -               (syntax-case** dr #t x () free-identifier=?
> -                              [(_ . pattern) (syntax/loc x template)]))))]
> -        [(dr (foo . pattern) template)
> -         (raise-syntax-error 'define-syntax-rule "expected an identifier" stx #'foo)]
> -        [(dr (foo . pattern))
> +           (define-syntax name
> +             (lambda (user)
> +               (syntax-case** dr #t user () free-identifier=?
> +                              [(_ . pattern) (syntax/loc user template)]
> +                              [else (raise-syntax-error 'name (format "~a did not match pattern ~a" (syntax->datum user) '(name . pattern)))]
> +                              ))))]
> +        [(dr (name . pattern) template)
> +         (raise-syntax-error 'define-syntax-rule "expected an identifier" stx #'name)]
> +        [(dr (name . pattern))
>           (raise-syntax-error 'define-syntax-rule "no template provided" stx)]
> -        [(dr (foo . pattern) template . etc)
> +        [(dr (name . pattern) template . etc)
>           (raise-syntax-error 'define-syntax-rule "too many templates" stx #'etc)]
>          [(dr head . template)
>           (raise-syntax-error 'define-syntax-rule "invalid pattern" stx #'head)])))



Posted on the dev mailing list.