Test if a class has a certain selector?

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

Test if a class has a certain selector?

Hannes Hirzel
Hello

Is there a simpler way of writing

     Character class selectors includes: #cr

(= test if Character class has method  #cr)

--Hannes
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Test if a class has a certain selector?

Tobias Pape

Am 2012-04-28 um 00:45 schrieb H. Hirzel:

> Hello
>
> Is there a simpler way of writing
>
>     Character class selectors includes: #cr
>
> (= test if Character class has method  #cr)

Character canUnderstand: #cr

remember, its messages,
=>
('a' respondsTo: #first) == (String canUnderstand: #first)

:)

Best
        -Tobias

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Test if a class has a certain selector?

Herbert König
In reply to this post by Hannes Hirzel
Hi Hannes,

HH> Is there a simpler way of writing

HH>      Character class selectors includes: #cr

Character respondsTo: #cr


Cheers,

Herbert  

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Test if a class has a certain selector?

Hannes Hirzel
Thank you Tobias and Herbert for the answers

Interestingly

Squeak 4.3
--------------
('a' respondsTo: #first) == (String canUnderstand: #first)
evaluates to true

(Character respondsTo: #cr) == (Character canUnderstand: #cr)
evaluates to false

Pharo 1.4
-----------
the same as Squeak

Cuis 4.0
---------
true in both cases.

--Hannes

On 4/28/12, Herbert König <[hidden email]> wrote:

> Hi Hannes,
>
> HH> Is there a simpler way of writing
>
> HH>      Character class selectors includes: #cr
>
> Character respondsTo: #cr
>
>
> Cheers,
>
> Herbert
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Test if a class has a certain selector?

Tobias Pape

Am 2012-04-28 um 01:35 schrieb H. Hirzel:

> Thank you Tobias and Herbert for the answers
>
> Interestingly
>
> Squeak 4.3
> --------------
> ('a' respondsTo: #first) == (String canUnderstand: #first)
> evaluates to true
>
> (Character respondsTo: #cr) == (Character canUnderstand: #cr)
> evaluates to false
>
> Pharo 1.4
> -----------
> the same as Squeak
>
> Cuis 4.0
> ---------
> true in both cases.

Then in Cuis you can either do

        Character class cr

Or Character does not understand #cr

Right?

Best
        -Tobias

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Test if a class has a certain selector?

Tobias Pape
In reply to this post by Tobias Pape
(resend, wrong from: mail)
Am 2012-04-28 um 01:01 schrieb Tobias Pape:

>
> Am 2012-04-28 um 00:45 schrieb H. Hirzel:
>
>> Hello
>>
>> Is there a simpler way of writing
>>
>>   Character class selectors includes: #cr
>>
>> (= test if Character class has method  #cr)
>
> Character canUnderstand: #cr
>
> remember, its messages,
> =>
> ('a' respondsTo: #first) == (String canUnderstand: #first)
>

Unless, of course, you really wanted to know whether

        Character class

knows about #cr. But bear in mind, Character class is not
the “class side” of Character but the Metaclass of Character

        Character class isKindOf: Metaclass "=> true"

The “class side” of Character is simply Character

        Character isKindOf: Class "=> true"

The “instance side” of Character is, you know it,
a character itself

        $a isKindOf: Character "=> true"

==

So, if you want to know whether the “class side” of
Character knows of the method #cr, the correct one is:

        Character respondsTo: #cr

HTH

Best
        -Tobias





_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners