<?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: SICP sections 4.1.6 - 4.1.7</title>
	<atom:link href="http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/</link>
	<description>Eli Bendersky's personal website</description>
	<pubDate>Fri, 21 Nov 2008 18:45:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Sigrid</title>
		<link>http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-134207</link>
		<dc:creator>Sigrid</dc:creator>
		<pubDate>Wed, 15 Oct 2008 19:24:23 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-134207</guid>
		<description>Hi Eli,
thanks again for publishing your solutions and very helpful analyses.Regarding exercise 4.20, I would also assume that substituting letrec with let, e.g.

`&lt;code&gt;((lambda (even? odd?) (even? 7)) (lambda (n) (if (= n 0) #t (odd? (- n 1)))) (lambda (n) (if (= n 0) #f (even? (- n 1)))))&lt;/code&gt;`

should not work - I imagine the environment like this:
The outer lambda is evaluated in the global environment, then it is applied in an environment E1, and for that it's arguments are evaluated, also in the global environment, i.e.the new procedures are created in the global environment. So, the variables odd? and even? in E1 point to these  newly created procedures. Now when I apply even?, a new frame E2 is constructed not from E1, but from the global environment. In this new frame, odd? should not be known, so I should get an error.

However, the above code works - I wonder why? I wonder if my environment sketch is wrong (or might it be an implementation feature of PLT scheme?)

best greetings,
Sigrid</description>
		<content:encoded><![CDATA[<p>Hi Eli,<br />
thanks again for publishing your solutions and very helpful analyses.Regarding exercise 4.20, I would also assume that substituting letrec with let, e.g.</p>
<div class="backtick"><pre><code>((lambda (even? odd?) (even? 7)) (lambda (n) (if (= n 0) #t (odd? (- n 1)))) (lambda (n) (if (= n 0) #f (even? (- n 1)))))</code></pre></div>
<p>should not work - I imagine the environment like this:<br />
The outer lambda is evaluated in the global environment, then it is applied in an environment E1, and for that it&#8217;s arguments are evaluated, also in the global environment, i.e.the new procedures are created in the global environment. So, the variables odd? and even? in E1 point to these  newly created procedures. Now when I apply even?, a new frame E2 is constructed not from E1, but from the global environment. In this new frame, odd? should not be known, so I should get an error.</p>
<p>However, the above code works - I wonder why? I wonder if my environment sketch is wrong (or might it be an implementation feature of PLT scheme?)</p>
<p>best greetings,<br />
Sigrid</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-106616</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Tue, 05 Feb 2008 16:23:58 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-106616</guid>
		<description>Yes, but in my &lt;tt&gt;dolist&lt;/tt&gt; loop I can push to both lists, without traversing the body twice.</description>
		<content:encoded><![CDATA[<p>Yes, but in my <tt>dolist</tt> loop I can push to both lists, without traversing the body twice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flávio Cruz</title>
		<link>http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-106147</link>
		<dc:creator>Flávio Cruz</dc:creator>
		<pubDate>Mon, 04 Feb 2008 19:10:53 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/14/sicp-sections-416-417/#comment-106147</guid>
		<description>In exercise 4.16, "defines" and "non-defines" could be better built using filter, eg:


(define (scan-out-defines proc)
  
  (define (create-defs define)
    (list (definition-variable define)
          '*unassigned*))
  
  (define (create-sets define)
    (list 'set! (definition-variable define) (definition-value define)))
  
  (let ((defs (filter definition? proc)))
    (if (

This way, we avoid reversing the lists, later on.</description>
		<content:encoded><![CDATA[<p>In exercise 4.16, &#8220;defines&#8221; and &#8220;non-defines&#8221; could be better built using filter, eg:</p>
<p>(define (scan-out-defines proc)</p>
<p>  (define (create-defs define)<br />
    (list (definition-variable define)<br />
          &#8216;*unassigned*))</p>
<p>  (define (create-sets define)<br />
    (list &#8217;set! (definition-variable define) (definition-value define)))</p>
<p>  (let ((defs (filter definition? proc)))<br />
    (if (</p>
<p>This way, we avoid reversing the lists, later on.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
