Re: named array

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

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...

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu