模式匹配erlang中的地图字段

时间:2015-05-14 06:53:34

标签: erlang erlang-shell

我目前正在读书<<编程Erlang,第2版>。当我查看Map' s字段的模式匹配时,书中的代码片段在我的Erlang提示中抱怨一些错误。

%% Book's version
1> Henry8 = #{ class => king, born => 1491, died => 1547 }. 
#{ born => 1491, class=> king, died => 1547 }.
2> #{ born => B } = Henry8.
#{ born => 1491, class=> king, died => 1547 }.
3> B.
1491

%% My Eshell V6.2
65> Henry8 = #{ class => king, born => 1491, died => 1547 }.
#{born => 1491,class => king,died => 1547}
66> #{ born => B } = Henry8.
* 1: illegal pattern

我有什么遗失的吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

使用:=而不是=>

#{ born := B } = Henry8.

来源:http://erlang.org/doc/reference_manual/expressions.html#id79796