I don't think that is the cause, because it doesn't work for non-empty binaries either. Look at this:<br><br>> ABC = <<"ABC">>.<br> <<"ABC">><br><br>> A = <<"A">>.
<br> <<"A">><br><br>> <<A/binary, BC/binary>> = ABC.<br> ** exited: {{badmatch,<<"ABC">>},[{erl_eval,expr,3}]} **<br><br>And if I add the size of the binary it now works:
<br><br>> <<A:1/binary, BC/binary>> = ABC.<br> <<"ABC">><br><br><br><div><span class="gmail_quote">On 11/15/07, <b class="gmail_sendername">Jeremy Wall</b> <<a href="mailto:jeremy@marzhillstudios.com">
jeremy@marzhillstudios.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br><div><span class="q"><span class="gmail_quote">
On 11/15/07, <b class="gmail_sendername">Juan Jose Comellas</b> <<a href="mailto:juanjo@comellas.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">juanjo@comellas.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Why is this expression not matching?<br><br>A = <<"ABC">>,<br>Empty = <<>>,<br><<Empty/binary, Tail/binary>> = A.</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I was expecting that this would result in 'Tail' being bound to <<"ABC">>, but instead I'm getting a badmatch error. However, if I specify the length of the 'Empty' variable, it works:
<br><br><<Empty:0/binary, Tail/binary>> = A.</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">And if I put 'Empty' as the last part of the pattern it also works:
</blockquote></span><div><br><br>I suspect this is because empty binaries don't have a size so erlang can't determine the size for you meaning you have to explicitly specify a size of 0 for erlang to figure out how to match it. Might be nice if it could figure out the 0 part itself but not neccessarily a bug. Maybe a Core developer could shed more light?
<br></div><span class="q"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><<Head/binary, Empty/binary>> = A.</blockquote></span>
<div><br><br>Since /binary on the end just means the rest of the binary I would expect this to work exactly as it does without specifying a size.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><span class="q">Is matching for binaries supposed to work like this or is it a bug?
<br><br>
<br></span>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">erlang-questions@erlang.org
</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><span class="sg">
<br>
<br clear="all"><br>-- <br>Jeremy Wall<br><a href="http://jeremy.marzhillstudios.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://jeremy.marzhillstudios.com</a><br><a href="mailto:Jeremy@marzhillstudios.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Jeremy@marzhillstudios.com</a>
</span></blockquote></div><br>