Associative array/Creation: Difference between revisions

Added Elixir
(Added Elixir)
Line 7:
 
{{Template:See also lists}}
 
=={{header|ActionScript}}==
Because ActionScript does not have associative arrays in the normal sense, Object objects are used instead and keys are simply properties on those objects.
Line 775 ⟶ 776:
 
].</lang>
 
=={{header|Elixir}}==
{{trans|Erlang}}
There is <code>HashDict</code> or <code>Map</code> in the implementing of <code>Dict</code>.
<lang elixir>defmodule RC do
def dict_create(dict_impl \\ Map) do
d = dict_impl.new #=> creates an empty Dict
d1 = Dict.put(d,:foo,1)
d2 = Dict.put(d1,:bar,2)
print_vals(d2)
print_vals(Dict.put(d2,:foo,3))
end
defp print_vals(d) do
IO.inspect d
Enum.each(d, fn {k,v} -> IO.puts "#{k}: #{v}" end)
end
end
 
IO.puts "< create Map.new >"
RC.dict_create
IO.puts "\n< create HashDict.new >"
RC.dict_create(HashDict)</lang>
 
{{out}}
<pre>
< create Map.new >
%{bar: 2, foo: 1}
bar: 2
foo: 1
%{bar: 2, foo: 3}
bar: 2
foo: 3
 
< create HashDict.new >
#HashDict<[foo: 1, bar: 2]>
foo: 1
bar: 2
#HashDict<[foo: 3, bar: 2]>
foo: 3
bar: 2
</pre>
 
=={{header|Emacs Lisp}}==
Anonymous user