OSDN Git Service

0.9.8.6の更新に関しての差分を反映. 翻訳作業へ
[omake-japanese/omake_trans.git] / language.rst
index c07b5d6..7a4e0f1 100644 (file)
@@ -34,7 +34,7 @@
 
 .. Unlike make(1), variable expansion is eager and pure (see also the section on Scoping). That is, variable values are expanded immediately and new variable definitions do not affect old ones. For example, suppose we extend the previous example with following variable definitions.
 
-``make(1)`` とは違い、変数の展開は *先行して(eager)* 行われ、 *純粋な(pure)* メカニズムとなっています(詳細は ":ref:`label4.8`",":ref:`label6.1`" を参照してください)。これはつまり、変数の値は即座に展開されることによって、新しい変数への束縛が古い値に影響されないことを意味しています。例えば、前回の例を以下のような変数の束縛に拡張した場合について考えてみましょう。 ::
+``make(1)`` とは違い、変数の展開は *先行して(eager)* 行われ、 *純粋な(pure)* メカニズムとなっています(詳細は ":ref:`label4.9`",":ref:`label6.1`" を参照してください)。これはつまり、変数の値は即座に展開されることによって、新しい変数への束縛が古い値に影響されないことを意味しています。例えば、前回の例を以下のような変数の束縛に拡張した場合について考えてみましょう。 ::
 
    X = $(COMMAND)
    COMMAND = $(COMMAND) -O3
     Printer(She)
 
 .. index::
-   single: コメント
+   single: キーワード引数
+.. _label4.5.1:
+
+4.5.1 キーワード引数
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+.. This feature was introduced in version 0.9.8.6.
+
+*この機能はバージョン0.9.8.6で導入されました。*
+
+.. Functions can also have keyword parameters and arguments. The syntax of a keyword parameter/argument is [~|?]<id> [= <expression>], where the keyword name <id> is preceeded by the character ~ (for required arguments), or ? (for optional arguments). If a default value = <expression> is provided, the argument is always optional.
+
+Functions can also have keyword parameters and arguments. The syntax of a keyword parameter/argument is [~|?]<id> [= <expression>], where the keyword name <id> is preceeded by the character ~ (for required arguments), or ? (for optional arguments). If a default value = <expression> is provided, the argument is always optional.
+
+.. Keyword arguments and normal anonymous arguments are completely separate. Also, it is an error to pass a keyword argument to a function that does not define it as a keyword parameter. 
+
+Keyword arguments and normal anonymous arguments are completely separate. Also, it is an error to pass a keyword argument to a function that does not define it as a keyword parameter. ::
+
+    osh>f(x, ?y = 1, z) =
+           add($(mul $x, 100), $(mul $y, 10), $z)
+    - : <fun 0>
+    osh>f(1, ~y = 2, 3)
+    - : 123 : Int
+    osh>f(1, 3, ~y = 2)
+    - : 123 : Int
+    osh>f(1, 3)
+    - : 113 : Int
+    osh>f(1, 2, 3)
+    *** omake error:
+       File -: line 11, characters 0-10
+       arity mismatch: expected 2 args, got 3
+    osh>f(~z = 7)
+    *** omake error:
+       File -: line 12, characters 0-8
+       no such keyword: z
+
+.. An optional keyword argument defaults to the empty value. 
+
+An optional keyword argument defaults to the empty value. ::
+
+    osh> g(?x) =
+             println($">>>$x<<<")
+    - : <fun 0>
+    osh> g()
+    >>><<<
+    osh> g(~x = xxx)
+    >>>xxx<<<
+
+.. It is an error to omit a required keyword argument.
+
+It is an error to omit a required keyword argument. ::
+
+    osh> h(~x, ~y) =
+             println(x = $x; y = $y)
+    - : <fun 0>
+    osh> h(~y = 2, ~x = 1)
+    x = 1; y = 2
+    osh> h(~y = 2)
+    *** omake error:
+       File -: line 11, characters 0-9
+       keyword argument is required: x
+
+.. index::
+   single: カリー化
+   single: Curried function
 .. _label4.6:
 
-4.6 コメント
+4.6 カリー化関数
+-------------------------------------
+.. This feature was introduced in version 0.9.8.6.
+
+*この機能はバージョン0.9.8.6で導入されました。*
+
+.. Functions that are marked with the classifier curry can be called with “too many” arguments. It is expected that a curried function returns a function that consumes the remaining arguments. All arguments must be specified. 
+
+Functions that are marked with the classifier curry can be called with “too many” arguments. It is expected that a curried function returns a function that consumes the remaining arguments. All arguments must be specified. ::
+
+    osh>curry.f(x, y) =
+            println($"Got two arguments: x = $x, y = $y")
+            g(z) =
+               add($x, $y, $z)
+    osh> f(1, 2, 3)
+    Got two arguments: x = 1, y = 2
+    - : 6 : Int
+    osh> f(1, 2)
+    Got two arguments: x = 1, y = 2
+    *** omake error:
+       File -: line 62, characters 0-7
+       arity mismatch: expected 1 args, got 0
+
+.. The function apply can be used to compute partial applications, whether or not the function is labeled as a curried function.
+
+The function apply can be used to compute partial applications, whether or not the function is labeled as a curried function. ::
+
+    osh> f1(a, ~b = 2, ~c = 3, d) =
+            println($"a = $a, b = $b, c = $c, d = $d")
+    - : <fun 0>
+    osh> f2 = $(apply $(f1), ~c = 13, 11)
+    - : <curry 0>
+    osh> f2(14, ~b = 12)
+    a = 11, b = 12, c = 13, d = 14
+    osh> f2(24)
+    a = 11, b = 2, c = 13, d = 24
+
+.. index::
+   single: コメント
+.. _label4.7:
+
+4.7 コメント
 ----------------
 .. Comments begin with the # character and continue to the end of the line.
 
 .. index::
    single: include
    single: open
-.. _label4.7:
+.. _label4.8:
 
-4.7 ファイルのインクルード
+4.8 ファイルのインクルード
 -----------------------------
 .. Files may be included with the include or open form. The included file must use the same syntax as an OMakefile.
 
 .. index::
    single: section
    single: export
-.. _label4.8:
+.. _label4.9:
 
-4.8 スコーピング、セクション
+4.9 スコーピング、セクション
 -------------------------------
 .. Scopes in omake are defined by indentation level. When indentation is increased, such as in the body of a function, a new scope is introduced.
 
@@ -274,9 +378,9 @@ omakeのスコープはインデントのレベルで定義されます。イン
 .. index::
    single: 条件分岐
    single: if
-.. _label4.9:
+.. _label4.10:
 
-4.9 条件分岐
+4.10 条件分岐
 ----------------
 .. Top level conditionals have the following form.
 
@@ -325,9 +429,9 @@ omakeのスコープはインデントのレベルで定義されます。イン
    single: case
    single: default
    single: 正規表現
-.. _label4.10:
+.. _label4.11:
 
-4.10 マッチング
+4.11 マッチング
 -------------------
 .. Pattern matching is performed with the switch and match forms.
 
@@ -388,9 +492,9 @@ omakeのスコープはインデントのレベルで定義されます。イン
    single: オブジェクト
    single: フィールド
    single: メソッド
-.. _label4.11:
+.. _label4.12:
 
-4.11 オブジェクト
+4.12 オブジェクト
 ---------------------
 .. OMake is an object-oriented language. Generally speaking, an object is a value that contains fields and methods. An object is defined with a . suffix for a variable. For example, the following object might be used to specify a point (1, 5) on the two-dimensional plane.
 
@@ -415,9 +519,9 @@ OMakeはオブジェクト指向言語です。一般的に、オブジェクト
 .. index::
    single: クラス
    single: class
-.. _label4.12:
+.. _label4.13:
 
-4.12 クラス
+4.13 クラス
 ---------------
 .. We can also define classes. For example, suppose we wish to define a generic Point class with some methods to create, move, and print a point. A class is really just an object with a name, defined with the class directive.
 
@@ -460,9 +564,9 @@ OMakeはオブジェクト指向言語です。一般的に、オブジェクト
 
 .. index::
    single: 継承
-.. _label4.13:
+.. _label4.14:
 
-4.13 継承
+4.14 継承
 ---------------
 .. Classes and objects support inheritance (including multiple inheritance) with the extends directive. The following definition of Point3D defines a point with x, y, and z fields. The new object inherits all of the methods and fields of the parent classes/objects.
 
@@ -489,9 +593,9 @@ OMakeはオブジェクト指向言語です。一般的に、オブジェクト
    single: CheckProg()
    single: ConfMsgChecking()
    single: ConfMsgResult()
-.. _label4.14:
+.. _label4.15:
 
-4.14 static.
+4.15 static.
 ---------------
 .. The static. object is used to specify values that are persistent across runs of OMake. They are frequently used for configuring a project. Configuring a project can be expensive, so the static. object ensure that the configuration is performed just once. In the following (somewhat trivial) example, a static section is used to determine if the LATEX command is available. The $(where latex) function returns the full pathname for latex, or false if the command is not found.
 
@@ -524,9 +628,9 @@ OMakeの標準ライブラリを用いると第14章( :ref:`label14` )にある
 .. index::
    single: .STATIC
    single: awk()
-.. _label4.14.1:
+.. _label4.15.1:
 
-4.14.1 .STATIC
+4.15.1 .STATIC
 ^^^^^^^^^^^^^^^^^^
 .. This feature was introduced in version 0.9.8.5.
 
@@ -585,9 +689,9 @@ OMakeの標準ライブラリを用いると第14章( :ref:`label14` )にある
 
 .. index::
    single: .MEMO
-.. _label4.14.1.1:
+.. _label4.15.1.1:
 
-4.14.1.1  .MEMO
+4.15.1.1  .MEMO
 """"""""""""""""""
 .. A .MEMO rule is just like a .STATIC rule, except that the results are not saved between independent runs of omake.
 
@@ -597,9 +701,9 @@ OMakeの標準ライブラリを用いると第14章( :ref:`label14` )にある
    single: :key:
    single: .MEMO
    single: 再帰関数
-.. _label4.14.1.2:
+.. _label4.15.1.2:
 
-4.14.1.2  :key:
+4.15.1.2  :key:
 """"""""""""""""""
 .. The .STATIC and .MEMO rules also accept a :key: value, which specifies a “key” associated with the values being computed. It is useful to think of a .STATIC rule as a dictionary that associates keys with their values. When a .STATIC rule is evaluated, the result is saved in the table with the :key: defined by the rule (if a :key: is not specified, a default key is used instead). In other words, a rule is like a function. The :key: specifies the function “argument”, and the rule body computes the result.
 
@@ -691,9 +795,9 @@ OMakeの標準ライブラリを用いると第14章( :ref:`label14` )にある
    single: 無名関数
    single: 字句解析
    single: パーサ
-.. _label4.15:
+.. _label4.16:
 
-4.15 定数
+4.16 定数
 -----------------
 .. Internally, OMake represents values in several forms, which we list here.
 
@@ -901,7 +1005,7 @@ OMakeではいろんな方法でそれぞれの値を表すことができます
                   f(i, j) =
                       add($i, $j)
 
-            o This feature will be introduced in version 0.9.9.0.As an anonymous function argument.
+            o (This feature was introduced in version 0.9.8.6.) As an anonymous function argument.
 
                   osh>foreach(i => $(add $i, 1), 1 2 3)
                   - : <array 2 3 4> : Array
@@ -921,7 +1025,7 @@ OMakeではいろんな方法でそれぞれの値を表すことができます
         f(i, j) =
             add($i, $j)
 
-    * *この機能はバージョン0.9.9.0で導入されました。* 無名関数の引数 ::
+    * *この機能はバージョン0.9.8.6で導入されました。* 無名関数の引数 ::
 
         osh>foreach(i => $(add $i, 1), 1 2 3)
         - : <array 2 3 4> : Array