Changeset 13589 for docs/Perl6/Spec
- Timestamp:
- 09/25/06 07:19:13 (2 years ago)
- Files:
-
- 1 modified
-
docs/Perl6/Spec/Functions.pod (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/Perl6/Spec/Functions.pod
r13528 r13589 13 13 Mark Stosberg <mark@summersault.com> 14 14 Date: 12 Mar 2005 15 Last Modified: 2 0Sep 200616 Version: 815 Last Modified: 23 Sep 2006 16 Version: 9 17 17 18 18 This document attempts to document the list of builtin functions in Perl 6. … … 492 492 =item splice 493 493 494 our List multi method splice( @array is rw ,Int $offset = 0, Int $size?, *@values ) is export494 our List multi method splice( @array is rw: Int $offset = 0, Int $size?, *@values ) is export 495 495 496 496 C<splice> fills many niches in array-management, but its fundamental behavior … … 692 692 role Str { 693 693 our Str multi method reverse ( $str: ) is export { 694 split('', $str).reverse.join694 $str.split('').reverse.join 695 695 ) 696 696 } … … 768 768 =head2 Hash 769 769 770 The following are defined in the Hash role. 771 770 772 =over 4 771 773 772 774 =item delete 773 775 774 our List multi method Hash::delete (*@keys )775 our Scalar multi method Hash::delete ($key ) is default776 our List multi method delete ( %hash: *@keys ) 777 our Scalar multi method delete ( %hash: $key ) is default 776 778 777 779 Deletes the elements specified by C<$key> or C<$keys> from the invocant. … … 796 798 =item exists 797 799 798 our Bool multi method Hash::exists ($key )800 our Bool multi method exists ( %hash: $key ) 799 801 800 802 True if invocant has an element whose key matches C<$key>, false … … 869 871 will support the same levels as the input, unless specified otherwise. 870 872 873 The following are all provided by the C<Str> role: 874 871 875 =over 872 876 873 877 =item p5chop 874 878 875 our Char multi P5emul::Str::p5chop ( Str $string is rw)876 our Char multi P5emul::Str::p5chop ( Str *@strings = ($+_) is rw)879 our Char multi method p5chop ( Str $string is rw: ) is export(:P5) 880 my Char multi p5chop ( Str *@strings is rw ) is export(:P5) 877 881 878 882 Trims the last character from C<$string>, and returns it. Called with a … … 882 886 =item chop 883 887 884 our Str method Str::chop ( Str $string: )888 our Str method method chop ( Str $string: ) is export 885 889 886 890 Returns string with one Char removed from the end. … … 888 892 =item p5chomp 889 893 890 our Int multi P5emul::Str::p5chomp ( Str $string is rw)891 our Int multi P5emul::Str::p5chomp ( Str *@strings = ($+_) is rw)894 our Int multi method p5chomp ( Str $string is rw: ) is export(:P5) 895 my Int multi p5chomp ( Str *@strings is rw ) is export(:P5) 892 896 893 897 Related to C<p5chop>, only removes trailing chars that match C</\n/>. In … … 896 900 =item chomp 897 901 898 our Str method Str::chomp ( Str $string: )902 our Str method method chomp ( Str $string: ) is export 899 903 900 904 Returns string with newline removed from the end. An arbitrary … … 908 912 =item crypt 909 913 910 our Str multi Str::crypt ( Str $plaintext, Str $salt ) 911 our Str multi method Str::crypt ( Str $plaintext: Str $salt ) 914 [I don't think this should be a built-in anymore. -law] 915 916 our Str multi method p5crypt ( Str $plaintext: Str $salt ) is export(:P5) 912 917 913 918 Encrypts the string using a one-way hash function. This yields a string … … 938 943 =item lc 939 944 940 our Str multi Str::lc ( Str $string )945 our Str multi method lc ( Str $string: ) is export 941 946 942 947 Returns the input string after converting each character to its lowercase … … 946 951 =item lcfirst 947 952 948 our Str multi Str::lcfirst ( Str $string )953 our Str multi method lcfirst ( Str $string: ) is export 949 954 950 955 Like C<lc>, but only affects the first character. … … 953 958 =item uc 954 959 955 our Str multi Str::uc ( Str $string )960 our Str multi method uc ( Str $string: ) is export 956 961 957 962 Returns the input string after converting each character to its uppercase … … 962 967 =item ucfirst 963 968 964 our Str multi Str::ucfirst ( Str $string )969 our Str multi method ucfirst ( Str $string: ) is export 965 970 966 971 Performs a Unicode "titlecase" operation on the first character of the string. … … 969 974 =item capitalize 970 975 971 our Str multi Str::capitalize ( Str $string )976 our Str multi method capitalize ( Str $string: ) is export 972 977 973 978 Has the effect of first doing an C<lc> on the entire string, then performing a … … 981 986 =item index 982 987 983 our StrPos multi Str::index( Str $string, Str $substring, StrPos $pos = 0 )988 our StrPos multi method index( Str $string: Str $substring, StrPos $pos = 0 ) is export 984 989 985 990 C<index> searches for the first occurrence of C<$substring> in C<$string>, … … 992 997 =item pack 993 998 994 our Str multi Str::pack( Str::Encoding $encoding, Pair *@items )995 our Str multi Str::pack( Str::Encoding $encoding, Str $template, *@items )996 our buf8 multi Str::pack( Pair *@items )997 our buf8 multi Str::pack( Str $template, *@items )999 our Str multi pack( Str::Encoding $encoding, Pair *@items ) 1000 our Str multi pack( Str::Encoding $encoding, Str $template, *@items ) 1001 our buf8 multi pack( Pair *@items ) 1002 our buf8 multi pack( Str $template, *@items ) 998 1003 999 1004 C<pack> takes a list of pairs and formats the values according to … … 1036 1041 =item quotemeta 1037 1042 1038 our Str multi Str::quotemeta ( Str $string )1043 our Str multi method quotemeta ( Str $string: ) is export 1039 1044 1040 1045 Returns the input string with all non-"word" characters back-slashed. … … 1044 1049 =item rindex 1045 1050 1046 our StrPos multi Str::index( Str $string, Str $substring, StrPos $pos? )1051 our StrPos multi method rindex( Str $string: Str $substring, StrPos $pos? ) is export 1047 1052 1048 1053 Returns the position of the last C<$substring> in C<$string>. If C<$pos> … … 1052 1057 =item split 1053 1058 1054 our List multi Str::split ( Str $delimiter , Str $input_, Int $limit = inf ) 1055 our List multi Str::split ( Rule $delimiter = /\s+/, Str $input, Int $limit = inf ) 1056 our List multi Str::split ( Str $input ; Str $delimiter , Int $limit = inf ) 1057 our List multi Str::split ( Str $input ; Rule $delimiter , Int $limit = inf ) 1059 our List multi method split ( Str $input: Str $delimiter, Int $limit = * ) is export 1060 our List multi method split ( Str $input: Rule $delimiter , Int $limit = * ) is export 1058 1061 1059 1062 String delimiters must not be treated as rules but as constants. The 1060 1063 default is no longer S<' '> since that would be interpreted as a constant. 1061 P5's C<< split('S< >') >> will translate to C<.words> or some such. Null trailing fields 1062 are no longer trimmed by default. We might add some kind of :trim flag or 1063 introduce a trimlist function of some sort. 1064 P5's C<< split('S< >') >> will translate to C<comb>. Null trailing fields 1065 are no longer trimmed by default. 1066 1067 The C<split> function no longer has a default delimiter nor a default invocant. 1068 In general you should use C<comb> to split on whitespace now, or to break 1069 into individual characters. See below. 1070 1071 As with Perl 5's C<split>, if there is a capture in the pattern it is 1072 returned in alternation with the split values. Unlike with Perl 5, 1073 multiple such captures are returned in a single Match object. Also unlike 1074 Perl 5, the string to be split is always the invocant or first argument. 1075 A warning should be issued if the string appears to be a short constant 1076 string and the delimiter does not. 1077 1078 =item comb 1079 1080 our List multi method comb ( Str $input: Rule $matcher = /\S+/, Int $limit = * ) is export 1081 1082 The C<comb> function looks through a string for the interesting bits, 1083 ignoring the parts that don't match. In other words, it's a version 1084 of split where you specify what you want, not what you don't want. 1085 By default it pulls out all the words. Saying 1086 1087 $string.comb(/pat/, $n) 1088 1089 is equivalent to 1090 1091 $string.match(rx:global:x(0..$n):c/pat/) 1092 1093 You may also comb lists and filehandles. C<+$*IN.comb> counts the words on 1094 standard input, for instance. C<comb($thing, /./) returns a list of C<Char> 1095 from anything that can give you a C<Str>. 1096 1097 If there are captures in the pattern, a list of C<Match> objects (one 1098 per match) is returned instead of strings. The unmatched portions 1099 are never returned. If the function is combing a lazy structure, 1100 the return values may also be lazy. (Strings are not lazy, however.) 1064 1101 1065 1102 =item sprintf 1066 1103 1067 our Str multi method Str::sprintf ( Str $format: *@args ) 1068 our Str multi Str::sprintf ( Str $format, *@args ) 1104 our Str multi method sprintf ( Str $format: *@args ) is export 1069 1105 1070 1106 This function is mostly identical to the C library sprintf function. … … 1185 1221 Should replace vec with declared arrays of bit, uint2, uint4, etc. 1186 1222 1187 =item words1188 1189 our List multi Str::words ( Rule $matcher = /\S+/, Str $input, Int $limit = inf )1190 our List multi Str::words ( Str $input ; Rule $matcher = /\S+/, Int $limit = inf )1191 1192 1223 =back 1193 1224 … … 1299 1330 =item ord 1300 1331 1301 our Uni multi Str::chr( Uni $codepoint ) 1302 our Uni multi Str::ord( Uni $character ) 1303 multi Str::ord( Str $string ) 1332 role Uni { 1333 our Uni multi chr( Uni $codepoint ) 1334 our Uni multi ord( Uni $character ) 1335 } 1336 multi method ord( Str $string: ) is export 1304 1337 1305 1338 These functions are available for purposes of backward compatibility. … … 1308 1341 numified and a single character when stringified. Thus, chr is just: 1309 1342 1310 our Uni multi Str::chr( Uni $codepoint) { $codepoint; }1343 our Uni multi chr( Uni $codepoint) { $codepoint; } 1311 1344 1312 1345 C<ord> is almost the same, but it also has a form that takes a string. … … 1753 1786 Please post errors and feedback to perl6-language. If you are making 1754 1787 a general laundry list, please separate messages by topic. 1788
