Nick --<br><br>tailMin isn't a name you can bind to a value, use TailMin instead.<br><br>tailMin = 2 asserts that the atom 'tailMin' is equal to the integer 2.<br><br>-- rec --<br><br><div class="gmail_quote">2008/2/25 nick james <<a href="mailto:nick.james@cadar.co.uk">nick.james@cadar.co.uk</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 link="blue" vlink="purple" lang="EN-GB">
<div>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Hi,</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> I have a program which results in a run time error I don't
understand. The program is:</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">-module(lists1).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">-export([min/1]).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">min(N) when number(N) -></span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> N;</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">min([H|[]]) -></span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> H;</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">min([H|T]) -></span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> tailMin = min(T),</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> if</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> tailMin > H -> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> H;</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> tailMin =< H -> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> tailMin</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> end</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">.</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">And the output is:</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Eshell V5.6 (abort with ^G)</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">1> c(lists1).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">{ok,lists1}</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">2> lists1:min(1).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">1</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">3> lists1:min([1]).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">1</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">4> lists1:min([1,2]).</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">** exception error: no match of right hand side value 2</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> in function lists1:min/1</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">5></span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">My expectation is that lists1:min([1,2]) would be picked up
by min([H|T]) . Can anyone enlighten me?</span></font></p>
<p><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p><i><font face="Comic Sans MS" size="3"><span style="font-size: 12pt; font-style: italic;">Nick James</span></font></i><br>
<font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Cadar
Measurement Solutions Ltd</span></font><br>
<font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">tel
08453 708 709</span></font><br>
<font face="Arial" size="1"><span style="font-size: 7.5pt; font-family: Arial;">Registered
in England,
no.2027817, 100 Fitzwalter Road,
Sheffield S2 2SP</span></font></p>
<p><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font></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://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>