The difference is that 3 is an immediate value object. There is only
ever one object with the value 3.
When I do:
a = 3
I am aliasing (referencing) 3; I am not setting an object to have
the immediate value 3.
Thus, if I were to do a.succ!, it would be no different than if I
were doing 3.succ!, because of the immediacy of Fixnum values and
the fact that variables are ONLY references to objects, and not
objects themselves.
(To be honest, I haven’t missed ++ because I’ve been working in
PL/SQL and Pascal recently.)
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.25 at 23.33.34
···
On Tue, 26 Nov 2002 13:15:31 +0900, Jason Persampieri wrote:
You’re not changing the letter ‘a’ itself; you’re changing a
string which has the letter ‘a’ in it.To put it another way:
You can have more than one “a” string:
s = “a”
t = “a”
and if you change or increment s:
s.succ! # s is now “b”
t doesn’t change.But there’s only one of each number. If you were allowed to do
3.succ!
or
3 += 1
then when you did this:
puts 3 * 5
the output would be “20”, because you would have incremented the
actual object 3.
So wouldn’t it make send to have a somewhat global …succ! method
and only allow the programmer to increment (++) on those that have
it?I mean, C doesn’t allow 3++ either (well, it may ALLOW it, but it
doesn’t mean anything). I think that argument is pretty bogus.