Re: named array
- Posted by DerekParnell (admin) Sep 02, 2013
- 2179 views
TheresNoTime said...
I need a structure similar to map. But standard Euphoria's maps does not suit me because of side effects. Advise how to do something like the symbols ...
What 'side effects' are a concern to you? Using the map library it's simply ...
include std/map.e map Object = map:new() map:put(Object, 'X') = 100 map:put(Object, 'Y') = -200 map:put(Object, 'Z') = 300 puts(1, map:get(Object, 'Z'))
Or if the 'ugliness' of showing all the detailed assignments is too much for you ...
Create a map helper library such as ...
include std/map.e function mapset(sequence vals) object o o = map:new() for i = 1 to length(vals) do map:put(o, vals[i][1], vals[i][2]) end for return o end function function mapget(object o, object k) return map:get(o,k) end function
Then use it to emulate for favourite slow interpreter, such as Erlang or Ruby ...
include maphelp.e object Object = mapset( {{'X',100}, {'Y',-200}, {'Z',300}}) puts(1, mapget(Object, 'Z'))