<div dir="ltr">It's the same with binaries:<div><br></div><div><<"a", Rest/binary>> = <<"abc">></div><div>%%=> Rest = <<"bc">></div><div><br></div><div>a() -> <<"a">></div><div>Prefix = <<(a())/binary>></div><div>PrefixSize = byte_size(Prefix) %% Compilation fails if size is not provided</div><div><<Prefix:PrefixSize/binary, Rest/binary>> = <<"abc">></div><div><div>%%=> Rest = <<"bc">></div></div><div><br></div><div>Not sure what the differences may be due to compilation v. in the REPL.</div><div><br></div><div>I never understood however why this was "just sugar" or why PrefixSize is explicitly needed:</div><div> in</div><div> f(Prefix) when is_list(Prefix) -></div><div> Prefix ++ Rest = "my_list_thing",</div><div> Rest.</div><div> why isn't the compiler able to generate a pattern match? Is it missing some concept, some structures?</div><div>What are the missing pieces and what can be done to add them?</div><div><br></div><div>Same question with binaries:</div><div> since we have a "prefix-match of binaries only providing PrefixSize at runtime" instruction,</div><div> * Why don't we have one for lists?</div><div> * And oh God why do we have to provide that PrefixSize "manually"? (binding the variable ourselves, when the compiler could do that itself)</div><div> * Why isn't suffix-matching of binaries implemented yet? (how different to prefix-matching can it be?)</div><div><br></div><div>I could never find the answer to all of these questions.</div><div>WRT binaries my thinking is that they are actually a mix of "bytes" and references to binaries,</div><div>making some crucial operations O(log n) instead of O(1)... but prefix match exists...</div><div><br></div><div>I really want to be able to write things like:</div><div> <<"{", Name/binary, "}">> = PathToken</div><div><br></div><div>%%=> Name = <<"id">> given PathToken = <<"{id}">></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div><br></div><div>Cheers,</div><div>-- </div><div>Pierre Fenoll</div></div><div><br></div></div></div></div>
<br><div class="gmail_quote">On 25 October 2017 at 09:27, Kostis Sagonas <span dir="ltr"><<a href="mailto:kostis@cs.ntua.gr" target="_blank">kostis@cs.ntua.gr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/25/2017 08:56 AM, Stefan Hellkvist wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Is it because this syntactic sugar is transformed more or less as a preprocessing step where the value of Prefix needs to be known,<br>
</blockquote>
<br></span>
Yes, that's the reason. It's a purely _syntactic_ thing.<br>
<br>
Kostis<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
</blockquote></div><br></div>