BlockClosures - Equality and Things

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

BlockClosures - Equality and Things

Sean P. DeNigris
Administrator
While developing Magritte, I have a problem because blocks that are
read/written to/from strings (e.g. via Magritte forms) have a different
outerContext before and after and thus I don't know how (without an ugly
hack) to determine whether they were changed by the user.

Question: Is there a smarter way to do block equality?
Currently in Pharo block comparison is via #==. In Squeak, there is:
BlockClosure >> #= aClosure
        self == aClosure ifTrue: [^true].
        aClosure class = self class ifFalse: [^false].
        (self method == aClosure method and: [startpc = aClosure startpc
and: [self
isClean]]) "<--- this line"
                ifTrue: [^true].
        ^outerContext = aClosure outerContext and: [startpc = aClosure
startpc]

I'm not totally sold on the implementation due to the `startpc = aClosure
startpc` the first time it appears (in the comment-marked line). With it, in
a workspace, the following is false: `[1] = [1]`, but removing that test
makes it true. I'd like something that returns true if both blocks are clean
and they "do the same thing". But I like the track it's on...



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

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: BlockClosures - Equality and Things

ducasse
Hi sean

just a question since I started to finally understand for real the multiple objects that
closures represent :)
Would it not make sense to have internally an object (not a closure) that represent
a method and that answer the method value or value:

You could save this object and on potentially even generate a block if needed.
I do not think that in magritte we use the closuring aspect of closure we use them
as anonymous method.

Stef

> On 5 Oct 2019, at 04:58, Sean P. DeNigris <[hidden email]> wrote:
>
> While developing Magritte, I have a problem because blocks that are
> read/written to/from strings (e.g. via Magritte forms) have a different
> outerContext before and after and thus I don't know how (without an ugly
> hack) to determine whether they were changed by the user.
>
> Question: Is there a smarter way to do block equality?
> Currently in Pharo block comparison is via #==. In Squeak, there is:
> BlockClosure >> #= aClosure
>        self == aClosure ifTrue: [^true].
>        aClosure class = self class ifFalse: [^false].
>        (self method == aClosure method and: [startpc = aClosure startpc
> and: [self
> isClean]]) "<--- this line"
>                ifTrue: [^true].
>        ^outerContext = aClosure outerContext and: [startpc = aClosure
> startpc]

Do you know if they have the new closure model because we are working to move to it.

>
> I'm not totally sold on the implementation due to the `startpc = aClosure
> startpc` the first time it appears (in the comment-marked line). With it, in
> a workspace, the following is false: `[1] = [1]`, but removing that test
> makes it true. I'd like something that returns true if both blocks are clean
> and they "do the same thing". But I like the track it's on...
>
>
>
> -----
> Cheers,
> Sean
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
>