Unary - Binary message
Gary McGovern
garywork at lineone.net
Thu Oct 25 03:53:10 UTC 2001
----- Original Message -----
From: "Richard A. O'Keefe" <ok at atlas.otago.ac.nz>
To: <squeak-dev at lists.squeakfoundation.org>
Sent: Thursday, October 25, 2001 1:14 AM
Subject: Re: Unary - Binary message
> "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).
Thanks Richard,
You're right, I've just found my increment method didn't actually increment.
> 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.
Thanks!
From: Alan Kay
To: squeak-dev at lists.squeakfoundation.org
Sent: Thursday, October 25, 2001 1:01 AM
Subject: Re: Unary - Binary message
>A way around this is to make a class to hold numbers that can be
>incremented (we used to call this a "gauge"). If you stick one of these in
a >variable slot, then all will work pretty well. Can you see where you
should >subclass gauge?
Thanks Alan,
My guess would be make an IntegerArray with the index changing on
incrementing. Close ?
>P.S. The Etoy system does implement "incremen" and "decrement" and
>"multiply" as operations on variables.
I'm using 2.7 while working through the Squeak book and EToySystem has no
methods written.
Thanks!
Gary
More information about the Squeak-dev
mailing list
|