[erlang-questions] Can not understand the example.

LUKE luke@REDACTED
Fri Jan 19 16:35:32 CET 2007


-module(tut1).
-export([fac/1]).

fac(1) ->
    1;
fac(N) ->
    N * fac(N - 1).
==================================
How can i know the function will STOP at N=1?
===================================
-module(tut4).

-export([list_length/1]).

list_length([]) ->
    0;    
list_length([First | Rest]) ->
    1 + list_length(Rest).

===================================
How can i know the loop will stop when First=[ ]?
===================================
How to explain theses code?

In perl:
for (my $i=0;$i<=10;$i++){
....
}

It is very clear the process will stop when $i > 10.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070119/649def9b/attachment.htm>


More information about the erlang-questions mailing list