Skip to content

Instantly share code, notes, and snippets.

@bizenn
Created October 1, 2013 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bizenn/6773408 to your computer and use it in GitHub Desktop.
Save bizenn/6773408 to your computer and use it in GitHub Desktop.
Add some Japanese text to Gauche's info.
diff --git a/doc/corelib.texi b/doc/corelib.texi
index ae84764..da3885c 100644
--- a/doc/corelib.texi
+++ b/doc/corelib.texi
@@ -10327,26 +10327,49 @@ Common Lisp.
@subsection Folding generated values
@c NODE 生成された値の畳み込み
+@c EN
Sometimes a procedure is used as a @emph{generator} of a series
of values, by yielding one value at a time. Customary an EOF
object is used to mark the end of the series. For example,
@code{read-char} is such a procedure that yields a series
of characters, terminated by EOF.
+@c JP
+一度にひとつの値を生成することで、手続きを一連の値を生成する@emph{ジェネレータ}として
+使うことがあります。値の連続の終端を表すマークとしては、慣例としてEOFが使われます。
+例えば@code{read-char}はそうした、一連の文字を生成し、終端としてEOFを返す手続きです。
+@c COMMON
+@c EN
Since it is such a handy abstraction, Gauche provides a
set of utilties (see @ref{Generators}) to construct and generators
out of various sources, including other generators.
+@c JP
+こうした抽象化は手軽であるため、Gaucheは、他のジェネレータを含むさまざまなソースから
+ジェネレータを構築するユーティリティをひとそろい提供しています。
+@c COMMON
+@c EN
The generated values needs to be consumed eventually. Here we
provide several procedures to do that. These are useful
when combined with input procedures like @code{read}, so we
have them built-in instead of putting them in a separate module.
+@c JP
+生成された値は最終的に消費されなければなりません。そのための手続きもいくつか
+提供されています。こうした手続きは、@code{read}のような入力手続きと組み合わせるのに
+有用です。このため、別のモジュールに分割するのではなく、ビルトイン手続きになっています。
+@c COMMON
@defun generator-fold proc seed gen gen2 @dots{}
+@c EN
Works like @code{fold} on the generated values by generator
procedures @var{gen} @var{gen2} @dots{} (@xref{Walking over lists},
for the details of @code{fold}).
+@c JP
+ジェネレータである手続き @var{gen} @var{gen2} @dots{} が生成する値に対して
+ @code{fold} のように働きます(@code{fold}の詳細: @xref{Walking over lists})。
+@c COMMON
+@c EN
When one generator is given, for each value @var{v} generated by @var{gen},
@var{proc} is called as @code{(@var{proc} @var{v} @var{r})}, where
@var{r} is the current accumulated result; the initial value of the
@@ -10354,13 +10377,29 @@ accumulated result is @var{seed},
and the return value from @var{proc} becomes the next accumulated result.
When @var{gen} returns EOF, the accumulated result at that time is returned
from @code{generator-fold}.
+@c JP
+引数としてジェネレータがひとつ与えられると、その @var{gen} が生成する各値 @var{v} に
+対して、@var{proc} が @code{(@var{proc} @var{v} @var{r})} のように呼び出されます。
+@var{r}は現在の積算結果であり、その初期値は @var{seed} です。そして、@var{proc} が
+返す値が次回の @var{proc} 呼び出し時の積算値として渡されることになります。
+@var{gen}がEOFを返すと、その時点の積算値が @code{generator-fold} から値として
+返されます。
+@c COMMON
+@c EN
When more than one generator is given, @var{proc} is
called as @code{(@var{proc} @var{v1} @var{v2} @dots{} @var{r})},
where @var{v1}, @var{v2} @dots{} are the values yielded from
@var{gen}, @var{gen2}, @dots{}, respectively, and @var{r} is
the current accumulated result. The iteration terminates when
any one of the generators returns EOF.
+@c JP
+2つ以上のジェネレータが渡された場合は、@var{proc}は
+@code{(@var{proc} @var{v1} @var{v2} @dots{} @var{r})} のように呼び出されます。
+@var{v1}, @var{v2} @dots{} はそれぞれ @var{gen}, @var{gen2}, @dots{} が生成
+した値であり、@var{r}は現在の積算値です。ジェネレータのどれかひとつ以上がEOFを返すと、
+イテレーションは終了します。
+@c COMMON
@example
(with-input-from-string "a b c d e"
@@ -10370,19 +10409,34 @@ any one of the generators returns EOF.
@end defun
@defun generator-fold-right proc seed gen gen2 @dots{}
+@c EN
Works like @code{fold-right} on the generated values by generator
procedures @var{gen} @var{gen2} @dots{} (@xref{Walking over lists},
for the details of @code{fold-right}).
+@c JP
+ジェネレータである手続き@var{gen} @var{gen2} @dots{}が生成する値に対して
+@code{fold-right}のように働きます(@code{fold-right}の詳細: @xref{Walking over lists})。
+@c COMMON
+@c EN
This is provided for completeness, but it isn't a good way to
handle generators; in order to combine values right-associatively,
we should read all the values from the generators (until any one
of the generator returns EOF), then start
calling @var{proc} as
+@c JP
+この手続きは完全性のために提供されていますが、ジェネレータをうまく扱えません;
+値を右結合で計算していくためには、ジェネレータから(少なくともどれかひとつのジェネレータがEOFを返すまで)
+全ての値を読み取らなければなりません。そうして初めて @var{proc} の呼び出しが始まることになります。
+@c COMMON
@example
(proc v0_0 v1_0 ... (proc v0_1 v1_1 ... (proc v0_n v1_n ... seed) ...))
@end example
+@c EN
where @var{vn_m} is the @var{m}-th value yielded by @var{n}-th generator.
+@c JP
+@var{vn_m}は、@var{n}番目のジェネレータが@var{m}回目の呼び出しで返した値です。
+@c COMMON
@example
(with-input-from-string "a b c d e"
@@ -10390,23 +10444,44 @@ where @var{vn_m} is the @var{m}-th value yielded by @var{n}-th generator.
@result{} (a b c d e . z)
@end example
+@c EN
As you see, keeping all intermediate values kind of defeats the
benefit of generators.
+@c JP
+ごらんのように、全ての中間値を保持することで、ジェネレータの利点が
+ある意味帳消しになってしまうのです。
+@c COMMON
@end defun
@defun generator-for-each proc gen gen2 @dots{}
+@c EN
A generator version of @code{for-each}. Repeatedly applies @var{proc} on
the values yielded by @var{gen}, @var{gen2} @dots{} until any one of
the generators yields EOF. The values returned from @var{proc} are discarded.
+@c JP
+ジェネレータ版の@code{for-each}です。@var{gen}, @var{gen2} @dots{} が生成する
+値に対して、ジェネレータのどれかがEOFを返すまで @var{proc} を繰り返し適用していきます。
+@var{proc}が返す値は無視されます。
+@c COMMON
+@c EN
This is a handy procedure to consume generated values with side effects.
+@c JP
+これは、生成される値を副作用で消費するのに便利です。
+@c COMMON
@end defun
@defun generator-map proc gen gen2 @dots{}
+@c EN
A generator version of @code{map}. Repeatedly applies @var{proc} on
the values yielded by @var{gen}, @var{gen2} @dots{} until any one of
the generators yields EOF. The values returned from @var{proc}
are collected into a list and returned.
+@c JP
+ジェネレータ版の@code{map}です。@var{gen}, @var{gen2} @dots{} が生成する
+値に対して、ジェネレータのどれかがEOFを返すまで @var{proc} を繰り返し適用していきます。
+@var{proc}が返す値をひとつのリストに束ねて返します。
+@c COMMON
@example
(with-input-from-string "a b c d e"
@@ -10414,9 +10489,14 @@ are collected into a list and returned.
@result{} ("a" "b" "c" "d" "e")
@end example
+@c EN
The same effects can be achieved by combining @code{generator->list}
and @code{gmap} (@xref{Generator operations}). This procedure
is provided for the backward compatibility.
+@c JP
+@code{generator->list}と@code{gmap}(@xref{Generator operations})の組み合わせと
+同じ挙動を実現します。この手続きは後方互換性のために提供されています。
+@c COMMON
@example
(generator->list (gmap proc gen gen2 @dots{}))
@@ -10424,20 +10504,33 @@ is provided for the backward compatibility.
@end defun
@defun generator-find pred gen
+@c EN
Returns the first item from the generator @var{gen} that satisfies
the predicate @var{pred}.
+@c JP
+ジェネレータ@var{gen}から返された中から、述語@var{pred}を満たす最初の要素を返します。
+@c COMMON
+@c EN
The following example returns the first line matching the regexp
@code{#/XYZ/} from the file @file{foo.txt}.
+@c JP
+以下の例は、ファイル@file{foo.txt}の中から正規表現@code{#/XYZ/}にマッチする最初の行を返します。
+@c COMMON
@example
(with-input-from-file "foo.txt"
(cut generator-find #/XYZ/ read-line))
@end example
+@c EN
Note: If you want to pick all the lines matching the regexp,
like the @code{grep} command,
you can use @code{gfilter} and @code{generator->list}.
+@c JP
+註: @code{grep}コマンドのように、正規表現にマッチする全ての行を取り出したいなら、
+@code{gfilter}と@code{generator->list}が使えます。
+@c COMMON
@end defun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment