<br><br><div class="gmail_quote">On Fri, May 13, 2011 at 23:44, Jesper Louis Andersen <span dir="ltr"><<a href="mailto:jesper.louis.andersen@gmail.com">jesper.louis.andersen@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 class="im">On Fri, May 13, 2011 at 22:23, Joe Armstrong <<a href="mailto:erlang@gmail.com">erlang@gmail.com</a>> wrote:<br>
> No good reason. Erlang evolved from Prolog and that how it was done in<br>
> Prolog<br>
> no deep thought was involved ..<br>
<br>
</div>Interestingly, that is also the style of Haskell:<br>
<br>
len :: [a] -> Integer<br>
len [] = 0<br>
len (x : xs) = 1 + (len xs)<br>
<br>
And also of Standard ML:<br>
<br>
fun len [] = 0<br>
| len (x :: xs) = 1 + (len xs)<br>
<br>
..<br>
<br>
My usual rewrite in many cases is to use a case. It almost notates as<br>
the original idea of a simplification of the syntax:<br>
<br>
len(L) -><br>
case L of<br>
[] -> 0;<br>
[_|R] -> 1 + len(R)<br>
end.<br></blockquote><div><br>This is - in my book - a step backwards.<br>You should haev the spec for the function and then pattern matching in the function clauses since it gives you:<br><ol><li>Overview of what the function does.</li>
<li>1st level overview of how the function branches out.</li></ol>This makes debugging so much faster than having to get inside a function only to meet a case on the parameters as the first thing.<br><br>Cheers,<br>Torben<br>
<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
<br>
--<br>
<font color="#888888">J.<br>
</font><div><div></div><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.linkedin.com/in/torbenhoffmann">http://www.linkedin.com/in/torbenhoffmann</a><br>