<div dir="ltr"><div>It is irregular list, that is list which doesn't have [] as tail element, and has 0 there instead. While its legal to have such a value, some list handling functions will be waiting for [] as tail element thus they will be confused.<br></div>Solution: don't have 0 there, or cut it away temporarily and append later as X = [CutList | 0].<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 21, 2014 at 4:46 PM, Stu Bailey <span dir="ltr"><<a href="mailto:stu.bailey@gmail.com" target="_blank">stu.bailey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm sure I'm missing something obvious, but here goes:<div><br></div><div>What is going on here? Is L4 a list? If so, why can't I reverse it?</div><div><br></div><div>
<p><font face="courier new, monospace">70> L4. </font></p>
<p><font face="courier new, monospace">[[<<"8">>,<<"7">>,<<"6">>,<<"5">>],</font></p>
<p><font face="courier new, monospace"> [<<"4">>,<<"3">>,<<"2">>,<<"1">>]|</font></p>
<p><font face="courier new, monospace"> 0]</font></p>
<p><font face="courier new, monospace">71> lists:reverse(L4).</font></p>
<p><font face="courier new, monospace">** exception error: bad argument</font></p>
<p><font face="courier new, monospace"> in function lists:reverse/2</font></p>
<p><font face="courier new, monospace"> called as lists:reverse(0,</font></p>
<p><font face="courier new, monospace"> [[<<"4">>,<<"3">>,<<"2">>,<<"1">>],</font></p>
<p><font face="courier new, monospace"> [<<"8">>,<<"7">>,<<"6">>,<<"5">>]])</font></p>
<p><font face="courier new, monospace"> in call from lists:reverse/1 (lists.erl, line 152)</font></p>
<p><font face="courier new, monospace">72> [Head1|Rest1] = L4.</font></p>
<p><font face="courier new, monospace">[[<<"8">>,<<"7">>,<<"6">>,<<"5">>],</font></p>
<p><font face="courier new, monospace"> [<<"4">>,<<"3">>,<<"2">>,<<"1">>]|</font></p>
<p><font face="courier new, monospace"> 0]</font></p>
<p><font face="courier new, monospace">73> Rest1.</font></p>
<p><font face="courier new, monospace">[[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]</font></p>
<p><font face="courier new, monospace">74> lists:reverse(Rest1).</font></p>
<p><font face="courier new, monospace">** exception error: no function clause matching lists:reverse([[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]) (lists.erl, line 145)</font></p>
<p><font face="courier new, monospace">75> [Head2|Rest2] = Rest1.</font></p>
<p><font face="courier new, monospace">[[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]</font></p>
<p><font face="courier new, monospace">76> Head2.</font></p>
<p><font face="courier new, monospace">[<<"4">>,<<"3">>,<<"2">>,<<"1">>]</font></p>
<p><font face="courier new, monospace">77> Rest2. </font></p>
<p><font face="courier new, monospace">0</font></p>
<p><font face="courier new, monospace">78></font></p><p><br></p><p>In practice, the kind of structure demonstrated in L4 is being returned by a function from another library I'm trying to use, but I'm trying to understand what's going on in general.</p></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>