模式匹配Erlang中的Map字段

9w11ddsr  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(155)

I'm currently reading book << Programming Erlang, 2nd edition >>. When I looked through the pattern matching of Map's field, the code snippet in the book complains some error on my Erlang prompt.

%% 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

Is there anything that I'm missing? Thanks in advance.

blmhpbnm

blmhpbnm1#

使用:=代替=〉

#{ born := B } = Henry8.

source: http://erlang.org/doc/reference_manual/expressions.html#maps-in-patterns

相关问题