[GOODIE] Arithmetic assignments (+= and friends)

Andreas Raab Andreas.Raab at gmx.de
Mon Jun 17 16:54:36 UTC 2002


Diego,

> I'm only trying to avoid the inclusion in the 'official' updates.

And what makes you think that I'm proposing such an inclusion? Or are
you just afraid that some Squeakers might eventually like it and that it
could change The Only True And Pure Holy Language(tm)?! ;-)

> >I have no interest in any kind of minimal syntax. And the
> >complexity of explaining that += means "increase this 
> >variable's value by X" doesn't seem a big hurdle to me.
> 
> This is not true in Smalltalk.

The above explanation is a first order theory. Simple to explain, simple
to grasp. If you will notice, the eToy system contains "increaseBy:"
(exactly equivalent to #+=) and kids in fourth grade have apparently no
problem mastering this concept.

> I read:
>   a += 2.
> 
> as: Send the message #+= to the object named a and then name 
> a to the answer.

And that's the second order theory. One that you only have to understand
if you actually wish to implement #+= efficiently. 

> and I feel more natural to write:
> 
>   a := a + 1.
> 
> because is more direct the translation.

This might well be but it's lacking the point of my exercise entirely.
The reason why I did this was to have the ability to have polymorphic
receivers of #+= (like collections) which may implement #+= more
efficiently than #+ but still be able to perform it on "atomic objects"
like integers. E.g., try
	ff := FloatArray new: 100000.
	1 to: 100 do:[:i| ff := ff + 1.0].
vs.
	ff := FloatArray new: 100000.
	1 to: 100 do:[:i| ff += 1.0].
The latter, of course won't work (and correctly so) if you got ints or
floats and that's what prompted the modifications in the first place.

> PS: Will We see at SqueakNic the June/22?

No I won't - the connections are too bad for me to make it forth and
back in time for other arrangements.

Cheers,
  - Andreas




More information about the Squeak-dev mailing list