[squeak-dev] valueWithReceiver for BlockClosures?
Yoshiki Ohshima
Yoshiki.Ohshima at acm.org
Mon Jan 21 18:29:04 UTC 2013
I have a potential application of valueWithReceiver for BlockClosures
(not CompiledMethod) in my little project. It'd start with something
like:
k1 := Dictionary new.
k1 at: #foo put: 3.
k1 at: #bar put: 4.
k2 := Dictionary new.
k2 at: #foo put: 6.
k2 at: #bar put: 8.
and then a closure is created in the context of k1 (thus "self" in the
following is k1):
self at: #block put: [(self at: #foo) + (self at: #bar)]
Then later, I'd like to "steal" the block from k1 and evaluate it in
the context of k2:
(k1 at: #block) valueWithReceiver: k2.
to get 14 instead of 7. (Otherwise, in my application, the "equal"
closure that only differ in their "self" would be created many, many
times. So, I want to share them.)
....
And Bert told me that I can just store "k2" into the outerContext's
receiver and it works. As long as there is no concurrent invocation,
it'd just work. Do people see other potential problems?
--
-- Yoshiki
More information about the Squeak-dev
mailing list
|