[erlang-questions] how: Matching empty binaries at the beginning

Juan Jose Comellas juanjo@REDACTED
Thu Nov 15 16:56:17 CET 2007

Why is this expression not matching?

A = <<"ABC">>,
Empty = <<>>,
<<Empty/binary, Tail/binary>> = A.

I was expecting that this would result in 'Tail' being bound to <<"ABC">>,
but instead I'm getting a badmatch error. However, if I specify the length
of the 'Empty' variable, it works:

<<Empty:0/binary, Tail/binary>> = A.

And if I put 'Empty' as the last part of the pattern it also works:

<<Head/binary, Empty/binary>> = A.

Is matching for binaries supposed to work like this or is it a bug?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071115/d68da35d/attachment.htm>

More information about the erlang-questions mailing list