[plt-scheme] match-lambda and syntax objects

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Tue May 29 15:15:34 EDT 2007

On Tue, May 29, 2007 at 02:05:34PM -0400, Ryan Culpepper wrote:
>  On May 29, 2007, at 1:06 PM, Sridhar Ratna wrote:
>
> > I am reading sexps from a file and parsing them using `match.ss'..
> > something like this:

<SNIP>

> > Now that instead of READ I will have to use READ-SYNTAX which returns a
> > SYNTAX object.

<SNIP>

> It would be difficult to use 'match' gracefully to destructure syntax
> objects.

Oh, there are ways:   <grin>

    Welcome to MzScheme v369.10 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
    > (require (planet "views.ss" ("cobbe" "views.plt" 1 1)))
    > (require (lib "match.ss"))
    > (define-view Stx syntax? (syntax-object->datum))
    > (match #'(+ 3 4)
        [(Stx ('+ x y)) (+ x y)])
    7

I don't think this approach has any real advantages over syntax-case*,
though, and Ryan will undoubtedly point out some obscure little corner of
the syntax system that I've overlooked that means this will fail horribly
in certain cases.  (There's always at least one such weirdness, and usually
several.)

Richard


Posted on the users mailing list.