Pid可以映射关键吗?
从#{}语法构建映射,错误说Pid不能是密钥.
用map模块构建bug,Pid可以是关键.
18>
18> Pid = self().
<0.39.0>
19> #{Pid => 1}.
* 1: illegal use of variable 'Pid' in map
20>
20> M1 = maps:from_list([{Pid, 1}]).
#{<0.39.0> => 1}
21>
21> #{Pid := V} = M1.
* 2: illegal use of variable 'Pid' in map
22>
22> maps:get(Pid, M1).
1
Run Code Online (Sandbox Code Playgroud)
"Erlang 18(候选版本2)"中已经提供了对地图模式中任意键的支持.
$ erl
Erlang/OTP 18 [RELEASE CANDIDATE 2] [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.0 (abort with ^G)
1> Pid = self().
<0.33.0>
2> #{Pid => 1}.
#{<0.33.0> => 1}
Run Code Online (Sandbox Code Playgroud)