Re: named array
- Posted by TheresNoTime Sep 04, 2013
- 1985 views
I could go further, and envision a new function to map that'd go even further.
function willAccident_Map(map State, atom Time) atom Velocity = map:get(State, "velocity") -- get velocity of system atom Acceleration = map:get(State, "acceleration") -- get acceleration of system Velocity += Acceleration * Time -- no need to keep the old velocity! map NewState = map:clone_and_put(State, "velocity", Velocity) -- because we can get new state return isAccident(NewState) -- no need to save answer end function
Yes, it is possible. But why? For what reason? Do you not see that either way - it's my way, but unnecessarily complicated. Your way of using maps plus a crutch to overcome their side effect. My method uses sequences because they initially do not have such effect. Yes, you will have one simple function, and I have three plus the map for keys "behind the scenes". However, if you look at the principle, not to it's implementation, my approach is simpler. It is better to have a new type of data than to remember that it is necessary to use a crutch for old type. Your variation of "willAccident" is shorter, but you just put some of my code into a separate function "clone_and_put". This is the same backup and restore (just disguised), but for the entire map! Pfff...