The Erlang bit syntax is wonderful, if complicated.
Say you have a Binary like:
84> Bin1 = <<1,0,2>>.
<<1,0,2>>
Then, this will match:
85> <<A:1/binary, B:8, C:1/binary>> = Bin1.
<<1,0,2>> %% A => 1, C => 2
But this will not match:
86> <<A:1/binary, B:1/binary, C:1/binary>> = Bin1.
=ERROR REPORT==== 19-Aug-2007::17:46:17 ===
Error in process <0.139.0> with exit value: {{badmatch,<<3>>},[{erl_eval,expr,3}]}
** exited: {{badmatch,<<1,0,2>>,[{erl_eval,expr,3}]} **
It seems that I can specify a literal '0' as an int type (the default type) but not a binary type (see http://erlang.org/doc/reference_manual/expressions.html#bit_syntax for the gory details). Wonder why?
No comments:
Post a Comment