Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!rayssd!trr From: trr@rayssd.ray.com (Terry R. Raymond) Newsgroups: comp.lang.smalltalk Subject: Re: subclasses of Float in Smalltalk/V Summary: cannot do it!! Message-ID: <8354@rayssd.ray.com> Date: 22 Jun 89 17:08:49 GMT References: <56225@linus.UUCP> Sender: trr@rayssd.ray.com (Terry R. Raymond @ Raytheon Company, Portsmouth RI) Organization: Raytheon Company, Portsmouth RI Lines: 37 I tried to do it and this is what I found. Apparently, the primitives that perform the actual operations check the class of the object. They appear to test "is it a Float" not "is it kindof a Float" which would permit subclasses. This is what I did. I created a class Degree as a variableByteSubclass of Float, just like Float. I created a class method "new:". new: anInteger ^(Float fromInteger: anInteger) become: (self basicNew). The method "become:" is in Behavior, it changes the class of the receiver to the class of the argument. The method "basicNew" is also in Behavior, this method is never overridden by a subclass. I then evaluated the following expressions. (Degree new: 50) + 4.0 This produces a floating point exception error. 4.0 + (Degree new: 50) This produces a stack overflow. The stack over flow was produced because the "+" method trys to convert the Degree instance to a float, i.e. it does not consider Degree to be class Float. I suggest that you look at the class Fraction and implement your class in a similar way. -- Terry Raymond Raytheon Submarine Signal Division; Portsmouth RI; (401)-847-8000 x5597 ------------------------------------------------------------------------------ Internet: trr@rayssd.ray.com (trr%rayssd.ray.com@a.cs.uiuc.edu) UUCP: {decuac,gatech,mimsy,mirror,necntc,sun,uiucdcs,ukma}!rayssd!trr