This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
enums [was: blog entry - Kawa in Computer Languages "shootout"]
On 10/20/2010 03:01 PM, Jamison Hope wrote:
Is there a more Kawa-native way of producing an enum than explicitly
subclassing java.lang.Enum?
That would be nice. There is also an R6RS enumeration library,
but it doesn't appear practical to come up with something compatible
with both R6RS enums (which are symbols) and java.lang.Enum. And
prioritizing the latter probably makes better sense. For example,
R6RS has a problem with two enum values with the same name in
different enum types - they're the same symbol.
What I think makes most sense is a (define-enum NAME ...) macro that
expands to (define-simple-class NAME (java.lang.Enum) ...). Perhaps:
(define-enum TYPE option-pair... (E0 ... EN) OTHER-DEFS...)
mapping to:
(define-simple-class TYPE (java.lang.Enum) option-pair...
(E0 :: TYPE allocation: 'static init: (TIME "E0" 0))
...
(EN :: TYPE allocation: 'static init: (TIME "E0" N))
((values)::TYPE[] ...)
OTHER-DEFS...)
This doesn't handle *all* the options of a Java enum
declaration, but it handles the most important ones, and
the other ones could be added later if need be.
Any volunteers? This should probably be done using syntax-case.
--
--Per Bothner
per@bothner.com http://per.bothner.com/