<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Help with anagram example' | Pragmatic Forums</title>
    <link>http://forums.pragprog.com/forums/27/topics/130</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Help with anagram example posted by Matt Youell @ Wed, 07 Nov 2007 03:15:56 -0000</title>
      <description>&lt;p&gt;After some time away I think it&amp;#8217;s more likely author perspective: Joe is an fp guy. If another fp guy saw this example he would probably yawn and move on. Similarly there are some awkward imperative examples in the book. So it&amp;#8217;s just a different &lt;span class="caps"&gt;POV&lt;/span&gt; and there are some corner cases where that difference is confusing.&lt;/p&gt;


	&lt;p&gt;Btw, I later saw a footnote in &lt;a href="http://www.amazon.com/Structure-Interpretation-Computer-Programs-Engineering/dp/0262510871/ref=pd_bbs_1/102-6883631-0706569?ie=UTF8&amp;#38;s=books&amp;#38;qid=1194405264&amp;#38;sr=8-1"&gt;&lt;span class="caps"&gt;SICP&lt;/span&gt;&lt;/a&gt; that explains that map() in Scheme works this same way with multiple lists. Perhaps if I had actually &lt;em&gt;read&lt;/em&gt; SICP maybe I would have yawned too. :)&lt;/p&gt;</description>
      <pubDate>Wed, 07 Nov 2007 03:15:56 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:130:1908</guid>
      <author>Matt Youell</author>
      <link>http://forums.pragprog.com/forums/27/topics/130</link>
    </item>
    <item>
      <title>Help with anagram example posted by Peter Miller @ Tue, 06 Nov 2007 06:34:43 -0000</title>
      <description>&lt;blockquote&gt;
		&lt;p&gt;But I&#8217;m still stuck with the problem of the syntactic sugar obscuring behavior. I don&#8217;t see how I am supposed to comprehend (pardon the pun) this behavior by looking at the code. Certainly in the future I&#8217;ll know what&#8217;s going on, hopefully. But how many people look at something like this (especially those of us from the imperative world) and just give up?&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;A good question to ask. I did not know what to expect coming out of that code until I ran it and reverse engineered how it should work. I also find the comparison to nested for loops helpful. Maybe, as you suggest, this was just a &amp;#8220;tough love&amp;#8221; approach to get us to learn on our own&amp;#8230;&lt;/p&gt;</description>
      <pubDate>Tue, 06 Nov 2007 06:34:43 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:130:1907</guid>
      <author>Peter Miller</author>
      <link>http://forums.pragprog.com/forums/27/topics/130</link>
    </item>
    <item>
      <title>Help with anagram example posted by Matt Youell @ Sun, 04 Nov 2007 04:01:13 -0000</title>
      <description>&lt;p&gt;Hi Peter.&lt;/p&gt;


	&lt;p&gt;Thanks! Your blog posts cover everything I went through last night. In fact, your last expansion is actually almost identical to what I worked out in my text editor. So unfortunately you&amp;#8217;ve gone right up to the point where I got confused. Your post did help me think more about the problem though, and I&amp;#8217;ve made good progress.&lt;/p&gt;


	&lt;p&gt;Thoughts I had tonight:&lt;/p&gt;


	&lt;p&gt;Why haven&amp;#8217;t I run into this problem with list comprehensions in other languages?&lt;/p&gt;


	&lt;p&gt;I realized that every example of list comprehensions I had seen was trivial, with a single dependent variable. I had never seen a multi-variable list comprehension before. My model for list comprehension has always been equivalent to a single foreach loop. Which isn&amp;#8217;t correct beyond trivial cases.&lt;/p&gt;


	&lt;p&gt;What does this look like in Lisp?&lt;/p&gt;


	&lt;p&gt;I don&amp;#8217;t use Lisp but it is the only functional language I&amp;#8217;ve had any exposure to. Google led me to &lt;a href="http://en.literateprograms.org/List_comprehension_(Lisp)"&gt;an article on list comprehensions&lt;/a&gt; where a complex comprehension is rewritten with nested for loops. That seems to be a model that actually works for me.&lt;/p&gt;


	&lt;p&gt;What does a multi-variable list comprehension like perms() output if you give it several explicit lists?&lt;/p&gt;


	&lt;p&gt;Sure enough, after thinking in terms of nested for loops, when I coded a simple 3 variable list comprehension in Erlang the output matched my prediction. So I feel I&amp;#8217;m back on solid footing again.&lt;/p&gt;


	&lt;p&gt;But I&amp;#8217;m still stuck with the problem of the syntactic sugar obscuring behavior. I don&amp;#8217;t see how I am supposed to comprehend (pardon the pun) this behavior by looking at the code. Certainly in the future I&amp;#8217;ll know what&amp;#8217;s going on, hopefully. But how many people look at something like this (especially those of us from the imperative world) and just give up?&lt;/p&gt;


	&lt;p&gt;I think if the recursion hadn&amp;#8217;t been in the example I probably wouldn&amp;#8217;t have stumbled so hard. An example (like you posted in your reply Peter) with two explicitly different lists would not have caused the confusion. I can&amp;#8217;t fault a tough example though. I learned a lot.&lt;/p&gt;


	&lt;p&gt;So thanks again, and sorry for the novel-length reply!!&lt;/p&gt;


	&lt;p&gt;Matt&lt;/p&gt;</description>
      <pubDate>Sun, 04 Nov 2007 04:01:13 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:130:1902</guid>
      <author>Matt Youell</author>
      <link>http://forums.pragprog.com/forums/27/topics/130</link>
    </item>
    <item>
      <title>Help with anagram example posted by Peter Miller @ Sun, 04 Nov 2007 01:02:07 -0000</title>
      <description>&lt;p&gt;Matt,&lt;/p&gt;


	&lt;p&gt;I am also learning Erlang and I blogged about the perms function, so please &lt;a href="http://blogs.claritycon.com/blogs/peter_miller/default.aspx"&gt;check it out&lt;/a&gt; and maybe that will help you understand what is going on (or at least what I think is going on).&lt;/p&gt;


	&lt;p&gt;I basically used substitution to fully expand out the function calls/recursion. Try evaluating the following in an Erlang session:&lt;/p&gt;


&lt;code&gt;[ X+Y || X &amp;lt;- [1,10,20], Y &amp;lt;- [1,2,3] ].&lt;/code&gt;

	&lt;p&gt;You will get:&lt;/p&gt;


	&lt;p&gt;[2,3,4,11,12,13,21,22,23]&lt;/p&gt;


	&lt;p&gt;So in effect, you are right that X &amp;#8220;anchors&amp;#8221; itself at 1 while Y goes through 1, 2 and 3.&lt;/p&gt;</description>
      <pubDate>Sun, 04 Nov 2007 01:02:07 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:130:1901</guid>
      <author>Peter Miller</author>
      <link>http://forums.pragprog.com/forums/27/topics/130</link>
    </item>
    <item>
      <title>Help with anagram example posted by Matt Youell @ Sat, 03 Nov 2007 20:40:44 -0000</title>
      <description>&lt;p&gt;I&amp;#8217;m having trouble understanding how the Anagram example in chapter 3 works exactly. (Page 54.) I&amp;#8217;ve run the example and it works just like in the book. So I know I&amp;#8217;m misunderstanding something. That&amp;#8217;s really bugging me because up until that point I was doing just fine with the material.&lt;/p&gt;


	&lt;p&gt;I haven&amp;#8217;t had problems in the past with understanding list comprehensions, and I&amp;#8217;m generally ok with recursion, but the combination in Erlang is confusing the heck out of me. It&amp;#8217;s even hard for me to phrase the question, so please bear with me.&lt;/p&gt;


	&lt;p&gt;When I first looked over the code I expected 3 permutations. When I saw the result was 6 permutations I was confused. It took me a long time to understand that, in the case of perms(&amp;#8220;123&amp;#8221;), the top level perms call somehow considers H as &amp;#8220;1&amp;#8221; twice while allowing the &amp;#8220;inner&amp;#8221; perms call to evaluate to emit both of it&amp;#8217;s list values for T (which will be &amp;#8220;23&amp;#8221; and &amp;#8220;32&amp;#8221;).&lt;/p&gt;


	&lt;p&gt;My question is, how does H &amp;#8220;know&amp;#8221; to stay anchored to a value of &amp;#8220;1&amp;#8221; while T takes on those two different values so that perms will eventually emit both &amp;#8220;123&amp;#8221; and &amp;#8220;132&amp;#8221;?&lt;/p&gt;


	&lt;p&gt;Am I missing something really basic, or is this as mind bending as it seems?&lt;/p&gt;


	&lt;p&gt;Thanks,&lt;/p&gt;


	&lt;p&gt;Matt&lt;/p&gt;</description>
      <pubDate>Sat, 03 Nov 2007 20:40:44 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:27:130:1899</guid>
      <author>Matt Youell</author>
      <link>http://forums.pragprog.com/forums/27/topics/130</link>
    </item>
  </channel>
</rss>
