<?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.1 - 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>
	<pubDate>Fri, 21 Nov 2008 17:45:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Michal Marczyk</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#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' 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' 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-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'm now reading 'Lisp In Small Pieces'. Hope I'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>
	<item>
		<title>By: eliben</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-102931</link>
		<dc:creator>eliben</dc:creator>
		<pubDate>Tue, 29 Jan 2008 17:34:50 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-102931</guid>
		<description>valeriy, this is an interesting question. Perhaps it's not valid to do the optimization you mention exactly for this reason ?
It would be interesting to find out the answer, maybe in the comp.lang.scheme newsgroup</description>
		<content:encoded><![CDATA[<p>valeriy, this is an interesting question. Perhaps it&#8217;s not valid to do the optimization you mention exactly for this reason ?<br />
It would be interesting to find out the answer, maybe in the comp.lang.scheme newsgroup</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: valeriy</title>
		<link>http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-102561</link>
		<dc:creator>valeriy</dc:creator>
		<pubDate>Mon, 28 Jan 2008 23:33:17 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/12/06/sicp-sections-411-412/#comment-102561</guid>
		<description>It is interesting, can you explain one thing about ex 4.1 in SICP.
I understand that solutions with let* must be correct, as well as with
two nested let's. But, in Scheme R5RS, all 'let' forms are listed as 'library syntax',
and that every form of variable binding can be expressed with 'lambda'. This:

(let ((x a)) (f x))     is      ((lambda (x) (f x)) a)

Now, if we rewrite the function with lambda's:

(define (list-of-values exps env)
  (if (no-operands? exps)
      '()
      ((lambda (x) 
	 ((lambda (y) cons x y) (list-of-values (rest-operands exps))))
       (eval (first-operand exps) env))))

We notice that both lambdas are actually closures. The problem is that R5RS does
not specify semantics of procedure creation, but only procedure application.
And, for evaluator, it would be a valid strategy to evaluate the subexpressions
of the closure which only depend on the free variables when constructing the lambdas, this could be actually a good optimization somethings.
So it basically can evaluate (list-of-values (rest-operands exps)),
when creating the outer lambda, thus, the order of evaluation would be from right to left.

I feel something is wrong with my reasoning, but I don't understand where.</description>
		<content:encoded><![CDATA[<p>It is interesting, can you explain one thing about ex 4.1 in SICP.<br />
I understand that solutions with let* must be correct, as well as with<br />
two nested let&#8217;s. But, in Scheme R5RS, all &#8216;let&#8217; forms are listed as &#8216;library syntax&#8217;,<br />
and that every form of variable binding can be expressed with &#8216;lambda&#8217;. This:</p>
<p>(let ((x a)) (f x))     is      ((lambda (x) (f x)) a)</p>
<p>Now, if we rewrite the function with lambda&#8217;s:</p>
<p>(define (list-of-values exps env)<br />
  (if (no-operands? exps)<br />
      &#8216;()<br />
      ((lambda (x)<br />
	 ((lambda (y) cons x y) (list-of-values (rest-operands exps))))<br />
       (eval (first-operand exps) env))))</p>
<p>We notice that both lambdas are actually closures. The problem is that R5RS does<br />
not specify semantics of procedure creation, but only procedure application.<br />
And, for evaluator, it would be a valid strategy to evaluate the subexpressions<br />
of the closure which only depend on the free variables when constructing the lambdas, this could be actually a good optimization somethings.<br />
So it basically can evaluate (list-of-values (rest-operands exps)),<br />
when creating the outer lambda, thus, the order of evaluation would be from right to left.</p>
<p>I feel something is wrong with my reasoning, but I don&#8217;t understand where.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
