creating Complex

Bert Freudenberg bert at isgnw.CS.Uni-Magdeburg.De
Tue Mar 23 15:06:59 UTC 1999


On Tue, 23 Mar 1999, SLAWICK CHARLIER wrote:

> I am a new squeak user (I use squeak to learn object oriented
> programming).
> To learn programming smalltalk, I actulally try to create a complex number
> class. I've got a little problem: I want the programm to create a complex
> when writing the command:
> 	5+4i
> (for example); I've tried to add a method to the superclass 'number' but I
> can't name it '+i' or '+ t1 i'...
> Is there a way for me to deal with this problem?...

You can implement 'i' in Number returning a Complex with a real part of
zero. Then '5 + 4 i' would be 'Number + Complex' which should yield
another Complex by proper coercion (see Number's class comment).

/bert

-- 
 Bert Freudenberg                                       Departement of 
                                                        Simulation and
 mailto:bert at isg.cs.uni-magdeburg.de                    Computer Graphics
 http://isgwww.cs.uni-magdeburg.de/isg/bert.html        Univ. of Magdeburg





More information about the Squeak-dev mailing list