[squeak-dev] [Pharo-dev] FullBlockClosure - How to create one...

Eliot Miranda eliot.miranda at gmail.com
Fri May 1 17:31:14 UTC 2020


On Fri, May 1, 2020 at 10:02 AM Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

> Yes, I want that in Squeak too !
>

I just committed it ;-)


>
> Le ven. 1 mai 2020 à 18:58, Eliot Miranda <eliot.miranda at gmail.com> 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 <eliot.miranda at gmail.com>
>> wrote:
>>
>>> Hi Max,
>>>
>>> On Thu, Apr 30, 2020 at 11:51 PM Max Leske <maxleske at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200501/693ff2cd/attachment.html>


More information about the Squeak-dev mailing list