[squeak-dev] A question about block closures.
David Goehrig
dave at nexttolast.com
Tue Jul 7 22:58:36 UTC 2009
Dear Squeakers,
I have a question for some of Squeak gurus on the list. I've been porting a
javascript project I did a couple months back to Squeak, and in the process
of porting it, added an ad hoc object class that handled the prototype based
inheritance I used in the javascript version.
One of the issues I encountered was that when I did a copy of my object, the
block closures supplied for various properties required a bit of a hack so I
have a method:
doesNotUnderstand: aMessage
"Generic catch all that performs all selectors"
(self can: aMessage selector) ifTrue: [
(self s: aMessage selector ) outerContext receiver: self.
^( self s: aMessage selector )valueWithEnoughArguments: aMessage arguments
].
^ self s: aMessage selector.
Now this seems to do exactly what I wanted 99% of the time. It mimics the
behavior of using a block closure as a javascript function() {} object, and
all other objects are returned as intended. The #s: method returns nil if
the property is not found in the object's dictionary as well, and #can: is
just a fancy way to test if the property is a block
closure. By using valueWithEnoughArguments: it even gets padded out
with nils like JS would.
I'm not entirely happy with how hackish this seems, patching the
outerContext and then re-rolling the arguments array to one of the
proper size just to copy into a MethodContext.
My question is "Is there a better way?"
Dave
--
-=-=-=-=-=-=-=-=-=-=- http://blog.dloh.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090707/3140791b/attachment.htm
More information about the Squeak-dev
mailing list
|