Noob - Getting Started Infinte Loop?

fbg111 <>
Wed Aug 30 13:06:31 CEST 2006


Hi all, I'm an Erlang noob working through the getting started material at
erlang.org, and I have a question about a problem that's occuring with my
code.  If this isn't the appropriate place for this question, my apologies
for wasting the bandwidth, please point me in the right direction. 
Otherwise, running the function listlen([1,2,...n]) crashes the Erlang
emulator in WinXP.  However, I can't see the difference b/t my code and the
example code:

http://erlang.org/doc/doc-5.5/doc/getting_started/seq_prog.html#2.5 Example
code: 


> The following example shows how we find the length of a list: 
> 
> -module(tut4).
> -export([list_length/1]).
> 
> list_length([]) ->
>     0;    
> list_length([First | Rest]) ->
>     1 + list_length(Rest).
> 
> Compile (file tut4.erl) and test: 
> 29> c(tut4).
> {ok,tut4}
> 30> tut4:list_length([1,2,3,4,5,6,7]).
> 7
> 

My code:


> -module(tut).
> -export([double/1,fac/1,mult/2,convert/1,conv/2,listlen/1]).
> 
> double(X) -> 2 * X.
> fac(0) -> 1;
> fac(N) -> N * fac(N-1).
> mult(X,Y) -> X*Y.
> conv(M,toInch) -> M/2.54;
> conv(N,toCentimeter) -> N*2.54.
> convert({M,centimeters}) -> {M/2.54,inches};
> convert({M,inches}) -> {M*2.54,centimeters}.
> listlen([]) -> 0;
> listlen([First|TheRest]) -> 1 + listlen([TheRest]).
> 

And the result of running my code:


> Erlang (BEAM) emulator version 5.5 [async-threads:0]
> 
> Eshell V5.5  (abort with ^G)
> 1> c(tut).
> ./tut.erl:13: Warning: variable 'First' is unused
> {ok,tut}
> 2> tut:listlen([]).
> 0
> 3> tut:listlen([1,2]).
> 
> Crash dump was written to: erl_crash.dump
> eheap_alloc: Cannot allocate 583848200 bytes of memory (of type "heap").
> 
> Abnormal termination
> 

Windows Task Manager confirms the process werl is trying to use 581MB of
RAM.  Before I tried to run this, Task Manager showed 821MB RAM in use, out
of 1GB.  Is this a problem with my code, or with my memory useage?  Any
suggestions about what I'm doing wrong?  Thanks,

Byron
-- 
View this message in context: http://www.nabble.com/Noob---Getting-Started-Infinte-Loop--tf2189189.html#a6056733
Sent from the Erlang Questions forum at Nabble.com.




More information about the erlang-questions mailing list