<?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: SICP sections 4.1.1 &#8211; 4.1.2</title>
	<atom:link href="http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/</link>
	<description>Eli Bendersky's personal website</description>
	<lastBuildDate>Wed, 28 Jul 2010 12:22:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: wang zhi yong</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-223260</link>
		<dc:creator>wang zhi yong</dc:creator>
		<pubDate>Wed, 04 Nov 2009 07:48:21 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-223260</guid>
		<description>i am wonder the solution of 4.8. i change it with scheme and test the example of 4.8 in MIT Edwin, but it loops forever. 
Please give me some advise, thanks a lot!
The code is as follows:

(define (let-combination exp)
  (if (name-let? exp)
     (sequence-&gt;exp
      (list
    (list
      &#039;define
      (cons (name-let-var exp) (name-let-binding-vars exp))
      (name-let-body exp))
    (cons (name-let-var exp)
          (name-let-binding-values exp))))
     (expand-let-clauses (let-clause exp)))) ;; normal let case
    
(define (expand-let-clauses clauses)
  (newline)
  (display clauses)
  (let ((var-exp (car clauses))
         (body (cdr clauses)))
        (cons (make-lambda (map car var-exp) body) (map cadr var-exp))))

(define (let-clause exp)
  (cdr exp))
 
(define (name-let? exp) (and (not (null? (cadr exp)))
                             (not (pair? (cadr exp)))))
(define (name-let-var exp)
  (cadr exp))
(define (name-let-binding-vars exp)
  (map car (caddr exp)))
(define (name-let-binding-values exp)
  (map cadr (caddr exp)))
(define (name-let-body exp)
  (cadddr exp))</description>
		<content:encoded><![CDATA[<p>i am wonder the solution of 4.8. i change it with scheme and test the example of 4.8 in MIT Edwin, but it loops forever.<br />
Please give me some advise, thanks a lot!<br />
The code is as follows:</p>
<p>(define (let-combination exp)<br />
  (if (name-let? exp)<br />
     (sequence-&gt;exp<br />
      (list<br />
    (list<br />
      &#8216;define<br />
      (cons (name-let-var exp) (name-let-binding-vars exp))<br />
      (name-let-body exp))<br />
    (cons (name-let-var exp)<br />
          (name-let-binding-values exp))))<br />
     (expand-let-clauses (let-clause exp)))) ;; normal let case</p>
<p>(define (expand-let-clauses clauses)<br />
  (newline)<br />
  (display clauses)<br />
  (let ((var-exp (car clauses))<br />
         (body (cdr clauses)))<br />
        (cons (make-lambda (map car var-exp) body) (map cadr var-exp))))</p>
<p>(define (let-clause exp)<br />
  (cdr exp))</p>
<p>(define (name-let? exp) (and (not (null? (cadr exp)))<br />
                             (not (pair? (cadr exp)))))<br />
(define (name-let-var exp)<br />
  (cadr exp))<br />
(define (name-let-binding-vars exp)<br />
  (map car (caddr exp)))<br />
(define (name-let-binding-values exp)<br />
  (map cadr (caddr exp)))<br />
(define (name-let-body exp)<br />
  (cadddr exp))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-199217</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Wed, 26 Aug 2009 20:28:19 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-199217</guid>
		<description>Sorry, ignore my last post. I am wrong.</description>
		<content:encoded><![CDATA[<p>Sorry, ignore my last post. I am wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-199215</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Wed, 26 Aug 2009 20:23:51 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-199215</guid>
		<description>Hi,

I believe there is a small problem with your solution to problem 4. Particularly, (and) should return true and (or) should return false. However, simply calling (and) or (or) without any additional parameters will fail the tagged-list? test.

-Matthew</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I believe there is a small problem with your solution to problem 4. Particularly, (and) should return true and (or) should return false. However, simply calling (and) or (or) without any additional parameters will fail the tagged-list? test.</p>
<p>-Matthew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PShin</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-174547</link>
		<dc:creator>PShin</dc:creator>
		<pubDate>Wed, 03 Jun 2009 00:19:13 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-174547</guid>
		<description>It&#039;s possible that I may have misread your code (I&#039;m working in Scheme), but if I&#039;m correct the following code 

`&lt;code&gt;(define x 1)
(cond ((begin (set! x (+ x 1)) x) =__abENT__gt; display))&lt;/code&gt;`

would be translated to 

`&lt;code&gt;(if (begin (set! x (+ x 1)) x)
    (display (begin (set! x (+ x 1)) x))
    __abENT__#46;__abENT__#46;__abENT__#46;&lt;/code&gt;`

which would result in x being set twice.</description>
		<content:encoded><![CDATA[<p>It&#8217;s possible that I may have misread your code (I&#8217;m working in Scheme), but if I&#8217;m correct the following code </p>
<div class="backtick"><pre><code>(define x 1)
(cond ((begin (set! x (+ x 1)) x) =&gt; display))</code></pre></div>
<p>would be translated to </p>
<div class="backtick"><pre><code>(if (begin (set! x (+ x 1)) x)
    (display (begin (set! x (+ x 1)) x))
    &#46;&#46;&#46;</code></pre></div>
<p>which would result in x being set twice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-173449</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Sat, 30 May 2009 04:50:01 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-173449</guid>
		<description>@PShin,

4.5: why is it evaluated twice, in your opinion? Doesn&#039;t the assignment in let copy it?

4.6: fixed, thanks. For some reason it was already cddr when I looked at the original code - I probably found the bug and forgot to update the blog post.</description>
		<content:encoded><![CDATA[<p>@PShin,</p>
<p>4.5: why is it evaluated twice, in your opinion? Doesn&#8217;t the assignment in let copy it?</p>
<p>4.6: fixed, thanks. For some reason it was already cddr when I looked at the original code &#8211; I probably found the bug and forgot to update the blog post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PShin</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-173305</link>
		<dc:creator>PShin</dc:creator>
		<pubDate>Fri, 29 May 2009 17:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-173305</guid>
		<description>let-body procedure in Exercise 4.6 seems incorrect ...

It would return incorrect answer for following let:
`&lt;code&gt;(let ((x 1) (y 2)) (+ x y) (* x y))&lt;/code&gt;`</description>
		<content:encoded><![CDATA[<p>let-body procedure in Exercise 4.6 seems incorrect &#8230;</p>
<p>It would return incorrect answer for following let:<br />
<code class="backtick">(let ((x 1) (y 2)) (+ x y) (* x y))</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PShin</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-173291</link>
		<dc:creator>PShin</dc:creator>
		<pubDate>Fri, 29 May 2009 16:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-173291</guid>
		<description>I believe your solution to Exercise 4.5 is flawed.  Your solution causes the cond predicate to be evaluated twice.  If the predicate was purely functional, your solution would be merely inefficient, but if it contained code to change some state (as shown below), you would get an incorrect answer.

`&lt;code&gt;(define x 1)
(cond ((begin (set! x (+ x 1)) x) =__abENT__gt; display))&lt;/code&gt;`</description>
		<content:encoded><![CDATA[<p>I believe your solution to Exercise 4.5 is flawed.  Your solution causes the cond predicate to be evaluated twice.  If the predicate was purely functional, your solution would be merely inefficient, but if it contained code to change some state (as shown below), you would get an incorrect answer.</p>
<div class="backtick"><pre><code>(define x 1)
(cond ((begin (set! x (+ x 1)) x) =&gt; display))</code></pre></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giovans</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-165418</link>
		<dc:creator>Giovans</dc:creator>
		<pubDate>Thu, 09 Apr 2009 10:14:05 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-165418</guid>
		<description>Hi Eli,
         thanks for your gorgeous work here. It serves me as stimulus when I&#039;m on my way through the SICP.

I have a question: in exercise 4.8 and 4.9, it appears to me that named-let-name and while-iter procedures, are still visibles out of the scope of the named-let and the while, respectively.

Shouldn&#039;t they be enclosed whithin some sort of scope cage (a lambda expression, maybe)  in order to get hidden ?

Sorry for the English,</description>
		<content:encoded><![CDATA[<p>Hi Eli,<br />
         thanks for your gorgeous work here. It serves me as stimulus when I&#8217;m on my way through the SICP.</p>
<p>I have a question: in exercise 4.8 and 4.9, it appears to me that named-let-name and while-iter procedures, are still visibles out of the scope of the named-let and the while, respectively.</p>
<p>Shouldn&#8217;t they be enclosed whithin some sort of scope cage (a lambda expression, maybe)  in order to get hidden ?</p>
<p>Sorry for the English,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal Marczyk</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-109117</link>
		<dc:creator>Michal Marczyk</dc:creator>
		<pubDate>Mon, 11 Feb 2008 01:24:17 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-109117</guid>
		<description>It seems to me that the expressions composing the body of the lambda cannot be evaluated at the time of creation of the lambda, because in general:

(1) they may cause side effects which the user would presumably expect to take place if and when the lambda is executed (applied to a set of arguments) -- and, in general, it is hard to tell whether an expression has the potential to cause any side effects or not (it would be necessary to check any and all procedures which would be called if the expression was to be evaluated, possibly finding further procedures inside those first ones and so on...);

(2) if they reference free variables, then those variables can hold different values at the time of execution of the procedure created by the lambda form than those they held at the time of evaluation of the lambda form, in which case the new values should be used at the time of execution.

If it was actually possible to determine that a given lambda is `safe&#039; in the sense that one does not have to worry about (1) and (2) above, or any similar concerns, in its particular case -- which may be the case with very simple procedures or if we know beforehand that the environment in which the procedure will be closed has no bindings for any `un-safe&#039; constructs (no value changes for variables) -- then that would mean that we are dealing with a purely functional fragment of Lisp/Scheme and evaluation order is inconsequential anyway.

All best</description>
		<content:encoded><![CDATA[<p>It seems to me that the expressions composing the body of the lambda cannot be evaluated at the time of creation of the lambda, because in general:</p>
<p>(1) they may cause side effects which the user would presumably expect to take place if and when the lambda is executed (applied to a set of arguments) &#8212; and, in general, it is hard to tell whether an expression has the potential to cause any side effects or not (it would be necessary to check any and all procedures which would be called if the expression was to be evaluated, possibly finding further procedures inside those first ones and so on&#8230;);</p>
<p>(2) if they reference free variables, then those variables can hold different values at the time of execution of the procedure created by the lambda form than those they held at the time of evaluation of the lambda form, in which case the new values should be used at the time of execution.</p>
<p>If it was actually possible to determine that a given lambda is `safe&#8217; in the sense that one does not have to worry about (1) and (2) above, or any similar concerns, in its particular case &#8212; which may be the case with very simple procedures or if we know beforehand that the environment in which the procedure will be closed has no bindings for any `un-safe&#8217; constructs (no value changes for variables) &#8212; then that would mean that we are dealing with a purely functional fragment of Lisp/Scheme and evaluation order is inconsequential anyway.</p>
<p>All best</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: valery</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/comment-page-1/#comment-103903</link>
		<dc:creator>valery</dc:creator>
		<pubDate>Thu, 31 Jan 2008 15:06:56 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-103903</guid>
		<description>I&#039;m now reading &#039;Lisp In Small Pieces&#039;. Hope I&#039;ll understand this after I am through.</description>
		<content:encoded><![CDATA[<p>I&#8217;m now reading &#8216;Lisp In Small Pieces&#8217;. Hope I&#8217;ll understand this after I am through.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
