[plt-dev] problems with extending `for' syntax

From: Sam TH (samth at ccs.neu.edu)
Date: Sun Feb 22 17:44:42 EST 2009

I'd like to write a sequence syntax that uses `match'-style pattern
matching.  Unfortunately, this doesn't seem to be currently possible,
but it's close.

First, something like this is ruled straight out:

(for/list ([(? (lambda (x) #t) x) (:match (list 1 2 3))]) x)

since (lambda (x) #t) is not an identifier.  This is ruled out
*before* the `:match' expander is given control.

Second, it's not possible to distinguish between the client writing this:

(for/list ([x (:match e)]) ...)

and this:

(for/list ([(x) (:match e)]) ...)

which, while they have the same semantics for `in-list', would have
very different semantics for `:match'.

I think the easiest solution would be to (1) accept any pattern in the
binding position, and have individual sequence-syntax forms rule them
out (perhaps `define-sequence-syntax' could make this easy), and (2)
provide a lower-level form which is given the raw pattern, without any

I'll write up a patch, provided anyone is interested.
sam th
samth at ccs.neu.edu

Posted on the dev mailing list.