although there is not the orthogonal x.prev, which seems like the
Principle of Most Surprise in effect :-). One way to rectify that is
to open up Integer yourself:
Basically it is a consequence of the decision to make integers
immutable which makes assignment necessary for a variable which is
incremented. I guess Matz wanted to make this explicit, hence "+="
Co.
Otherwise you need a counter class, e.g.
Counter = Struct.new :value do
def initialize(x = 0)
self.value = x
end
def plusplus
self.value += 1
end
alias incr plusplus
def minusminus
self.value += 1
end
alias decr minusminus
end
Kind regards
robert
···
2009/8/13 Shajith Chacko <demerzel@gmail.com>:
On Wed, Aug 12, 2009 at 11:20 PM, Adam Lauper<adamlauper@gmail.com> wrote:
Anyone know the history on this deliberate omission?
There is also #succ and #pred. But this is not the point: all of them
work by returning _a different object_. You can easily verify by
looking at the result's #object_id. Operators ++ and -- in C++ on the
other hand change the object (int, long etc.) itself. The difference
is whether you will have aliasing or not.
Kind regards
robert
···
2009/8/13 Mark Thomas <mark@thomaszone.com>:
Don't forget there's already
x.next
although there is not the orthogonal x.prev, which seems like the
Principle of Most Surprise in effect :-). One way to rectify that is
to open up Integer yourself:
Makes sense, though strictly speaking x++ could be syntactic sugar for
x+=1 or x =x +1
but this would probably be very confusing for many folks for the very
reason you gave.
Cheers
Robert
···
On Thu, Aug 13, 2009 at 11:31 AM, Robert Klemme<shortcutter@googlemail.com> wrote:
2009/8/13 Shajith Chacko <demerzel@gmail.com>:
On Wed, Aug 12, 2009 at 11:20 PM, Adam Lauper<adamlauper@gmail.com> wrote:
Anyone know the history on this deliberate omission?