argra****@users*****
argra****@users*****
2009年 2月 10日 (火) 13:46:09 JST
Index: docs/perl/5.6.1/overload.pod diff -u docs/perl/5.6.1/overload.pod:1.7 docs/perl/5.6.1/overload.pod:1.8 --- docs/perl/5.6.1/overload.pod:1.7 Sat Feb 7 00:54:20 2009 +++ docs/perl/5.6.1/overload.pod Tue Feb 10 13:46:09 2009 @@ -226,6 +226,8 @@ =item C<++> and C<--> +(C<++> と C<-->) + =begin original The routines which implement these operators are expected to actually @@ -235,7 +237,7 @@ =end original これらの演算子を実装するルーチンは、実際はこれらの引数を -I<ミューテート> することを想定しています。 +I<変更(mutate)> することを想定しています。 それで、$obj が数値へのリファレンスと仮定すると、 sub incr { my $n = $ {$_[0]}; ++$n; $_[0] = bless \$n} @@ -264,6 +266,8 @@ =item C<x=> and other assignment versions +(C<x=> とその他の代入演算子) + =begin original There is nothing special about these methods. They may change the @@ -331,9 +335,9 @@ =end original -is asking for trouble, since for code C<$obj += $foo> the subroutine -is called as C<$obj = add($obj, $foo, undef)>, or C<$obj = [\$obj, -\$foo]>. +は自ら災いを招くことになります; なぜなら C<$obj += $foo> というコードでは +サブルーチンは C<$obj = add($obj, $foo, undef)> あるいは C<$obj = [\$obj, +\$foo]> として呼び出されるからです。 もしこのようなサブルーチンを使うことが重要な最適化なら、 非「最適化」版で明示的に C<+=> をオーバーロードするか、 もし C<not defined $_[2]> なら非最適化版に切り替えることができます @@ -462,7 +466,7 @@ =end original 未定義であれば、足し算と引き算のメソッドが代わりに使われます。 -これらの演算子は、プリフィクスとしても、ポストフィクスとしても使われます。 +これらの演算子は、前置としても後置としても使われます。 =item * I<Transcendental functions> @@ -501,7 +505,7 @@ も定義してあれば、それを代わりに使うことができます。 C<bool> は、(C<while> のような) フロー制御演算子や、 三項演算子 "C<?:>" で使われます。 -これらの関数は、任意の Perl値を返すことができます。 +これらの関数は、任意の Perl 値を返すことができます。 この値に対応する演算子もオーバーロードされている場合には、 その演算子がその時の値を使って、再度呼び出されることになります。 @@ -692,11 +696,10 @@ =end original -If C<A> inherits from C<B> and C<C> (in this order), C<B> overloads -C<+> with C<\&D::plus_sub>, and C<C> overloads C<+> by C<"plus_meth">, -then the subroutine C<D::plus_sub> will be called to implement -operation C<+> for an object in package C<A>. -(TBT) +もし C<A> が C<B> を C<C> を (この順序で) 継承していて、C<B> が C<+> を +C<\&D::plus_sub> でオーバーロードし、C<C> が C<+> を C<"plus_meth"> で +オーバーロードしている場合、パッケージ C<A> でオブジェクトのために +演算 C<+> を実装するために、サブルーチン C<D::plus_sub> が呼び出されます。 =back @@ -709,11 +712,10 @@ =end original -Note that since the value of the C<fallback> key is not a subroutine, -its inheritance is not governed by the above rules. In the current -implementation, the value of C<fallback> in the first overloaded -ancestor is used, but this is accidental and subject to change. -(TBT) +C<fallback> キーの値はサブルーチンではないので、この継承は上述のルールには +従いません。 +現在の実装では、最初にオーバーロードした祖先の C<fallback> の値が +使われますが、これは偶然で、変更される予定です。 =head1 SPECIAL SYMBOLS FOR C<use overload> @@ -893,7 +895,7 @@ =end original この演算は、以下のような、他のリファレンスとオブジェクトを共有する -リファレンスに対して、ミューテーターを使うときに呼び出されます。 +リファレンスに対して、ミューテータを使うときに呼び出されます。 $a=$b; ++$a; @@ -916,7 +918,7 @@ C<$$a> が C<$$b> に一致します)、行われます。 これはC<++> が C<'++'> か C<'+='> (か C<nomethod>) のメソッドを通じて 表現されているときにだけ行なわれます。 -この演算子が、非ミューテーター C<"+"> を使って記述されている場合、 +この演算子が、非ミューテータ C<"+"> を使って記述されている場合、 $a=$b; $a=$a+1; @@ -939,7 +941,7 @@ =end original -コピーコンストラクタが、いくつかのミューテーターの実行中に必要となって、 +コピーコンストラクタが、いくつかのミューテータの実行中に必要となって、 C<'='> が指定されていないときには、そのオブジェクトが 単なるスカラであれば、文字列コピーとして自動生成されます。 @@ -1018,7 +1020,7 @@ =item I<Assignment forms of arithmetic operations> -(算術演算子の代入形式) +(I<算術演算子の代入形式>) =begin original @@ -1032,7 +1034,7 @@ =item I<Conversion operations> -(変換演算子) +(I<変換演算子>) =begin original @@ -1046,7 +1048,7 @@ =item I<Increment and decrement> -(インクリメントとデクリメント) +(I<インクリメントとデクリメント>) =begin original @@ -1070,7 +1072,7 @@ =item I<Unary minus> -(単項のマイナス) +(I<単項のマイナス>) =begin original @@ -1096,7 +1098,7 @@ =item I<Concatenation> -(連結) +(I<連結>) =begin original @@ -1108,7 +1110,7 @@ =item I<Comparison operations> -(比較演算子) +(I<比較演算子>) =begin original @@ -1125,15 +1127,19 @@ =item I<Iterator> +(I<反復子>) + <> in terms of builtin operations =item I<Dereferencing> +(I<デリファレンス>) + ${} @{} %{} &{} *{} in terms of builtin operations =item I<Copy operator> -(コピー演算) +(I<コピー演算子>) =begin original @@ -1149,6 +1155,8 @@ =head1 Losing overloading +(オーバーロードが失われるとき) + =begin original The restriction for the comparison operation is that even if, for example, @@ -1186,8 +1194,8 @@ =end original マスマジカルなオブジェクトを chop() すると、文字列になり、 -マスマジカルな性質はなくなります。 同じことは、他の演算でも -起こります。 +マスマジカルな性質はなくなります。 +同じことは、他の演算でも起こります。 =head1 Run-time Overloading @@ -1370,19 +1378,17 @@ =end original -The corresponding values are references to functions which take three arguments: -the first one is the I<initial> string form of the constant, the second one -is how Perl interprets this constant, the third one is how the constant is used. -Note that the initial string form does not -contain string delimiters, and has backslashes in backslash-delimiter -combinations stripped (thus the value of delimiter is not relevant for -processing of this string). The return value of this function is how this -constant is going to be interpreted by Perl. The third argument is undefined -unless for overloaded C<q>- and C<qr>- constants, it is C<q> in single-quote -context (comes from strings, regular expressions, and single-quote HERE -documents), it is C<tr> for arguments of C<tr>/C<y> operators, -it is C<s> for right-hand side of C<s>-operator, and it is C<qq> otherwise. -(TBT) +対応する値は 3 つの引数を取る関数へのリファレンスへのリファレンスです: +最初のものは定数の I<初期> 文字列形式、2 番目は Perl がこの定数を +どのように解釈するか、3 番目は定数をどのように使うかです。 +初期文字列形式は文字列デリミタを含んでおらず、バックスラッシュ-デリミタの +組み合わせでのバックスラッシュは削除されている(従ってデリミタの値は +この文字列を処理するには適切ではない)ことに注意してください。 +この関数の返り値はこの定数が Perl によってどのように解釈されるかです。 +3 番目の引数は、オーバーロードされた C<q>- か C<qr>- 定数以外では未定義値、 +(文字列、正規表現、シングルクォートヒヤドキュメントによる) +シングルクォートコンテキストの場合は C<q>、C<tr>/C<y> 演算子の引数の +場合は C<tr>、C<s> 演算子の右側の場合は C<s>、その他では C<qq> になります。 =begin original @@ -1393,11 +1399,10 @@ =end original -Since an expression C<"ab$cd,,"> is just a shortcut for C<'ab' . $cd . ',,'>, -it is expected that overloaded constant strings are equipped with reasonable -overloaded catenation operator, otherwise absurd results will result. -Similarly, negative numbers are considered as negations of positive constants. -(TBT) +式 C<"ab$cd,,"> は単に C<'ab' . $cd . ',,'> のショートカットなので、 +オーバーロード定数文字列は妥当なオーバーロードされた結合演算子を +装備していると想定していて、さもなければ不合理な結果となります。 +同様に、負数は正数の否定として扱われます。 =begin original @@ -1720,15 +1725,13 @@ =end original $a の「オブジェクト性」は保存されません。 -But Perl I<has> a way to make assignments -to an object do whatever you want. +しかし、Perl にはオブジェクトへの代入を望み通りのやり方にする方法が +I<あります>。 これは単にオーバーロードではなく、tie() するインターフェースです (L<perlfunc/tie> を参照してください)。 -Adding a FETCH() method -which returns the object itself, and STORE() method which changes the -value of the object, one can reproduce the arithmetic metaphor in its -completeness, at least for variables which were tie()d from the start. -(TBT) +オブジェクト自身を返す FETCH() メソッドと、オブジェクトの値を変更する +STORE() メソッドを追加することで、少なくとも最初から tie() されている +変数に対しては、完全性に対して算術の比喩を再現できます。 =begin original @@ -1798,6 +1801,8 @@ =head2 Two-face references +(2 面リファレンス) + =begin original Suppose you want to create an object which is accessible as both an @@ -1808,12 +1813,11 @@ =end original -Suppose you want to create an object which is accessible as both an -array reference and a hash reference, similar to the -L<pseudo-hash|perlref/"Pseudo-hashes: Using an array as a hash"> -builtin Perl type. Let's make it better than a pseudo-hash by -allowing index 0 to be treated as a normal element. -(TBT) +Perl 組み込みの +L<擬似ハッシュ|perlref/"Pseudo-hashes: Using an array as a hash"> 型のような、 +配列リファレンスとハッシュリファレンスの両方としてアクセス可能な +オブジェクトを作りたいとします。 +添え字 0 を普通の要素として扱える擬似ハッシュよりもよいものを作りましょう。 package two_refs; use overload '%{}' => \&gethash, '@{}' => sub { $ {shift()} }; @@ -1898,12 +1902,13 @@ =end original -Both these problems can be cured. Say, if we want to overload hash -dereference on a reference to an object which is I<implemented> as a -hash itself, the only problem one has to circumvent is how to access -this I<actual> hash (as opposed to the I<virtual> hash exhibited by the -overloaded dereference operator). Here is one possible fetching routine: -(TBT) +これらの問題の両方は修正できます。 +例えば、ハッシュ自身として I<実装されている> オブジェクトへの +リファレンスに対するハッシュのデリファレンスをオーバーロードしたい場合、 +回避する必要がある唯一の問題は、(オーバーロードされた +デリファレンス演算子によって提供される I<仮想> ハッシュではなく) +この I<実際の> ハッシュにどうやってアクセスするかです。 +これは可能なフェッチルーチンの一つです: sub access_hash { my ($self, $key) = (shift, shift); @@ -2036,13 +2041,13 @@ =end original -This module is very unusual as overloaded modules go: it does not -provide any usual overloaded operators, instead it provides the L<Last -Resort> operator C<nomethod>. In this example the corresponding -subroutine returns an object which encapsulates operations done over -the objects: C<new symbolic 3> contains C<['n', 3]>, C<2 + new -symbolic 3> contains C<['+', 2, ['n', 3]]>. -(TBT) +このモジュールは、オーバーロードするモジュールとしてはかなり変わっています: +通常のオーバーロード演算子は何も提供せず、その代わりに +L<Last Resort> 演算子 C<nomethod> を提供します。 +この例で、対応するサブルーチンはオブジェクトに対して行われた演算を +カプセル化したオブジェクトを返します: +C<new symbolic 3> は C<['n', 3]> を含み、C<2 + new symbolic 3> は +C<['+', 2, ['n', 3]]> を含みます。 =begin original @@ -2220,7 +2225,7 @@ しかし、偽かどうかをチェックする演算子 C<bool> が (今回はオーバーロードされた C<""> 経由で) オーバーロードされていて、 長い文字列を返すので、型 C<symbolic> のあらゆるオブジェクトは真です。 -こrを乗り越えるために、オブジェクトを 0 と比較する方法が必要です。 +これを乗り越えるために、オブジェクトを 0 と比較する方法が必要です。 実際、これは数値変換ルーチンを書くより簡単です。 =begin original @@ -2363,12 +2368,11 @@ =end original -Due to L<Calling Conventions for Mutators>, we do not need anything -special to make C<+=> and friends work, except filling C<+=> entry of -%subr, and defining a copy constructor (needed since Perl has no -way to know that the implementation of C<'+='> does not mutate -the argument, compare L<Copy Constructor>). -(TBT) +L<Calling Conventions for Mutators> によって、%subr の C<+=> エントリを +埋めることと、コピーコンストラクタを定義すること (これは C<'+='> の実装が +引数を変更しないことを Perl が知る方法はないために必要です; +L<Copy Constructor> と比較してください) のほかに、C<+=> とその親類が +動作するために必要なことは何もありません。 =begin original @@ -2510,10 +2514,9 @@ =end original -One may wonder why we call the above calculator symbolic. The reason -is that the actual calculation of the value of expression is postponed -until the value is I<used>. -(TBT) +なぜ私達が上述の計算機をシンボリックと呼ぶのかを疑問に思う人も +いるかもしれません。 +その理由は、式の値の実際の計算はその値が I<使われる> まで延期されます。 =begin original @@ -2772,11 +2775,9 @@ これは、オーバーロードの存在のチェックが早すぎて、tie() したアクセスを 試みる前に行われるために起こります。 -If the FETCH()ed class of the -tie()d value does not change, a simple workaround is to access the value -immediately after tie()ing, so that after this call the I<previous> class -coincides with the current one. -(TBT) +もし tie() された値の FETCH() されたクラスが変更していないなら、簡単な +回避法は tie() した直後に値にアクセスすることで、この呼び出しの後 +I<以前の> クラスは現在のものと同期します。 =begin original