<br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 2:30 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>ur original message wasn&#39;t clear on the subject) that what you do when you want to reuse one of these closures is that you copy the closure and its enclosing MethodContext (remember this is a chain and blocks could be nested) and assign the new receiver in the copy.  That&#39;s not too bad but its still very heavyweight because you&#39;re not sharing code between instances.<br>
<div class="gmail_quote"><div class="im">
<div></div></div></div></blockquote><div><br></div><div>No I actually am using the chain as is, and counting on the fact that these blocks are nested.   The only tricksy bit is</div><div>you can&#39;t actually use ^ in the BlockClosures or you run into the sender&#39;s context no longer exists error :)  I&#39;m exploiting</div>
<div>the fact that you can hard ref them, and keep the garbage collector from scavaging them.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote">
<div>But you don&#39;t need to copy the MethodDictionaries.  With the above approach they&#39;re shared/inherited.  So when a message is sent to a subinstance the lookup machinery will follow the prototype chain until it finds a method or triggers dNU. </div>
</div></blockquote><div><br></div><div>Ah that&#39;s one thing I need to explain.  There&#39;s no prototype chain!   Each object is standalone with copies of closures from 2 or more objects.  Some of those closures are actually generated on the fly, and orphaned from their original context.  Prototyping doesn&#39;t work, when you need partial inheritance from multiple objects!</div>
<div><br></div><div>For example, I have a method called &quot;which:&quot; which performs a test upon each property of an object, and returns a new</div><div>object instance with only those properties.  Often I use this to do things like take the intersection of two objects, ie inherit those properties which are common to two arbitrary parents, and then extend using a 3rd archetype.</div>
<div><br></div><div>So I actually do need to copy MethodDictionaries, as objects often alter their own and others periodically at runtime.  For example, the implementation of a method #draw may change over time, as an animation timer swaps out new</div>
<div>BlockClosures for each frame in the animation.  Some times the #down event that is dispatch to all widgets get replace based on the application state, rather than performing checks within the method.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div> In the activation self is bound to the original receiver.  The issue is hence making sure that slot layouts in subinstances match their parents so that parent methods work correctly on subinstances.  But that&#39;s not a new problem, Smalltalk does exactly that :)</div>
<div class="im">
<div></div></div></div></blockquote><div><br></div><div>Yeah, that becomes a huge problem, as I often remove slots from children that exist in the parent objects.  And since</div><div>these are ad hoc objects, there&#39;s no set relationship between parent and child.  An object may derive from one object,</div>
<div>and then at a later date, serve as reference for the object that was its parent, such as:</div><div>  </div><div>A -&gt; B -&gt; C </div><div>              &amp;D -&gt; A</div><div><br></div><div>A is now A&#39;s own great grandson.  B doesn&#39;t however derive any changes from C, as it has its own copy of each property.</div>
<div><br></div><div>The Javascript version of this code doesn&#39;t even use prototype based inheritance!  The idea behind this sort of </div><div>unstructured Object Oriented programming is &quot;object sex&quot;.    You treat each object as a stand alone entity, that</div>
<div>can swap out its genes with other objects as necessary.  So it isn&#39;t &quot;prototype&quot; based in the traditional sense, it</div><div>is more archetype based with ad hoc morphology.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div>Please keep me in the loop.  This is interesting and I&#39;m happy to review.</div></div></blockquote><div><br></div><div>Very cool, will do!</div><div><br></div><div>Dave </div></div>-- <br>
-=-=-=-=-=-=-=-=-=-=- <a href="http://blog.dloh.org/">http://blog.dloh.org/</a><br>