Re: named array
- Posted by TheresNoTime Sep 03, 2013
- 2124 views
It's not senseless if it makes life easier.
I have repeatedly tried to explain that this approach made my life more difficult. That's why I came up with a "narr" because it makes my life easier.
Though I must admit that I don't see how using a map would be storing the key twice.
Two maps.
You're not getting more side effects with your narr implementation (OK, I guess you could manage it doing things completely differently). Anyways, with maps, you're just passing a reference to your data and manipulating it directly instead of passing and returning by value. Doing it by reference is likely to be faster, especially as the amount of data grows. The map library goes to a bit of effort to avoid unnecessary copies on write.
So, I have to take care of that to backup data to be temporarily changed, and then must be restored. When I use a narr, I can just keep the previous state!
Person = narr:new({"citizenship = USA", "actions = law-abiding", "task = Consume!"}) ClarkKent = narr:put(Person, {"name = Clark Kent", "apparel = suit", "sweetheart = Lana Lane"}) Superman = narr:put(ClarkKent, {"name = Superman", "apparel = tights"}) if equal(narr:get(Person, "task"), "Save the free world!") then Person = Superman else Person = ClarkKent end if
Nah...I'm a lazy American. I do what's easy and then if there's some performance problem, I fix that. If you aren't having to deal with a lot of data (I believe this is what you said) then why worry about duplicating some things?
I don't warry about that. The fact that the keys are not duplicated in the narrs was not my intention. This is an additional effect. I wanted to get something like the symbols of Ruby, because they are simple and easy. You do not want to say that Ruby and Erlang (may be other) created by idiots?
Just use nested maps:
I not only lazy but also stupid a bit. I do not like to use a nested structures, where possible to implement primitive one-dimensional array/list etc.