[R6RS] Enumerations proposal pre-draft
    Michael Sperber 
    sperber at informatik.uni-tuebingen.de
       
    Mon Apr 24 13:09:55 EDT 2006
    
    
  
William D Clinger <will at ccs.neu.edu> writes:
>> Is this:
>>
>> > (color-index (color purple))       => 2
>>                ^^^^^^^^^^^^^
>>
>> supposed to be 'purple?
>
> Yes.  Sorry.
OK.  Would it be an acceptable tweak to add an operand to
`define-enum-type' like so:
(define-enum-type <type-name>
  <elements-name>
  <predicate-name>
  <index-accessor>
  (<symbol> ...))
where <elements-name> is what <type-name> was before, and where
<type-name> is defined to be a macro that will accept the name of an
enumeration value, and return the corresponding symbol, if the name
indeed belongs to the enumeration, and raise an expansion-time error
otherwise?
Example:
(define-enum-type color
  colors
  color?
  color-index
  (black white purple maroon))
(colors)                           => (black white purple maroon)
(color? 'black)                    => #t
(color? 'gold)                     => #f
(color black)                      => 'black
(color purpel)                     => <expansion-time error>
(color-index (color purple))       => 2
-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
    
    
More information about the R6RS
mailing list