<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Arial;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.Typed
{font-family:"Courier New";}
span.tty
{font-family:"Courier New";}
span.Name
{font-style:italic;}
span.Variable
{font-family:"Times New Roman";
font-style:italic;}
span.EmailStyle21
{font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='color:navy'>My guess is that it has to do with
the fact that the list comprehension version, </span><span style='font-family:
Consolas;color:navy'>odds_and_evens/1</span><span style='color:navy'> allocates
memory for the lists </span><span style='font-family:Consolas;color:navy'>L</span><span
style='color:navy'>, </span><span style='font-family:Consolas;color:navy'>Odds</span><span
style='color:navy'>, and </span><span style='font-family:Consolas;color:navy'>Evens</span><span
style='color:navy'> simultaneously, whereas the accumulator version, </span><span
style='font-family:Consolas;color:navy'>odds_and_evens_acc/1</span><span
style='color:navy'> only has to allocate enough memory for </span><span
style='font-family:Consolas;color:navy'>Odds</span><span style='color:navy'>, </span><span
style='font-family:Consolas;color:navy'>Evens</span><span style='color:navy'>,
and only the suffix of </span><span style='font-family:Consolas;color:navy'>L</span><span
style='color:navy'> that has not yet been processed.</span></p>
<p class=MsoNormal><span style='color:navy'> </span></p>
<p class=MsoNormal><span style='color:navy'>Just a guess.</span></p>
<p class=MsoNormal><span style='color:navy'> </span></p>
<p class=MsoNormal><span style='color:navy'>Cheers,</span></p>
<p class=MsoNormal><span style='color:navy'> </span></p>
<p class=MsoNormal><span style='color:navy'>David</span></p>
<p class=MsoNormal><span style='color:navy'> </span></p>
<div>
<div class=MsoNormal align=center style='text-align:center'>
<hr size=2 width="100%" align=center tabindex=-1>
</div>
<p class=MsoNormal><b><span style='font-family:Tahoma'>From:</span></b><span
style='font-family:Tahoma'> erlang-questions-bounces@erlang.org
[mailto:erlang-questions-bounces@erlang.org] <b>On Behalf Of </b>Shimon Cohen<br>
<b>Sent:</b> Tuesday, August 21, 2007 15:15<br>
<b>To:</b> erlang-questions@erlang.org<br>
<b>Subject:</b> [erlang-questions] Lists Comprehentions vs. Accumulators</span></p>
</div>
<p class=MsoNormal> </p>
<p class=MsoNormal>Hi<br>
<br>
My question concerning section 3.12 in Joe's "Programming Erlang":<br>
<br>
Why odd_and_evens should be less space efficient than odd_and_evens_acc ?<br>
<br>
I guess it must be somthing with tail-recursion, but can't see why <br>
List Comprehetions can't be implemented tail-recursive or even as a plain loop.<br>
<br>
Thanks,<br>
Shimon Cohen.</p>
</div>
</body>
</html>