[erlang-questions] Re: binary expression with fixed and variablefields
Fri Jul 2 03:13:51 CEST 2010
The main reason why 4> isn't valid is that the default type of a
binary segment is an integer. So by not qualifying A you are trying to
match an integer from ABC with the *binary* <<"a">>, which can never
match. That 1> works is because a string literal in a binary is
expanded into the sequence of bytes in the string. So in effect 1> is
<<$a,_/binary>> = <<$a,$b,$c>>.
On 2 July 2010 02:58, Steve Davis <> wrote:
> On a related note, I find it curious that there's the following
> limitation forcing you to manually calculate the size of an already
> known binary:
> 1> <<"a", _/binary>> = <<"abc">>.
> 2> A = <<"a">>.
> 3> ABC = <<"abc">>.
> 4> <<A, _/binary>> = ABC.
> ** exception error: no match of right hand side value <<"abc">>
> 5> Size = size(A).
> 6> <<A:Size/binary, _/binary>> = ABC.
> ...a minor inconvenience, but irritating.
> Perhaps there's a reason that I don't immediately see why 4> isn't
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
More information about the erlang-questions