14.1 汎用的な自動設定関数
----------------------------------
-.. The following general-purpose functions can be used to discover the properties of your build environment in a fashion similar to the one used by GNU autoconf tool you may be familiar with. It is recommended that these function be used from an appropriate static. block (see Section 4.14 for more information).
+.. The following general-purpose functions can be used to discover the properties of your build environment in a fashion similar to the one used by GNU autoconf tool you may be familiar with. It is recommended that these function be used from an appropriate static. block (see Section 4.15 for more information).
-以下にリストしてある汎用的な関数では、あなたの『ビルド環境(the properties of your build environment)』について調べることができます。これらの関数の中には、恐らくあなたがよく知っているであろうGNU autoconfツールによく似ているものも含まれています。また、これらの関数は適切な ``static.`` ブロックで使うことを推奨しています(詳細は ":ref:`label4.14`" を参照してください)。
+以下にリストしてある汎用的な関数では、あなたの『ビルド環境(the properties of your build environment)』について調べることができます。これらの関数の中には、恐らくあなたがよく知っているであろうGNU autoconfツールによく似ているものも含まれています。また、これらの関数は適切な ``static.`` ブロックで使うことを推奨しています(詳細は ":ref:`label4.15`" を参照してください)。
.. In order to use the following general-purpose functions, you need to have the line included in your OMakefile or OMakeroot.
14.3 事前に用意された設定テスト
------------------------------------------
-.. A number of configuration tests are already included in the standard library. In order to use them in your project, simply open (see Section 4.7) the corresponding build file in your OMakefile and the tests will run the first time OMake is executed. Note that it is not a problem to open these files from more than one place in your project — if you do that, the test will still run only once.
+.. A number of configuration tests are already included in the standard library. In order to use them in your project, simply open (see Section 4.8) the corresponding build file in your OMakefile and the tests will run the first time OMake is executed. Note that it is not a problem to open these files from more than one place in your project — if you do that, the test will still run only once.
-OMakeでは数多くの設定テスト(configuration tests)が標準ライブラリに含まれています。あなたのプロジェクトでこれらを使うためには、単純に対象の ``OMakefile`` に、設定テストを記述したビルドファイルを『 ``open`` (詳細は ":ref:`label4.7`" を参照してください)』するだけです。そうすれば、OMakeを初めて実行した時点で設定テストが実行されます。これは、あなたのプロジェクト上で二回以上設定テストが ``open`` されるわけではない点に注意してください。たとえ二回以上呼び出したとしても、このテストは一回だけしか実行されません。
+OMakeでは数多くの設定テスト(configuration tests)が標準ライブラリに含まれています。あなたのプロジェクトでこれらを使うためには、単純に対象の ``OMakefile`` に、設定テストを記述したビルドファイルを『 ``open`` (詳細は ":ref:`label4.8`" を参照してください)』するだけです。そうすれば、OMakeを初めて実行した時点で設定テストが実行されます。これは、あなたのプロジェクト上で二回以上設定テストが ``open`` されるわけではない点に注意してください。たとえ二回以上呼び出したとしても、このテストは一回だけしか実行されません。
.. index::
single: NCURSES_AVAILABLE
.. 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.
.. index::
single: 条件分岐
single: if
-.. _label4.9:
+.. _label4.10:
-4.9 条件分岐
+4.10 条件分岐
----------------
.. Top level conditionals have the following form.
single: case
single: default
single: 正規表現
-.. _label4.10:
+.. _label4.11:
-4.10 マッチング
+4.11 マッチング
-------------------
.. Pattern matching is performed with the switch and match forms.
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.
.. 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.
.. 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.
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.
.. 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.
.. 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.
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.
single: 無名関数
single: 字句解析
single: パーサ
-.. _label4.15:
+.. _label4.16:
-4.15 定数
+4.16 定数
-----------------
.. Internally, OMake represents values in several forms, which we list here.
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
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