[erlang-questions] Construct and match binaries
Tue Nov 6 23:26:08 CET 2012
Switch the match around and it works.
1> A = <<$a>>.
2> B = <<$b>>.
3> <<"a:b">> = <<A/binary, $:, B/binary>>.
If I understand the way it works correctly you are attempting to assign the
right side to the left side in your example. If I am wrong I am sure one of
the smarter Erlangers will flog me.
On Tue, Nov 6, 2012 at 2:16 PM, Olav Frengstad <> wrote:
> I'm trying to wrap my head around a problem I have with constructing
> and matching a binary.
> Take the following example (will fail with "a binary field without
> size is only allowed at the end of a binary pattern"):
> 2> A = <<$a>>, B = <<$b>>,
> 2> <<A/binary, $:, B/binary>> = <<"a:b">>.
> * 2: a binary field without size is only allowed at the end of a binary
> Using size specification yields the expected result:
> 3> <<A:1/binary, $:, B:1/binary>> = <<"a:b">>.
> Even equality checks works:
> 4> <<A/binary, $:, B/binary>> == <<"a:b">>.
> I would assume that the size of the binary is known when performing
> construction and therefore the first example should work (considering
> <<X/binary,...>> equality checks works).
> Can anyone shed some light on what's happening here?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions