Boolean expressions (was: Re: [squeak-dev] Re: Object>>#is:?
(was: Re: PackageDependencyTest))
Juan Vuletich
juan at jvuletich.org
Thu Mar 4 21:14:38 UTC 2010
Levente Uzonyi wrote:
> On Thu, 4 Mar 2010, Juan Vuletich wrote:
>
>> Stéphane Rollandin wrote:
>>>
>>> ...
>>> let's now consider MySpecializedMorph, a subclass of MyMorph that I
>>> *do not* want to be considered as MyMorph:
>>>
>>> is: aSymbol
>>> (super is: aSymbol and: [aSymbol =~ #MyMorph])
>>> or: [aSymbol == #MySpecializedMorph]) ifTrue: [^ true].
>>> ^ false
>>>
>>> see the problem ?
>>
>> Yes, I see it. As I see it, #is: is for asking about conformance to a
>> certain protocol. And your MySpecializedMorph does know what
>> protocols it conforms. So it can implement something like:
>>
>> is: aSymbol
>> aSymbol == #Morph ifTrue: [^true].
>> aSymbol == #MySpecializedMorph ifTrue: [^true].
>> ^false
>
> I don't get you guys, why do these expressions have to be so
> complicated? Just compare this with those above:
>
> is: aSymbol
>
> ^aSymbol == #Morph or: [ aSymbol == #MySpecializedMorph ]
>
> If you have a lot of protocols you can use the super fast primitive
> supported #pointsTo: and have a lot cleaner (and possibly faster) code:
>
> is: aSymbol
>
> ^#(Morph MySpecializedMorph FooMorph BarMorph) pointsTo: aSymbol
>
>
> Levente
Oh! #pointsTo: ! Sweet!
Cheers,
Juan Vuletich
More information about the Squeak-dev
mailing list
|