Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
immutable means immutable
Gotcha with Erlang
v-kserl-v-02-code erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V5.10.4 (abort with ^G)
1> VALUE = fun() -> io:format("I have value!~n") end.
#Fun<erl_eval.20.80484245>
2> K = mykey.
mykey
3> D1 = dict:new().
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
4> dict:store(K, VALUE, D1).
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],
[[mykey|#Fun<erl_eval.20.80484245>]],
[],[],[],[],[],[]}}}
5> D1.
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
6> dict:fetch(K, D1).
** exception error: bad argument
in function dict:fetch/2
called as dict:fetch(mykey,
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[]}}})
7> D2 = dict:store(K, VALUE, D1).
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],
[[mykey|#Fun<erl_eval.20.80484245>]],
[],[],[],[],[],[]}}}
8> dict:fetch(K, D2).
#Fun<erl_eval.20.80484245>
9>
[erlang] 0:..erl-v-02-code* "Jamess-MacBook-Air.loc" 21:48 20-Jun-14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.