<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
Yes, your function fac/1 is using recursion to calculate the product of the first N natural numbers.<div><br class="webkit-block-placeholder"></div><div>Something to be worried about is if N is less than 1.<br><div><br class="webkit-block-placeholder"></div><div>When you call fac(5), you get successive calls to fac(4), fac(3), and fac(2). All 4 of these calls go to the second clause of your function (i.e. fac(N)). </div><div><br class="webkit-block-placeholder"></div><div>The final call is to fac(1) which is handled by the first clause of your function (i.e. fac(1)). This is the terminal case of your recursion.</div><div><br class="webkit-block-placeholder"></div><div><br class="webkit-block-placeholder"></div><div>Gabe</div><div><br class="webkit-block-placeholder"></div><div><br><div><div>On Aug 29, 2007, at 9:58 AM, Lone Wolf wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><font face="Verdana">Hi.</font></div> <div><font face="Verdana">Consider please this Erlang code:</font></div> <div> </div> <div><font face="Verdana" size="1">code:</font> </div> <div> <hr> </div> <blockquote><pre><font size="2"><br>fac(1) -><br> 1;<br>fac(N) -><br> N * fac(N - 1).<br></font></pre> <hr> </blockquote> <div><br>I don't understand whats happening when I call:<br>fac(5)<br>I'm not sure but it seems to me it is "Recursion", right?<br>5 * fac(4)<br>4 * fac(3)<br>3 * fac(2)<br>etc.. </div> <div>Thanks.</div><br><br><div id="RTEContent"> <div align="left"> <div align="left"><font face="georgia" color="#444f75" size="2"><strong><em>Deep into that darkness peering, long I stood there, wondering, fearing, Doubting, dreaming dreams no mortal ever dreamed before.</em></strong></font></div> <div align="center"><strong><font face="Verdana" color="#444f75"><em>E.A Poe</em></font></strong></div> <div align="center"><strong><font face="verdana" color="#444f75" size="7"><em></em></font></strong></div> <div align="left"><strong><font face="verdana" color="#444f75"><em></em></font></strong> </div></div></div><div> <br class="khtml-block-placeholder"></div><hr size="1">Boardwalk for $500? In 2007? Ha! <br><a href="http://us.rd.yahoo.com/evt=48223/*http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow">Play Monopoly Here and Now</a> (it's updated for today's economy) at Yahoo! Games.<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">erlang-questions mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a></div> </blockquote></div><br></div></div></body></html>