Author: autrijus Date: Sat Apr 1 10:34:41 2006 New Revision: 8521 Modified: doc/trunk/design/syn/S03.pod
Log: * S03: Value-type semantics; $obj.id.true disambiguates between prototypes and instances; user-defined value objects has to return some builtin values as their .id. Modified: doc/trunk/design/syn/S03.pod ============================================================================== --- doc/trunk/design/syn/S03.pod (original) +++ doc/trunk/design/syn/S03.pod Sat Apr 1 10:34:41 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 25 Feb 2006 + Last Modified: 1 Apr 2006 Number: 3 - Version: 13 + Version: 14 =head1 Operator renaming @@ -84,14 +84,22 @@ types, checks whether they have the same identity value. For reference types that do not define an identity, the reference itself is used (eg. it is not true that C<[1,2] === [1,2]>, but it is true that C<[EMAIL PROTECTED] === [EMAIL PROTECTED]>). -Any reference type may pretend to be a value type by defining a C<.id> method. -(It may also overload C<< infix:<===> >> for more efficient comparison of -any two objects of that type, but it had better return the same result as if -the two identity values had been generated and compared.) Two values are -never equivalent unless they are of exactly the same type. By contrast, -C<eq> always coerces to string, while C<==> always coerces to numeric. -In fact, C<$a eq $b> really means "C<~$a === ~$b>" and C<$a == $b> means -"C<+$a === +$b>. + +Any reference type may pretend to be a value type by defining a C<.id> method +which returns a built-in value, i.e. an immutable object or a native value, +as specified in S06. + +Because Perl 6 uses a false C<.id> to signify a non-instantiated prototype, +all instances should arrange to return a C<.id> that boolifies to true. + +A class may also overload C<< infix:<===> >> for more efficient comparison of +any two objects of that type, but it must return the same result as if +the two identity values had been generated and compared. + +Two values are never equivalent unless they are of exactly the same type. By +contrast, C<eq> always coerces to string, while C<==> always coerces to +numeric. In fact, C<$a eq $b> really means "C<~$a === ~$b>" and C<$a == $b> +means "C<+$a === +$b>. Note also that, while string hashes use C<eq> semantics by default, object hashes use C<===> semantics.