On Wed, Apr 07, 2010 at 06:33:46AM -0700, Jon Lang wrote: : That said, don't we already have a means of assigning specific values : to individual members of an enum? I forget the exact syntax, but I : believe that it involves an assignment operator within the : enumeration. Mind you, this is from memory: : : enum Perms { Read = 1, Write = 2, Exec = 4, Fold = 8, Spindle = : 16, Mutilate = 32 } : : ...or something to that effect. Clumsy, sure; but it seems to me that : this is exactly the sort of thing that hyper-operators were designed : to handle: : : enum Perms { Read, Write, Exec, Fold, Spindle, Mutilate } »=« (1, : 2, 4 ... 32) : enum Perms { Read, Write, Exec, Fold, Spindle, Mutilate } »=» (1, : 2, 4 ... *) : : ...or something along those lines. I'll check the exact syntax later, : when I have more time; but I wonder if something to this effect is : already possible with the language spec as written.
You're right, though you're reaching for the wrong meta-operator, since hypers have parallel and run-to-completion semantics, and therefore don't like infinite lists. Instead, you want a nice, ordered, lazy, "zipwith". In the currently specced syntax, that would be: enum Perms (<Read Write Exec Fold Spindle Mutilate> Z=> 1,2,4...*); That just creates a list of pairs, and stops at the end of the shorter list. Which is exactly what we want. The parens are necessary because the enum declaration currently takes a single list term which is tighter than comma, syntactically speaking. We could make enum declarators even more like constant declarators by using a pseudo assignment. Then we could use = instead of parens: enum Perms = <Read Write Exec Fold Spindle Mutilate> Z=> 1,2,4...*; This works because list infix is tighter than list assignment. I've been thinking of switching enums to this form for some time, and this may tip me over the edge. (Presuming of course that I wasn't tipped over the edge many years ago...) Larry