<br><br><div class="gmail_quote">On Tue, Jul 19, 2011 at 11:07 AM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
i'd vote for keeping #== .<br></blockquote><div><br></div><div>But if one needs #==, which is the unusual case, one can use method hasLiteralSuchThat: [:l| l == foo].</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Remember there was a discussion whether:<br>
<br>
'abc' == 'abc'<br>
<br>
should answer true or false.<br>
<br>
And if it returns false, meaning that compiler doesn't bother to<br>
optimize literals used, then<br>
#hasLiretal:<br>
should also use #== .<br>
<br>
Also, suppose that<br>
<br>
aMethod hasLiteral: #DateAndTime->DateAndTime<br>
<br>
answers true.<br>
But method's literal holds a variable binding , but not association<br>
which you just created.<br>
And then if you try something like following:<br>
<br>
assoc := #DateAndTime -> DateAndTime.<br>
(aMethod hasLiteral: assoc) ifTrue: [ assoc value: Foo ].<br>
<br>
it won't make any effect on method, since it using different object.<br>
So, many tools (especially refactoring ones) can be confused by this,<br>
if they using #hasLiteral: in combination with mutating/replacing<br>
those literals .<br>
<div><div></div><div class="h5"><br>
<br>
On 19 July 2011 19:52, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br>
><br>
><br>
> On Tue, Jul 19, 2011 at 10:44 AM, Nicolas Cellier<br>
> <<a href="mailto:nicolas.cellier.aka.nice@gmail.com">nicolas.cellier.aka.nice@gmail.com</a>> wrote:<br>
>><br>
>> Hmm, there's the tricky edge case:<br>
>><br>
>> 0.5s2 = 0.5s3<br>
>> 0.5s2 class = 0.5s3 class.<br>
>><br>
>> But they should be different literals.<br>
>> I think there is a test case for it.<br>
>><br>
>> Same goes for arrays<br>
>><br>
>> #( 0 ) = #( 0.0 )<br>
>><br>
>> I think we defined a #literalEquals: or something like that to handle this<br>
>> kind of cases.<br>
><br>
> Yes, indeed. I can change this. But before doing so does anyone else agree<br>
> that the whole hasLiteral: hasLiteralThorough: is too heavy-weight and we<br>
> should ditch hasLiteralThorough: and make hasLiteral: be thorough? And I<br>
> suppose more importantly does anyone disagree?<br>
><br>
>><br>
>> Nicolas<br>
>><br>
>> 2011/7/19 Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>><br>
>>><br>
>>><br>
>>> On Mon, Jul 18, 2011 at 2:40 PM, Sean P. DeNigris <<a href="mailto:sean@clipperadams.com">sean@clipperadams.com</a>><br>
>>> wrote:<br>
>>>><br>
>>>> I tried:<br>
>>>><br>
>>>> aMethod hasLiteral: #DateAndTime->DateAndTime<br>
>>>><br>
>>>> and got false, even though an "=" literal is indeed there.<br>
>>>><br>
>>>> Why doesn't #hasLiteral: use #=?<br>
>>><br>
>>> Well, the tricky thing with literals is that 0.0 = 0 and 'one' = #one but<br>
>>> these are all different literals. That said, it looks like a bug to me. It<br>
>>> should surely be<br>
>>> !CompiledMethod methodsFor: 'literals' stamp: 'eem 7/19/2011 09:19'!<br>
>>> hasLiteral: literal<br>
>>> | litClass lit |<br>
>>> "Answer whether the receiver references the argument, literal."<br>
>>> litClass := literal class.<br>
>>> 2 to: self numLiterals - 1 do: "exclude superclass + selector/properties"<br>
>>> [:index |<br>
>>> lit := self objectAt: index.<br>
>>> (litClass == lit class and: [literal = lit]) ifTrue: [^true]].<br>
>>> ^false! !<br>
>>> !Array methodsFor: 'private' stamp: 'eem 7/19/2011 09:20'!<br>
>>> hasLiteral: literal<br>
>>> "Answer true if literal is identical to any literal in this array, even<br>
>>> if imbedded in further array structure. This method is only intended<br>
>>> for private use by CompiledMethod hasLiteralSymbol:"<br>
>>> | litClass lit |<br>
>>> litClass := literal class.<br>
>>> 1 to: self size do:<br>
>>> [:index |<br>
>>> (litClass == (lit := self at: index) class<br>
>>> and: [literal = lit]) ifTrue: [^true].<br>
>>> (Array == lit class<br>
>>> and: [lit hasLiteral: literal]) ifTrue: [^true]].<br>
>>> ^false! !<br>
>>> I've run all the tests in a trunk 4.2 before and after and making the<br>
>>> above change makes no difference. So I think I'll go ahead and commit the<br>
>>> change to Squeak trunk. I'll leave the Pharo folks to apply it there-in.<br>
>>> Files attached.<br>
>>>><br>
>>>> Thanks.<br>
>>>> Sean<br>
>>>><br>
>>>> --<br>
>>>> View this message in context:<br>
>>>> <a href="http://forum.world.st/Why-does-CompiledMethod-hasLiteral-use-tp3676573p3676573.html" target="_blank">http://forum.world.st/Why-does-CompiledMethod-hasLiteral-use-tp3676573p3676573.html</a><br>
>>>> Sent from the Pharo Smalltalk mailing list archive at Nabble.com.<br>
>>>><br>
>>><br>
>>><br>
>>><br>
>>> --<br>
>>> best,<br>
>>> Eliot<br>
>>><br>
>>><br>
>>><br>
>><br>
>><br>
>><br>
>><br>
><br>
><br>
><br>
> --<br>
> best,<br>
> Eliot<br>
><br>
><br>
><br>
><br>
<br>
<br>
<br>
</div></div><font color="#888888">--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>best,<div>Eliot</div><br>