[plt-scheme] combining ... and . in syntax-case patterns

From: Sam TH (samth at ccs.neu.edu)
Date: Sat Jan 19 15:02:54 EST 2008

On Jan 19, 2008 2:56 PM, Robby Findler <robby at cs.uchicago.edu> wrote:
> I think you probably have to write it a little more explicitly,
> perhaps in a loop:
>  ([v t] . rest) ;; pattern for collect & recur
>  (x . rest)     ;; pattern for all done

Yeah, I think that's what I will do.  Unfortunately, this makes it
tricky to go on to the other patterns when the match fails, since I've
already committed to a particular case.

match.ss has a nice way of doing this (in addition to handling the
original pattern properly).  You can write a pattern like this:

[(pattern) (=> break) .... (break) ...]

And break is bound in the RHS to a function that jumps out of the RHS
and continues on down the list of possible matches.  You can simulate
something like this with the pattern guards in syntax-case, but at the
cost of a lot of code duplication.

> But it seems like syntax-case should signal a syntax error for
> patterns like that (altho perhaps there is some interesting reason why
> that's tricky?)

I think an error is definitely preferable to the current never-match behavior.

sam th
samth at ccs.neu.edu

Posted on the users mailing list.