[plt-scheme] match single symbol

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Sep 3 00:26:10 EDT 2009

On Thu, Sep 3, 2009 at 12:20 AM, Jon Rafkind<rafkind at cs.utah.edu> wrote:
> 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?

What have literals (which compare against a single value) got to do
with predicates (which often match a whole class of values)?

--Carl


Posted on the users mailing list.