Author: lwall Date: 2009-02-27 08:03:18 +0100 (Fri, 27 Feb 2009) New Revision: 25606
Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S12-objects.pod Log: some enum cleanup Modified: docs/Perl6/Spec/S02-bits.pod =================================================================== --- docs/Perl6/Spec/S02-bits.pod 2009-02-27 06:46:09 UTC (rev 25605) +++ docs/Perl6/Spec/S02-bits.pod 2009-02-27 07:03:18 UTC (rev 25606) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 10 Aug 2004 - Last Modified: 25 Feb 2009 + Last Modified: 26 Feb 2009 Number: 2 - Version: 155 + Version: 156 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -2459,8 +2459,8 @@ Fat arrow Adverbial pair Paren form ========= ============== ========== - a => 1 :a - a => 0 :!a + a => True :a + a => False :!a a => 0 :a(0) a => $x :a($x) a => 'foo' :a<foo> :a(<foo>) Modified: docs/Perl6/Spec/S12-objects.pod =================================================================== --- docs/Perl6/Spec/S12-objects.pod 2009-02-27 06:46:09 UTC (rev 25605) +++ docs/Perl6/Spec/S12-objects.pod 2009-02-27 07:03:18 UTC (rev 25606) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 27 Oct 2004 - Last Modified: 12 Feb 2009 + Last Modified: 26 Feb 2009 Number: 12 - Version: 69 + Version: 70 =head1 Overview @@ -1298,11 +1298,6 @@ my enum Day ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; my enum Day <Sun Mon Tue Wed Thu Fri Sat>; -For any enum value the C<.perl> method will return its long name. -A numeric enum value numifies to its numeric value and stringifies to its short name. -A string enum value has no special numeric value, and stringifies to its string value -rather than its name. [XXX inconsistent] - If the first value is unspecified, it defaults to 0. To specify the first value, use pair notation (see below). @@ -1316,6 +1311,23 @@ my Int enum day ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; my enum day of uint4 <Sun Mon Tue Wed Thu Fri Sat>; +For any enum value of an object type, the object itself knows its own +type, so the C<.perl> method will return its long name, while C<.name> +returns its short name. Other than that, number valued enums act +just like numbers, while string valued enums act just like strings. + +Enums based on native types may be used only for their value, since a +native value doesn't know its own type. To translate such a value back to its name +requires a call to the name method, which must be qualified by the type: + + 3.day::name # returns "Wed" + +Alternatively, native types may be placed in a typed variable, which determines +which method to call: + + my day $d = 3; + $d.name # returns "Wed" + An anonymous enum just makes sure each string turns into a pair with sequentially increasing values, so: @@ -1414,11 +1426,11 @@ Two built-in enums are: - our bit enum Bool <False True>; - our bit enum Taint <Untainted Tainted>; + our Bit enum Bool <False True>; + our Bit enum Taint <Untainted Tainted>; Note that C<Bool> and C<Taint> are really role names, and the enum -values are really subset types of the C<bit> integer type. You can +values are really subset types of the C<Bit> integer type. You can call the C<.Bool> coercion or the C<true> function or the C<?> prefix operator on any built-in type, but the value returned is of type C<bit>. Never compare a value to "C<true>", or even "C<True>".