[erlang-questions] Strange difference between construction and matching of binaries

Ameretat Reith ameretat.reith@REDACTED
Wed Dec 23 19:16:10 CET 2015


`
1) AB = <<"AB">>.
2) << AB:1/bytes, $B >> = AB. %% does not match
3) AB = << AB:1/bytes, $B >>. %% will match
`

It's another example which I faced some days ago.  I think size
specifier in matching segment just apply to unbound variables, in
another word when construction will happen.

I think It's just an implementation issue and a try to avoid making
intermediate variables [1] and matching will checked bit-by-bit with
referenced variables and finished as soon as It finds bits are not
aligned anymore. I very like hear more about this too :)

1:
http://www.erlang.org/doc/efficiency_guide/binaryhandling.html#match_context



More information about the erlang-questions mailing list