[racket] getting the term in syntax-id-rules

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Mon Sep 5 12:13:03 EDT 2011

On Mon, Sep 5, 2011 at 11:50 AM, Shriram Krishnamurthi <sk at cs.brown.edu> wrote:
> In a syntax-case, I can obtain the term being processed: eg,
> (define-syntax (foo stx)
>  (syntax-case stx ()
>   [... (with-syntax ([term stx]) ... #'term)]))
> In syntax-id-rules, the RHS is like a syntax-*rules*, so I don't know
> of a way of obtaining access to the source.  This would be
> particularly useful since my id macros are expanding into regular term
> macros, but I'd like the user to see errors in terms of the id text
> (which I'm storing in a structure, hence the #'term above).
> Sorry if I'm missing something obvious; hopefully an archival answer
> to this will help anyway.

Is there a reason not to just use `syntax-case' (or even better,
`syntax-parse')?  To convert it into a macro that works with `set!',
you'll need to do something like this:

(define-syntax foo
    (lambda (stx)
      (syntax-parse stx ...))))
sam th
samth at ccs.neu.edu

Posted on the users mailing list.