Re: Nested constants
- Posted by Icy_Viking Jun 22, 2020
- 1093 views
Erm, what I want is the actual constants plus three arrays, which line up by index:
constant LEFT = 331, RIGHT = 333, UP = 328, DOWN = 336, KEYS = {LEFT,RIGHT,UP,DOWN}, NAMES = {"LEFT","RIGHT","UP","DOWN"}, DESCS = {"move left","shift right","go up","drop down"}
mainly so I can use idx=find() on the first sequence and then [idx] the other two, and I can't think of any way for enum to do anything beyond the top line.
(I have 61 constants in this particular set already, and from past and painful experience I know that keeping 4 such independent sets in step is no fun at all.)
The only other way I can think of that would achieve anything similar (sanely, and defining everything related side-by-side) might be something like this
sequence keys = {}, names = {}, descs = {} function add_key(integer key, string name, desc) keys = append(keys,key) names = append(names,name) descs = append(descs,desc) return key end function constant LEFT = add_key(331, "LEFT", "move left" ), RIGHT = add_key(333, "RIGHT", "shift right"), UP = add_key(328, "UP", "go up" ), DOWN = add_key(336, "DOWN", "drop down" ), KEYS = keys, NAMES = names, DESCS = descs
but with this new ":=" syntax you can just do
constant {KEYS, NAMES, DESCS} = columnize({ {LEFT := 331, "LEFT", "move left"}, {RIGHT := 333, "RIGHT", "shift right"}, {UP := 328, "UP", "go up"}, {DOWN := 336, "DOWN", "drop down"}})
All three options given would create the same seven constants, such that
?{LEFT,KEYS,NAMES,DESCS} -- {331,{331,333,328,336},{"LEFT","RIGHT","UP","DOWN"},{"move left","shift right","go up","drop down"}}
Does that make more sense?
PS What's that saying? Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
I see what you mean. You want a more advanced way of declaring constants then simple constant and enum. I just thought it could be achieved through enums, but with your method, you need a new way. I mean I do think its a good idea. Here we are still waiting for a new official release of Euphoria, we still keep talking about new features. I just hope the next offical release has some sorta of struct support.