Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!portc02.blue.aol.com!newsjunkie.ans.net!newsfeeds.ans.net!gatech!EU.net!uknet!usenet1.news.uk.psi.net!uknet!uknet!bcc.ac.uk!news
From: Bo Cai <bcai@eleceng.ucl.ac.uk>
Subject: Help needed in understanding isInteger or isFloat etc
Sender: news@ucl.ac.uk (Usenet News System)
Message-ID: <32E6380E.30AB@eleceng.ucl.ac.uk>
Date: Wed, 22 Jan 1997 15:53:50 GMT
Reply-To: bcai@eleceng.ucl.ac.uk
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
X-Mailer: Mozilla 3.01Gold (Win16; I)
Organization: UCL
Lines: 39

Hi,
I am learning smalltalk and have implemented a Complex class, subclass
of Number.
All is well for working with my new type but the problem arises when I
want to test
to see the the object passed to my method is an instance of Complex or
something else.
eg.
+ aNumber
        "Answer the result of adding
         the receiver to aNumber."
         ^ Complex real: (real+aNumber real) imag: (imag + aNumber imag)

this is fine if aNumber is Complex. But I want to test that aNumber is
something else
so I  did this:

+ aNumber
        "Answer the result of adding
         the receiver by aNumber."
aNumber isFloat
ifFalse: [
         ^ Complex real: (real+aNumber real) imag: (imag + aNumber imag)
         ]
ifTrue:  [
         ^ Complex real:real+aNumber imag:imag
         ]

which also works.

Heres my problem:  if I tested for 'aNumber isComplex' and aNumber
wasn't, I got an error because Float or integer didn't understand.
Why is this, because I can do tests like '1 isFloat' with no error, or
'1.0 isInteger'.


I am completely confused.

channing

