<?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"
	>
<channel>
	<title>Comments on: Naive Programming Follow-Up</title>
	<atom:link href="http://cdiggins.com/2007/07/02/naive-programming-follow-up/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/</link>
	<description>Christopher Diggins</description>
	<pubDate>Fri, 04 Jul 2008 20:17:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: soegaard</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-533</link>
		<dc:creator>soegaard</dc:creator>
		<pubDate>Tue, 03 Jul 2007 13:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-533</guid>
		<description>Thanks for indenting the code in my comment. 

After checking with SICP I notice they have a footnote 29) which is what they would have 
written in "real" code.

Btw, I forgot a 1 in the srfi-42 version.</description>
		<content:encoded><![CDATA[<p>Thanks for indenting the code in my comment. </p>
<p>After checking with SICP I notice they have a footnote 29) which is what they would have<br />
written in &#8220;real&#8221; code.</p>
<p>Btw, I forgot a 1 in the srfi-42 version.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: will</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-532</link>
		<dc:creator>will</dc:creator>
		<pubDate>Tue, 03 Jul 2007 11:24:00 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-532</guid>
		<description>From Iverson's "The Description of Finite Sequential Processes":
&lt;blockquote&gt;A programming language is commonly characterized as problem-oriented or machine-oriented, according as it is intended mainly for the description and analysis of algorithms or for their execution.&lt;/blockquote&gt;
Where are the problem-oriented languages today? None of the languages we learn and use--even those considered "academic"--are effective tools of thought. C++, Java, Lisp, Haskell, even Cat all fall terribly short of the mark.</description>
		<content:encoded><![CDATA[<p>From Iverson&#8217;s &#8220;The Description of Finite Sequential Processes&#8221;:</p>
<blockquote><p>A programming language is commonly characterized as problem-oriented or machine-oriented, according as it is intended mainly for the description and analysis of algorithms or for their execution.</p></blockquote>
<p>Where are the problem-oriented languages today? None of the languages we learn and use&#8211;even those considered &#8220;academic&#8221;&#8211;are effective tools of thought. C++, Java, Lisp, Haskell, even Cat all fall terribly short of the mark.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: will</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-531</link>
		<dc:creator>will</dc:creator>
		<pubDate>Tue, 03 Jul 2007 10:42:04 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-531</guid>
		<description>Chris, have you read Iverson's Turing Award lecture?

I've also been struggling with this issue. Haven't connected all the dots, though.</description>
		<content:encoded><![CDATA[<p>Chris, have you read Iverson&#8217;s Turing Award lecture?</p>
<p>I&#8217;ve also been struggling with this issue. Haven&#8217;t connected all the dots, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kirit</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-530</link>
		<dc:creator>Kirit</dc:creator>
		<pubDate>Tue, 03 Jul 2007 05:42:08 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-530</guid>
		<description>The point at issue has to do with tail-call optimisation. The Scheme standard states that it must perform this in order to get O(1) memory overhead (I have an explanation of the memory overhead issues in recursive forms &lt;a href="http://www.kirit.com/Recursive%20rights%20and%20wrongs" rel="nofollow"&gt;no my web site&lt;/a&gt;).

In order to get the recursive functions into a form that the compiler can optimise they have to be given in tail recursive form which for a function like factorial involves the use of a separate accumulator argument.

Re-writing recursive algorithms into a tail recursive form can be an extremely hard challenge. I thought the power function I used as an example impossible after trying without success for a few days. Luckily somebody else knew the solution.

The compiler is basically looking for a way to remove the function call overhead by re-using the same stack frame for each step. In effect it converts the recursion into a for loop.</description>
		<content:encoded><![CDATA[<p>The point at issue has to do with tail-call optimisation. The Scheme standard states that it must perform this in order to get O(1) memory overhead (I have an explanation of the memory overhead issues in recursive forms <a href="http://www.kirit.com/Recursive%20rights%20and%20wrongs" rel="nofollow">no my web site</a>).</p>
<p>In order to get the recursive functions into a form that the compiler can optimise they have to be given in tail recursive form which for a function like factorial involves the use of a separate accumulator argument.</p>
<p>Re-writing recursive algorithms into a tail recursive form can be an extremely hard challenge. I thought the power function I used as an example impossible after trying without success for a few days. Luckily somebody else knew the solution.</p>
<p>The compiler is basically looking for a way to remove the function call overhead by re-using the same stack frame for each step. In effect it converts the recursion into a for loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cdiggins</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-529</link>
		<dc:creator>cdiggins</dc:creator>
		<pubDate>Mon, 02 Jul 2007 22:06:36 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-529</guid>
		<description>Thanks for your feedback Jens, and sharing a more idiomatic Scheme approach. Clearly I am not much of a Scheme expert. :-) 
&lt;br/&gt;&lt;br/&gt;
I actually lifted both samples directly from the SICP page I linked to.</description>
		<content:encoded><![CDATA[<p>Thanks for your feedback Jens, and sharing a more idiomatic Scheme approach. Clearly I am not much of a Scheme expert. :-) </p>
<p>I actually lifted both samples directly from the SICP page I linked to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: soegaard</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-528</link>
		<dc:creator>soegaard</dc:creator>
		<pubDate>Mon, 02 Jul 2007 21:49:33 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-528</guid>
		<description>Since factorial and fibonacci is always used in benchmarks the idiomatic names are "fact" and "fib" due to the puns.

Be that as it may, it strikes me as odd, that your original example counts down where as the last one counts up. A more natural translation into SICP-style would be:

&lt;pre&gt;&lt;code&gt;
(define (fact n)
  (define (fact-iter product n)
    (if (= n 1)
        product
        (fact-iter (* n product) (- n 1))))
  (fact-iter 1 n))&lt;/code&gt;&lt;/pre&gt;

However, I don't think SICP-style is idiomatic Scheme anymore. A much more common approach to these kinds of loops are named lets:

&lt;pre&gt;&lt;code&gt;
(define (fact n)
  (let loop ([product 1] [n n])
    (if (= n 1)
        product
        (loop (* n product) (- n 1)))))&lt;/code&gt;&lt;/pre&gt;

A srfi-42 addict as me would write:

&lt;pre&gt;&lt;code&gt;
(define (fact n)
  (product-ec (: i (+ n 1))
              i))&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Since factorial and fibonacci is always used in benchmarks the idiomatic names are &#8220;fact&#8221; and &#8220;fib&#8221; due to the puns.</p>
<p>Be that as it may, it strikes me as odd, that your original example counts down where as the last one counts up. A more natural translation into SICP-style would be:</p>
<pre><code>
(define (fact n)
  (define (fact-iter product n)
    (if (= n 1)
        product
        (fact-iter (* n product) (- n 1))))
  (fact-iter 1 n))</code></pre>
<p>However, I don&#8217;t think SICP-style is idiomatic Scheme anymore. A much more common approach to these kinds of loops are named lets:</p>
<pre><code>
(define (fact n)
  (let loop ([product 1] [n n])
    (if (= n 1)
        product
        (loop (* n product) (- n 1)))))</code></pre>
<p>A srfi-42 addict as me would write:</p>
<pre><code>
(define (fact n)
  (product-ec (: i (+ n 1))
              i))</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: cdiggins.com &#187; My Goal: Naive Programming</title>
		<link>http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-527</link>
		<dc:creator>cdiggins.com &#187; My Goal: Naive Programming</dc:creator>
		<pubDate>Mon, 02 Jul 2007 18:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://cdiggins.com/2007/07/02/naive-programming-follow-up/#comment-527</guid>
		<description>[...] make sure your language implementation can deal with it. PS: I&#8217;ve followed this up with a new post about naive programming containing some code [...]</description>
		<content:encoded><![CDATA[<p>[...] make sure your language implementation can deal with it. PS: I&#8217;ve followed this up with a new post about naive programming containing some code [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
