Re: [Pharo-dev] FullBlockClosure - How to create one...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] FullBlockClosure - How to create one...

Nicolas Cellier
Yes, I want that in Squeak too !

Le ven. 1 mai 2020 à 18:58, Eliot Miranda <[hidden email]> a écrit :
you might want to adapt this change set into a package, to rename BlockClosure's startups inst var to startpcOrMethod to clear up confusion.



On Fri, May 1, 2020 at 9:49 AM Eliot Miranda <[hidden email]> wrote:
Hi Max,

On Thu, Apr 30, 2020 at 11:51 PM Max Leske <[hidden email]> wrote:

Hi Sean,

You need an outer context. See Context>>cleanCopy, which Fuel uses to serialize blocks.


One does *not* need an outer context.  An outer context of nil should be fine, provided that the block never attempts an up-arrow return.


| blockMethod |
blockMethod := [:a :b| a < b] method.
(FullBlockClosure receiver: nil outerContext: nil method: blockMethod copiedValues: nil) value: 1 value: 2

So one needs to use FullBlockClosure class>>receiver:outerContext:method:copiedValues: and one can supply nil for the outerContext provided that the block does not do an up-arrow return.
 

Cheers,
Max

On 1 May 2020, at 3:23, Sean P. DeNigris wrote:

What am I not understanding about FullBlockClosure?

I have a clean block that I'd like to turn into a FullBlockClosure so that I
can serialize it without dragging (unneeded methods) into my object graph.
However, documentation and in-image example usages seem severely limited.
Here was one experiment that ended with a primitive failure. It seems like a
receiver is needed and it can't be a dummy value (see commented "receiver:
1"). But what would the receiver be in the absence of an outer context?!

aBlockClosure := [ :a :b | 1 + a + b ].
fbc := (FullBlockClosure
outerContext: nil
startpc: aBlockClosure startpc
numArgs: aBlockClosure argumentCount
copiedValues: Array new) "receiver: 1; yourself".

fbc value: 2 value: 3. "PrimitiveFailed: primitive #value:value: in
FullBlockClosure failed"



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html



--
_,,,^..^,,,_
best, Eliot


--
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] FullBlockClosure - How to create one...

Eliot Miranda-2


On Fri, May 1, 2020 at 10:02 AM Nicolas Cellier <[hidden email]> wrote:
Yes, I want that in Squeak too !

I just committed it ;-)
 

Le ven. 1 mai 2020 à 18:58, Eliot Miranda <[hidden email]> a écrit :
you might want to adapt this change set into a package, to rename BlockClosure's startups inst var to startpcOrMethod to clear up confusion.



On Fri, May 1, 2020 at 9:49 AM Eliot Miranda <[hidden email]> wrote:
Hi Max,

On Thu, Apr 30, 2020 at 11:51 PM Max Leske <[hidden email]> wrote:

Hi Sean,

You need an outer context. See Context>>cleanCopy, which Fuel uses to serialize blocks.


One does *not* need an outer context.  An outer context of nil should be fine, provided that the block never attempts an up-arrow return.


| blockMethod |
blockMethod := [:a :b| a < b] method.
(FullBlockClosure receiver: nil outerContext: nil method: blockMethod copiedValues: nil) value: 1 value: 2

So one needs to use FullBlockClosure class>>receiver:outerContext:method:copiedValues: and one can supply nil for the outerContext provided that the block does not do an up-arrow return.
 

Cheers,
Max

On 1 May 2020, at 3:23, Sean P. DeNigris wrote:

What am I not understanding about FullBlockClosure?

I have a clean block that I'd like to turn into a FullBlockClosure so that I
can serialize it without dragging (unneeded methods) into my object graph.
However, documentation and in-image example usages seem severely limited.
Here was one experiment that ended with a primitive failure. It seems like a
receiver is needed and it can't be a dummy value (see commented "receiver:
1"). But what would the receiver be in the absence of an outer context?!

aBlockClosure := [ :a :b | 1 + a + b ].
fbc := (FullBlockClosure
outerContext: nil
startpc: aBlockClosure startpc
numArgs: aBlockClosure argumentCount
copiedValues: Array new) "receiver: 1; yourself".

fbc value: 2 value: 3. "PrimitiveFailed: primitive #value:value: in
FullBlockClosure failed"



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html



--
_,,,^..^,,,_
best, Eliot


--
_,,,^..^,,,_
best, Eliot



--
_,,,^..^,,,_
best, Eliot