<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.11" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Scheme object systems: POS</title>
	<link>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/</link>
	<description>Scheme, web applications, tech</description>
	<pubDate>Wed, 19 Nov 2008 01:54:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.11</generator>

	<item>
		<title>by: Dan Muresan</title>
		<link>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-538</link>
		<pubDate>Tue, 01 May 2007 20:07:47 +0000</pubDate>
		<guid>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-538</guid>
					<description>Thanks for the comments, Graham and Pascal. I conjecture that with-slots and with-accessors are implemented using the technique described by Graham. I've implemented a similar with-* macro in Scheme a while ago:

&lt;pre&gt;&lt;code&gt;(define-syntax with-hash-table
  (syntax-rules ()
    ((_ ht (var ...) body ...)
     (let ((var (hash-table-ref ht 'var)) ...)  ;; let == lambda
       (define result (begin body ...))
       (hash-table-set! ht 'var var) ...  ;; final step: update ht
       result))))&lt;/code&gt;&lt;/pre&gt;

One caveat: the original method works fine for implementing accessors. However, we need an extra step to implement modifiers, since instance variables are only copied (passed by value) to lambda arguments. In this final step (see code above), the lambda arguments are copied back to the instance variables. But, of course, this final step can interact badly with any call/cc and dynamic-wind calls in the method body.</description>
		<content:encoded><![CDATA[<p>Thanks for the comments, Graham and Pascal. I conjecture that with-slots and with-accessors are implemented using the technique described by Graham. I&#8217;ve implemented a similar with-* macro in Scheme a while ago:</p>
<pre><code>(define-syntax with-hash-table
  (syntax-rules ()
    ((_ ht (var ...) body ...)
     (let ((var (hash-table-ref ht 'var)) ...)  ;; let == lambda
       (define result (begin body ...))
       (hash-table-set! ht 'var var) ...  ;; final step: update ht
       result))))</code></pre>
<p>One caveat: the original method works fine for implementing accessors. However, we need an extra step to implement modifiers, since instance variables are only copied (passed by value) to lambda arguments. In this final step (see code above), the lambda arguments are copied back to the instance variables. But, of course, this final step can interact badly with any call/cc and dynamic-wind calls in the method body.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Graham</title>
		<link>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-537</link>
		<pubDate>Tue, 01 May 2007 13:17:37 +0000</pubDate>
		<guid>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-537</guid>
					<description>It's not impossible to inject code into a closure; you can pass in lambdas which can be stored, for example, in a class-wide a-list; this would be searched after all static methods have been exhausted. The trick is that the lambdas must take an argument list matching all the variables that are bound within the object's closure, e.g.

&lt;pre&gt;&lt;code&gt;(add-method-to Rect get-perimeter
 (lambda (top left bottom right)
   (* 2 (+ (- right left) (- bottom top)))))&lt;/code&gt;&lt;/pre&gt;

Then have the Rect object "call" the lambda with the appropriate arguments if this method is selected. (This does imply that the list of attributes (bound variables) is fixed at class-definition time.) 

Perhaps you could define some syntax when Rect is defined, e.g. "add-method-to-Rect", which would expand to an expression like the one above, but would be simpler to write:

&lt;pre&gt;&lt;code&gt;(add-method-to-Rect get-perimeter  ; where add-method-to-Rect is syntax...
  (* 2 (+ (- right left) (- bottom top))))&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>It&#8217;s not impossible to inject code into a closure; you can pass in lambdas which can be stored, for example, in a class-wide a-list; this would be searched after all static methods have been exhausted. The trick is that the lambdas must take an argument list matching all the variables that are bound within the object&#8217;s closure, e.g.</p>
<pre><code>(add-method-to Rect get-perimeter
 (lambda (top left bottom right)
   (* 2 (+ (- right left) (- bottom top)))))</code></pre>
<p>Then have the Rect object &#8220;call&#8221; the lambda with the appropriate arguments if this method is selected. (This does imply that the list of attributes (bound variables) is fixed at class-definition time.) </p>
<p>Perhaps you could define some syntax when Rect is defined, e.g. &#8220;add-method-to-Rect&#8221;, which would expand to an expression like the one above, but would be simpler to write:</p>
<pre><code>(add-method-to-Rect get-perimeter  ; where add-method-to-Rect is syntax...
  (* 2 (+ (- right left) (- bottom top))))</code></pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Pascal Costanza</title>
		<link>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-535</link>
		<pubDate>Tue, 01 May 2007 11:29:54 +0000</pubDate>
		<guid>http://www.omnigia.com/news/2007/04/30/scheme-object-systems-pos/#comment-535</guid>
					<description>CLOS (for Common Lisp) has two forms with-slots and with-accessors that give you a similar expressiveness to a certain degree. With those forms, you can write this:

&lt;pre&gt;&lt;code&gt;(defmethod area ((rect rect))
  (with-slots (top bottom right left) rect
     (* (- top bottom) (- right left))))&lt;/code&gt;&lt;/pre&gt;

It's a bit tedious to have to reintroduce the variable names, but for longer methods this doesn't matter that much. On the plus side, you can introduce variable names for slots from several objects within the same method.

See http://www.lispworks.com/documentation/HyperSpec/Body/m_w_slts.htm and http://www.lispworks.com/documentation/HyperSpec/Body/m_w_acce.htm for more examples.

With the introduction of identifier macros in R6RS, it should be a piece of cake to introduce something similar for any object system in Scheme.</description>
		<content:encoded><![CDATA[<p>CLOS (for Common Lisp) has two forms with-slots and with-accessors that give you a similar expressiveness to a certain degree. With those forms, you can write this:</p>
<pre><code>(defmethod area ((rect rect))
  (with-slots (top bottom right left) rect
     (* (- top bottom) (- right left))))</code></pre>
<p>It&#8217;s a bit tedious to have to reintroduce the variable names, but for longer methods this doesn&#8217;t matter that much. On the plus side, you can introduce variable names for slots from several objects within the same method.</p>
<p>See <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_w_slts.htm" rel="nofollow">http://www.lispworks.com/documentation/HyperSpec/Body/m_w_slts.htm</a> and <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_w_acce.htm" rel="nofollow">http://www.lispworks.com/documentation/HyperSpec/Body/m_w_acce.htm</a> for more examples.</p>
<p>With the introduction of identifier macros in R6RS, it should be a piece of cake to introduce something similar for any object system in Scheme.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
