Skip to content

Instantly share code, notes, and snippets.

@jwhiteman
Created July 18, 2014 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwhiteman/079fe77fc626d49c9f8a to your computer and use it in GitHub Desktop.
Save jwhiteman/079fe77fc626d49c9f8a to your computer and use it in GitHub Desktop.
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