[erlang-questions] Bit syntax decscription in erlang reference manual?
成立涛
litaocheng@REDACTED
Fri Jun 20 06:00:08 CEST 2008
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 <erlang-questions_efine@REDACTED>:
> 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
> specification.
>
> 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>>.
>
> Example:
> 1> <<A/binary,B/binary>> = <<1,2,3>>.
> * 1: a binary field without size is only allowed at the end of a binary
> pattern
> 2> <<A:1/binary,B/binary>> = <<1,2,3>>.
> <<1,2,3>>
> 3> A.
> <<1>>
> 4> B.
> <<2,3>>
> 5>
>
> Hope this helps.
> 2008/6/19 成立涛 <litaocheng@REDACTED>:
>
>> 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
>> specification."
>> 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
>> Size.
>> Is it a conflict with reference manual?
>> thanks!
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080620/b291eb2e/attachment.htm>
More information about the erlang-questions
mailing list