[plt-scheme] Contract Request
I've added one-of/c that behaves like symbols, but allows whatever
values you want and uses eqv? to compare them.
I'm not entirely sure that this is the right thing and am considering
restricting one-of/c to only accept things like symbols, numbers,
booleans, characters, keywords, null and other atomic values I may be
forgetting. But it is there without restriction for now, in SVN.
Robby
At Sun, 9 Apr 2006 16:06:03 -0700 , "Williams, M. Douglas" wrote:
> I have begun using keywords in several of my collections. One problem I
> have is that there are no predefined contracts - that I know of, anyway -
> for recognizing them. Would it be possible to get 'keywords' added as a
> contract that would be the same as 'symbols', but for matching against
> keywords.
>
> An implementation that works, based on the definition of symbols is:
>
> (define (keywords . ss)
> (unless ((length ss) . >= . 1)
> (error 'keywords "expected at least one argument"))
> (unless (andmap keyword? ss)
> (error 'keywords "expected keywords as arguments, given: ~a"
> (apply string-append (map (lambda (x) (format "~e " x)) ss))))
> (flat-named-contract
> `(keywords ,@(map (lambda (x) x) ss))
> (lambda (x)
> (memq x ss))))
>
> Doug
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme