[erlang-questions] Bit syntax decscription in erlang reference manual?
Fri Jun 20 08:04:39 CEST 2008
Sounds right to me.
One little thing, though: the newer versions of Erlang support a type,
"bytes", which is identical to binary, but a more accurate description.
There is also a size_bytes() function. As I understand it, we are encouraged
to phase out the use of binary in favor of bytes.
So the example could have been written with a more "modern" syntax as:
<<A:1/bytes,B/bytes>> = <<1,2,3>>.
S = byte_size(B).
10> <<A:1/bytes,B/bytes>> = <<1,2,3>>.
11> S = byte_size(B).
Hope this helps.
On Fri, Jun 20, 2008 at 12:00 AM, 成立涛 <> wrote:
> yeah. I see. Thank you very much Edwin.
> my opinion: in binary syntax, the integer, float can always use their
> default size, but binary(bits and bytes) must declare its size specification
> except the very last binary element. Is't right?
> I come from china, so my english is not good, please don't mind my
> expression. :)
> 2008/6/20 Edwin Fine <>:
> There's a subtlety here that you may have missed. The manual says
>> All other *bit string or binary* elements in the matching must have a size
>> In <<A, B, C>> = <<1,2,3>>, all elements on the left hand side are by
>> default of type integer, not bitstring or binary. Therefore sizes are
>> assumed to be 1 byte each.
>> Your example is the same as writing
>> <<A/integer, B/integer, C/integer>> = <<1,2,3>>.
>> This below, for example, would NOT work:
>> <<A/binary,B/binary>> = <<1,2,3>>.
>> You would have to write
>> <<A:1/binary,B/binary>> = <<1,2,3>>.
>> 1> <<A/binary,B/binary>> = <<1,2,3>>.
>> * 1: a binary field without size is only allowed at the end of a binary
>> 2> <<A:1/binary,B/binary>> = <<1,2,3>>.
>> 3> A.
>> 4> B.
>> Hope this helps.
>> 2008/6/19 成立涛 <>:
>>> In erlang reference mannual, the Bit Syntax Expressions section, about
>>> the binary Size, the manual said:
>>> "In matching, this default value is only valid for the very last element.
>>> All other bit string or binary elements in the matching must have a size
>>> we know the default size for integer is 8, float is 64, binary is the
>>> whole bytes.
>>> for example:
>>> > <<A, B, C>> = <<1, 2, 3>>.
>>> I think in this pattern match, the variables A, B, C all use the dafault
>>> Is it a conflict with reference manual?
>>> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions