Typed Systems, Type Inference, etc

Brian Keefer mgomes21 at cox.net
Sat Jul 20 20:48:01 UTC 2002


> Point>>+ otherPoint
> 
>         ^(self x + otherPoint x) @ (self y + otherPoint y)
> 
> The only requirement for otherPoint is to answer #x and #y messages [*].
> 
> [*] Answer a message don't means implement a method. Example: a object
> using #doesNotUnderstand: can answer to several messages without a method.

I was suprised to see Squeak bothering to cast a number into a point like
1 at 2 + 3 --> 1 at 2 + (3 at 3). What's wrong with just making a more specific
version of a method, and playing games with polymorphism?
-------------- next part --------------
'From Squeak 3.2 of 11 July 2002 [latest update: #4917] on 20 July 2002 at 4:47:08 pm'!

!Number methodsFor: 'as yet unclassified' stamp: 'bmk 7/20/2002 16:01'!
xOrNumber
^self! !

!Number methodsFor: 'as yet unclassified' stamp: 'bmk 7/20/2002 16:01'!
yOrNumber
^self! !


!Point methodsFor: 'accessing' stamp: 'bmk 7/20/2002 16:02'!
xOrNumber
^x! !

!Point methodsFor: 'accessing' stamp: 'bmk 7/20/2002 16:02'!
yOrNumber
^y! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:41'!
* arg 
	"Answer a Point that is the product of the receiver and arg."

	^ (x * arg xOrNumber) @ (y * arg yOrNumber).! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:02'!
+ arg 
	"Answer a Point that is the sum of the receiver and arg."

^ (x + arg xOrNumber) @ (y + arg yOrNumber)! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:41'!
- arg 
	"Answer a Point that is the difference of the receiver and arg."

	^ (x - arg xOrNumber) @ (y - arg yOrNumber)
	! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:42'!
/ arg 
	"Answer a Point that is the quotient of the receiver and arg."

	^ (x / arg xOrNumber) @ (y / arg yOrNumber)! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:42'!
// arg 
	"Answer a Point that is the quotient of the receiver and arg."

	^ (x // arg xOrNumber) @ (y // arg yOrNumber)! !

!Point methodsFor: 'arithmetic' stamp: 'bmk 7/20/2002 16:42'!
\\ arg 
	"Answer a Point that is the mod of the receiver and arg."

	^ (x \\ arg xOrNumber) @ (y \\ arg yOrNumber)! !



More information about the Squeak-dev mailing list