Closed Dunbaratu closed 9 years ago
I like the appeal of a dictionary/hashmap - and as you say have it feel similar to the dynamic suffixes that have been discussed in the past.
My main reasoning is quite personal, and I just don't like the look of the main code example you provide in your post.
Hashmap: #963. Isn't it?
I suppose it's a little different to do hashmaps than having an actual eval, but if I want eval later, it can be a new issue then.
I just got done answering this question of someone in the reddit forum:
http://www.reddit.com/r/Kos/comments/2rebou/unique_variablenames_in_loops/
What they were trying to do would have required late-binding - that you can store a value into a variable, the name of which is unknown until runtime. For example, this:
As you know, there's no way the above could ever work in kOS right now. you have to choose the variable names up front with early binding rules.
It occurs to me that there's no real reason kOS couldn't allow this. In reality, kOS could allow late-binding in which it adds values to the variable dictionary as needed, but right now it's not made to do that, and making it allow it would be an ugly syntax overhaul of the var_identifier rule in the tinyPG file.
But it does occur to me that we could allow two late-binding-ish features two different ways:
SET ${"hello"+count} TO count*10.
(the syntax shown here is just an example taken from bash scripting - it could do something different). It would make little difference, because identifiers are ALREADY not really inserted into the symbol table until encountered at runtime anway, despite how the syntax is laid out.) This was an idea I first had for trying to solve the filename problem (expressions expected filenames to be identifiers making it impossible to leave them unknown until runtime), but now this is another use case calling for the same feature.SET myHellos(count) to count*10.
instead of the line from the code above. Or, we can even make it work directly from the suffix system, with dynamic suffix names for the key values.The question is... do we want this, and do we want way 1, way 2, or both?