I am wanting to test the equality of blocks, as are the two blocks that
I have defined in the same method context. I vaguely remember some mention of a "fix" for this... any pointers would be appreciated thanks in advance Keith |
On Dec 23, 2007 3:11 PM, Keith Hodges <[hidden email]> wrote:
> I am wanting to test the equality of blocks, as are the two blocks that > I have defined in the same method context. Are you talking about using #== here? Two blocks are equal if and only if they are the same block? Or is there some other kind of block equality you're looking for? --Tom Phoenix |
Tom Phoenix wrote:
> On Dec 23, 2007 3:11 PM, Keith Hodges <[hidden email]> wrote: > > >> I am wanting to test the equality of blocks, as are the two blocks that >> I have defined in the same method context. >> > > Are you talking about using #== here? Two blocks are equal if and only > if they are the same block? Or is there some other kind of block > equality you're looking for? > > --Tom Phoenix > BlockClosures for equality. However I had to define my own test for BlockContext's This does what I want BlockContext>>#= other self class == other class ifFalse: [^ false]. self home receiver == other home receiver ifFalse: [^ false]. self home selector == other home selector ifFalse: [^ false]. ^ self startpc == other startpc TestBlock>>#blocks ^ Array with: [1] with: [1] TestBlock>>testBlocks self assert: (self blocks = self blocks). self deny: (self blocks first = self blocks second). self deny: (self blocks first == self blocks first). "**" ** a #== comparison will not succeed since although it is actually the same block, the instance of blockContext is different Keith |
Hi Keith,
comparing the selector of two block's home is, IHMO, like comparing a person's name with its nickname. Also a CompiledMethod might not have a meaningful selector (for example if it's as yet not in a MethodDictionary, which is the case since Compiler's DoIt evaluation was hacked [recently]). I'd suggest a more general form, replacing that line by self home method = other home method ifFalse: [^ false]. which ensures equal blocks would execute the same bytecode. Moreover, the two blocks could have been created from different MethodContexts, so an even more general form (which implicitly compares the receiver, args + temps and the method) would be self home = other home ifFalse: [^ false]. /Klaus On Mon, 24 Dec 2007 02:29:59 +0100, Keith Hodges wrote: > Tom Phoenix wrote: >> On Dec 23, 2007 3:11 PM, Keith Hodges <[hidden email]> wrote: >> >> >>> I am wanting to test the equality of blocks, as are the two blocks that >>> I have defined in the same method context. >>> >> >> Are you talking about using #== here? Two blocks are equal if and only >> if they are the same block? Or is there some other kind of block >> equality you're looking for? >> >> --Tom Phoenix >> > According to http://bugs.squeak.org/view.php?id=6599 you can test > BlockClosures for equality. > However I had to define my own test for BlockContext's > > This does what I want > > BlockContext>>#= other > > self class == other class ifFalse: [^ false]. > self home receiver == other home receiver ifFalse: [^ false]. > self home selector == other home selector ifFalse: [^ false]. > ^ self startpc == other startpc > > TestBlock>>#blocks > > ^ Array with: [1] with: [1] > > TestBlock>>testBlocks > > self assert: (self blocks = self blocks). > self deny: (self blocks first = self blocks second). > self deny: (self blocks first == self blocks first). "**" > > ** a #== comparison will not succeed since although it is actually the > same block, the instance of blockContext is different > > Keith > > > > > > > |
Free forum by Nabble | Edit this page |