On Thu, 3 Mar 2005 22:07:44 +0900, Randy Kramer <rhkramer / gmail.com>
wrote:
> Aren't there other cases somewhat like that--iiuc, a string is
> normally mutable but you force it to be non-mutable (with, IIUC,
> the ! to make destructive operations (if I have the terminology
> right)?
> 
> Is the "++" syntax used for some other operation, thus precluding
> its use for a synonym for increment. And wouldn't the right thing
> for ++ be to increment to the next number?

This comes up every so often, and as much as it has to do with the
problem of mutating a fixed value (e.g., 5++), it has much more to
do with the understanding of Ruby variables and the true nature of
object orientation in Ruby, as well as operator overriding.

At least, IMO.

There's two ways to implement ++. The first way is to implement it
as an operator, like #+ and #*. Because it is a unary operator, it
would probably be something like:

  def @++
    # implementation
  end

OK. That's fine. That's probably the better way, but then you've got
the question of -- how do you distinguish between prefix and
postfix? So now, you need *two* operators instead of one -- because
you know that people will use both (they have different meanings).
But you have to define both if you want one.

Ouch.

Okay, the other way is as syntax sugar. Define "a++" such that it is
the same as "a += 1". But what if a is a String? Your program blows
up. So we're back to option 1.

-austin
-- 
Austin Ziegler * halostatue / gmail.com
               * Alternate: austin / halostatue.ca