YAMASHINA Hio
hio****@users*****
2006年 11月 2日 (木) 00:52:16 JST
Index: docs/modules/autobox-Core-0.3/Core.pod diff -u /dev/null docs/modules/autobox-Core-0.3/Core.pod:1.1 --- /dev/null Thu Nov 2 00:52:16 2006 +++ docs/modules/autobox-Core-0.3/Core.pod Thu Nov 2 00:52:16 2006 @@ -0,0 +1,749 @@ + +=encoding utf-8 + +=head1 åå + +autobox::Core - Perl çµã¿è¾¼ã¿é¢æ°ãããªããã£ãåã®ã¡ã½ããã« + +=head1 æ¦è¦ + + use autobox; + use autobox::Core; + + "Hello, World\n"->uc()->print(); + +=head1 説æ + +Methods wrapping F<perl>'s built-in functions for minipulating numbers, strings, arrays, +hashes, and code references. It is handy to use built-in functions as methods to avoid +messy dereferencing syntaxes and parenthesis pile ups. + +æ°å¤, æåå, é å, ããã·ã¥, ããã¦ã³ã¼ããªãã¡ã¬ã³ã¹ãæä½ãã +F<perl>çµã¿è¾¼ã¿é¢æ°ãã©ããããã¡ã½ãã. åä»ãªããªãã¡ã¬ã³ã¹æ§æã +æ¬å¼§ã®è¡çªãé¿ããããã«çµã¿è¾¼ã¿é¢æ°ãã¡ã½ãããã¦å©ç¨ããã®ã«ä¾¿å©ã§ã. + +L<autobox> lets you call methods in scalars that aren't object references. +Numbers, strings, scalars containing numbers, scalars containing strings, +array references, hash references, and code references all work as objects. +L<autobox> adds this feature to L<perl> but does not itself provide any +methods to call. That is left to the user or another module. For example, +this module. + +L<autobox> ã¯ãªãã¸ã§ã¯ããªãã¡ã¬ã³ã¹ã§ã¯ãªãã¹ã«ã©ã¼ã«å¯¾ã㦠+ã¡ã½ããå¼ã³åºããæä¾ãã¾ã. æ°å¤, æåå, æ°å¤ãå«ãã ã¹ã«ã©ã¼, +æååãå«ãã ã¹ã«ã©ã¼, é åãªãã¡ã¬ã³ã¹, ããã·ã¥ãªãã¡ã¬ã³ã¹, +ããã¦ã³ã¼ããªãã¡ã¬ã³ã¹å ¨ã¦ãªãã¸ã§ã¯ãã¨ãã¦åä½ãã¾ã. +L<autobox> 㯠L<perl> ã«ãã®æ©è½ãæä¾ãã¾ããããèªèº«ã§ã¯ +å¼ã³åºãããã¡ã½ãããä½ãæä¾ãã¾ãã. ããã¯ã¦ã¼ã¶ããã®ä»ã® +ã¢ã¸ã¥ã¼ã«ã«ä»»ããã¦ãã¾ã. ãã, ä¾ãã°ä»è¦ã¦ãããã®ã¢ã¸ã¥ã¼ã«. + +F<autobox::Core> is what you'd call a I<stub> module. It is merely glue, presenting +existing functions with a new interface. Most of the methods read like +C<< sub hex ($) { hex($_[0]) } >>. +Besides built-ins that operate on hashes, arrays, scalars, and code references, +some Perl 6-ish things were thrown in, and some keyword like C<foreach> have +been turned into methods. + +F<autobox::Core> ã¯ããªãã®å¼ã³åºã I<ã¹ã¿ã> ã¢ã¸ã¥ã¼ã«ã§ã. +ããã¯åã«æ¥çå¤(glue)ã§ãã, æ¢åã®é¢æ°ãæ°ããã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ +表ç¾ãã¦ãã¾ã. ã»ã¨ãã©ã®é¢æ°ã¯ C<< sub hex ($) { hex($_[0]) } >> ã® +ããã«èªã¿åãã¾ã. +ããã·ã¥, é å, ã¹ã«ã©ã¼, ããã¦ã³ã¼ããªãã¡ã¬ã³ã¹ãæä½ãã +ãã«ãã¤ã³é¢æ°ã«å ãã¦, ããã¤ãã® Perl 6 çãªãã®ãæå ¥ãã㦠+ãã¾ã. ãã㦠C<foreach> ã®æ§ãªå¹¾ã¤ãã®ãã¼ã¯ã¼ããã¡ã½ããã« +ãªã£ã¦ãã¾ã. + +=head2 ä½ãå®è£ ããã¦ããã®ã + +All of the functions listed in L<perldoc> under the headings: +"Functions for real @ARRAYs", +"Functions for real %HASHes", +"Functions for list data", +and "Functions for SCALARs or strings", plus a few taken from other sections +and documented below. +Some things expected in Perl 6, such as C<last>, C<elems>, and C<curry>, have been thrown in. +For use in conjuction with L<Perl6::Contexts>, C<flatten> explicitly flattens an array. + +L<perldoc> ã®ä¸ã§æ¬¡ã®è¦åºãã§ãªã¹ãã¢ããããã¦ããå ¨ã¦ã®é¢æ°: +"å®éã® @ARRAY ã«å¯¾ããé¢æ°(Functions for real @ARRAYs)", +"å®éã® %HASH ã«å¯¾ããé¢æ°(Functions for real %HASHes)", +"ãªã¹ããã¼ã¿ã«å¯¾ããé¢æ°(Functions for list data)", +ãã㦠"SCALAR è¥ããã¯æååã«å¯¾ããé¢æ°(Functions for SCALARs or +strings)", å ãã¦å¾è¿°ã®ä»ã® +ã»ã¯ã·ã§ã³ãããã¥ã¡ã³ãããåã£ã¦ããããã¤ã. +Perl 6 ã§äºå®ããã¦ããå¹¾ã¤ãã®äºé , C<last>, C<elems>, ãã㦠C<curry> +ãæå ¥ããã¦ãã¾ã. L<Perl6::Contexts>, C<flatten> 㨠conjuction ã㦠+使ãããã«ã¯æ示çã«é åãå¹³å¦ã«ãã(flatten)ããå¿ è¦ãããã¾ã. + +Of the built-in stuff, the things you use most often on data are all implemented. +Here's a small sample: + +çµã¿è¾¼ã¿ã®ãã®ã®, ãã¼ã¿ã«å¯¾ãã¦ã¨ã¦ããã使ãç©ã¯å ¨ã¦å®è£ ããã¦ãã¾ã. +ã¡ãã£ã¨ããä¾: + + print [10, 20, 30, 40, 50]->pop(), "\n"; + print [10, 20, 30, 40, 50]->shift(), "\n"; + + my $arrref = [10, 20, 30]; + + my $lala; + $lala = "Lalalalala\n"; print "chomp: ", $lala->chomp(), ' ', $lala, "\n"; + $lala = "Lalalalala\n"; print "lcfirst: ", $lala->lcfirst(), ' ', $lala, "\n"; + + my $hashref = { foo => 10, bar => 20, baz => 30, qux => 40 }; + print "hash keys: ", join ' ', $hashref->keys(), "\n"; + +Besides those sections of L<perlfunc>, I've implemented +C<tie>, +C<tied>, +C<ref>, +C<undef>, +C<bless>, +and C<vec>, where they make sense. +C<tie>, C<tied>, and C<undef> don't work on code references, and C<bless> doesn't work on non-reference +scalars. +C<quotemeta> works on non-reference scalars, along with C<split>, C<m>, and C<s> for regular expression operations. + +L<perlfunc> ã®ãããã®ã»ã¯ã·ã§ã³ã®å㧠+C<tie>, +C<tied>, +C<ref>, +C<undef>, +C<bless>, +ãã㦠C<vec>, ãããããæå³ããªãããã«å®è£ ãã¾ãã. +C<tie>, C<tied>, ãã㦠C<undef> ã¯ã³ã¼ããªãã¡ã¬ã³ã¹ã§ã¯åä½ãã, +C<bless> ã¯ãªãã¡ã¬ã³ã¹ã§ã¯ãªãã¹ã«ã©ã¼ã§ã¯åä½ãã¾ãã. +C<quotemeta> ã¯ãªãã¡ã¬ã³ã¹ã§ã¯ãªãã¹ã«ã©ã¼ã§åä½ã, +æ£è¦è¡¨ç¾æä½ã¯ C<split>, C<m>, ãã㦠C<s> ã¨å ±ã«ããã¾ã. + + my $arr = [ 1 .. 10 ]; + $arr->undef; + +Array references can tell you how many elements they contain and the index of their last element: + +é åãªãã¡ã¬ã³ã¹ã¯ä½åã®è¦ç´ ãæã£ã¦ããããæ°ããã, æå¾ã®è¦ç´ ã® +æ·»åãè¨ããã¨ãåºæ¥ã¾ã. + + my $arr = [ 1 .. 10 ]; + print '$arr contains ', $arr->size, + ' elements, the last having an index of ', $arr->last, "\n"; + +Array references have a C<flatten> method to dump their elements. +This is the same as C<< @{$array_ref} >>. + +é åãªãã¡ã¬ã³ã¹ã¯ãã®è¦ç´ ããã³ãããããã« C<flatten> ã¡ã½ããã +æã£ã¦ãã¾ã. ãã㯠C<< @{$array_ref} >> ã¨åãã§ã. + + my $arr = [ 1 .. 10 ]; + print join " -- ", $arr->flatten, "\n"; + +Under L<Perl6::Contexts>, you'll often need to write code equivalent to the follow: + +L<Perl6::Contexts> ã®å½±é¿ä¸ã§ã¯ä»¥ä¸ã¨ç価ãªã³ã¼ããæ¸ãå¿ è¦ãããã¾ã: + + use Perl6::Contexts; + use autobox; + use autobox::Core; + + my @arr = ( 1 .. 10 ); + do_something(@arr->flatten); + +Array references can be iterated on using C<for> and C<foreach>. Both take a code +reference as the body of the for statement. +C<foreach> passes the current element itself in each pass. +C<for> passes the index of the current element in to that code block, and then +the current element, and then a reference to the array itself. + +é åãªãã¡ã¬ã³ã¹ã¯ C<for> åã³ C<foreach> ã使ã£ã¦ã¤ãã¬ã¼ã·ã§ã³ãã +äºãåºæ¥ã¾ã. ã©ã¡ãã for æã®æ¬ä½ã¨ãã¦ã³ã¼ããªãã¡ã¬ã³ã¹ã +åãã¾ã. C<foreach> ã¯ååã渡ãã®ä¸ã§ç¾å¨ã®ã¨ã¬ã¡ã³ãèªèº«ã +渡ãã¾ã. C<for> ã¯ã³ã¼ããããã¯ã«ç¾å¨ã®è¦ç´ ã®ã¤ã³ããã¯ã¹, ããã¦ç¾å¨ã® +è¦ç´ , ããã«é åèªèº«ã®ãªãã¡ã¬ã³ã¹ã渡ãã¾ã. + + my $arr = [ 1 .. 10 ]; + $arr->foreach(sub { print $_[0], "\n" }); + $arr->for(sub { die unless $_[1] == $_[2]->[$_[0]] }); + +C<sum> is a toy poke at doing L<Language::Functional>-like stuff: + +C<sum> 㯠L<Language::Functional> ã£ã½ããã¨ãããããã¡ãã½ã£ãã§ã: + + print $arrref->sum(), "\n"; + +If this goes over well, I'll make L<Langauge::Functional> a dependency and expose +its function as methods on the correct data types. Or maybe I will do this anyway. + +ããããã¾ããããã¨ãåå³ããä¸ã§, L<Langauge::Functional> ã«ä¾åã㦠+ãã®é¢æ°ãé©åãªãã¼ã¿ã«å¯¾ããã¡ã½ããã¨ãã¦é²åºããããã¨æãã¾ã. +è¥ããã¯ã¨ããããã§è¡ãããããã¾ãã. + +C<each> is like C<foreach> but for hash references. For each key in the hash, +the code reference is invoked with the key and the corresponding value as arguments: + +C<each> 㯠C<foreach> ã¨ä¼¼ã¦ãã¾ããããã·ã¥ãªãã¡ã¬ã³ã¹ã«å¯¾ã㦠+è¡ãã¾ã. ããã·ã¥ã®ä¸ã®åãã¼ã«å¯¾ãã¦, å¼æ°ã«ãã¼ã¨å¯¾å¿ããå¤ã +ã¤ãã¦ã³ã¼ããªãã¡ã¬ã³ã¹ãå¼ã³åºãã¾ã: + + my $hashref = { foo => 10, bar => 20, baz => 30, quux => 40 }; + $hashref->each(sub { print $_[0], ' is ', $_[1], "\n" }); + +There is currently no way to have the elements sorted before they are handed to the +code block. If someone requests a way of passing in a sort criteria, I'll implement it. + +ä»ã®ã¨ããã³ã¼ããããã¯ã«æ¸¡ãåã«è¦ç´ ãã½ã¼ãããæ¹æ³ã¯ããã¾ãã. +ãã誰ããã½ã¼ãã®å¤æåºæºã渡ãæ¹æ³ãæ±ãããå®è£ ããã§ããã. + +C<m> is C<< m// >> and C<s> is C<< s/// >>. These work on scalars. +Pass a regular expression created with C<< qr// >> and specify flags to the regular expression +as part of the regular expression using the C<< (?imsx-imsx) >> syntax documented in L<perlre>. +C<m> returns an array reference so that things such as C<map> and C<grep> may be called on the result. + +C<m> 㯠C<< m// >> 㧠C<s> 㯠C<< s/// >> ã§ã. ãããã¯ã¹ã«ã©ã¼ +ã«å¯¾ãã¦åä½ãã¾ã. C<< qr// >> ã§ä½æããæ£è¦è¡¨ç¾ã¨, L<perlre> +ã§è¨è¿°ããã¦ãã C<< (?imsx-imsx) >> æ§æã使ã£ãæ£è¦è¡¨ç¾ã®ä¸é¨ +ã¨ãã¦æ£è¦è¡¨ç¾ã¸ã®ãã©ã°ãæå®ãã¾ã. C<m> ã¯é åãªãã¡ã¬ã³ã¹ã +è¿ãã®ã§, C<map> ã C<grep> ã¨ãã£ãç©ããã®çµæã«å¯¾ãã¦å¼ã³åºã +äºãåºæ¥ã¾ã. + + my ($street_number, $street_name, $apartment_number) = + "1234 Robin Drive #101"->m(qr{(\d+) (.*)(?: #(\d+))?})->elements; + + print "$street_number $street_name $apartment_number\n"; + +C<split> is called on a non-reference scalar with the regular expression passed in. This is +done for consistency with C<m> and C<s>. + +C<split> ã¯ãªãã¡ã¬ã³ã¹ã§ã¯ãªãã¹ã«ã©ã¼ã«å¯¾ãã¦æ£è¦è¡¨ç¾ãä¼´ã£ã¦ +å¼ã³åºãã¾ã. ãã㯠C<m> åã³ C<s> ã¨åãã§ã. + + print "10, 20, 30, 40"->split(qr{, ?})->elements, "\n"; + +You may C<curry> code references: + +ã³ã¼ããªãã¡ã¬ã³ã¹ã C<curry> åãããã¨ãåºæ¥ã¾ã. + + $adding_up_numbers = sub { + my $first_number = shift; + my $second_number = shift; + return $first_number + $second_number; + }; + + my $adding_five_to_numbers = $adding_up_numbers->curry(5); + + $adding_five_to_numbers->(20)->print; "\n"->print; + +That's it. + +以ä¸. + +=head2 足ããªãé¨å + +Operators. I'm tired. I'll do it in the morning. Maybe. Send me a patch. + +æ¼ç®å. ã§ãããç²ããã. ããã¯æã«ããã. å¤å. ãããããã£ã¨ãã¦. + +File and socket operations are already implemented in an object-oriented fashion +care of L<IO::Handle> and L<IO::Socket::INET>. +Functions listed in the L<perlfunc> headings "System V interprocess communication functions", +"Fetching user and group info", +"Fetching network info", +"Keywords related to perl modules", +"Functions for processes and process groups", +"Keywords related to scoping", +"Time-related functions", +"Keywords related to the control flow of your perl program", +"Functions for filehandles, files, or directories", +and +"Input and output functions". +These things are likely implemented in an object oriented fashion by other CPAN +modules, are keywords and not functions, +take no arguments, +or don't make sense as part of the string, number, array, hash, or code API. +C<srand> because you probably shouldn't be using it. +C<each> on hashes. There is no good reason it is missing. + +ãã¡ã¤ã«ã¨ã½ã±ããã®æä½ã¯ L<IO::Handle> 㨠L<IO::Socket::INET> +ã®æ¹ã§ãªãã¸ã§ã¯ãæåçã«å®è£ ããã¦ãã¾ã. +L<perlfunc> ã®ä»¥ä¸ã®è¦åºãã§ãªã¹ãã¢ããããã¦ããç©: +"System V ããã»ã¹ééä¿¡é¢æ°(System V interprocess communication functions)", +"ã¦ã¼ã¶åã³ã°ã«ã¼ãæ å ±ã®åå¾(Fetching user and group info)", +"ãããã¯ã¼ã¯æ å ±ã®åå¾(Fetching network info)", +"perl ã¢ã¸ã¥ã¼ã«ã«é¢é£ãããã¼ã¯ã¼ã(Keywords related to perl modules)", +"ããã»ã¹ã¨ããã»ã¹ã°ã«ã¼ãã«å¯¾ããé¢æ°(Functions for processes and process groups)", +"ã¹ã³ã¼ãã«å¯¾ããé¢æ°(Keywords related to scoping)", +"æéé¢ä¿ã®é¢æ°(Time-related functions)", +"perl ããã°ã©ã ã®ããã¼å¶å¾¡ã«é¢ãããã¼ã¯ã¼ã(Keywords related to +the control flow of your perl program)", +"ãã¡ã¤ã«ãã³ãã«, ãã¡ã¤ã«, è¥ããã¯ãã£ã¬ã¯ããªã«å¯¾ããé¢æ°(Functions +for filehandles, files, or directories)", +ãã㦠"å ¥åºåé¢æ°(Input and output functions)". +ãããã¯ä»ã®CPANã¢ã¸ã¥ã¼ã«ã«ãã£ã¦ãªãã¸ã§ã¯ãæåã«å®è£ ããã¦ãã +ãªãã®, é¢æ°ã§ã¯ãªããã¼ã¯ã¼ã, å¼æ°ãåããªãç©, ããã +æåå, æ°å¤, é å, ããã·ã¥, ã³ã¼ãã®APIã¨ãã¦æå³ããªããã® +ãã¡ã§ã. +C<srand> ã¯ä½¿ãã¹ãã§ã¯ãªãã§ããã. +C<each> ã¯ããã·ã¥ã«å¯¾ãã¦. ããããªããã¨ã®ä¸æãªçç±ã¯ããã¾ãã. + +=head2 autoboxå + +I<This section quotes four pages from the manuscript of Perl 6 Now: The Core Ideas Illustrated with Perl 5 by myself, Scott Walters. The text appears in the book starting at page 248. This copy lacks the benefit of copyedit - the finished product is of higher quality. See the shameless plug in the SEE ALSO section for information on ordering Perl 6 Now.> + +I<ãã®ã»ã¯ã·ã§ã³ã§ã¯ç§, Scott Walters ã«ãã Perl 6 Now: The Core Ideas Illustrated with Perl 5 ãã4ãã¼ã¸ãå¼ç¨ãã¦ãã¾ã. ããã¹ãã¯æ¬ã®248ãã¼ã¸ +ããããã¾ã. ãã®ã³ãã¼ã¯è¤è£½ã®å©çãæ¬ ãã¦ãã¾ã - å®æãã製å㯠+ããé«å質ã§ã. Perl 6 Now ã®ãªã¼ãã¼ã«é¢ãã¦ã¯ SEE ALSO ã»ã¯ã·ã§ã³ã® +ç¡æ¥ãªåºåãåç §ãã¦ãã ãã. > + +A I<box> is an object that contains a primitive variable. +Boxes are used to endow primitive types with the capabilities of objects. +This is essential in strongly typed languages but never strictly required in Perl. +Programmers might write something like C<< my $number = Int->new(5) >>. +This is manual boxing. +To I<autobox> is to convert a simple type into an object type automatically, or only conceptually. +This is done by the language. +It makes a language look to programmers as if everything is an object while the interpreter +is free to implement data storage however it pleases. +Autoboxing is really making simple types such as numbers, strings, and arrays appear to be objects. + +I<box> ã¨ã¯ããªããã£ãå¤æ°ãå«ãã§ãããªãã¸ã§ã¯ãã§ã. box ã«ã¯ +ããªããã£ãåã«å¯¾ãã¦ãªãã¸ã§ã¯ãã¨ãã¦ã®æ©è½ã賦ä¸ããçºã« +使ããã¾ã. ããã¯å¼·ãåä»ããããè¨èªã§ã®è¦ç´ ã§ãã£ã¦å³å¯ã«ã¯ +Perl ã«ã¯å¿ è¦ã®ãªãç©ã§ã. ããã°ã©ã㯠C<< my $number = Int->new(5) >> +ã¨æ¸ããã¨ãã§ãã¾ã. ããã¯æä½æ¥ã®boxåã§ã. I<autobox> (èªåboxå) +ã¨ã¯ç°¡åãªåããªãã¸ã§ã¯ãåã«èªåçã«å¤æãããã¨è¥ããã¯ãã® +æ¦å¿µã§ã. ããã¯è¨èªã«ãã£ã¦è¡ããã¾ã. ããã¯ããã°ã©ãã«è¨èªã® +ã¤ã³ã¿ããªã¿ããã¼ã¿æ ¼ç´åã®å®è£ ã¯èªç±ã§ããã«ãããããã +å ¨ã¦ããªãã¸ã§ã¯ãã§ãããã®ããã«è¦ãã¾ã. +autobox ã¯å®éã«æ°å¤, æåå, é åã¨ãã£ãç°¡åãªåããªãã¸ã§ã¯ãã¨ã㦠+å ·ç¾åãã¾ã. + +C<int>, C<num>, C<bit>, C<str>, and other types with lower case names, are primitives. +They're fast to operate on, and require no more memory to store than the data held strictly requires. +C<Int>, C<Num>, C<Bit>, C<Str>, and other types with an initial capital letter, are objects. +These may be subclassed (inherited from) and accept traits, among other things. +These objects are provided by the system for the sole purpose of representing primitive types as objects, +though this has many ancillary benefits such as making C<is> and C<has> work. +Perl provides C<Int> to encapsulate an C<int>, C<Num> to encapsulate a C<num>, C<Bit> to encapsulate a C<bit>, and so on. +As Perl's implementations of hashes and dynamically expandable arrays store any type, not just objects, Perl +programmers almost never are required to box primitive types in objects. +Perl's power makes this feature less essential than it is in other languages. + +C<int>, C<num>, C<bit>, C<str>, ããã¦ä»ã®å°æåã®ååã®å㯠+ããªããã£ãã§ã. ãããã¯æä½ãéã, æ ¼ç´ã®éã«ãã¼ã¿ãå³å¯ã«å¿ è¦ã¨ +ããããä½è¨ãªã¡ã¢ãªãå¿ è¦ã¨ãã¾ãã. C<Int>, C<Num>, C<Bit>, C<Str> +ããã¦ï¼æåç®ã大æåã«ãªã£ã¦ãããã®ä»ã®åã¯ãªãã¸ã§ã¯ãã§ã. +ãããã¯ãµãã¯ã©ã¹å(ä»ããæ´¾ç)ãã¦ãã¦, ç¹å¾´ãã®ä»ãåãç¶ãã§ãã +ã§ããã. ãããã®ãªãã¸ã§ã¯ãã¯ããªããã£ãåããªãã¸ã§ã¯ãã¨ã㦠+表ç¾ããã¨ãããã ï¼ã¤ã®ç®çã®ããã«ã·ã¹ãã ã«ãã£ã¦æä¾ãã㦠+ãã¾ãã, ããã«ã¯ C<is> ã C<has> ãæ©è½ãããã¨ãã£ãå¤ãã®è£å©ç㪠+å©çãããããã¾ã. Perl 㯠C<int> ããããããã« C<Int> ã, +C<num> ããããããã« C<Num> ã, C<bit> ããããããã« C<Bit> ã, +çã ãæä¾ãã¾ã. Perl ã®ããã·ã¥ãåçã«æ¡å¼µå¯è½ãªé åã®å®è£ 㯠+ãªãã¸ã§ã¯ãã ãã§ãªãä»»æã®åãæ ¼ç´ã§ãããã, Perl ããã°ã©ã㯠+ããªããã£ãåããªãã¸ã§ã¯ãã«boxåããå¿ è¦ã¯ã»ã¨ãã©ããã¾ãã. +Perl ã®åã¯ãã®æ©è½ãä»ã®è¨èªãè¡ãããæ¬è³ªã§ãªããã¦ãã¾ã. + +X<autobox>ing makes primitive objects and they're boxed versions equivalent. +An C<int> may be used as an C<Int> with no constructor call, no passing, nothing. +This applies to constants too, not just variables: + +X<autobox> autoboxåã¯ããªããã£ãããªãã¸ã§ã¯ãã¨ã, ããã¯boxåãã +ãã®ã¨ç価ã§ã. C<int> ã¯ã³ã³ã¹ãã©ã¯ã¿ãå¼ã³åºããã渡ããããå ¨ã +ãããã¨ãªãã« C<Int> ã¨ãã¦ä½¿ããã¨ãã§ãã¾ã. + + # Perl 6 - autoboxing associates classes with primitives types: + # Perl 6 - autobox åã¯ã¯ã©ã¹ã¨ããªããã£ãåãçµã³ã¤ãã¾ã. + + print 4.sqrt, "\n"; + +This is perfectly valid Perl 6. + +ããã¯å®å ¨ã«æå¹ãª Perl 6 ã®æã§ã. + +All of this applies to hashes and arrays, as well: + +ããã¯ããã·ã¥ãé åã«ãåæ§ã«é©ç¨ã§ãã¾ã: + + # Perl 6 - autoboxing associates classes with primitive types: + # Perl 6 - autobox åã¯ã¯ã©ã¹ã¨ããªããã£ãåãçµã³ã¤ãã¾ã. + + print [ 1 .. 20 ].elems, "\n"; + +The language is free to implement data storage however it wishes but the programmer +sees the variables as objects. + +è¨èªã§ã¯ãã¼ã¿æ ¼ç´åã好ããªããã«å®è£ ã§ãã¾ãã, ããã°ã©ããã㯠+å¤æ°ããªãã¸ã§ã¯ãã§ãããã®ããã«è¦ãã¾ã. + +Expressions using autoboxing read somewhat like Latin suffixes. +In the autoboxing mind-set, you might not say that something is "made more mnemonic", +but has been "mnemonicified". + +autoboxãå©ç¨ããå¼ã¯ã©ãã³æ¥å°¾è¾ã®ãããªä½ãã®ããã«èªãã¾ã. +autoboxã®ç²¾ç¥ã§ã¯, ä½ãããã"mnemonic"ã«ããã¨ããã®ã§ã¯ãªãã¦, +ããã "mnemonicified" ãããã¨è¨ãã¾ã. + +Autoboxing may be mixed with normal function calls. +In the case where the methods are available as functions and the functions are +available as methods, it is only a matter of personal taste how the expression should be written: + +autoboxåã¯é常ã®é¢æ°å¼ã³åºãã¨æ··å¨ã§ãã¾ã. ã¡ã½ãããé¢æ°ã¨ã㦠+å©ç¨å¯è½ã§ããé¢æ°ãã¡ã½ããã¨ãã¦å©ç¨å¯è½ã§ããå ´åã«ã¯, å¼ã +ã©ãè¨è¿°ãããã¯å人ã®å好ã«ä»»ãããã¦ãã¾ã. + + # Calling methods on numbers and strings, these three lines are equivalent + # Perl 6 + # æ°åã¨æåã«å¯¾ãã¦ã¡ã½ããã®å¼ã³åºã, ãã®ï¼è¡ã¯ Perl 6 çã«ç価ã§ã. + + print sqrt 4; + print 4.sqrt; + 4.sqrt.print; + +The first of these three equivalents assumes that a global C<sqrt()> function exists. +This first example would fail to operate if this global function were removed and only +a method in the C<Num> package was left. + +ãããï¼ã¤ã®ãã¡æåã®ï¼ã¤ã¯ã°ãã¼ãã«ãª C<sqrt()> é¢æ°ãåå¨ãããã¨ã +ä»®å®ãã¦ãã¾ã. ãã®ã°ãã¼ãã«é¢æ°ãåé¤ãã C<Num> ããã±ã¼ã¸ã«ã®ã¿ +æ®ã£ãå ´åã«ã¯æåã®ä¾ã¯å¤±æãã¾ã. + +Perl 5 had the beginnings of autoboxing with filehandles: + +Perl 5 ã§ã¯ãã¡ã¤ã«ãã³ãã«ã® autobox åãå§ãã¾ãã. + + use IO::Handle; + open my $file, '<', 'file.txt' or die $!; + $file->read(my $data, -s $file); + +Here, C<read> is a method on a filehandle we opened but I<never blessed>. +This lets us say things like C<< $file->print(...) >> rather than the often ambagious +C<< print $file ... >>. +To many people, much of the time, it makes more conceptual sense as well. + +ããã§, C<read> ã¯ç§ãã¡ãéãããã¡ã¤ã«ãã³ãã«ä¸ã®ã¡ã½ããã§ãã +ããã¯I<å ¨ã bless ããã¦ãã¾ãã>. ããã¯ææ§ãª C<< print $file ... >> +ã§ã¯ãªã C<< $file->print(...) >> ã®ãããªãã®ã¨è¨ããã¾ã. +å¤ãã®äººã ã®å¤ãã®æéã®ããã«, ããã¯åæ§ã«ããæ¦å¿µã®æå³ãä½ãã¾ã. + +=head3 ããªããã£ãåãBoxåããçç± + +What good is all of this? + +ããã¯çµå±ä½ã®å½¹ã«ç«ã¤ã®? + +=over 1 + +=item Makes conceptual sense to programmers used to object interfaces as I<the> way +to perform options. + +ãªãã¸ã§ã¯ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã使ã£ã¦ããããã°ã©ãã«ãªãã·ã§ã³ãå¦ç +ããããã®I<ãã®>æ¹æ³ã¨ãã¦æ¦å¿µçãªæè¦ãçã¿åºãã¾ã. + +=item Alternative idiom. Doesn't require the programmer +to write or read expressions with complex precedence rules or strange operators. + +ããä¸ã¤ã®è¡¨ç¾. ããã°ã©ãã«è¤éãªæç¶ãã«ã¼ã«ãå¥å¦ãªæ¼ç®åã +èªã¿æ¸ããããå¿ è¦ãããã¾ãã. + +=item Many times that parenthesis would otherwise have to span a large expression, the expression +may be rewritten such that the parenthesis span only a few primitive types. + +é·å¤§ãªå¼ãè£ãããã®æ¬å¼§ãå¿ è¦ã«ãªãå¤ãã®ç¶æ³ã§ã¯å°ãã®ããªããã£ãå +ã«æ¬å¼§ãè£ãã ãã«æ¸ãæãããã¨ãã§ããã§ããã. + +=item Code may often be written with fewer temporary variables. + +ã³ã¼ããããå°ãªããã³ãã©ãªå¤æ°ã§æ¸ãç´ããã¨ãã§ãã¾ã. + +=item Autoboxing provides the benefits of boxed types without the memory bloat of +actually using objects to represent primitives. Autoboxing "fakes it". + +autobox ã¯ãªãã¸ã§ã¯ããå®éã«ããªããã£ãåã表ç¾ããããã« +ã¡ã¢ãªããµããã¾ãããã¨ãªãã« box ãããåã®æ©æµãæä¾ãã¾ã. +autobox ã¯"ãããæ¬è£ " ãã¾ã. + +=item Strings, numbers, arrays, hashes, and so on, each have their own API. +Documentation for an C<exists> method for arrays doesn't have to explain how hashes are +handled and vice versa. + +æåå, æ°å¤, é å, ããã·ã¥, ãã®ä»ã¯ããããå¥ã ã®APIãæã£ã¦ãã¾ã. +é åç¨ã® C<exists> ã¡ã½ããã®ããã¥ã¡ã³ãã§ã¯ããã·ã¥ã§ããã +ã©ã®ããã«å¦çããããã説æããå¿ è¦ã¯ããã¾ãã. + +=item Perl tries to accommodate the notion that the "subject" of a statement +should be the first thing on the line, and autoboxing furthers this agenda. + +Perl ã¯æã®"主èª"ã¯è¡ã®å é ã«ç½®ãã¹ãã§ããã¨ããææ¡ã試ã¿ã¦ãã¦, +ãã㦠autobox ã¯ãããä¿é²ãã¦ãã¾ã. + +=back + +Perl is an idiomatic language and this is an important idiom. + +Perl ã¯æ £ç¨å¥çãªè¨èªã§ãã, ããã¯éè¦ãªè¡¨ç¾ã§ã. + +=head3 主èªãå é ã«: ä½è« + +Perl's design philosophy promotes the idea that the language should be flexible enough +to allow programmers to place the X<subject> of a statement first. +For example, C<< die $! unless read $file, 60 >> looks like the primary purpose of the statement is +to C<die>. +While that might be the programmers primary goal, when it isn't, the programmer +can communicate his real primary intention to programmers by reversing the order of +clauses while keeping the exact same logic: C<< read $file, 60 or die $! >>. +Autoboxing is another way of putting the subject first. +Nouns make good subjects, and in programming, variables, constants, and object names are the nouns. +Function and method names are verbs. +C<< $noun->verb() >> focuses the readers attention on the thing being acted on rather than the action being performed. +Compare to C<< $verb($noun) >>. + +Perl ã®è¨è¨å²å¦ã§ã¯, è¨èªã¯ããã°ã©ãã«æã®å é ã«X<主èª>主èªãç½®ã +ã®ã許ãããããååã«æè»ã§ããã¹ãã¨ããã¾ã. ä¾ãã°, +C<< die $! unless read $file, 60 >> ã¯ãã®æã®ç¬¬ä¸ã®ç®çã C<die> 㧠+ããããã«è¦ãã¾ã. ãããããã°ã©ãã®ç¬¬ä¸ã®ç®çã¨æãã¾ãã, +ããã§ãªãã¨ãã«ã¯ããã°ã©ãã¯å½¼ã®ç¬¬ä¸ã®ç®çãå ¨ãåããã¸ãã¯ã +ä¿ã£ãã¾ã¾ç¯ã®é åºãå転ããããã¨ã§ææã®çéãã¨ããã¨ãã§ãã¾ã: +C<< read $file, 60 or die $! >>.autobox ã¯ä¸»èªãå é ã«ç½®ã +ããä¸ã¤ã®æ¹æ³ã§ã. é¢æ°ãã¡ã½ããã¯å士ã§ã. +C<< $noun->verb() >> ã¯åä½ãå¦çããããã¨ã§ã¯ãªã +åä½ã®å¯¾è±¡ã¨ãªããã®ãã®ã«èªã¿æã®æ³¨æãå¼ãã§ããã. +C<< $verb($noun) >> ã¨æ¯è¼ãã¦ã¿ã¦ãã ãã. + +=head3 autoboxåã¨ã¡ã½ããã®çµæ + +In Chapter 11 [Subroutines], we had examples of ways an expression could be +written. +Here it is again: + +第11ç¯ [ãµãã«ã¼ãã³] ã§, å¼ãè¨è¿°ããæ¹æ³ãä¾ç¤ºãã¾ãã. +ããã§ã¾ã示ãã¾ã: + + # Various ways to do the same thing: + # åããã¨ãããããã«æ§ã ãªæ¹æ³ãããã¾ã: + + print(reverse(sort(keys(%hash)))); # Perl 5 - pathological parenthetic + # Perl 5 - ç çãªæ¬å¼§ + print reverse sort keys %hash; # Perl 5 - no unneeded parenthesis + # Perl 5 - ä¸è¦ãªæ¬å¼§ãåé¤ + + print(reverse(sort(%hash,keys)))); # Perl 6 - pathological + # Perl 6 - ç ç + print reverse sort %hash.keys; # Perl 6 - no unneeded parenthesis + # Perl 6 - ä¸è¦ãªæ¬å¼§ãé¤å» + + %hash.keys ==> sort ==> reverse ==> print; # Perl 6 - pipeline operator + # Perl 6 - ãã¤ãã©ã¤ã³æ¼ç®å + + %hash.keys.sort.reverse.print; # Perl 6 - autobox + + %hash->keys->sort->reverse->print; # Perl 5 - autobox + +This section deals with the last two of these equivalents. +These are method calls + +ãã®ç¯ã§ã¯ãããç価ãªå¼ã®ä¸ã§æå¾ã®ï¼ã¤ãæ±ãã¾ã. +次ã®ãããªã¡ã½ããå¼ã³åºããèãã¦ã¿ã¾ã: + + use autobox; + use autobox::Core; + use Perl6::Contexts; + + my %hash = (foo => 'bar', baz => 'quux'); + + %hash->keys->sort->reverse->print; # Perl 5 - autobox + + # prints "foo baz" + +Each method call returns an array reference, in this example. +Another method call is immediately performed on this value. +This feeding of the next method call with the result of the previous call is the common mode +of use of autoboxing. +Providing no other arguments to the method calls, however, is not common. + +ãã®ä¾ã«ããã¦ã¯, åã¡ã½ããå¼ã³åºãã¯é åãªãã¡ã¬ã³ã¹ãè¿ãã¾ã. +ä»ã®ã¡ã½ããå¼ã³åºãã¯ãã®å¤ãç´ãã«å¦çãã¦ãã¾ã. +åã®å¼ã³åºãã®çµæã§æ¬¡ã®ã¡ã½ããå¼ã³åºãããããã®éé㯠+autobox ã®å©ç¨ã«ãããä¸è¬çãªç¨æ³ã§ã. ã¡ã½ããå¼ã³åºãã«ä½ã® +å¼æ°ãä¸ãã¦ããªãã®ã¯ä¸è¬çã¨ããããã§ã¯ããã¾ããã. + +F<Perl6::Contexts> recognizes object context as provided by C<< -> >> and +coerces C<%hash> into a reference, suitable for use with F<autobox>. +F<autobox> associates primitive types, such as references of various sorts, with classes. +F<autobox::Core> throws into those classes methods wrapping Perl's built-in functions. +In the interest of full disclosure, F<Perl6::Contexts> and F<autobox::Core> are my creations. + +F<Perl6::Contexts> ã¯ãªãã¸ã§ã¯ãã®ã³ã³ããã¹ãã C<< -> >> ã«ãã£ã¦ +å®ã¾ããã¨ãèªèãã¦, C<%hash> ãF<autobox> ãå©ç¨ããã®ã«é©å㪠+ãªãã¡ã¬ã³ã¹ã¸ã¨å¤æãã¾ã. F<autobox> ã¯æ§ã ãªç¨®é¡ã®ãªãã¡ã¬ã³ã¹ã® +ãããªããªããã£ãåã, ã¯ã©ã¹ã«é¢ä¿ããã¾ã. F<autobox::Core> 㯠+Perl ã®çµã¿è¾¼ã¿é¢æ°ãã©ãããã¦ãããããã®ã¯ã©ã¹ã®ã¡ã½ããã« +æãã¾ã. å ¨å®¹ãé示ããèæ¯ã«, F<Perl6::Contexts> 㨠F<autobox::Core> +ã¯ç§ã®å¶ä½ã¨ãããã¨ãããã¾ã. + +=head3 å¼ãç°¡åã«ããããã® autobox + +One of my pet peeves in programming is parenthesis that span large expression. +It seems like about the time I'm getting ready to close the parenthesis I opened +on the other side of the line, I realize that I've forgotten something, and I have to +arrow back over or grab the mouse. +When the expression is too long to fit on a single line, it gets broken up, then +I must decide how to indent it if it grows to 3 or more lines. + +ããã°ã©ãã³ã°ã«ããã¦ç§ã®ãå¾æã®ããããã®ä¸ã¤ã«, +é·ããªã£ãå¼ãè£ãããã®æ¬å¼§ãããã¾ã. +ããã¯è¡ã®å§ãã§éããæ¬å¼§ãéããæºåãããæéã®ãããªç©ã§, +å¿ãã¦ããä½ããæãåºã, ç¢å°ã§æ»ãããã¦ã¹ãæã¾ããªããã°ãªãã¾ãã. +å¼ãï¼è¡ã«ç´ããã®ã«ã¯é·ããã¦ãã¾ã£ãã¨ãã«ã¯, ããã¯å解ãã, +ï¼è¡ã¨ããã以ä¸ã§ããã°ã©ããªé¢¨ã«ã¤ã³ãã³ããããã決ããªããã° +ãªãã¾ãã. + + # Perl 5 - a somewhat complex expression + # Perl 5 - ä½ãè¤éãªå¼ + + print join("\n", map { CGI::param($_) } @cgi_vars), "\n"; + # Perl 5 - again, using autobox: + # Perl 5 - ããä¸åº¦, ä»åº¦ã¯ autobox ã§: + + @cgi_vars->map(sub { CGI::param($_[0]) })->join("\n")->concat("\n")->print; + +The autoboxed version isn't shorter, but it reads from left to right, and +the parenthesis from the C<join()> don't span nearly as many characters. +The complex expression serving as the value being C<join()>ed in the non-autoboxed version +becomes, in the autoboxed version, a value to call the C<join()> method on. + +autobox ãå©ç¨ãããã¼ã¸ã§ã³ã¯çãããã§ã¯ããã¾ããã, ãã㯠+å·¦ããå³ã«èªããã¨ãåºæ¥, C<join()> ã®æ¬å¼§ã¯ããããéã®æåãå²ã +ãã¨ãããã¾ãã. autobox ã使ããªããã¼ã¸ã§ã³ã«ãã C<join()> +ãããå¤ãæä¾ãã¦ããè¤éãªå¼ã¯, autobox ãå©ç¨ãããã¼ã¸ã§ã³ +ã§ã¯, C<join()> ã¡ã½ãããå¼ã³ã ãå ã®å¤ã«ãªã£ã¦ãã¾ã. + +This C<print> statement takes a list of CGI parameter names, reads the values for +each parameter, joins them together with newlines, and prints them with a newline +after the last one. + +ãã® C<print> æ㯠CGI ãã©ã¡ã¼ã¿åã®ãªã¹ããåã, åãã©ã¡ã¼ã¿ã® +å¤ãèªã¿, ããããæ¹è¡ã§ã¤ãªãåãã, ããã¦æå¾ã«æ¹è¡ãã¤ã㦠+åºåãã¦ãã¾ã. + +Pretending that this expression were much larger and it had to be broken to span +several lines, or pretending that comments are to be placed after each part of +the expression, you might reformat it as such: + +æ¢ãã¦ãã®å¼ãããé·ãè¤æ°è¡ã«åããå¿ è¦ãããã¨ããã, +ãããåå¼è¦ç´ ã«ã³ã¡ã³ããããã¨ããã, ããã¯æ¬¡ã®ããã«ãªãã§ããã: + + @cgi_vars->map(sub { CGI::param($_[0]) }) # turn CGI arg names into values + # CGI å¼æ°åãå¤ã«. + ->join("\n") # join with newlines + # æ¹è¡ã§é£çµ. + ->concat("\n") # give it a trailing newline + # æ«å°¾ã®æ¹è¡ã追å . + ->print; # print them all out + # ãããå ¨é¨ãåºå. + +This could also have been written: + +è¥ããã¯ãã®ããã«ãæ¸ããã§ããã: + + sub { CGI::param($_[0]) }->map(@cgi_vars) # turn CGI arg names into values + # CGI å¼æ°åãå¤ã«. + ->join("\n") # join with newlines + # æ¹è¡ã§é£çµ. + ->concat("\n") # give it a trailing newline + # æ«å°¾ã®æ¹è¡ã追å . + ->print; # print them all out + # ãããå ¨é¨ãåºå. + +C<map()> is X<polymorphic>. +The C<map()> method defined in the C<CODE> package takes for its arguments the things +to map. +The C<map()> method defined in the C<ARRAY> package takes for its argument a code reference +to apply to each element of the array. + +C<map()> 㯠X<å¤æ >å¤æ æ§ãæã£ã¦ãã¾ã. C<CODE> ããã±ã¼ã¸ã§ +å®ç¾©ããã¦ãã C<map()> ã¡ã½ããã¯å¼æ°ã« map ãã対象ç©ãã¨ãã¾ã. +C<ARRAY> ããã±ã¼ã¸ã«å®ç¾©ããã¦ãã C<map()> ã¯é åã®åè¦ç´ ã« +é©ç¨ãããã³ã¼ããªãã¡ã¬ã³ã¹ããã®å¼æ°ã«ããã¾ã. + +I<Here ends the text quoted from the Perl 6 Now manuscript.> + +I<Perl 6 now ã®å稿ããã®å¼ç¨ã¯ããã¾ã§ã§ã.> + +=head1 ãã° + +Yes. Report them to the author, L<scott****@slowa*****>. +This code is not well tested. +The API is not yet stable - Perl 6-ish things and local extensions are still being renamed. + +ã¯ã. ããã¯ä½è , L<scott****@slowa*****> ã«éã£ã¦ä¸ãã. +ãã®ã³ã¼ãã¯ãããªã«ãã¹ãããã¦ãã¾ãã. +API ãã¾ã 確å®ãã¦ãã¾ãã - Perl 6 çãªç©ããã¼ã«ã«ãªæ¡å¼µã¯ +ä»å¾ããªãã¼ã ãããããããã¾ãã. + +=head1 å±¥æ´ + +Version 0.3 fixes a problem where C<unpack> wasn't sure it had enough arguments +according to a test introduced in Perl 5.8.6 or perhaps 5.8.5. +This problem was reported by Ron Reidy - thanks Ron! +Version 0.3 also added the references to Perl 6 Now and the excerpt. + +Version 0.3 ã§ã¯ C<unpack> ã Perl 5.8.6 ããããã 5.8.5 㧠+å°å ¥ããããã¹ãã®ããã«ååãªå¼æ°ãä¼´ã£ã¦ããªãåé¡ãä¿®æ£ãã¾ãã. +ãã®ç¾è±¡ã¯ Ron Reidy ããå ±åããã¾ãã - ãããã¨ã Ron! +Version 0.3 ã§ã¯ Perl 6 Now ã¨æç²ã¸ã®ãªãã¡ã¬ã³ã¹ã追å +ãã¾ãã. + +Version 0.2 rounded out the API and introduced the beginnings of functional-ish methods. + +Version 0.2 ã§ã¯ API ãå®æãã, é¢æ°çãªã¡ã½ãããå§ãã¦ã¿ã¾ãã. + +Version 0.1 was woefully incomplete. + +Version 0.1 ã¯æ²ãããããä¸å®å ¨ã§ãã. + +=head1 é¢é£é ç® + +L<autobox>. + + +L<Perl6::Contexts>. + + +Perl 6: L<< http://dev.perl.org/perl6/apocalypse/ >>. + + +(Shameless plug alert!) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5> +dedicates a sizable portion of Chapter 14, Objects, to autoboxing +and the idea is used heavily throughout the book. Chapter 8, Data Structures, +also has numerous examples. +See L<http://perl6now.com> or look for ISBN 1-59059-395-2 at your favorite +bookstore for more information. + +(åºåè¦å!) I<Perl 6 Now: The Core Ideas Illustrated with Perl 5> +ã¯ãã®ç¬¬14ç¯, ãªãã¸ã§ã¯ãã®ããªãã®é¨åã, autoboxã«ããã¦ãã¦, +ã¾ããã®çºæ³ã¯å ¨ä½ãéãã¦å¼·ã使ããã¦ãã¾ã. 第8ç¯, ãã¼ã¿æ§é +ã«ãå¤æ°ã®ä¾ãããã¾ã. +詳ããæ å ±ã¯ L<http://perl6now.com> ã, ãæ°ã«å ¥ãã®æ¸åºã§ +ISBN 1-59059-395-2 ã確èªãã¦ã¿ã¦ä¸ãã. + +=head1 èè + +Scott Walters, L<scott****@slowa*****> +Thanks to chocolateboy for L<autobox> and for the encouragement! + +Scott Walters, L<scott****@slowa*****> +chocolateboy, L<autobox> ã, ããã¦æ¿å±ããããã¨ã! + +=begin COMMENT + +å訳 + + å±±ç§ æ°·é (YAMASHINA Hio) <hio****@hio*****> + +Origlnal distribution is autobox-Core VERSION 0.3. +Translated at 2006-10-26. + +åå ¸: autobox-Core VERSION 0.3. +翻訳æ¥: 2006-10-26. + +=end COMMENT +