Jason Persampieri <helgaorg / yahoo.com> wrote:
> 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.  

Think of it in terms of levels of indirection. A variable is just a
reference to an object, and methods called on a variable are actually
message sends to the object it references.

Now, in the case of a non-immediate value, we have

[Var]---->[Object]---->[Data]

so that, say, a = String.new("Hello World") is

[a]--->[String <id>]--->[Hello World]

and modifying 'a' modifies the *data* in the String object, not the
string object itself.

For immediate values, there is no intermediate per-instance object; all
Fixnums point to the *same* [3]. So a = 3; b=3; means

[a]--\
     +->[3]
[b]--/

Therefore there's no real way to define a succ! on numbers, unless you
want to go the Java route and have int vs Int. And other than numbers
and iterators, I don't think I've ever had the need to ++ something in
C++. I'd be a lot more annoyed if ruby had a ++ that didn't work on
numbers than if it just didn't have one.

Possibly illustrative:

a = 3; b = 3
puts a.id, b.id #=> 7, 7

c = "Hello World"; d = "Hello World"
puts c.id, d.id #=> 19659500 19659392

e = [c]; f = [c]
puts e.id, f.id #=> 19659128 19659008

c.succ!
p c,d,e,f #=> "Hello Worle" "Hello World" ["Hello Worle"] ["Hello Worle"]

martin