Changeset 13589 for docs/Perl6/Spec

Show
Ignore:
Timestamp:
09/25/06 07:19:13 (2 years ago)
Author:
lwall
Message:

Renamed .words to .comb
More Foo:: whackage and "method is export" insertage.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/Perl6/Spec/Functions.pod

    r13528 r13589  
    1313                Mark Stosberg <mark@summersault.com> 
    1414 Date:          12 Mar 2005 
    15  Last Modified: 20 Sep 2006 
    16  Version:       8 
     15 Last Modified: 23 Sep 2006 
     16 Version:       9 
    1717 
    1818This document attempts to document the list of builtin functions in Perl 6. 
     
    492492=item splice 
    493493 
    494  our List multi method splice( @array is rw, Int $offset = 0, Int $size?, *@values ) is export 
     494 our List multi method splice( @array is rw: Int $offset = 0, Int $size?, *@values ) is export 
    495495 
    496496C<splice> fills many niches in array-management, but its fundamental behavior 
     
    692692 role Str { 
    693693     our Str multi method reverse ( $str: ) is export { 
    694         split('', $str).reverse.join 
     694        $str.split('').reverse.join 
    695695     ) 
    696696 } 
     
    768768=head2 Hash 
    769769 
     770The following are defined in the Hash role. 
     771 
    770772=over 4 
    771773 
    772774=item delete 
    773775 
    774  our List  multi method Hash::delete ( *@keys ) 
    775  our Scalar multi method Hash::delete ( $key ) is default 
     776 our List  multi method delete ( %hash: *@keys ) 
     777 our Scalar multi method delete ( %hash: $key ) is default 
    776778 
    777779Deletes the elements specified by C<$key> or C<$keys> from the invocant. 
     
    796798=item exists 
    797799 
    798  our Bool multi method Hash::exists ( $key ) 
     800 our Bool multi method exists ( %hash: $key ) 
    799801 
    800802True if invocant has an element whose key matches C<$key>, false 
     
    869871will support the same levels as the input, unless specified otherwise. 
    870872 
     873The following are all provided by the C<Str> role: 
     874 
    871875=over 
    872876 
    873877=item p5chop 
    874878 
    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) 
    877881 
    878882Trims the last character from C<$string>, and returns it. Called with a 
     
    882886=item chop 
    883887 
    884  our Str method Str::chop ( Str  $string: ) 
     888 our Str method method chop ( Str  $string: ) is export 
    885889 
    886890Returns string with one Char removed from the end. 
     
    888892=item p5chomp 
    889893 
    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) 
    892896 
    893897Related to C<p5chop>, only removes trailing chars that match C</\n/>. In 
     
    896900=item chomp 
    897901 
    898  our Str method Str::chomp ( Str $string: ) 
     902 our Str method method chomp ( Str $string: ) is export 
    899903 
    900904Returns string with newline removed from the end.  An arbitrary 
     
    908912=item crypt 
    909913 
    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) 
    912917 
    913918Encrypts the string using a one-way hash function. This yields a string 
     
    938943=item lc 
    939944 
    940  our Str multi Str::lc ( Str $string ) 
     945 our Str multi method lc ( Str $string: ) is export 
    941946 
    942947Returns the input string after converting each character to its lowercase 
     
    946951=item lcfirst 
    947952 
    948  our Str multi Str::lcfirst ( Str $string ) 
     953 our Str multi method lcfirst ( Str $string: ) is export 
    949954 
    950955Like C<lc>, but only affects the first character. 
     
    953958=item uc 
    954959 
    955  our Str multi Str::uc ( Str $string ) 
     960 our Str multi method uc ( Str $string: ) is export 
    956961 
    957962Returns the input string after converting each character to its uppercase 
     
    962967=item ucfirst 
    963968 
    964  our Str multi Str::ucfirst ( Str $string ) 
     969 our Str multi method ucfirst ( Str $string: ) is export 
    965970 
    966971Performs a Unicode "titlecase" operation on the first character of the string. 
     
    969974=item capitalize 
    970975 
    971  our Str multi Str::capitalize ( Str $string ) 
     976 our Str multi method capitalize ( Str $string: ) is export 
    972977 
    973978Has the effect of first doing an C<lc> on the entire string, then performing a 
     
    981986=item index 
    982987 
    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 
    984989 
    985990C<index> searches for the first occurrence of C<$substring> in C<$string>, 
     
    992997=item pack 
    993998 
    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 ) 
    9981003 
    9991004C<pack> takes a list of pairs and formats the values according to 
     
    10361041=item quotemeta 
    10371042 
    1038  our Str multi Str::quotemeta ( Str $string ) 
     1043 our Str multi method quotemeta ( Str $string: ) is export 
    10391044 
    10401045Returns the input string with all non-"word" characters back-slashed. 
     
    10441049=item rindex 
    10451050 
    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 
    10471052 
    10481053Returns the position of the last C<$substring> in C<$string>. If C<$pos> 
     
    10521057=item split 
    10531058 
    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 
    10581061 
    10591062String delimiters must not be treated as rules but as constants.  The 
    10601063default 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. 
     1064P5's C<< split('S< >') >> will translate to C<comb>.  Null trailing fields 
     1065are no longer trimmed by default. 
     1066 
     1067The C<split> function no longer has a default delimiter nor a default invocant. 
     1068In general you should use C<comb> to split on whitespace now, or to break 
     1069into individual characters.  See below. 
     1070 
     1071As with Perl 5's C<split>, if there is a capture in the pattern it is 
     1072returned in alternation with the split values.  Unlike with Perl 5, 
     1073multiple such captures are returned in a single Match object.  Also unlike 
     1074Perl 5, the string to be split is always the invocant or first argument. 
     1075A warning should be issued if the string appears to be a short constant 
     1076string 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 
     1082The C<comb> function looks through a string for the interesting bits, 
     1083ignoring the parts that don't match.  In other words, it's a version 
     1084of split where you specify what you want, not what you don't want. 
     1085By default it pulls out all the words.  Saying 
     1086 
     1087    $string.comb(/pat/, $n) 
     1088 
     1089is equivalent to 
     1090 
     1091    $string.match(rx:global:x(0..$n):c/pat/) 
     1092 
     1093You may also comb lists and filehandles.  C<+$*IN.comb> counts the words on 
     1094standard input, for instance.  C<comb($thing, /./) returns a list of C<Char> 
     1095from anything that can give you a C<Str>. 
     1096 
     1097If there are captures in the pattern, a list of C<Match> objects (one 
     1098per match) is returned instead of strings.  The unmatched portions 
     1099are never returned.  If the function is combing a lazy structure, 
     1100the return values may also be lazy.  (Strings are not lazy, however.) 
    10641101 
    10651102=item sprintf 
    10661103 
    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 
    10691105 
    10701106This function is mostly identical to the C library sprintf function. 
     
    11851221Should replace vec with declared arrays of bit, uint2, uint4, etc. 
    11861222 
    1187 =item words 
    1188  
    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  
    11921223=back 
    11931224 
     
    12991330=item ord 
    13001331 
    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 
    13041337 
    13051338These functions are available for purposes of backward compatibility. 
     
    13081341numified and a single character when stringified. Thus, chr is just: 
    13091342 
    1310  our Uni multi Str::chr( Uni $codepoint) { $codepoint; } 
     1343 our Uni multi chr( Uni $codepoint) { $codepoint; } 
    13111344 
    13121345C<ord> is almost the same, but it also has a form that takes a string. 
     
    17531786Please post errors and feedback to perl6-language.  If you are making 
    17541787a general laundry list, please separate messages by topic. 
     1788