<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Erlang Programming Exercise: 3-5</title>
	<atom:link href="http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5/</link>
	<description>// [bgh] todo, add something clever here.</description>
	<lastBuildDate>Wed, 09 Mar 2011 02:11:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Carlo</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5/comment-page-1/#comment-598</link>
		<dc:creator>Carlo</dc:creator>
		<pubDate>Fri, 25 Feb 2011 16:44:31 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=118#comment-598</guid>
		<description>Hi, I&#039;m studying erlang too. 
My version of concatenate use only two functions, but instead, the helper has one more case:

concatenate(Lists) -&gt; 
	reverse(concatenateHelper(Lists, [])).

concatenateHelper([], Acc) -&gt; Acc;
concatenateHelper([H &#124; T], Acc) -&gt; 
	Acc2 = concatenateHelper(H, Acc),
	concatenateHelper(T, Acc2);
concatenateHelper(X, Acc) -&gt;
	[X &#124; Acc].

Thinking about flatten, I realized that this can also be used to flatten a list.

concatenate([[1,[2,[3],[]]], [[[4]]], [5,6]]).
[1,2,3,4,5,6]

Do you think that my reasoning is correct?</description>
		<content:encoded><![CDATA[<p>Hi, I&#8217;m studying erlang too.<br />
My version of concatenate use only two functions, but instead, the helper has one more case:</p>
<p>concatenate(Lists) -&gt;<br />
	reverse(concatenateHelper(Lists, [])).</p>
<p>concatenateHelper([], Acc) -&gt; Acc;<br />
concatenateHelper([H | T], Acc) -&gt;<br />
	Acc2 = concatenateHelper(H, Acc),<br />
	concatenateHelper(T, Acc2);<br />
concatenateHelper(X, Acc) -&gt;<br />
	[X | Acc].</p>
<p>Thinking about flatten, I realized that this can also be used to flatten a list.</p>
<p>concatenate([[1,[2,[3],[]]], [[[4]]], [5,6]]).<br />
[1,2,3,4,5,6]</p>
<p>Do you think that my reasoning is correct?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrei Marius</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5/comment-page-1/#comment-557</link>
		<dc:creator>Andrei Marius</dc:creator>
		<pubDate>Tue, 14 Dec 2010 17:02:53 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=118#comment-557</guid>
		<description>Hi,
Nice job with the exercises :)
My observation is that the exercise with the concatenation is not tail-recursive.
I like to see your way of resolving after I first tried on my own. 
So here is the tail-recursive version I wrote, since, probably,  a lot of people is reading your site when they get to the exercises. I have tested it with the sample from the book.

concatenate([]) -&gt;
	[];
concatenate(ListOfLists) -&gt;
	concatenate_acc(ListOfLists, []).

concatenate_acc([], ConList) -&gt;
	lists:reverse(ConList);
concatenate_acc([H&#124;T], ConList) -&gt;
	concatenate_acc(H, T, ConList).
concatenate_acc([H&#124;T], Lists, ConList) -&gt;
	concatenate_acc(T, Lists, [H&#124;ConList]);
concatenate_acc([], Lists, ConList) -&gt;
	concatenate_acc(Lists, ConList).

Andrei Marius</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Nice job with the exercises <img src='http://benjaminhalsted.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
My observation is that the exercise with the concatenation is not tail-recursive.<br />
I like to see your way of resolving after I first tried on my own.<br />
So here is the tail-recursive version I wrote, since, probably,  a lot of people is reading your site when they get to the exercises. I have tested it with the sample from the book.</p>
<p>concatenate([]) -&gt;<br />
	[];<br />
concatenate(ListOfLists) -&gt;<br />
	concatenate_acc(ListOfLists, []).</p>
<p>concatenate_acc([], ConList) -&gt;<br />
	lists:reverse(ConList);<br />
concatenate_acc([H|T], ConList) -&gt;<br />
	concatenate_acc(H, T, ConList).<br />
concatenate_acc([H|T], Lists, ConList) -&gt;<br />
	concatenate_acc(T, Lists, [H|ConList]);<br />
concatenate_acc([], Lists, ConList) -&gt;<br />
	concatenate_acc(Lists, ConList).</p>
<p>Andrei Marius</p>
]]></content:encoded>
	</item>
</channel>
</rss>

