[plt-scheme] match single symbol

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Thu Sep 3 00:20:03 EDT 2009

Ryan Culpepper wrote:
> Jon Rafkind wrote:
>> I was trying to match a single symbol but I didn't see a match 
>> pattern for it. This code seems to do what I want
>>
>> (define (match-symbol sym)
>>  (match sym
>>    [x (=> f) (if (not (symbol? x)) (f) 'ok)]
>>    [else 'bad]))
>
> (define (match-symbol sym)
>   (match sym
>     [(? symbol?) 'ok]
>     [_ 'bad]))
>
Ah right, good call. It seems like predicates could be used for other 
literals too, like char?, string?, etc. So is there a good reason for 
the current set of literals that can be used in a pattern?


Posted on the users mailing list.