[erlang-questions] Lists Comprehentions vs. Accumulators
David Mercer
dmercer@REDACTED
Tue Aug 21 22:55:48 CEST 2007
My guess is that it has to do with the fact that the list comprehension
version, odds_and_evens/1 allocates memory for the lists L, Odds, and Evens
simultaneously, whereas the accumulator version, odds_and_evens_acc/1 only
has to allocate enough memory for Odds, Evens, and only the suffix of L that
has not yet been processed.
Just a guess.
Cheers,
David
_____
From: erlang-questions-bounces@REDACTED
[mailto:erlang-questions-bounces@REDACTED] On Behalf Of Shimon Cohen
Sent: Tuesday, August 21, 2007 15:15
To: erlang-questions@REDACTED
Subject: [erlang-questions] Lists Comprehentions vs. Accumulators
Hi
My question concerning section 3.12 in Joe's "Programming Erlang":
Why odd_and_evens should be less space efficient than odd_and_evens_acc ?
I guess it must be somthing with tail-recursion, but can't see why
List Comprehetions can't be implemented tail-recursive or even as a plain
loop.
Thanks,
Shimon Cohen.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070821/ce299a19/attachment.htm>
More information about the erlang-questions
mailing list