Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!mtune!codas!usfvax2!chips From: chips@usfvax2.UUCP (Chip Salzenberg) Newsgroups: comp.lang.smalltalk Subject: Re: A question... Message-ID: <814@usfvax2.UUCP> Date: Thu, 6-Aug-87 10:15:26 EDT Article-I.D.: usfvax2.814 Posted: Thu Aug 6 10:15:26 1987 Date-Received: Sat, 8-Aug-87 11:05:27 EDT References: <4357@felix.UUCP> Organization: AT Engineering, Tampa, FL Lines: 41 Summary: How about "asPoint"? In article <4357@felix.UUCP>, preston@felix.UUCP writes: > I have been writing a set of class definitions to support graphics in > Little Smalltalk from the descriptions in the Smalltalk-80 books. > > The class Point responds to '+'. The examples show both: > > aPoint + aPoint i.e. (1 @ 2) + (3 @ 4) = (4 @ 6) > and > aPoint + aNumber i.e. (1 @ 2) + 3 = (4 @ 5) > > What I don't see is how to write the method for '+' without explicitly > testing the class of the parameter. > > Preston L. Bannister > USENET : ucbvax!trwrb!felix!preston Perhaps you could implement the method asPoint in the class Integer: asPoint "Return a Point with x and y both equal to self." ^self @ self. Then, in class Point: asPoint "Return self." ^self. and, then the method you wanted: + delta "Return the sum of two points. Delta may be an integer." | aPoint | aPoint := delta asPoint. ^(self x) + (aPoint x) @ (self y) + (aPoint y). This may not be very fast, but it would work. -- Chip Salzenberg UUCP: "uunet!ateng!chip" or "chips@usfvax2.UUCP" A.T. Engineering, Tampa Fidonet: 137/42 CIS: 73717,366 "Use the Source, Luke!" My opinions do not necessarily agree with anything.