On 2009-Nov-28, at 1:56 pm, pugs-comm...@feather.perl6.nl wrote:
+    Fri.name    # 'Fri'

Since enums are like hashes, why not .key instead of .name? (Also might be less confusing should you happen to have an enum where the keys are numbers and the values are names. (Of course, enum Key(hopeful=>"A", wild=>"B", gay=>"C", triumphal=>"D", boisterous=>"E", peaceful=>"F", serious=>"G") will be confusing no matter what.))


+    3 ~~ Day    # True, using Day as a subset of Int

Should enums be subsets or subtypes? A subset is a shorthand for certain members of a class, but an enum seems like a way to represent a different kind of thing. Weekdays aren't particular ints the way "natural numbers" are, and it seems useful to be able to tell that $foo is a Day and not a Month or a Colour.

3 == any(Day.mapping.values) would work if you really want to go by values (a bit more verbose, but the actual values are a kind of implementation detail that the user shouldn't be concerned with most of the time anyway). Or "defined Day(3)".

(At first I wrote "?Day(3)", but that wouldn't work if there was value that was false. On the other hand, shouldn't enums typically be true? Does it fit the common case better for enums to start at 1 instead of 0, or maybe start at 0 but true?)


-David

Reply via email to