<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1586" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2>Perhaps you should read the on-line erlang course:</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff size=2><A
href="http://www.erlang.org/course/course.html">http://www.erlang.org/course/course.html</A></FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2>Especially:</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff size=2><A
href="http://www.erlang.org/course/sequential_programming.html">http://www.erlang.org/course/sequential_programming.html</A></FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff size=2>To
answer your question, the following quote from the above
course:</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007> Clauses are scanned sequentially until
a match is found.</SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2>Perhaps another missing detail is that the return value of a function is
the result of the last expression. In the case of fac(1), it's the number
1.</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff size=2>Also
from the above course:</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007>
<H2><A name=evaluation>Evaluation example</A></H2><PRE> factorial(0) -> 1;
factorial(N) ->
N * factorial(N-1)
</PRE><PRE> > factorial(3)
matches N = 3 in clause 2
== 3 * factorial(3 - 1)
== 3 * factorial(2)
matches N =2 in clause 2
== 3 * 2 * factorial(2 - 1)
== 3 * 2 * factorial(1)
matches N = 1 in clause 2
== 3 * 2 * 1 * factorial(1 - 1)
== 3 * 2 * 1 * factorial(0)
== 3 * 2 * 1 * 1 (clause 1)
== 6
</PRE></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff
size=2>BR,</FONT></SPAN></DIV>
<DIV><SPAN class=425160518-19012007><FONT face=Arial color=#0000ff size=2>Ulf
W</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> erlang-questions-bounces@erlang.org
[mailto:erlang-questions-bounces@erlang.org] <B>On Behalf Of
</B>LUKE<BR><B>Sent:</B> den 19 januari 2007 16:36<BR><B>To:</B>
erlang-questions@erlang.org<BR><B>Subject:</B> [erlang-questions] Can not
understand the example.<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV>-module(tut1).<BR>-export([fac/1]).<BR><BR>fac(1)
-><BR> 1;<BR>fac(N) -><BR> N * fac(N
- 1).<BR><FONT size=2>==================================</FONT></DIV>
<DIV><FONT size=2>How can i know the function will STOP at N=1?</FONT></DIV>
<DIV><FONT size=2>
<DIV><FONT
size=2>===================================</FONT></DIV></FONT></DIV>
<DIV>-module(tut4).<BR><BR>-export([list_length/1]).<BR><BR>list_length([])
-><BR> 0; <BR>list_length([First |
Rest]) -><BR> 1 + list_length(Rest).<BR>
<DIV><FONT size=2>===================================</FONT></DIV>
<DIV><FONT size=2>How can i know the loop will stop when First=[
]?</FONT></DIV></DIV>
<DIV><FONT size=2>===================================</FONT></DIV>
<DIV><FONT size=2>How to explain theses code?</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>In perl:</FONT></DIV>
<DIV><FONT size=2>for (my $i=0;$i<=10;$i++){</FONT></DIV>
<DIV><FONT size=2>....</FONT></DIV>
<DIV><FONT size=2>}</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>It is very clear the process will stop when $i >
10.</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV></BLOCKQUOTE></BODY></HTML>