[plt-scheme] example of match quasipattern

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Aug 22 22:51:03 EDT 2002

> I am trying to do something like
> 
> (let ((sym 'duck))
>     (match-lambda
>       [(`, at sym . rest) rest] 
>       [else #f]))
> 
> that would match (list 'duck) or (list 'duck ...). Currently it matches any
> pair.

I think the only escape back to Scheme within a pattern is `?':

   (let ((sym 'duck))
     (match-lambda
      [((? (lambda (x) (equal? x sym))) . rest) rest] 
      [else #f]))

Matthew




Posted on the users mailing list.