Sounds right to me. <br><br>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.<br>
<br>So the example could have been written with a more "modern" syntax as:<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><<A:1/bytes,B/bytes>> = <<1,2,3>>.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">S = byte_size(B).</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Example:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">10> <<A:1/bytes,B/bytes>> = <<1,2,3>>.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><<1,2,3>></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">11> S = byte_size(B).</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">2</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">12> A.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><<1>></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">13> B.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><<2,3>></span><br><br>Hope this helps.<br><br>
<div class="gmail_quote">On Fri, Jun 20, 2008 at 12:00 AM, 成立涛 <<a href="mailto:litaocheng@gmail.com">litaocheng@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
yeah. I see. Thank you very much Edwin.<br>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?<br>
I come from china, so my english is not good, please don't mind my expression. :)<span style="color: rgb(121, 6, 25);"></span><br><br><div class="gmail_quote">2008/6/20 Edwin Fine <<a href="mailto:erlang-questions_efine@usa.net" target="_blank">erlang-questions_efine@usa.net</a>>:<div>
<div></div><div class="Wj3C7c"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">There's a subtlety here that you may have missed. The manual says<div><br>
<br>All other *bit string or binary*
elements in the matching must have a size specification.<br><br></div>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. <br>
<br>Your example is the same as writing<br><br><<A/integer, B/integer, C/integer>> = <<1,2,3>>.<br><br>This below, for example, would NOT work:<br><br><<A/binary,B/binary>> = <<1,2,3>>.<br>
<br>You would have to write<br><br><<A:1/binary,B/binary>> = <<1,2,3>>.<br><br>Example:<br>1> <<A/binary,B/binary>> = <<1,2,3>>.<br>* 1: a binary field without size is only allowed at the end of a binary pattern<br>
2> <<A:1/binary,B/binary>> = <<1,2,3>>.<br><<1,2,3>><br>3> A.<br><<1>><br>4> B.<br><<2,3>><br>5> <br><br>Hope this helps.<br><div class="gmail_quote">
2008/6/19 成立涛 <<a href="mailto:litaocheng@gmail.com" target="_blank">litaocheng@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div>In erlang reference mannual, the Bit Syntax Expressions section, about the binary Size, the manual said:<br>
"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."<br>we know the default size for integer is 8, float is 64, binary is the whole bytes.<br>for example:<br>> <<A, B, C>> = <<1, 2, 3>>.<br>
I think in this pattern match, the variables A, B, C all use the dafault Size.<br>Is it a conflict with reference manual?<br>thanks!<br>
<br></div></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>
</blockquote></div></div></div><br>
</blockquote></div><br>