Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!rutgers!ucla-cs!zen!ucbvax!decvax!tektronix!tekcrl!tekchips!stevev From: stevev@tekchips.TEK.COM (Steve Vegdahl) Newsgroups: comp.lang.smalltalk Subject: Re: A question... Message-ID: <1549@tekchips.TEK.COM> Date: Wed, 5-Aug-87 12:27:25 EDT Article-I.D.: tekchips.1549 Posted: Wed Aug 5 12:27:25 1987 Date-Received: Sat, 8-Aug-87 09:17:25 EDT References: <4357@felix.UUCP> Organization: Tektronix Inc., Beaverton, Or. Lines: 30 In article <4357@felix.UUCP>, preston@felix.UUCP (Preston Bannister) writes: > > 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. Something like: > > + delta > (delta class == Point) > ifTrue: [^ Point new x: (self x + (delta x)) y: (self y + (delta y)) ] > ifFalse: [^ Point new x: (self x + delta) y: (self y + delta) ] I believe that most Smalltalk images have a coercion selector "asPoint", where 3@7 asPoint --> 3@7 but 6 asPoint --> 6@6 Then your '+' method for Point looks something like: + delta | temp | temp <- delta asPoint ^(self x + temp x) @ (self y + temp y) Steve Vegdahl Computer Research Lab Tektronix Labs Beaverton, Oregon