Unary - Binary message

Richard A. O'Keefe ok at atlas.otago.ac.nz
Thu Oct 25 00:14:57 UTC 2001


"Gary McGovern" <garywork at lineone.net> wrote:
	I'd like to ask a serious question without being pelted with rotten =
	tomatoes. I've been trying to write an unary message to increment an =
	integer (++ but don't tell anyone :-)).
	
Oh, like
    "in Number"
    next
        ^self + 1

Integers are values (like instances of Integer in Java) and cannot be
changed; unlike early Fortrans, there is no way to turn (1) into (2).

	But this won't work, I think because ++ is meant to be a binary =
	selector. Can someone give me a short =
	explanation on why I can't use this.

Because the lexical rules of the language say
    - unary selectors are like identifiers
    - binary selectors are made up of funny symbols like + and *
    - keyword selectors are made of words each ending with a colon

Why are the lexical rules like that?  I'll let the real experts answer
that, but note that they work darned well.

>From other programming languages, I would certainly expect ++ to be an
infix operator, probably list or string concatenation.




More information about the Squeak-dev mailing list