<?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: Chaining vs. Nesting</title>
	<atom:link href="http://frankschmitt.org/2010/01/chaining-v-nesting/feed" rel="self" type="application/rss+xml" />
	<link>http://frankschmitt.org/2010/01/chaining-v-nesting</link>
	<description>Information, projects</description>
	<lastBuildDate>Sun, 11 Mar 2012 22:37:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Okke</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29970</link>
		<dc:creator>Okke</dc:creator>
		<pubDate>Wed, 20 Jan 2010 21:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29970</guid>
		<description>&lt;p&gt;I think matlab works around explicit branches quite nicely.&lt;/p&gt;

&lt;p&gt;Matlab is  used for working with matrixes (MATrix LABoratory), and instead of looping through the whole matrix, one can specify a condition on the elements of the matrix and then perform a calculation only on these elements:&lt;/p&gt;

&lt;p&gt;x = [1 2 3];
x(x =&lt; 2) = 0;&lt;/p&gt;

&lt;p&gt;would produce a new matrix (&#039;list&#039;) with elements [0 0 3].&lt;/p&gt;

&lt;p&gt;As you see, this syntax does not explicitly use an if at all. A kind of selector is used instead.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I think matlab works around explicit branches quite nicely.</p>

<p>Matlab is  used for working with matrixes (MATrix LABoratory), and instead of looping through the whole matrix, one can specify a condition on the elements of the matrix and then perform a calculation only on these elements:</p>

<p>x = [1 2 3];
x(x =&lt; 2) = 0;</p>

<p>would produce a new matrix (&#8216;list&#8217;) with elements [0 0 3].</p>

<p>As you see, this syntax does not explicitly use an if at all. A kind of selector is used instead.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: must_submit_this_pic</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29968</link>
		<dc:creator>must_submit_this_pic</dc:creator>
		<pubDate>Wed, 20 Jan 2010 18:43:59 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29968</guid>
		<description>&lt;p&gt;netstat -n 
&#124; grep tcp 
&#124; awk &#039;{ print $5}&#039; 
&#124; sort 
&#124; uniq -c 
&#124; sort -n&lt;/p&gt;

&lt;p&gt;in LINQ, assuming some a function netstat exists, this becomes something like&lt;/p&gt;

&lt;p&gt;nestat(resolve=false)
.Where(line =&gt; line.Contains(&quot;tcp&quot;))
.Select(line =&gt; line.Split(&quot; &quot;)[5])
.Distinct()
.Select(ip =&gt; new { 
  IP=ip,
  Octets=ip
    .Split(&quot;.&quot;)
    .Select(int.Parse)
    .ToArray() })
.OrderBy(t =&gt; t.Octets[3])
.OrderBy(t =&gt; t.Octets[2])
.OrderBy(t =&gt; t.Octets[1])
.OrderBy(t =&gt; t.Octets[0])
.Select(t =&gt; t.IP)&lt;/p&gt;

&lt;p&gt;I&#039;m guessing this will look totally unreadable, so I&#039;ll leave a readable version over at reddit where I found this.&lt;/p&gt;

&lt;p&gt;See http://www.reddit.com/r/programming/comments/arsu8/chaining_vs_nesting/.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>netstat -n 
| grep tcp 
| awk &#8216;{ print $5}&#8217; 
| sort 
| uniq -c 
| sort -n</p>

<p>in LINQ, assuming some a function netstat exists, this becomes something like</p>

<p>nestat(resolve=false)
.Where(line =&gt; line.Contains(&#8220;tcp&#8221;))
.Select(line =&gt; line.Split(&#8221; &#8220;)[5])
.Distinct()
.Select(ip =&gt; new { 
  IP=ip,
  Octets=ip
    .Split(&#8220;.&#8221;)
    .Select(int.Parse)
    .ToArray() })
.OrderBy(t =&gt; t.Octets[3])
.OrderBy(t =&gt; t.Octets[2])
.OrderBy(t =&gt; t.Octets[1])
.OrderBy(t =&gt; t.Octets[0])
.Select(t =&gt; t.IP)</p>

<p>I&#8217;m guessing this will look totally unreadable, so I&#8217;ll leave a readable version over at reddit where I found this.</p>

<p>See <a href="http://www.reddit.com/r/programming/comments/arsu8/chaining_vs_nesting/." rel="nofollow">http://www.reddit.com/r/programming/comments/arsu8/chaining_vs_nesting/.</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Lee Smith</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29962</link>
		<dc:creator>Mark Lee Smith</dc:creator>
		<pubDate>Wed, 20 Jan 2010 11:25:26 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29962</guid>
		<description>&lt;p&gt;@mvm&lt;/p&gt;

&lt;p&gt;You may be interested to know that this isn&#039;t remotely unique to Haskell, or functional programming.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@mvm</p>

<p>You may be interested to know that this isn&#8217;t remotely unique to Haskell, or functional programming.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Lee Smith</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29961</link>
		<dc:creator>Mark Lee Smith</dc:creator>
		<pubDate>Wed, 20 Jan 2010 11:04:38 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29961</guid>
		<description>&lt;p&gt;You should look at Smalltalk or some related language where If is commonly written as like so:&lt;/p&gt;

&lt;p&gt;price &gt; 50 ifTrue: [ &quot;expensive&quot; ] ifFalse: [ &quot;cheap&quot; ].&lt;/p&gt;

&lt;p&gt;This could of course be simplified to the following with suitable semantics:&lt;/p&gt;

&lt;p&gt;(price &gt; 50) then: &quot;expensive&quot; else: &quot;cheap&quot;.&lt;/p&gt;

&lt;p&gt;Which I think reads perfectly well.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You should look at Smalltalk or some related language where If is commonly written as like so:</p>

<p>price &gt; 50 ifTrue: [ "expensive" ] ifFalse: [ "cheap" ].</p>

<p>This could of course be simplified to the following with suitable semantics:</p>

<p>(price &gt; 50) then: &#8220;expensive&#8221; else: &#8220;cheap&#8221;.</p>

<p>Which I think reads perfectly well.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jimmy</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29957</link>
		<dc:creator>jimmy</dc:creator>
		<pubDate>Wed, 20 Jan 2010 07:52:21 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29957</guid>
		<description>&lt;p&gt;Smalltalk defined if as methods on the True and False objects.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Smalltalk defined if as methods on the True and False objects.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Edward Kmett</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29956</link>
		<dc:creator>Edward Kmett</dc:creator>
		<pubDate>Wed, 20 Jan 2010 07:47:08 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29956</guid>
		<description>&lt;p&gt;Then there is the Haskell version:&lt;/p&gt;

&lt;p&gt;mapM_ (putStrLn . show) . nub . sort . awk 5 $ filter &quot;tcp&quot; netstat_n&lt;/p&gt;

&lt;p&gt;No pollution of the intervening classes, no syntactic noise from parentheses.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Then there is the Haskell version:</p>

<p>mapM_ (putStrLn . show) . nub . sort . awk 5 $ filter &#8220;tcp&#8221; netstat_n</p>

<p>No pollution of the intervening classes, no syntactic noise from parentheses.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Haley</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29955</link>
		<dc:creator>Matt Haley</dc:creator>
		<pubDate>Wed, 20 Jan 2010 07:46:41 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29955</guid>
		<description>&lt;p&gt;I thought the idea of implementing Array#if in Ruby would be interesting. Turned out to be ridiculously simple.&lt;/p&gt;

&lt;p&gt;class Array
  def if(predicate)
    predicate ? self.first : self.last
  end
end&lt;/p&gt;

&lt;p&gt;http://gist.github.com/281687&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I thought the idea of implementing Array#if in Ruby would be interesting. Turned out to be ridiculously simple.</p>

<p>class Array
  def if(predicate)
    predicate ? self.first : self.last
  end
end</p>

<p><a href="http://gist.github.com/281687" rel="nofollow">http://gist.github.com/281687</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: masklinn</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29954</link>
		<dc:creator>masklinn</dc:creator>
		<pubDate>Wed, 20 Jan 2010 07:31:22 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29954</guid>
		<description>&lt;blockquote&gt;
  &lt;p&gt;You could introduce a new syntax, for instance using a comma to separate two inputs that should be directed to a single consumer&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;this thing is utterly terrible, and Smalltalk solved the problem of expressing conditionals via means of method dispatch some 30 years ago:&lt;/p&gt;

&lt;p&gt;(price &gt; 50) ifTrue:[&#039;expensive&#039;] ifFalse:[&#039;cheap&#039;]&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;It would make more sense to have if be a method on a boolean expression, but I can’t think of a clean way to encode that without having a clean way to feed a function multiple inputs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;you know it&#039;s possible to give a function more than one parameter don&#039;t you?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote>
  <p>You could introduce a new syntax, for instance using a comma to separate two inputs that should be directed to a single consumer</p>
</blockquote>

<p>this thing is utterly terrible, and Smalltalk solved the problem of expressing conditionals via means of method dispatch some 30 years ago:</p>

<p>(price &gt; 50) ifTrue:['expensive'] ifFalse:['cheap']</p>

<blockquote>
  <p>It would make more sense to have if be a method on a boolean expression, but I can’t think of a clean way to encode that without having a clean way to feed a function multiple inputs.</p>
</blockquote>

<p>you know it&#8217;s possible to give a function more than one parameter don&#8217;t you?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29896</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Sun, 17 Jan 2010 08:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29896</guid>
		<description>&lt;p&gt;Clojure has the &#039;thread&#039; macro.&lt;/p&gt;

&lt;p&gt;Your example:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;(print (sort_n (uniq_c (sort (awk (grep (netstat_n) &quot;tcp&quot;) 5)))))
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;can be written something like&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;&lt;code&gt;(-&gt; (netstat_n) (grep &quot;tcp&quot;) (awk &quot;5&quot;) sort uniq_c sort_n print)
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;... you&#039;re &quot;threading&quot; the first form through the remaining forms.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Clojure has the &#8216;thread&#8217; macro.</p>

<p>Your example:</p>

<p><pre><code>(print (sort_n (uniq_c (sort (awk (grep (netstat_n) "tcp") 5)))))
</code></pre></p>

<p>can be written something like</p>

<p><pre><code>(-&gt; (netstat_n) (grep "tcp") (awk "5") sort uniq_c sort_n print)
</code></pre></p>

<p>&#8230; you&#8217;re &#8220;threading&#8221; the first form through the remaining forms.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: rflrob</title>
		<link>http://frankschmitt.org/2010/01/chaining-v-nesting/comment-page-1#comment-29883</link>
		<dc:creator>rflrob</dc:creator>
		<pubDate>Sat, 16 Jan 2010 23:15:10 +0000</pubDate>
		<guid isPermaLink="false">http://frankschmitt.org/?p=99#comment-29883</guid>
		<description>&lt;p&gt;In python, you could actually do something like the last format with very little change:
(&#039;cheap&#039;, &#039;expensive&#039;)[price &gt; 50] is perfectly valid---if fairly weird---code.  The trick, of course, is that you can index the literal tuple (&#039;cheap&#039;, &#039;expensive&#039;), and that the True/False gets converted to 1/0.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>In python, you could actually do something like the last format with very little change:
(&#8216;cheap&#8217;, &#8216;expensive&#8217;)[price &gt; 50] is perfectly valid&#8212;if fairly weird&#8212;code.  The trick, of course, is that you can index the literal tuple (&#8216;cheap&#8217;, &#8216;expensive&#8217;), and that the True/False gets converted to 1/0.</p>]]></content:encoded>
	</item>
</channel>
</rss>

