[plt-scheme] question about rnrs/enums-6
At Sun, 18 Jan 2009 05:39:02 -0800 (PST), Luka Stojanovic wrote:
> I am learning Scheme for a few week or so, and recently I've tried to make
> enumerated type:
>
> #lang/scheme
> (require rnrs/enums-6)
>
> (define my-enum1 (make-enumeration '(a b c)))
> ; will cause: make-enumeration: expected argument of type <list of
> symbols>; given (a b c)
This is a mismatch between the `scheme' language and the `r6rs'
language, which have different notions of "list". The `r6rs' variant is
mutable while the `scheme' variant is immutable.
The `rnrs/enums-6' library is designed to work with `r6rs'. If you want
to use it in a `scheme' module, you can bridge the two kinds of lists
by using the `scheme/mpair' library:
#lang scheme
(require rnrs/enums-6
scheme/mpair)
(define my-enum1 (make-enumeration (list->mlist '(a b c))))
> Anyway, I'll probably forget enums, because order doesn't make difference to
> me. I could use symbols, with possibility to check things like this:
>
> (define (my-enum? e) (or (eq? e 'a) (eq? e 'b) (eq? e 'c)))
>
> What would be "the proper", most idiomatic way to handle this
> situation anyway?
I'd write
(define (my-enum? e) (memq e '(a b c)))
Matthew