<br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 2:04 AM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div>

<div><br></div></div></div></div></blockquote></div></div><div>You could do something analogous with messages and methods an d have the Vm associate the receiver with the activation in... a message send :)</div>
<div>If you had a dictionary that cached translations form short forms of selectors, e.g. myJSFunc:with: -&gt; myJSFunc:with:with: then your code might look something like</div><div class="im"><div><br></div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>

doesNotUnderstand: aMessage</div><div><span style="white-space:pre">        </span>&quot;Generic catch all that performs all selectors&quot;</div></span><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;white-space:pre">        </span>(self can: aMessage selector) ifTrue:</div>

</div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;white-space:pre">                <span style="border-collapse:separate;font-family:arial;font-size:small;white-space:normal">[actualSelector := self s: aMessage selector.</span></span></div>

<div><span style="font-family:arial, sans-serif;border-collapse:collapse;white-space:pre"></span></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;white-space:pre">                 ^<span style="border-collapse:separate;font-family:arial;font-size:small;white-space:normal">self perform: actualSelector</span></span></div>

<div><span style="font-family:arial, sans-serif;border-collapse:collapse;white-space:pre"></span></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse;white-space:pre">                        <span style="border-collapse:separate;font-size:small;white-space:normal">withArguments: (aMessage arguments, (Array new: actualSelector numArgs - aMessage selector numArgs))]</span></span></div>

<div><span style="font-family:arial, sans-serif;border-collapse:collapse;white-space:pre"></span></div><div><br></div><div>Would this be better? </div></div></blockquote></div><br>Well it it had a prayer of working :)  Here&#39;s a little backstory.  The way this object works is it inherits from IdentityDictionary has two accessor methods:<div>
<br></div><div>has: aProperty of: aValue</div><div>        &quot; This corresponds to object.property = value and object[&#39;property&#39;] = value&quot;</div><div>        self at: aProperty put: aValue.</div><div>        ^ self.</div>
<div><br></div><div>and</div><div><br></div><div>s: aProperty</div><div>       &quot; This corresponds to object.property and object[&#39;property&#39;]&quot;</div><div>       ^ self at: aProperty ifAbsent: [^ nil ].<br clear="all">
<br></div><div>For a very limited sets of methods such as these, the ones that can not be overridden by end user code, these fields are accessed by doing a message</div><div>send to the object, and the dNU routine determines which route to return based on the method can:</div>
<div><br></div><div>can: aSymbol</div><div>     &quot; This corresponds to the javascript:  Object.prototype.can = function(k) { return this.hasOwnProperty(k) &amp;&amp; typeof(this[k]) == &#39;function&#39; }&quot;</div>
<div>     ^ ( self s: aSymbol ) isBlock.</div><div><br></div><div>What happens in most of the code is objects generate block closures which they then set as the values of other object&#39;s properties. The code ends up looking like this toy example:</div>
<div>----</div><div><div>(An object named: #Casper) has: #greets: of: [ :x | Transcript show: &#39;Hi &#39;, x name , &#39;! My name is &#39;, self name; cr].</div><div>(An object named: #George) from: Casper.</div><div><br>
</div><div>Casper greets: George.</div><div>George greets: Casper.</div><div><br></div><div>Casper has: #greets: of: [ :x | Transcript show: &#39;Goodbye &#39;, x name; cr]</div></div><div><br></div><div>Casper greets: George.</div>
<div>George greets: Casper.</div><div>----</div><div><br></div><div>And the Transcript then reads:</div><div>----</div><div><div>Hi George! My name is Casper</div><div>Hi Casper! My name is George</div><div>Goodbye George</div>
<div>Hi Casper! My name is George</div></div><div>----</div><div><br></div><div>The name and named: methods actually set key value and find key by value in the Smalltalk dictionary, so they&#39;re globals as in editing Javascript&#39;s window object.</div>
<div><br></div><div>But as you see, I&#39;m passing a block closure to one object, and copying it to another object, and both objects are referencing the same block closure!  I&#39;m overwriting the</div><div>original block closure&#39;s outerContext&#39;s receiver (which in this example is originally nil!), with whatever object is referencing it.  This is similar to what happens with Javascript </div>
<div>method calls, where the this variable is set by hacking the scope object at call time.  But this lets these objects respond to any message that may come their way, and usually</div><div>do the right thing.  My original dNU used the valueWithEnoughArugments: method, because it was the only way I could find to neatly get all the block closures to work in both</div>
<div>the case of over and underflow, as their equivalent functions worked in the JS version.</div><div><br></div><div>If I compile an actual method send, and dNU is not called, I then need to always compile a method every time a property is set, even if it is never executed. </div>
<div><br></div><div>In this application, objects inherit based on a shallow copy of object properties.  So you may inherit some methods using from: from one object, a bunch of others from another,</div><div>and then override some of each of those in a third.  (This scenario actually the norm not the exception btw!)  99% of the time, I want whatever the values the block closure </div>
<div>derived from its original defining context, with the sole exception of the outerContext&#39;s receiver, which is almost always wrong for my purposes.    </div><div><br></div><div>I&#39;m mostly wondering if there&#39;s a cleaner, more optimizeable way of messing around with the internals of either the resulting MethodContext or your closure objects :)</div>
<div><br></div><div>Dave</div><div><br></div><div><br></div><div>-- <br>-=-=-=-=-=-=-=-=-=-=- <a href="http://blog.dloh.org/">http://blog.dloh.org/</a><br>
</div>