"Chris" <nemo / hellotree.com> wrote in message
news:023301c298b6$6d6f3670$6401a8c0 / MELONBALLER...

>   x = 5
>   y = x++  #  So y == 6, which is 'wrong' from a C standpoint.
>   x        #  And x is still 5.  Terrible.
>

Nope,

x = 5
y = x++ # y = 6
# x = 6

You could also define

x = 5
y = x++ # y = 5
# x = 6

To be exactly like C, if you'd like to have both ++x and x++ operators, you
can choose the following path:

x = 5
y = x + x.next # y == 6
# x == 6

or

x = 5
y = (tmp = x; x = x.next; tmp) # y == 5
# x == 6

But personlly I prefer to just have x++ and avoid the tmp sideeffect at the
cost of not being entirely compatible - I have not strong opinions either
way.

> ----------------------------
> In algebraic terms, there is no 'one' element for Real numbers
> ----------------------------
>
> Uh, where did you get that idea?  The real number are a field.

Yes field, that's the term I was looking for (for real numbers, not the
general generator discussion). I simply forgot how much I had forgotten,
otherwise I would have looked it up. Others have pointed out multiplicative
identity. But the essential point was to have an operation that defines the
next element, and apparently this is the next method, although it would be
cool if it could be more closely releated to algebraic constructs.

> ----------------------------
> No we could equally well write
>
> a++ as a synonym for
> a = a.next
> ----------------------------
>
> No, we couldn't!  The only reason anyone wants a "++" operator is because
> they like it from C/C++/Java/etc.  However, if it didn't work like it does
> in other languages, it would be terrible!  We'd never hear the end of it!

Personally, it would please me if you could justifiably say Ruby is
different from Java ;-)
I think ++ is useful in its own right and people are used to ++ doing all
sorts of things depending on what it is operating on. Notably, ++ is often
defined on C++ lightweight reference objects called iterators, which fits
well with the next paradigm.

> (Hmm...  :) )  Like I said, if we can't implement it *exactly* like it
works
> in C, then it's a bad idea.  Surely no one disagrees with this?!
I disagree, but I believe I have shown how it could behave exactly as in C
for integers without loosing the general concept of combining next and
assignment.

> "++" is a relic from a language working too close to the processor
> instructions.

Register arithmetic has many sensible operations. They are not necessarily
bad because they are implemented in hardware. Being contrary, I'll even
argue C doesn't go far enough: I've long missed a rotate operation in C.
I've got applications that would benefit from that because the compiler has
decent opportunity to understand what is going on, that said, I can live
without rotate in Ruby - at least I've got Array#shift  : class Array; def
rotate; push shift; end; end ;-)



Mikkel