Numbers in Smalltalk

Hey,

I was just reading the discussion where William Cook is critiquing CTM. In this post, where he is contrasting Objects and ADTs, he says:

...the well-known problem of 'binary methods' in object-oriented programming. It is also one reason why numbers are hard to implement as objects: the operations +, *, / etc all require access to representations unless you are willing to give up a lot of performance. The way Smalltalk handles numbers is really fascinating, and not very well known.

Further down, he illustrates objects as follows:

The argument O is not the Client, the function is the Client:

Client = Fun{Container O}.... {O.get...} {O.put....} ... end.

It gets even more interesting when you have operations that take multiple object values, like "compare dictionary" or "append lists". Then you would have

Client2 = Fun{Container O1, Container O2}.... {O1.append(O2)...} {O2.compare(O1)....} ... end.

In this case the "class" of the two container objects O1 and O2 can be completely unrelated and everything will still work! This is a strong illustration of the power of objects. Again, see my paper on ADT vs OOP for more discussion. This is how numbers work in Smalltalk.

Oz makes me a bit cross-eyed, but this seems a pretty straight-forward use of OO. Hopefully someone can explain why binary operators are so fascinating in Smalltalk...

Cheers...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

comp.lang.smalltalk

double dispatching and generality

Ask on comp.lang.smalltalk or Squeak-dev

Wow

There's a blast from the past...