> A ++ operator is evil, because you cannot override or redefine it
> (like any other message).
In C++ you can.
> And it works only for numbers (no pointers
> in smalltalk)
> and so, completely falls out of object model.
It can be done and has been done in Helvetia without falling out of
the object model.
I don't remember the details, but I was essentially rewriting
i++
to something along
i increment: [ :v | i := v ]
where you the semantics of #increment: are implemented in the objects
as you wish. For numbers this would be something like:
Number>>#increment: aBlock
^ aBlock value: self + 1
For other objects other 'meaningful' implementations can be added, for example:
SequenceableCollection>>#increment: aBlock
^ aBlock value: self allButFirst , (Array with: self first)
Stream>>#increment: aBlock
^ aStream skip: 1
etc.
Cheers,
Lukas
--
Lukas Renggli
www.lukas-renggli.ch