[erlang-questions] Preventing Recursion from Crashing Me...

David Lloyd lloy0076@REDACTED
Sun Feb 24 00:33:23 CET 2008


I rather quickly discovered that:

-module(math1).
-export([factorial/1]).

factorial(0) -> 1;
factorial(N) -> N * factorial(N-1).


...

erl
% c(math1).
% math1:factorial(1000000).

...was able to take sufficient resources that I only just managed to 
send a ctrl+alt+break (I'm running Gnome/JDS on Solaris SXCE b72 on a 
Intel Quad Core E6600 with 4Gb of memory).

Apart from not using naive fibonacci ( :P ) is there a way to prevent 
erlang from running away with such processes?

DSL



More information about the erlang-questions mailing list