Revision 28502
- Date:
- 2009/09/29 17:50:27
- Files:
Legend:
- Added
- Removed
- Modified
-
docs/Perl6/Spec/S02-bits.pod
13 13 14 14 Created: 10 Aug 2004 15 15 16 Last Modified: 20 Sep 2009 17 Version: 180 16 Last Modified: 29 Sep 2009 17 Version: 181 18 18 19 19 This document summarizes Apocalypse 2, which covers small-scale 20 20 lexical items and typological issues. (These Synopses also contain … … 622 622 623 623 =item * 624 624 625 Perl supports generic types through what are called "roles" 626 which represent capabilities or interfaces. These roles 627 are generally not used directly as object types. For instance 628 all the numeric types perform the C<Numeric> role, and all 629 string types perform the C<Stringy> role, but there's no 630 such thing as a "Numeric" object. Common roles include: 631 632 Stringy 633 Numeric 634 Real 635 Integral 636 Callable 637 Positional 638 Associative 639 640 =item * 641 625 642 Perl 6 intrinsically supports big integers and rationals through its 626 643 system of type declarations. C<Int> automatically supports promotion 627 644 to arbitrary precision, as well as holding C<Inf> and C<NaN> values. … … 641 658 may also be explicitly cast to C<Num>. (Also, if either side is 642 659 C<Num> already, C<< infix:</> >> gives you a C<Num> instead of a C<Rat>.) 643 660 661 C<Rat> and C<Num> both do the C<Real> role. 662 644 663 Lower-case types like C<int> and C<num> imply the native 645 664 machine representation for integers and floating-point numbers, 646 665 respectively, and do not promote to arbitrary precision, though … … 971 990 Failure Failure (lazy exceptions, thrown if not handled properly) 972 991 973 992 Whenever you declare any kind of type, class, module, or package, you're 974 automatically declaring a undefined prototype value with the same name. 993 automatically declaring a undefined prototype value with the same name, known 994 as the I<type object>. The name itself returns that type object: 975 995 996 Object Perl 6 object (default block parameter type, either Any or junction) 997 Any Perl 6 object (default routine parameter type, excludes junction) 998 Int Any Int object 999 Widget Any Widget object 1000 1001 Type objects stringify to their name with empty parens concatenated. 1002 Note that type objects are not classes, but may be used to name 1003 classes: 1004 1005 Widget.new() # create a new Widget 1006 976 1007 Whenever a C<Failure> value is put into a typed container, it takes 977 1008 on the type specified by the container but continues to carry the 978 1009 C<Failure> role. (The C<undef> function merely returns the most … … 1028 1059 if and only if their types and contents are identical (that is, if 1029 1060 C<$x.WHICH> eqv C<$y.WHICH>). 1030 1061 1062 Str Perl string (finite sequence of Unicode characters) 1031 1063 Bit Perl single bit (allows traits, aliasing, undef, etc.) 1032 1064 Int Perl integer (allows Inf/NaN, arbitrary precision, etc.) 1033 Str Perl string (finite sequence of Unicode characters) 1034 Num Perl number 1035 Rat Perl rational 1065 Num Perl number (approximate Real) 1066 Rat Perl rational (exact Real) 1036 1067 Complex Perl complex number 1037 1068 Bool Perl boolean 1038 1069 Exception Perl exception … … 1042 1073 Range A pair of Ordered endpoints 1043 1074 Set Unordered collection of values that allows no duplicates 1044 1075 Bag Unordered collection of values that allows duplicates 1076 PairVal An immutable Pair 1077 PairValSet Set of PairVals with no duplicate keys 1045 1078 Signature Function parameters (left-hand side of a binding) 1079 Parcel List of syntactic objects 1046 1080 Capture Function call arguments (right-hand side of a binding) 1047 1081 Blob An undifferentiated mass of bits 1048 1082 Instant A point on the continuous atomic timeline (TAI) … … 1073 1107 a steady time base, such as POSIX systems, will simply have to make 1074 1108 their best guess as to the correct atomic time. 1075 1109 1110 These types do (at least) the following roles: 1111 1112 Class Roles 1113 ===== ===== 1114 Str Stringy 1115 Bit Numeric Boolean 1116 Int Numeric Integral 1117 Num Numeric Real 1118 Rat Numeric Real 1119 Complex Numeric 1120 Bool Boolean 1121 Exception Failure 1122 Block Callable 1123 List Iterable 1124 Seq Iterable 1125 Range Iterable 1126 Set Associative[Bool] 1127 Bag Associative[UInt] 1128 PairVal Associative 1129 PairValSet Associative 1130 Signature 1131 Parcel Positional 1132 Capture Positional Associative 1133 Blob 1134 Instant Real 1135 Duration Real 1136 1076 1137 =head2 Mutable types 1077 1138 1078 1139 Objects with these types have distinct C<.WHICH> values that do not change … … 1082 1143 Scalar Perl scalar 1083 1144 Array Perl array 1084 1145 Hash Perl hash 1085 KeyHash Perl hash that autodeletes values matching default 1086 1146 KeySet KeyHash of Bool (does Set in list/array context) 1087 1147 KeyBag KeyHash of UInt (does Bag in list/array context) 1088 1148 Pair A single key-to-value association 1089 Mapping Set of Pairs with no duplicate keys 1149 PairSet A Set of Pairs 1090 1150 Buf Perl buffer (a stringish array of memory locations) 1091 1151 IO Perl filehandle 1092 1152 Routine Base class for all wrappable executable objects … … 1096 1156 Macro Perl compile-time subroutine 1097 1157 Regex Perl pattern 1098 1158 Match Perl match, usually produced by applying a pattern 1099 Package Perl 5 compatible namespace 1100 Module Perl 6 standard namespace 1101 Class Perl 6 standard class namespace 1102 Role Perl 6 standard generic interface/implementation 1103 Grammar Perl 6 pattern matching namespace 1104 Any Perl 6 object (default routine parameter type, excludes junction) 1105 Object Perl 6 object (default block parameter type, either Any or junction) 1159 STASH A symbol table hash (package, module, class, lexpad, etc) 1106 1160 1107 A C<KeyHash> differs from a normal C<Hash> in how it handles default 1161 The C<KeyHash> role differs from a normal C<Associative> hash in how it handles default 1108 1162 values. If the value of a C<KeyHash> element is set to the default 1109 1163 value for the C<KeyHash>, the element is deleted. If undeclared, 1110 1164 the default default for a C<KeyHash> is 0 for numeric types, C<False> … … 1139 1193 replicated the number of times specified by its corresponding value. 1140 1194 (Use C<.kv> or C<.pairs> to suppress this behavior in list context.) 1141 1195 1142 As with C<Hash> types, C<Pair> and C<Mapping> are mutable in their 1196 As with C<Hash> types, C<Pair> and C<PairSet> are mutable in their 1143 1197 values but not in their keys. (A key can be a reference to a mutable 1144 1198 object, but cannot change its C<.WHICH> identity. In contrast, 1145 1199 the value may be rebound to a different object, just as a hash 1146 1200 element may.) 1147 1201 1202 The following roles are supported: 1203 1204 Scalar 1205 Array Positional 1206 Hash Associative 1207 KeySet KeyHash[Bool] 1208 KeyBag KeyHash[UInt] 1209 Pair Associative 1210 PairSet Associative 1211 Buf Stringy 1212 IO 1213 Routine Callable 1214 Sub Callable 1215 Method Callable 1216 Submethod Callable 1217 Macro Callable 1218 Regex Callable 1219 Match Positional Associative 1220 STASH Associative 1221 1148 1222 =head2 Value types 1149 1223 1150 1224 Explicit types are optional. Perl variables have two associated types: … … 1442 1516 role implies the ability to support C<< postcircumfix:<[ ]> >>. 1443 1517 1444 1518 Likewise, C<%x> may be bound to any object that does the C<Associative> 1445 role, such as C<Pair>, C<Mapping>, C<Set>, C<Bag>, C<KeyHash>, or 1519 role, such as C<Pair>, C<PairSet>, C<Set>, C<Bag>, C<KeyHash>, or 1446 1520 C<Capture>. The C<Associative> role implies the ability to support 1447 1521 C<< postcircumfix:<{ }> >>. 1448 1522 -
docs/Perl6/Spec/S03-operators.pod
14 14 15 15 Created: 8 Mar 2004 16 16 17 Last Modified: 21 Sep 2009 18 Version: 173 17 Last Modified: 29 Sep 2009 18 Version: 174 19 19 20 20 =head1 Overview 21 21 … … 611 611 612 612 Unlike in Perl 5, where C<+> is a no-op, this operator coerces to 613 613 numeric context in Perl 6. (It coerces only the value, not the 614 original variable.) For values that are not already considered 615 numeric, the narrowest appropriate type of C<Int>, C<Num>, or 614 original variable.) For values that do not already do the 615 C<Numeric> role, the narrowest appropriate type of C<Int>, C<Num>, or 616 616 C<Complex> will be returned; however, string containing two integers 617 617 separated by a C</> will be returned as a C<Rat>. Exponential notation 618 618 and radix notations are recognized. … … 631 631 632 632 ~$x 633 633 634 Coerces the value to a string. (It only coerces the value, not the 635 original variable.) 634 Coerces the value to a string, if it does not already do the C<Stringy> 635 role. (It only coerces the value, not the original variable.) As with 636 numerics, it is guaranteed only to coerce to something C<Stringy>, 637 not necessarily C<Str>. 636 638 637 639 =item * 638 640 … … 3247 3249 Any .<...> hash value slice truth ?all(X) i.e. ?all(.<...>) 3248 3250 3249 3251 Any Bool simple truth X 3250 Any Num numeric equality +$_ == X 3251 Any Str string equality ~$_ eq X 3252 Any Numeric numeric equality +$_ == X 3253 Any Stringy string equality ~$_ eq X 3252 3254 3253 3255 Hash Pair test hash mapping $_{X.key} ~~ X.value 3254 3256 Any Pair test object attribute ?."{X.key}" === ?X.value (e.g. filetests) -
docs/Perl6/Spec/S32-setting-library/Containers.pod
19 19 20 20 Created: 19 Feb 2009 extracted from S29-functions.pod 21 21 22 Last Modified: 12 May 2009 23 Version: 8 22 Last Modified: 29 Sep 2009 23 Version: 9 24 24 25 25 The document is a draft. 26 26 … … 719 719 =head1 Classes 720 720 721 721 This documents Buf, List, Seq, Range, Set, Bag, Junction, Array, Hash, KeyHash, KeySet, 722 KeyBag, Pair, and Mapping. 722 KeyBag, Pair, and PairSet. 723 723 724 724 =head2 Seq 725 725 … … 809 809 810 810 =back 811 811 812 =head2 Mapping 812 =head2 PairValSet 813 813 814 class Mapping does Associative {...} 814 class PairValSet does Associative {...} 815 815 816 816 An immutable hash value, essentially. The keys may 817 817 not contain duplicates, while the values may. 818 818 819 =head2 PairSet 820 821 class PairSet does Associative {...} 822 823 A hash value that is mutable only in values. The keys may 824 not contain duplicates, while the values may. 825 819 826 =head2 Set 820 827 821 828 class Set does Associative {...} … … 869 876 870 877 =head2 KeyHash 871 878 872 class KeyHash does Associative {...} 879 role KeyHash[::T $t, $default = 0] does Associative {...} 873 880 874 A KeyHash represents a mutable set of values, represented as the keys 881 A C<KeyHash> represents a mutable set of values, represented as the keys 875 882 of a C<Hash>. When asked to behave as a list it ignores its values 876 883 and returns only C<.keys>. C<KeySet> and C<KeyBag> are derived from 877 884 this type, but constrain their values to be C<Bool> and C<UInt>,