[plt-scheme] match single symbol

From: John Clements (clements at brinckerhoff.org)
Date: Thu Sep 3 19:15:01 EDT 2009

On Sep 3, 2009, at 9:03 AM, Carl Eastlund wrote:

> On Thu, Sep 3, 2009 at 11:58 AM, Jon Rafkind<rafkind at cs.utah.edu>  
> wrote:
>> I need to match any single symbol and got momentarily confused  
>> about the
>> literal patterns. I thought there was a pattern for matching any  
>> string, but
>> its just a literal string.
>> This is essentially what I need:
>> (define-match-expander symbol (lambda (stx) #'(? symbol?)))
>> (match 'x
>>      [symbol 'ok]
>>      [else 'bad])
> Bear in mind you will have to use (symbol), not symbol, to refer to
> that pattern.  If you just use an unadorned identifier, match will
> treat it as a variable, treat it as a match against any value, and
> bind it to that value in the right hand side.  All custom patterns
> must have the form of macro applications with parentheses.
> Honestly, for this case, you're probably best off just using (?
> symbol?) for uniformity with every other match-using program out
> there.  It's only 3 extra characters beyond (symbol).  But that's just
> my opinion.

+1 !


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20090903/4e8b4d31/attachment.p7s>

Posted on the users mailing list.