(resent as requested)

James Mastros wrote:

Here's my basic defintion of ID: Two things should have the same ID if-and-only-if they will behave exactly the same, now and forevermore.

Thus, there should be one ID for all constants of the same value, which is different from all constants of different value. (This is probably unimplementable if we gaurntee IDs are of some constant length.)

Two objects should only have the same ID if they are aliases of each-other: they always have the same instance values, and the same value (but) properties.

Promotable, but unpromoted, Ints should have different IDs, because they may at some point, have different values.

Any unconsidered cases?
What about value objects (objects with no methods to change state after
creation?

class Complex {
    # Hmmm, what's the attribute syntax this week?
    attr .real is ro is public;
    attr .imaginary is ro is public;

    sub new($r, $i) {
       my Complex $obj;
       $obj.real = $r;
       $obj.imaginary = $i;
       return $obj;
    }

    method .magnitude { return sqrt($.real * $.real
                                  + $.imaginary * $.imaginary);
    }

    method .conjugate ( return Complex::new($.real, -$.imaginary); }

    sub operator::* (Complex $a, Complex $b) is exported {
      return Complex::new($a.real*$b.real-$a.imaginary*$b.imaginary,
                          $a.real*$b.imaginary+$a.imaginary*$b.real);
    }
}

If I wrote the Perl6 code correctly (and no guarantees that I hit this
moving target), then once created, a Complex object cannot be modified
and is indistinguishable by behavior from any other Complex object with
the same value:

  my Complex $a = Complex::new(5,4);
  my Complex $b = Complex::new(5,4);

Is it reasonable to have $a.id == $b.id?





Reply via email to