On Wed, Apr 24, 2002 at 02:44:56PM +0900, Yukihiro Matsumoto wrote:
> I think you meant Integer#prev.

Or, rather, Integer#pred (opposite of successor is predecessor).

> I'm not sure how much useful it is.  And I'm (little bit) afraid of it
> might cause request for String#prev, which is way difficult to define.

It's useful for cases where I have an object which I can easily
increment or decrement, but for which I can't necessarily easily
implement +/-.  For example:

  class Array2 # not really an Array, but I don't have a better name
    def initialize(size = 0)
      @h = Hash.new
      @end_idx = index
    end

    def [](idx)
      return @h[idx]
    end

    def push(x)
      @h[@end_idx] = x
      @end_idx = @end_idx.succ
      return x
    end

    def pop()
      @end_idx = @end_idx.pred
      @h.delete(@end_idx)
    end
  end

This is a class that looks somewhat like an Array, but is indexable by
types other than just Integers (in fact, it works with any type that can
be put into a Hash and has succ and pred methods).  Array2 can be
implemented without pred, but would look and act differently.

Paul