[plt-scheme] match single symbol

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Wed Sep 2 20:49:12 EDT 2009

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]))

Ryan

> (match-symbol 'a)
> (match-symbol 23)
> (match-symbol '(1 2 3))
> 
> -->
> ok
> bad
> bad
> 
> Can something like this be added to scheme/match or is there an 
> existing/simpler way to do it?
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.