[racket-dev] [plt-scheme] Bug or misuse? match-expander ids not properly working (patch)

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri May 4 19:54:44 EDT 2012

On Fri, May 4, 2012 at 4:37 PM, Eli Barzilay <eli at barzilay.org> wrote:

> 20 minutes ago, Carl Eastlund wrote:
> >
> In case it wasn't clear enough, I said that I don't mind having it
> (and I'm willing to add it) -- I only added that I don't see any
> *practical* case where you'd use it.

Okay, then I think we're more or less on the same page.

I do think there is a practical use for such a form; specifically, macros
that expand into a use of match.  Here's a simple example:

(define-syntax (let/list stx)
  (syntax-parse stx
    [(_ {[(lhs:id ...) rhs:expr] ...} body:expr ...+)
       (match (list rhs ...)
         [(list (list lhs ...) ...) body ...]))]))

This is a straightforward use of match to destructure a list, but it isn't
transparent: it exposes to clients of let/list that _, ..., and any
hypothetical match id expanders are invalid choices for lhs.  There's no
real reason clients of let/list should know that match is even involved.
There are existing solutions -- don't use match in macros, or always bind
an extra set of temporaries -- but adding some kind of "no really, bind
this please" form would be even simpler.  I'd call it (var <name>) by
analogy to syntax-parse's (~var <name> [<optional-class>]), which I have in
fact used for the same purpose.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20120504/45a0e326/attachment.html>

Posted on the dev mailing list.