Re: named array

new topic     » goto parent     » topic index » view thread      » older message » newer message
mattlewis said...

To me, I don't see how this really adds any value, because it seems like you've just added a simple redirection layer on top of the normal map interface. So I would dump it and just use a regular map instead of a narr. smile

You completely misunderstood what I was trying to do. Map here is only the custodian of symbols. Theoretically, it can be replaced by a sequence or constants (it is the original version with the "enum"). This does not wrap around the map, and a wrap around sequences. At first I wanted to do this:

sequence Person = { 
{"first_name", "last_name", "income"}, 
{"James", "Bond", 1_000_000} 
} 
 
sequence FirstName = Person[2][find("first_name", Person[1])] 
sequence LastName = Person[2][find("last_name", Person[1])] 
integer Income = Person[2][find("income", Person[1])] 
Person[1] = append(Person[1], "targets") 
Person[2] = append(Person[2], {"Drax Industries", "OCTOPUS", "Scum"}) 

I wrote the corresponding functions, but I'm annoyed by some nuances. Firstly, "find" is ineffective. You can improve its efficiency by streamlining the keys in ascending order. Getting is easy. However, the procedure for adding new values ​will become less apparent. Secondly, there is no sense to store the keys in each sequence, if the keys are the same (or a plurality of keys intersect). For example, we create two types of narrs: Citizen and Superhero.

Citizen = narr:new({ 
"first_name = John",  -- such kind of syntax not realized yet (TODO) 
"second_name = Smith", 
"task = buy milk"}) 
 
Superhero = narr:new({ 
"first_name = Hedgehogman", 
"task = save world"}) 

Internally, it will look like:

-- map of indexes may contains "first_name" = 1, "second_name" = 2, "task" = 3 (order may be other, but numbers from 1 to 3) 
Citizen = {"John", "Smith", "buy milk"} 
Superhero = {"Hedgehogman", 0, "save world"} -- yes, the second element is not used, but it is done for uniformity and speed. 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu