[plt-scheme] Match - naming the result of pat ...

From: Ryan Culpepper (ryan_sml at yahoo.com)
Date: Mon Feb 6 18:46:05 EST 2006

--- Jens Axel Søgaard <jensaxel at soegaard.net> wrote:

> I have a feeling this have been asked before,
> and that the answer had something to do with
> (and ...), but ...
> 
> Consider:
> 
>  > (match '(1 2 3 a 4 5)
>      [((? number?) ... . more)
>       more])
> (a 4 5)
> 
> How do I get to the part matched by (? number?) ... ?

The '?' form allows you to put more patterns after the predicate, so
you could write the following to get the all-numeric prefix of the
list:

(match '(1 2 3 a 4 5)
  [((? number? nums) ... . more)
   nums])

Ryan


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Posted on the users mailing list.