<br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 12:55 PM, 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>Well the obvious way to clean up those closures is to pass the self reference as an argument, so</div><div><br></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>

(An object named: #Casper) has: #greets: of: [ :theSelf :x | Transcript show: &#39;Hi &#39;, x name , &#39;! My name is &#39;, theSelf name; cr].</div><div></div></span></div></div></blockquote><div><br></div><div>That&#39;s an even worse hack. :)</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><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>
<div class="im"><div>doesNotUnderstand: aMessage</div>
<div><span style="white-space:pre">        </span>&quot;Generic catch all that performs all selectors&quot;</div><div><span style="white-space:pre">        </span>(self can: aMessage selector) ifTrue:</div></div><div><span style="white-space:pre">                [<span style="white-space:normal">^( self s: aMessage selector ) valueWithEffectiveReceiver: self andEnoughArguments: aMessage arguments ].</span></span></div>

<div><span style="white-space:pre">        </span>^ self s: aMessage selector.</div><div></div></div></span></div></div></blockquote><div><br></div><div>I take it you&#39;d have to define #valueWithEffectiveReceiver:andEnoughArguments: as BlockClosure has no such beast.  If  the closure was promoted to a CompiledMethod, then I guess you could use #valueWithReceiver:arguments: and another patched Array.  Or did I miss something?</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><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>
<div><div>As regards more generic property handling I don&#39;t know of a better way than the doesNotUnderstand: handler for handling properties held in per-instance dictionaries if the constraint is that you definitely don&#39;t want to compile accessors for the property and you are using the vanilla VM. </div>
</div></div></span></div></div></blockquote><div><br></div><div>I figured the dNU approach was close enough to what Morphic did, that it was &quot;good enough&quot;.  But I was surprised how </div><div>weird the code got.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>
<div><div>But methods are cheap and so I don&#39;t see the benefit of avoiding methods in favour of blocks. </div></div></div></span></div></div></blockquote><div><br></div><div>It largely has to do with not being able to get methods to actually work :)  I originally was trying to patch in CompiledMethods but ran into too many of the blowing up in bizarre ways, and the semantics drifting too far</div>
<div>from the JS version of the API. </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>
<div><div>  Vassili came up with the great idea of generating bytecode for slot accessors directly and minting a set of 256 accessors that traversed the parent chain in a loop.  Effectively each accessor method looked like</div>

<div><br></div><div>accessSlot0</div><div>    | object |</div><div>    object := self.</div><div>    [object slot0 ifNotNil: [:value| ^value].</div><div>     (object := object parentSlot) ~~ nil] whileTrue.</div><div>    ^#undefined</div>
</div></div></span></div></div></blockquote><div><br></div><div>I have a OO Forth that does the exact same thing, except it rolls native x86 machine code :)</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><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div><div><div>
Both Claus Gittinger and Dan Ingalls have had the idea of creating an object that is an instance of itself.  One way, without VM mods (and ignoring issues with compact classes), is to do something like</div><div><br></div>

<div>prototype: aPrototype numNewSlots: numNewSlots</div><div>    | format object |</div><div>    object := (Array new: aPrototype numberOfSlots + numNewSlots + 3).</div><div>    object</div><div>         at: 1 &quot;superclass&quot; put: aPrototype;</div>

<div>         at: 2 &quot;methods&quot;    put: MethodDictionary new;</div><div>         at: 3 &quot;format&quot;       put: (self formatOf: aPrototype format withAdditionalSlots: numNewSlots).</div><div>   object changeClassTo: object.</div>

<div>   ^object</div><div></div></div></div></span></div></div></blockquote><div><br></div><div>I did something similar with another project, but I&#39;ve found doing the deep copies on the MethodDictionary ends up </div>
<div>failing in weird ways.  </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><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>
<div><div>Combine one with the other and you have the potential for a lean and mean prototype-based system using the existing VM technology, which would mean an efficient JavaScript implementation within Smalltalk.</div></div>
</div></span></div></div></blockquote><div><br></div><div>I guess I know what the next set of experiments I&#39;m going to do are :)</div><div><br></div><div>Thanks Eliot for thinking through this with me.</div><div><br></div>
<div>The main reason I&#39;m building this, is I&#39;ve got this very fluid ad hoc Javascript editing environment I wrote that I&#39;m trying to port to Squeak.  I&#39;ve been writing a book on programming that runs the reader through the process of designing a simple 8bit CPU, that has been implemented as step by step drag and drop examples on top of it.  </div>
<div><br></div><div>The only problem is that the only JS + HTML5 implementation out there in the wild that can actually handle it is Safari, and I can&#39;t bundle that with the book :)</div><div><br></div><div>If I can get it ported to Squeak, I can add an additional appendix and give the code listings in both Smalltalk and Javascript.  But I want the code to have direct analogues, so the translations of concepts between languages are</div>
<div>clear.</div><div><br></div><div>Dave</div></div>-- <br>-=-=-=-=-=-=-=-=-=-=- <a href="http://blog.dloh.org/">http://blog.dloh.org/</a><br>