On 21 April 2011 07:58, Tobias Pape <Das.Linux@gmx.de> wrote:
Am 2011-04-20 um 22:18 schrieb Ted F.A. van Gaalen:
Thanks Tobias and Igor for your thoughts about this increment/decrement theme. @Tobias: what kind of side effect(s) are you talking about? I don't understand, sorry.
No problem, I wrote a bit complicated. What I mean is that     i++ instructs the object âiâ to change its state, ie, increment itself. However, the Object in âiâ is meant to be an integer. So, how to interpret that? say, âiâ is 5. Essentially,     i++ says     âfive, change your state to be sixâ But that would imply, because all integers are the respecive same over the image, that all fives are suddenly sixes.
The point is, in C, variables denote memory cells, and it is a common operation to say âmemory cell, increment your content by oneâ, whereas in Smalltalk, a variable denotes an object and such an increment is rather senseless on integer objects.
In other words, each integer in a Smalltalk image is a kind of Singleton. (    as     1 = 1 " => true"     1 == 1 " => true" ) Hence, | a b | a := 1. b := 1. a = b " => true (a and b have the same content)". a == b "=> true (ie, they are the indentical object)".
"but"
a ++. "hypothetical" a = b "=> ??, probably false". a == b " => ??, can't think of that".
yes, because variables in smalltalk are references to objects. and variables in C are memory pointers. A ++ operator is evil, because you cannot override or redefine it (like any other message). And it works only for numbers (no pointers in smalltalk) and so, completely falls out of object model.
So Long, Â Â Â Â -Tobias
-- Best regards, Igor Stasenko AKA sig.