[erlang-questions] Construct and match binaries

Olav Frengstad olav@REDACTED
Tue Nov 6 23:16:41 CET 2012


Hey,

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 pattern

Using size specification yields the expected result:
3> <<A:1/binary, $:, B:1/binary>> = <<"a:b">>.
<<"a:b">>

Even equality checks works:
4> <<A/binary, $:, B/binary>> == <<"a:b">>.
true

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?

Cheers,
Olav



More information about the erlang-questions mailing list