[R6RS] Enumerations proposal pre-draft

Michael Sperber sperber at informatik.uni-tuebingen.de
Sun May 21 09:00:08 EDT 2006

William D Clinger <will at ccs.neu.edu> writes:

> How about we flush the <index-of> procedure altogether?
> Nothing in the proposal uses it, and it's hard to imagine
> any good use for it.

I was thinking that it doubled as a predicate for the enumeration
values.  Arguably, that could be done via memq, but I was getting the
impression that a macro could generate a faster version, also of the
index-of operation.  Possibly I'm wrong again---will Larceny
recognize, say, for memq, that its list argument is constant and
revert to hashing or something?

> 2.  revert <type-name> to your original macro (although
>     your draft also referred to it as a procedure and
>     used it as such; my repair of that bug was what
>     led me to overload <type-name>).

I'm probably slightly confused about what this means exactly---what's
the canonical way to generate a list or vector of the enumeration
values after the change?

If we reverted to my original macro, wouldn't it simplify matters to
also revert to giving a separate name to some opaque object
representing the enum-set type?  Like so:

(define-enum-type :color
  (black white purple maroon)

This would avoid confusion over, say, `enum-set-predicate', which, if
I understand your proposal correctly, would have:

((enum-set-predicate ((enum-set-constructor (color)) 'black)
 ((enum-set-constructor (color)) 'white))
 => #t

This would allow us to have the `define-enumeration' macro to be about
the syntax only, and relegate all the procedural stuff (<index-of>,
<constructor>, <predicate>) to operations that extract them from the
enum-set-type object.  (It would also make the argument order of
'enum-set-projection' less confusing.)  I'll get more concrete below

> 3.  either require or allow the short form to specify
>     either <constructor-syntax> or <constructor>.
> Comments?
> Another issue that needs to be resolved is whether the
> <constructor> takes a bunch of symbols as its arguments,
> or a list of symbols as its single argument.

I would think that <constructor-syntax> will be much more common.
Given that there's `enum-set-constructor', I don't think <constructor>
is needed in the syntax form.  Given that it's not expected to be the
common form, I think a list of symbols would be more appropriate.

So here's what I suggest.  (As I'm typing, I realize it's getting to
be more different from your proposal than I intended---let me know if
this is going in the completely wrong direction.)

Long form:

(define-enum-type <type-name> ; type name
  (<symbol> ...)                ; the symbols in this universe
  <constructor-syntax>          ; Mike's symbol-checking macro (hehe)
  <set-constructor-syntax>)     ; macro that constructs sets

Short form (if no sets are needed):

(define-enum-type <type-name> ; type name
  (<symbol> ...)                ; the symbols in this universe
  <constructor-syntax>)         ; Mike's symbol-checking macro (hehe)

(enum-type-universe enum-type) => enum-set
(enum-index enum-type) => procedure
(make-enum-set enum-type list-of-symbols) => enum-set
(enum-set-of? enum-type enum-set) => boolean

(enum-set-type enum-set) => enum-type
(enum-set->list enum-set) => list of symbols
(enum-set-member? symbol enum-set) => boolean
(enum-set-subset? enum-set enum-set) => boolean
(enum-set=? enum-set enum-set) => boolean
(enum-set-union enum-set enum-set) => enum-set
(enum-set-intersection enum-set enum-set) => enum-set
(enum-set-difference enum-set enum-set)
(enum-set-complement enum-set) => enum-set
(enum-set-projection enum-set enum-type) => enum-set


(define-enum-type :color
  (black white purple maroon)

(define-enum-type :other-color
  (black white purple maroon red green blue)

(color black)                      => black
(color purpel)                     => <expansion-time error>
(enum-set->list (enum-type-universe :color)) => (black white purple maroon)
(enum-index 'black :color)         => 0
(enum-index 'gold :color)          => #f
(enum-index :color (color purple)) => 2
(enum-index :color 'purple)        => 2

(enum-set->list (colors black white)) => (black white)
(colors purpel rain)               => <expansion-time error>

 (colors black purple)
 (make-numeration-set :color '(black purple))) => #t

 (colors black purple))            => (black purple)

(enum-set-of? :color (colors))     => #t

(enum-set-member? 'white (colors white maroon)) => #t

 (enum-set-complement (colors))
 (enum-type-universe :color))      => #t

 (colors black maroon)
 (enum-set-complement (colors white purple)
                                   => #t

 (colors white)
 (other-colors black white red green)) 
                                   => #t

  (colors black white)
  (other-colors black white))      => #t

 (enum-set-projection :color    
                      (enum-set-complement (other-colors))))
                                    => (black white purple maroon)

Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

More information about the R6RS mailing list