<?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 section 2.5.2</title>
	<atom:link href="http://eli.thegreenplace.net/2007/09/16/sicp-section-252/feed/" rel="self" type="application/rss+xml" />
	<link>http://eli.thegreenplace.net/2007/09/16/sicp-section-252/</link>
	<description>Eli Bendersky's personal website</description>
	<pubDate>Fri, 21 Nov 2008 21:46:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: bhrgunatha</title>
		<link>http://eli.thegreenplace.net/2007/09/16/sicp-section-252/#comment-108375</link>
		<dc:creator>bhrgunatha</dc:creator>
		<pubDate>Sat, 09 Feb 2008 14:19:56 +0000</pubDate>
		<guid isPermaLink="false">http://eli.thegreenplace.net/2007/09/16/sicp-section-252/#comment-108375</guid>
		<description>Hi Eli,
Ex 2.85 - Initially I tried the same idea of just applying drop at the exit point of apply-generic, but:
a) what happens when you call apply-generic with the 'raise operator?
b) earlier on we wrote the equ? and =zero? predicates which returned a boolean value, not tagged data types and drop fails if we pass it any untagged values.


I thought of 2 ways to solve this:
1) Have a list of safe operators that drop can be applied to and test against this within apply-generic.
2) Call drop within each package. We choose in the paackage implementation which procedures results can be dropped.


I prefer the latter because it feels wrong coupling the package implementations to apply-generic so tightly.
The authors specifically mention mpdifying apply-generic as the solution so I wrote:

&lt;code&gt;
(define (apply-generic op . args)
...
...
  (define (reduce-type result)
    (if (memq op '(add sub mul div))
        (drop result)
        result))
...
...
  (if proc 
      (reduce-type (apply proc (map contents args)))
...
...
&lt;/code&gt;


Anyway thanks for posting your solutions, it's nice to check my solutions against someone else's.</description>
		<content:encoded><![CDATA[<p>Hi Eli,<br />
Ex 2.85 - Initially I tried the same idea of just applying drop at the exit point of apply-generic, but:<br />
a) what happens when you call apply-generic with the &#8216;raise operator?<br />
b) earlier on we wrote the equ? and =zero? predicates which returned a boolean value, not tagged data types and drop fails if we pass it any untagged values.</p>
<p>I thought of 2 ways to solve this:<br />
1) Have a list of safe operators that drop can be applied to and test against this within apply-generic.<br />
2) Call drop within each package. We choose in the paackage implementation which procedures results can be dropped.</p>
<p>I prefer the latter because it feels wrong coupling the package implementations to apply-generic so tightly.<br />
The authors specifically mention mpdifying apply-generic as the solution so I wrote:</p>
<p><code><br />
(define (apply-generic op . args)<br />
...<br />
...<br />
  (define (reduce-type result)<br />
    (if (memq op '(add sub mul div))<br />
        (drop result)<br />
        result))<br />
...<br />
...<br />
  (if proc<br />
      (reduce-type (apply proc (map contents args)))<br />
...<br />
...<br />
</code></p>
<p>Anyway thanks for posting your solutions, it&#8217;s nice to check my solutions against someone else&#8217;s.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
