<?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 for Benjamin Halsted</title>
	<atom:link href="http://benjaminhalsted.com/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjaminhalsted.com</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.3.2</generator>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-7 by halzy</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/comment-page-1/#comment-601</link>
		<dc:creator>halzy</dc:creator>
		<pubDate>Wed, 09 Mar 2011 02:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=142#comment-601</guid>
		<description>I haven&#039;t made it far enough in the book to use the list comprehension. I saw it when reading through the other book, but wanted to keep with what had been taught so far in this book.</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t made it far enough in the book to use the list comprehension. I saw it when reading through the other book, but wanted to keep with what had been taught so far in this book.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-5 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>Comment on Erlang Programming Exercise: 3-5 (refactor) by Sergey Shelukhin</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/comment-page-1/#comment-588</link>
		<dc:creator>Sergey Shelukhin</dc:creator>
		<pubDate>Sun, 13 Feb 2011 21:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=136#comment-588</guid>
		<description>With restriction of using concatenate very similar function can be written:

flatten2(List) -&gt; reverse( flatten_helper(List,[]) ).
flatten_helper([],Dst) -&gt; Dst;
flatten_helper([H&#124;T],Dst) when is_list(H) -&gt; flatten_helper( concatenate([H,T]), Dst );
flatten_helper([H&#124;T],Dst) -&gt;  flatten_helper( T, [H&#124;Dst] ).

you could avoid is_list by matching [[HH&#124;HT]&#124;T] and [[]&#124;T] separately as in your example.

I am now trying to break it :)</description>
		<content:encoded><![CDATA[<p>With restriction of using concatenate very similar function can be written:</p>
<p>flatten2(List) -&gt; reverse( flatten_helper(List,[]) ).<br />
flatten_helper([],Dst) -&gt; Dst;<br />
flatten_helper([H|T],Dst) when is_list(H) -&gt; flatten_helper( concatenate([H,T]), Dst );<br />
flatten_helper([H|T],Dst) -&gt;  flatten_helper( T, [H|Dst] ).</p>
<p>you could avoid is_list by matching [[HH|HT]|T] and [[]|T] separately as in your example.</p>
<p>I am now trying to break it <img src='http://benjaminhalsted.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-5 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>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-5 (refactor) by Nate Kidwell</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/comment-page-1/#comment-547</link>
		<dc:creator>Nate Kidwell</dc:creator>
		<pubDate>Sat, 20 Nov 2010 18:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=136#comment-547</guid>
		<description>Heya-

Found your blog while doing the exercises and searching for the answer to a question I had about 3.5 (writing flatten).  Basically it says to use &quot;concatenate to solve flatten&quot; and even though I solved flatten similarly to the first way you did (my code below), I also didn&#039;t use concatenate. 

What I&#039;m OCDing on is I actually think his hint on using concatenate is wrong here, because erlang&#039;s lists are untyped (so you never know if your dealing with a list of lists (which is what concatenate takes) until you navigate it).

Regardless, great blog, and I&#039;m going to start following your solutions to his book.

************************

flatten([], Accum) -&gt;
	Accum;
flatten([H&#124;[]], Accum) -&gt;
	flatten(H, Accum);
flatten([H&#124;T], Accum) -&gt;
	flatten(H, flatten(T, Accum));
flatten(Val, Accum) -&gt;
	[Val &#124; Accum].

flatten(List)	-&gt;
	flatten(List,[]).</description>
		<content:encoded><![CDATA[<p>Heya-</p>
<p>Found your blog while doing the exercises and searching for the answer to a question I had about 3.5 (writing flatten).  Basically it says to use &#8220;concatenate to solve flatten&#8221; and even though I solved flatten similarly to the first way you did (my code below), I also didn&#8217;t use concatenate. </p>
<p>What I&#8217;m OCDing on is I actually think his hint on using concatenate is wrong here, because erlang&#8217;s lists are untyped (so you never know if your dealing with a list of lists (which is what concatenate takes) until you navigate it).</p>
<p>Regardless, great blog, and I&#8217;m going to start following your solutions to his book.</p>
<p>************************</p>
<p>flatten([], Accum) -&gt;<br />
	Accum;<br />
flatten([H|[]], Accum) -&gt;<br />
	flatten(H, Accum);<br />
flatten([H|T], Accum) -&gt;<br />
	flatten(H, flatten(T, Accum));<br />
flatten(Val, Accum) -&gt;<br />
	[Val | Accum].</p>
<p>flatten(List)	-&gt;<br />
	flatten(List,[]).</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-7 by Andy</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/comment-page-1/#comment-531</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 14 Sep 2010 21:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=142#comment-531</guid>
		<description>&quot;case&quot; in match/2 can be omitted:

match(Element, Db) -&gt;
	lists:filter(fun({_, E}) -&gt; E =:= Element end, Db).

but original exercise required that match/2 returns list of keys, not list of tuples, so it could look like:

match(Element, Db) -&gt;
	MatchedTuples = lists:filter(fun({_, E}) -&gt; E =:= Element end, Db),
	element(1, lists:unzip(MatchedTuples)).

But this is rather too complicated. Using list comprehension gives us a simpler version:

match(Element, Db) -&gt;
	[Key &#124;&#124; {Key, E} &lt;- Db, E =:= Element].</description>
		<content:encoded><![CDATA[<p>&#8220;case&#8221; in match/2 can be omitted:</p>
<p>match(Element, Db) -&gt;<br />
	lists:filter(fun({_, E}) -&gt; E =:= Element end, Db).</p>
<p>but original exercise required that match/2 returns list of keys, not list of tuples, so it could look like:</p>
<p>match(Element, Db) -&gt;<br />
	MatchedTuples = lists:filter(fun({_, E}) -&gt; E =:= Element end, Db),<br />
	element(1, lists:unzip(MatchedTuples)).</p>
<p>But this is rather too complicated. Using list comprehension gives us a simpler version:</p>
<p>match(Element, Db) -&gt;<br />
	[Key || {Key, E} &lt;- Db, E =:= Element].</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-8-1 (update) by Paul Cowan</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-8-1-update/comment-page-1/#comment-474</link>
		<dc:creator>Paul Cowan</dc:creator>
		<pubDate>Fri, 04 Jun 2010 23:42:01 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=159#comment-474</guid>
		<description>I am going through the same tests right now.

Here is my parser, it does not do unary minus yet but it does double digits:

http://github.com/dagda1/erlang_sandbox/blob/master/compiler/parser.erl</description>
		<content:encoded><![CDATA[<p>I am going through the same tests right now.</p>
<p>Here is my parser, it does not do unary minus yet but it does double digits:</p>
<p><a href="http://github.com/dagda1/erlang_sandbox/blob/master/compiler/parser.erl" rel="nofollow">http://github.com/dagda1/erlang_sandbox/blob/master/compiler/parser.erl</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-4 by Erlang Programming Exercise: 5-1 &#171; Benjamin Halsted</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-4/comment-page-1/#comment-446</link>
		<dc:creator>Erlang Programming Exercise: 5-1 &#171; Benjamin Halsted</dc:creator>
		<pubDate>Fri, 21 May 2010 01:00:28 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=109#comment-446</guid>
		<description>[...] through the &quot;Programming Erlang&quot; book by Joe Armstrong I ended up doing an exercise very much like Exercise 3-4, but I made a mistake and implemented it as a server, like this exercise. It&#039;s fun to compare my [...]</description>
		<content:encoded><![CDATA[<p>[...] through the &quot;Programming Erlang&quot; book by Joe Armstrong I ended up doing an exercise very much like Exercise 3-4, but I made a mistake and implemented it as a server, like this exercise. It&#39;s fun to compare my [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-4 by Erlang Programming Exercise: 3-7 &#171; Benjamin Halsted</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-4/comment-page-1/#comment-421</link>
		<dc:creator>Erlang Programming Exercise: 3-7 &#171; Benjamin Halsted</dc:creator>
		<pubDate>Tue, 23 Mar 2010 16:58:28 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=109#comment-421</guid>
		<description>[...] this exercise we get to rewrite Exercise 3-4 using the lists module. The author asks us how much shorter the newer version is from the first [...]</description>
		<content:encoded><![CDATA[<p>[...] this exercise we get to rewrite Exercise 3-4 using the lists module. The author asks us how much shorter the newer version is from the first [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Erlang Programming Exercise: 3-6 (quicksort) by halzy</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-6-1/comment-page-1/#comment-419</link>
		<dc:creator>halzy</dc:creator>
		<pubDate>Sat, 20 Mar 2010 00:20:38 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=139#comment-419</guid>
		<description>Andrea, thank you for the link! Section 2.4 is exactly what I was seeing. It also explains the performance similarity between [H]++Acc and [H&#124;Acc]:
&quot;Or it would be more efficient if the the compiler did not automatically rewrite [H]++Acc to [H&#124;Acc].&quot;

If you get a chance, check out the book that the exercises are from:
http://www.erlangprogramming.org/

So far, I like this book better than the other ones. I&#039;ll continue to work through the exercises and post them as my schedule permits. 

Cheers,
 -Halzy</description>
		<content:encoded><![CDATA[<p>Andrea, thank you for the link! Section 2.4 is exactly what I was seeing. It also explains the performance similarity between [H]++Acc and [H|Acc]:<br />
&#8220;Or it would be more efficient if the the compiler did not automatically rewrite [H]++Acc to [H|Acc].&#8221;</p>
<p>If you get a chance, check out the book that the exercises are from:<br />
<a href="http://www.erlangprogramming.org/" rel="nofollow">http://www.erlangprogramming.org/</a></p>
<p>So far, I like this book better than the other ones. I&#8217;ll continue to work through the exercises and post them as my schedule permits. </p>
<p>Cheers,<br />
 -Halzy</p>
]]></content:encoded>
	</item>
</channel>
</rss>

