.. 9-base .. _label9: 9. 基本ライブラリ ================================== .. index:: single: OMAKE_VERSION single: STDLIB single: OMAKEPATH single: OSTYPE single: SYSNAME single: NODENAME single: OS_VERSION single: MACHINE single: HOST single: USER single: HOME single: PID single: TARGETS single: BUILD_SUMMARY single: VERBOSE .. _label9.1: 9.1 ビルドイン変数 ---------------------------------- * **OMAKE_VERSION** OMakeのバージョンを表します。 .. Version of OMake. * **STDLIB** OMakeの基本ライブラリのファイルがあるディレクトリを表します。起動時に、この変数のデフォルトの値は以下のようにして決定されます。 * ``OMAKELIB`` 環境変数の値が存在している場合はその値が用いられます。ただし、値は絶対パスでなければなりません。 * Windows上では、レジストリのキー ``HKEY_CURRENT_USER\SOFTWARE\MetaPRL\OMake\OMAKELIB`` と ``HKEY_LOCAL_MACHINE\SOFTWARE\MetaPRL\OMake\OMAKELIB`` が調べられ、存在している場合にはその値が用いられます。 * さもなければコンパイルされた時の値が用いられます。 現在のデフォルトの値は ``omake --version`` を実行することによって参照できます。 .. The directory where the OMake standard library files reside. At startup, the default value is determined as follows. * The value of the OMAKELIB environment variable, if set (must contain an absolute path, if set), otherwise * On Windows, the registry keys HKEY_CURRENT_USER\SOFTWARE\MetaPRL\OMake\OMAKELIB and HKEY_LOCAL_MACHINE\SOFTWARE\MetaPRL\OMake\OMAKELIB are looked up and the value is used, if exist. * Otherwise a compile-time default it used. The current default value may be accessed by running omake --version * **OMAKEPATH** ``include`` と ``open`` 文における検索パスを指定した、ディレクトリの配列です(詳細は ":ref:`label4.8`" を参照してください)。デフォルトの値は ``.`` と ``$(STDLIB)`` の2つの成分を持った配列です。 .. An array of directories specifying the lookup path for the include and open directives (see Section 4.7). The default value is an array of two elements — . and $(STDLIB). * **OSTYPE** omakeを実行しているマシンのアーキテクチャの集合です。考えられる値は ``Unix`` (LinuxやMac OS Xを含む、すべてのUnixのバージョンを表します), ``Win32`` (MS-Windowsでは、OMakeはMSVC++かMingwを用いてコンパイルします), ``Cygwin`` (MS-Windowsでは、OMakeはCygwinを用いてコンパイルします)があります。 .. Set to the machine architecture omake is running on. Possible values are Unix (for all Unix versions, including Linux and Mac OS X), Win32 (for MS-Windows, OMake compiled with MSVC++ or Mingw), and Cygwin (for MS-Windows, OMake compiled with Cygwin). * **SYSNAME** 現在のマシンのOSの名前を表します。 .. The name of the operating system for the current machine. * **NODENAME** 現在のマシンのホスト名を表します。 .. The hostname of the current machine. * **OS_VERSION** OSのバージョンを表します。 .. The operating system release. * **MACHINE** マシンのアーキテクチャを表します(例: ``i386`` , ``sparc`` , etc...)。 .. The machine architecture, e.g. i386, sparc, etc. * **HOST** ``NODENAME`` と等価です。 .. Same as NODENAME. * **USER** 処理を実行しているユーザのログイン名を表します。 .. The login name of the user executing the process. * **HOME** 処理を実行しているユーザのホームディレクトリを表します。 .. The home directory of the user executing the process. * **PID** OMakeのプロセスIDを表します。 .. The OMake process id. * **TARGETS** コマンドラインのターゲットを表す文字列です。例えば、OMakeが以下のコマンドラインで実行されたとしましょう。 :: omake CFLAGS=1 foo bar.c この場合、 ``TARGETS`` は ``foo bar.c`` が定義されます。 .. The command-line target strings. For example, if OMake is invoked with the following command line, then TARGETS is defined as foo bar.c. * **BUILD_SUMMARY** ``BUILD_SUMMARY`` 変数は ``omake`` がビルド状況を要約したファイルが定義されています(メッセージはビルドの最後で出力されます)。ビルドが開始されたとき、このファイルは空です。あなたはビルド中にこのファイルを編集したり追加することで、ビルドの要約に何らかのメッセージを追加できます。 例えば、もしあなたがいくつかのアクションが発生した場所を把握しておきたいとしますと、ビルドの要約に以下を追加することで実現できます。 :: foo: boo echo "The file foo was built" >> $(BUILD_SUMMARY) ...build foo... .. The BUILD_SUMMARY variable refers to the file that omake uses to summarize a build (the message that is printed at the very end of a build). The file is empty when the build starts. If you wish to add additional messages to the build summary, you can edit/modify this file during the build. For example, if you want to point out that some action was taken, you can append a message to the build summary. * **VERBOSE** いくつかのコマンドのメッセージが冗長に出力されます。デフォルトの値は ``false`` で、 ``--verbose`` オプションを用いてOMakeが実行された場合、変数の値は ``true`` となります。 .. Whether certain commands should be verbose. A boolean flag that is false by default and is set to true when OMake is invoked with the --verbose option. .. _label9.2: 9.2 論理式、真偽関数、コマンドのコントロール ------------------------------------------------- .. Boolean values in omake are represented by case-insensitive strings. The false value can be represented by the strings false, no, nil, undefined or 0, and everything else is true. omakeのブーリアン型は状況に無反応な(case-insensitive)文字列によって表現されます。『偽』は文字列 ``false`` , ``no`` , ``nil`` , ``undefined`` , ``0`` のいづれかによって表現されます。それ以外はすべて『真』となります。 .. index:: single: not() .. _label9.2.1: 9.2.1 not ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(not e) : String e : String .. The not function negates a Boolean value. ``not`` 関数は真偽値を反転します。 .. For example, $(not false) expands to the string true, and $(not hello world) expands to false. 例えば、 ``$(not false)`` は ``true`` が返されて、 ``$(not hello world)`` は ``false`` が返されます。 .. index:: single: equal() .. _label9.2.2: 9.2.2 equal ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The equal function tests for equality of two values. ``equal`` 関数は2つの値が等しいかどうか比較します。 .. For example $(equal a, b) expands to false, and $(equal hello world, hello world) expands to true. 例えば、 ``$(equal a, b)`` は ``false`` が返されて、 ``$(equal hello world, hello world)`` は ``true`` が返されます。 .. index:: single: and() .. _label9.2.3: 9.2.3 and ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(and e1, ..., en) : String e1, ..., en: Sequence .. The and function evaluates to the conjunction of its arguments. ``and`` 関数は引数の論理積を評価します。 .. For example, in the following code, X is true, and Y is false. 例えば、以下のコードでは ``X`` は真で、 ``Y`` は偽となります。 :: A = a B = b X = $(and $(equal $(A), a) true $(equal $(B), b)) Y = $(and $(equal $(A), a) true $(equal $(A), $(B))) .. index:: single: or() .. _label9.2.4: 9.2.4 or ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(or e1, ..., en) : String e1, ..., en: String Sequence .. The or function evaluates to the disjunction of its arguments. ``or`` 関数は引数の選言を評価します。 .. For example, in the following code, X is true, and Y is false. 例えば、以下のコードでは ``X`` は真で、 ``Y`` は偽となります。 :: A = a B = b X = $(or $(equal $(A), a) false $(equal $(A), $(B))) Y = $(or $(equal $(A), $(B)) $(equal $(A), b)) .. index:: single: if() .. _label9.2.5: 9.2.5 if ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(if e1, e2[, e3]) : value e1 : String e2, e3 : value .. The if function represents a conditional based on a Boolean value. For example $(if $(equal a, b), c, d) evaluates to d. ``if`` 関数は真偽値を基にした条件分岐を行います。例えば、 ``$(if $(equal a, b), c, d)`` は ``d`` と評価されます。 .. Conditionals may also be declared with an alternate syntax. 条件分岐は以下のような文を用いても宣言できます。 :: if e1 body1 elseif e2 body2 ... else bodyn .. If the expression e1 is not false, then the expressions in body1 are evaluated and the result is returned as the value of the conditional. Otherwise, if e1 evaluates to false, the evaluation continues with the e2 expression. If none of the conditional expressions is true, then the expressions in bodyn are evaluated and the result is returned as the value of the conditional. もし式 ``e1`` が偽でなかったら ``body1`` が評価されて、結果は条件分岐の値として返されます。もし ``e1`` が偽であるなら、条件分岐は移り変わり ``e2`` の式が用いられます。もしどの条件式も真でなかった場合、 ``bodyn`` が評価されて、結果は条件分岐の値として返されます。 .. There can be any number of elseif clauses; the else clause is optional. ``if`` 文は任意の数の ``elseif`` 文を加えることができます。また、 ``else`` 文はなくても構いません。 .. Note that each branch of the conditional defines its own scope, so variables defined in the branches are normally not visible outside the conditional. The export command may be used to export the variables defined in a scope. For example, the following expression represents a common idiom for defining the C compiler configuration. .. note:: 各々の条件分岐文はそれぞれのスコープを持っているので、条件文中で定義された変数は通常外から見ることができません。 ``export`` コマンドはスコープ中で定義された変数をエクスポートするために用いられます。たとえば、以下の式はCコンパイラの設定を定義するために良く用いられる方法です。 :: if $(equal $(OSTYPE), Win32) CC = cl CFLAGS += /DWIN32 export else CC = gcc CFLAGS += -g -O2 export .. index:: single: switch() single: match() .. _label9.2.6: 9.2.6 switch, match ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The switch and match functions perform pattern matching. ``switch`` , ``match`` 関数はパターンのマッチングに用いられます。 ``$(switch , , , ..., , ) $(match , , , ..., , )`` .. The number of / pairs is arbitrary. They strictly alternate; the total number of arguments to must be odd. ``/`` の数は任意です。ただし、引数の数は必ず奇数でなければなりません。 .. The is evaluated to a string, and compared with . If it matches, the result of the expression is . Otherwise evaluation continues with the remaining patterns until a match is found. If no pattern matches, the value is the empty string. ```` は文字列として評価されて、 ```` を用いて比較されます。もしマッチしている場合、結果の式は ```` が返されます。そうでない場合、マッチする文が見つかるまで、残りのパターンを用いて評価が行われます。 .. The switch function uses string comparison to compare the argument with the patterns. For example, the following expression defines the FILE variable to be either foo, bar, or the empty string, depending on the value of the OSTYPE variable. ``switch`` 関数はパターンと引数を比較するために用いられます。例えば、以下の表現式では、 ``FILE`` 変数は ``OSTYPE`` 変数の値に依存して、 ``foo`` , ``bar`` , あるいは空の文字列が定義されます。 :: FILE = $(switch $(OSTYPE), Win32, foo, Unix, bar) .. The match function uses regular expression patterns (see the grep function). If a match is found, the variables $1, $2, ... are bound to the substrings matched between \( and \) delimiters. The $0 variable contains the entire match, and $* is an array of the matched substrings. to the matched substrings. ``match`` 関数は正規表現を用います( ":ref:`label10.11.1`" を参照してください)。もしマッチしているパターンが見つかった場合、変数 ``$1, $2, ...`` は ``\(`` と ``\)`` デリミタの間にある文字列が束縛されます。 ``\0`` 変数は全体のマッチ文が定義されており、 ``$*`` はマッチした文字列の配列が定義されます。 :: FILE = $(match foo_xyz/bar.a, foo_\\\(.*\\\)/\\\(.*\\\)\.a, foo_$2/$1.o) .. The switch and match functions also have an alternate (more usable) form. ``switch`` と ``match`` 関数は代わりに(もっと便利な)以下のような形に書くことができます。 :: match e case pattern1 body1 case pattern2 body2 ... default bodyd .. If the value of expression e matches pattern_i and no previous pattern, then body_i is evaluated and returned as the result of the match. The switch function uses string comparison; the match function uses regular expression matching. 式 ``e`` が前回のパターンでマッチせずに ``pattern_i`` でマッチした場合、 ``body_i`` が評価されて、 ``match`` の結果として返されます。 ``switch`` 関数は文字列の比較を行います。 ``match`` 関数は正規表現でのマッチングを行います。 :: match $(FILE) case $".*\(\.[^\/.]*\)" println(The string $(FILE) has suffix $1) default println(The string $(FILE) has no suffix) .. index:: single: try .. _label9.2.7: 9.2.7 try ^^^^^^^^^^^^^^^^^^^^^^^^^ :: try try-body catch class1(v1) catch-body when expr when-body ... finally finally-body .. The try form is used for exception handling. First, the expressions in the try-body are evaluated. ``try`` 文は例外を扱うために用いられます。はじめに、 ``try-body`` の式が評価されます。 .. If evaluation results in a value v without raising an exception, then the expressions in the finally-body are evaluated and the value v is returned as the result. 値 ``v`` が例外を出さなかった場合、 ``finally-body`` の式が評価され値 ``v`` が結果として返されます。 .. If evaluation of the try-body results in a exception object obj, the catch clauses are examined in order. When examining catch clause catch class(v), if the exception object obj is an instance of the class name class, the variable v is bound to the exception object, and the expressions in the catch-body are evaluated. ``try-body`` の評価がオブジェクト ``obj`` の例外を送出した場合、 ``catch`` 文が代わりに評価されます。 ``catch`` 文の ``catch class(v)`` を実行している最中、もし例外のオブジェクト ``obj`` がクラス名 ``class`` のインスタンスであったならば、変数 ``v`` が例外のオブジェクトとして束縛されて、 ``catch-body`` の式が評価されます。 .. If a when clause is encountered while a catch body is being evaluated, the predicate expr is evaluated. If the result is true, evaluation continues with the expressions in the when-body. Otherwise, the next catch clause is considered for evaluation. ``catch`` 文が評価されている間中 ``when`` 文に遭遇した場合、評価式 ``expr`` が評価されます。もし結果が真であったならば、 ``when-body`` の式が続けて評価されます。さもなければ、次の ``catch`` 文が評価されます。 .. If evaluation of a catch-body or when-body completes successfully, returning a value v, without encountering another when clause, then the expressions in the finally-body are evaluated and the value v is returned as the result. ``catch-body`` か ``when-body`` の評価が完全に終わった場合、別の ``when`` 文を評価することなく ``finally-body`` の式が評価されて、値 ``v`` が返されます。 .. There can be any number of catch clauses; the finally clause is optional. ``try`` 文には任意の数の ``catch`` 文を含めることができます。また、 ``finally`` 文はなくても構いません。 .. index:: single: raise() .. _label9.2.8: 9.2.8 raise ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The raise function raises an exception. The exn object can be any object. However, the normal convention is to raise an Exception object. ``raise`` 関数は例外を送出します。 ``exn`` は任意のオブジェクトです。しかしながら、通常は ``Exception`` オブジェクトを送出します。 .. If the exception is never caught, the whole object will be verbosely printed in the error message. However, if the object is an Exception one and contains a message field, only that field will be included in the error message. 例外が捕らえられなかった場合、全体のオブジェクトはエラーメッセージとして詳細に出力されます。しかしながら、もしオブジェクトが ``Exception`` で ``message`` フィールドを含んでいるのなら、エラーメッセージは ``message`` のみが出力されます。 .. index:: single: exit() .. _label9.2.9: 9.2.9 exit ^^^^^^^^^^^^^^^^^^^^^^^^^ :: exit(code) code : Int .. The exit function terminates omake abnormally. ``exit`` 関数はomakeを異常終了させます。 ``$(exit )`` .. The exit function takes one integer argument, which is exit code. Non-zero values indicate abnormal termination. ``exit`` 関数は終了コードである整数を引数に指定します。0でない値は異常終了を表します。 .. index:: single: defined() .. _label9.2.10: 9.2.10 defined ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(defined sequence) : String sequence : Sequence .. The defined function test whether all the variables in the sequence are currently defined. For example, the following code defines the X variable if it is not already defined. ``defined`` 関数はシーケンス中のすべての変数が現在定義されているか試します。例えば、以下のコードでは変数 ``X`` が既に定義されていないかどうかを定義しています。 :: if $(not $(defined X)) X = a b c export .. It is acceptable to use qualified names. これは修飾された変数にも用いることができます。 :: $(defined X.a.b) $(defined public.X) .. index:: single: defined-env() .. _label9.2.11: 9.2.11 defined-env ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(defined-env sequence) : String sequence : String .. The defined-env function tests whether a variable is defined as part of the process environment. ``defined-env`` 関数は処理している環境で、指定された変数が定義されているかどうか試します。 .. For example, the following code adds the -g compile option if the environment variable DEBUG is defined. 例えば、以下のコードでは、環境変数 ``DEBUG`` が定義されている場合は ``-g`` コンパイルオプションを追加します。 :: if $(defined-env DEBUG) CFLAGS += -g export .. index:: single: getenv() .. _label9.2.12: 9.2.12 getenv ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getenv name) : String $(getenv name, default) : String .. The getenv function gets the value of a variable from the process environment. The function takes one or two arguments. ``getenv`` 関数は現在処理している環境での変数の値を取得します。この関数は一つか二つの引数を指定する必要があります。 .. In the single argument form, an exception is raised if the variable variable is not defined in the environment. In the two-argument form, the second argument is returned as the result if the value is not defined. 一つの引数を指定した場合、もし環境中で変数が定義されていなかったならば例外を送出します。二つの引数を指定した場合、もし定義されていなかったならば二番目の引数が返されます。 .. For example, the following code defines the variable X to be a space-separated list of elements of the PATH environment variable if it is defined, and to /bin /usr/bin otherwise. 例えば、以下のコードでは、もし環境変数 ``PATH`` が定義されていた場合は、その値を空白で分割したリストとして ``X`` を定義します。さもなければ ``/bin /usr/bin`` が代わりに使われます。 :: X = $(split $(PATHSEP), $(getenv PATH, /bin:/usr/bin)) .. You may also use the alternate form. 以下のような形でも定義することができます。 :: getenv(NAME) default .. index:: single: setenv() .. _label9.2.13: 9.2.13 setenv ^^^^^^^^^^^^^^^^^^^^^^^^^ :: setenv(name, value) name : String value : String .. The setenv function sets the value of a variable in the process environment. Environment variables are scoped like normal variables. ``setenv`` 関数は現在処理している環境での変数を定義します。環境変数は通常の変数のようにスコープされます。 .. index:: single: unsetenv() .. _label9.2.14: 9.2.14 unsetenv ^^^^^^^^^^^^^^^^^^^^^^^^^ :: unsetenv(names) names : String Array .. The unsetenv function removes some variable definitions from the process environment. Environment variables are scoped like normal variables. ``unsetenv`` 関数は現在処理している環境からいくつかの変数を削除します。環境変数は通常の変数のようにスコープされます。 .. index:: single: get-registry() .. _label9.2.15: 9.2.15 get-registry ^^^^^^^^^^^^^^^^^^^^^^^^^ :: get-registry(hkey, key, field) : String get-registry(hkey, key, field, default) : String hkey : String key : String field : String .. The get-registry function retrieves a string value from the system registry on Win32. On other architectures, there is no registry. ``get-registry`` 関数はWin32上のシステムレジストリから文字列を取得します。他のアーキテクチャ上では、レジストリの値は返されません。 .. The hive (I think that is the right word), indicates which part of the registry to use. It should be one of the following values. ``hive`` (私はこの呼び方が正しいと思っています)では、使用するレジストリの区分を指定します。これは以下の値である必要があります。(訳注: よく意味がわかりませんがhkeyとfiveをもじったもの?) * HKEY_CLASSES_ROOT * HKEY_CURRENT_CONFIG * HKEY_CURRENT_USER * HKEY_LOCAL_MACHINE * HKEY_USERS .. Refer to the Microsoft documentation if you want to know what these mean. もしこれらの意味について知りたい場合はマイクロソフトのドキュメントを参照してください。 .. The key is the field you want to get from the registry. It should have a form like A\B\C (if you use forward slashes, they will be converted to backslashes). The field is the sub-field of the key. ``key`` はレジストリから取得したいフィールドを指定します。これは ``A\B\C`` のような形である必要があります(通常のスラッシュを用いた場合はバックスラッシュに変換されます)。 ``field`` は ``key`` のサブフィールドを指定します。 .. In the 4-argument form, the default is returned on failure. You may also use the alternate form. 4つの引数を取る場合、 ``default`` の値が失敗したときに返されます。あなたはこれを別の形で用いることもできます。 :: get-registry(hkey, key, field) default .. index:: single: getvar() .. _label9.2.16: 9.2.16 getvar ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(getvar name) : String .. The getvar function gets the value of a variable. ``getvar`` 関数は変数の値を取得します。 .. An exception is raised if the variable variable is not defined. 変数が定義されていない場合は例外が送出されます。 .. For example, the following code defines X to be the string abc. 例えば、以下のコードでは ``X`` を文字列 ``abc`` で定義します。 :: NAME = foo foo_1 = abc X = $(getvar $(NAME)_1) .. It is acceptable to use qualified names. これは修飾された変数にも使うことができます。 :: $(getvar X.a.b) .. index:: single: setvar() .. _label9.2.17: 9.2.17 setvar ^^^^^^^^^^^^^^^^^^^^^^^^^ :: setvar(name, value) name : String value : String .. The setvar function defines a new variable. For example, the following code defines the variable X to be the string abc. ``setvar`` 関数は新しい変数を定義します。例えば、以下のコードでは ``X`` は文字列 ``abc`` で定義されます。 :: NAME = X setvar($(NAME), abc) .. It is acceptable to use qualified names. これは修飾された変数にも使うことができます。 :: setvar(public.X, abc) 9.3 配列とシーケンス ---------------------------------- .. index:: single: array() .. _label9.3.1: 9.3.1 array ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(array elements) : Array elements : Sequence .. The array function creates an array from a sequence. If the is a string, the elements of the array are the whitespace-separated elements of the string, respecting quotes. ``array`` 関数はシーケンスから配列を生成します。もし ```` が文字列だった場合、配列の成分はホワイトスペースによって区切られた文字列となります。また、クオートによっても区切られます。 .. In addition, array variables can be declared as follows. 加えて、配列の変数は以下のように宣言することもできます。 :: A[] = ... .. In this case, the elements of the array are exactly , ..., , and whitespace is preserved literally. この場合、配列の成分は ```` , ... , ```` であり、ホワイトスペースは文字通りに取り扱われます。 .. index:: single: split() .. _label9.3.2: 9.3.2 split ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(split sep, elements) : Array sep : String elements : Sequence .. The split function takes two arguments, a string of separators, and a string argument. The result is an array of elements determined by splitting the elements by all occurrence of the separator in the elements sequence. ``split`` 関数は二つの引数を必要とし、一つめには文字列のデリミタ、二つめには区切りたい文字列を指定します。結果は ``elements`` シーケンスをセパレータによって区切った配列が返されます。 .. For example, in the following code, the X variable is defined to be the array /bin /usr/bin /usr/local/bin. 例えば、以下のコードでは、変数 ``X`` は配列 ``/bin /usr/bin /usr/local/bin`` に定義されます。 :: PATH = /bin:/usr/bin:/usr/local/bin X = $(split :, $(PATH)) .. The sep argument may be omitted. In this case split breaks its arguments along the white space. Quotations are not split. ``sep`` は除外することもできます。この場合 ``split`` はホワイトスペースで区切ります。クオーテーションは区切りません。 .. index:: single: concat() .. _label9.3.3: 9.3.3 concat ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(concat sep, elements) : String sep : String elements : Sequence .. The concat function takes two arguments, a separator string, and a sequence of elements. The result is a string formed by concatenating the elements, placing the separator between adjacent elements. ``concat`` 関数は二つの引数を必要とし、一つめには文字列のセパレータ、二つめにはシーケンスを指定します。結果は隣接した成分の間にセパレータを配置した、結合された文字列が返されます。 .. For example, in the following code, the X variable is defined to be the string foo_x_bar_x_baz. 例えば、以下のコードでは、変数 ``X`` は文字列 ``foo_x_bar_x_baz`` に定義されます。 :: X = foo bar baz Y = $(concat _x_, $(X)) .. index:: single: length() .. _label9.3.4: 9.3.4 length ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(length sequence) : Int sequence : Sequence .. The length function returns the number of elements in its argument. ``length`` 関数は引数の成分の数を返します。 .. For example, the expression $(length a b "c d") evaluates to 3. 例えば、式 ``$(length a b "c d")`` は3と評価されます。 .. index:: single: nth() .. _label9.3.5: 9.3.5 nth ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(nth i, sequence) : value i : Int sequence : Sequence raises RuntimeException .. The nth function returns the nth element of its argument, treated as a list. Counting starts at 0. An exception is raised if the index is not in bounds. ``nth`` 関数は引数のi番目の成分を返します。配列のインデックスは0から始まります。もしインデックスが存在しない成分を指定していた場合、例外が送出されます。 .. For example, the expression $(nth 1, a "b c" d) evaluates to "b c". 例えば、式 ``$(nth 1, a "b c" d)`` は ``"b c"`` と評価されます。 .. index:: single: replace-nth() .. _label9.3.6: 9.3.6 replace-nth ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(replace-nth i, sequence, x) : value i : Int sequence : Sequence x : value raises RuntimeException .. The replace-nth function replaces the nth element of its argument with a new value x. Counting starts at 0. An exception is raised if the index is not in bounds. ``replace-nth`` 関数はi番目の成分を新しい値 ``x`` に置き換えます。インデックスは0から始まります。もしインデックスが存在しない成分を指定していた場合、例外が送出されます。 .. For example, the expression $(replace-nth 1, a "b c" d, x) evaluates to a x d. 例えば、式 ``$(replace-nth 1, a "b c" d, x)`` は ``a x d`` と評価されます。 .. index:: single: nth-hd() .. _label9.3.7: 9.3.7 nth-hd ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(nth-hd i, sequence) : value i : Int sequence : Sequence raises RuntimeException .. The nth-hd function returns the first i elements of the sequence. An exception is raised if the sequence is not at least i elements long. ``nth-hd`` 関数は最初から ``i`` 個までの成分をもった配列を返します。もしシーケンスが ``i`` 個より少ない場合は例外が送出されます。 .. For example, the expression $(nth-hd 2, a "b c" d) evaluates to a "b c". 例えば、式 ``$(nth-hd 2, a "b c" d)`` は ``a "b c"`` と評価されます。 .. index:: single: nth-tl() .. _label9.3.8: 9.3.8 nth-tl ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(nth-tl i, sequence) : value i : Int sequence : Sequence raises RuntimeException .. The nth-tl function skips i elements of the sequence and returns the rest. An exception is raised if the sequence is not at least i elements long. ``nth-tl`` 関数は最初から ``i`` 個までの成分を除いた、残りの配列を返します。もしシーケンスが ``i`` 個より少ない場合には例外が送出されます。 .. For example, the expression $(nth-tl 1, a "b c" d) evaluates to "b c" d. 例えば、式 ``$(nth-tl 1, a "b c" d)`` は ``"b c" d`` と評価されます。 .. index:: single: subrange() .. _label9.3.9: 9.3.9 subrange ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(subrange off, len, sequent) : value off : Int len : Int sequence : Sequence raises RuntimeException .. The subrange function returns a subrange of the sequence. Counting starts at 0. An exception is raised if the specified range is not in bounds. ``subrange`` 関数はシーケンスの一部分を返します。インデックスは0から始まります。もし指定された範囲に成分が存在しない場合には例外が送出されます。 .. For example, the expression $(subrange 1, 2, a "b c" d e) evaluates to "b c" d. 例えば、式 ``$(subrange 1, 2, a "b c" d e)`` は ``"b c" d`` と評価されます。 .. index:: single: rev() .. _label9.3.10: 9.3.10 rev ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(rev sequence) : Sequence sequence : Sequence .. The rev function returns the elements of a sequence in reverse order. For example, the expression $(rev a "b c" d) evaluates to d "b c" a. ``rev`` 関数は指定された配列の順番を逆にした配列を返します。例えば、式 ``$(rev a "b c" d)`` は ``d "b c" a`` と評価されます。 .. index:: single: join() .. _label9.3.11: 9.3.11 join ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(join sequence1, sequence2) : Sequence sequence1 : Sequence sequence2 : Sequence .. The join function joins together the elements of the two sequences. For example, $(join a b c, .c .cpp .h) evaluates to a.c b.cpp c.h. If the two input sequences have different lengths, the remainder of the longer sequence is copied at the end of the output unmodified. ``join`` 関数は二つのシーケンスの成分を互いに結合させます。例えば、 ``$(join a b c, .c .cpp .h)`` は ``a.c b.cpp c.h`` と評価されます。もし二つの入力シーケンスが異なる長さであった場合は、長いシーケンスの残りの成分は、出力先の配列の終わりに修正されない状態でコピーされます。 .. index:: single: string() .. _label9.3.12: 9.3.12 string ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(string sequence) : String sequence : Sequence .. The string function flattens a sequence into a single string. This is similar to the concat function, but the elements are separated by whitespace. The result is treated as a unit; whitespace is significant. ``string`` 関数はシーケンスを一つの文字列にまとめます。これは ``concat`` 関数と似ていますが、この成分はホワイトスペースによって分割されています。結果は一つのユニットとして扱われます。ホワイトスペースは重要です。 .. index:: single: string-length() .. _label9.3.13: 9.3.13 string-length ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(string-length sequence) : Int sequence : Sequence .. The string-lenght returns a length (number of characters) in its argument. If the argument is a sequence, it flattens it, so $(string-length sequence) is equivalent to $(string-length $(string sequence)). ``string-length`` 関数は引数の文字列の長さを返します。もし引数がシーケンスであった場合、まとめられた状態で評価されます。よって、 ``$(string-length sequence)`` は ``$(string-length $(string sequence))`` と等価です。 .. index:: single: string-escaped() single: ocaml-escaped() single: html-escaped() single: html-pre-escaped() single: c-escaped() single: id-escaped() .. _label9.3.14: 9.3.14 string-escaped, ocaml-escaped, html-escaped, html-pre-escaped, c-escaped, id-escaped ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(string-escaped sequence) : String Array $(ocaml-escaped sequence) : String Array $(html-escaped sequence) : String Array $(html-pre-escaped sequence) : String Array $(c-escaped sequence) : String Array $(hex-escaped sequence) : StringArray sequence : Array .. The string-escaped function converts each element of its argument to a string, escaping it, if it contains symbols that are special to OMake. The special characters include :()\,$'"# and whitespace. This function can be used in scanner rules to escape file names before printing then to stdout. .. The ocaml-escaped function converts each element of its argument to a string, escaping characters that are special to OCaml. ``string-escaped`` 関数は引数の各々の成分を文字列に変換し、もしその成分がOMakeの特殊文字を含んでいた場合は、その文字をエスケープした状態で返します。特殊文字は ``:()\,$'"#`` とホワイトスペースを含みます。この関数はスキャナルール中で、 ``stdout`` に出力する前にファイル名をエスケープするために使われます。 .. The c-escaped function converts a string to a form that can be used as a string constant in C. ``ocaml-escaped`` 関数はOCamlの特殊文字をエスケープした状態で返します。 .. The id-escaped function turns a string into an identifier that may be used in OMake. ``c-escaped`` 関数はCの文字定数に使われるような形の文字列に変換します。 .. The id-escaped function turns a string into an identifier that may be used in OMake. ``id-escaped`` 関数はOMakeで使われるような識別子に変換します。 .. The html-escaped function turns a literal string into a form acceptable as HTML. The html-pre-escaped function is similar, but it does not translate newlines into
. ``html-escaped`` 関数はHTMLで文字通りに読み込まれるような形の文字列に変換します。 ``html-pre-escaped`` 関数と似ていますが、この関数では改行は ``
`` に変換されません。 :: println($(string $(string-escaped $"a b" $"y:z"))) a\ b y\:z .. index:: single: decode-uri() single: encode-uri() .. _label9.3.15: 9.3.15 decode-uri, encode-uri ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(decode-uri sequence) : sequence sequence : Sequence .. These two functions perform URI encoding, where special characters are represented by hexadecimal characters. これら二つの関数はURIのエンコーディングに用いられ、特殊文字を16進数の文字に置き換えます。 :: osh> s = $(encode-uri $'a b~c') "a+b%7ec" osh> decode-uri($s) "a b~c" .. index:: single: quote() .. _label9.3.16: 9.3.16 quote ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(quote sequence) : String sequence : Sequence .. The quote function flattens a sequence into a single string and adds quotes around the string. Inner quotation symbols are escaped. ``quote`` 関数はシーケンスを一つの文字列にまとめ、さらに文字列にクオートを付与します。内部のクオーテーションはエスケープされます。 .. For example, the expression $(quote a "b c" d) evaluates to "a \"b c\" d", and $(quote abc) evaluates to "abc". 例えば、式 ``$(quote a "b c" d)`` は ``"a \"b c\" d"`` に、 ``$(quote abc)`` は ``"abc"`` に評価されます。 .. index:: single: quote-argv() .. _label9.3.17: 9.3.17 quote-argv ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(quote-argv sequence) : String sequence : Sequence .. The quote-argv function flattens a sequence into a single string, and adds quotes around the string. The quotation is formed so that a command-line parse can separate the string back into its components. ``quote-argv`` 関数はシーケンスを一つの文字列にまとめ、さらに文字列にクオートを付与します。クオーテーションは変換されるため、コマンドラインのパーサは、正常に文字列をその構成要素へと戻すことができます。 .. index:: single: html-string() .. _label9.3.18: 9.3.18 html-string ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(html-string sequence) : String sequence : Sequence .. The html-string function flattens a sequence into a single string, and escaped special HTML characters. This is similar to the concat function, but the elements are separated by whitespace. The result is treated as a unit; whitespace is significant. ``html-string`` 関数はシーケンスを一つの文字列にまとめ、さらに特殊なHTML文字にエスケープします。 ``concat`` 関数と似ていますが、この関数はホワイトスペースで分割を行います。結果は一つの文字列として返されます。 .. index:: single: addsuffix() .. _label9.3.19: 9.3.19 addsuffix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(addsuffix suffix, sequence) : Array suffix : String sequence : Sequence .. The addsuffix function adds a suffix to each component of sequence. The number of elements in the array is exactly the same as the number of elements in the sequence. ``addsuffix`` 関数はシーケンスの各々の成分に接尾辞を付与します。返される配列の長さは、指定されたシーケンスの配列の長さと全く同じです。 .. For example, $(addsuffix .c, a b "c d") evaluates to a.c b.c "c d".c. 例えば、 ``$(addsuffix .c, a b "c d")`` は ``a.c b.c "c d".c`` と評価されます。 .. index:: single: mapsuffix() .. _label9.3.20: 9.3.20 mapsuffix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(mapsuffix suffix, sequence) : Array suffix : value sequence : Sequence .. The mapsuffix function adds a suffix to each component of sequence. It is similar to addsuffix, but uses array concatenation instead of string concatenation. The number of elements in the array is twice the number of elements in the sequence. ``mapsuffix`` 関数はシーケンスの各々の成分に接尾辞を付与します。これは ``addsuffix`` 関数と似ていますが、この関数は文字列をくっ付ける代わりに新しく成分を追加します。よって、返される配列の長さは、指定されたシーケンスの配列の長さの2倍です。 .. For example, $(mapsuffix .c, a b "c d") evaluates to a .c b .c "c d" .c. 例えば、 ``$(mapsuffix .c, a b "c d")`` は ``a .c b .c "c d" .c`` と評価されます。 .. index:: single: addsuffixes() .. _label9.3.21: 9.3.21 addsuffixes ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(addsuffixes suffixes, sequence) : Array suffixes : Sequence sequence : Sequence .. The addsuffixes function adds all suffixes in its first argument to each component of a sequence. If suffixes has n elements, and sequence has m elements, the the result has n * m elements. ``addsuffixes`` 関数は最初の引数に指定されたすべての接尾辞をシーケンスの各々の成分に付与します。もし ``suffixes`` が ``n`` 個の成分を、 ``sequence`` が ``m`` 個の成分を持っていた場合、結果は ``n * m`` 個の成分を持ったシーケンスが返されます。 .. For example, the $(addsuffixes .c .o, a b c) expressions evaluates to a.c a.o b.c b.o c.o c.a. 例えば、 ``$(addsuffixes .c .o, a b c)`` は ``a.c a.o b.c b.o c.c c.o`` と評価されます。 .. index:: single: removeprefix() .. _label9.3.22: 9.3.22 removeprefix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(removeprefix prefix, sequence) : Array prefix : String sequence : Array .. The removeprefix function removes a prefix from each component of a sequence. ``removeprefix`` 関数はシーケンスの各々の成分から接頭辞を取り除きます。 .. index:: single: removesuffix() .. _label9.3.23: 9.3.23 removesuffix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(removesuffix sequence) : Array sequence : String .. The removesuffix function removes the suffixes from each component of a sequence. ``removesuffix`` 関数はシーケンスの各々の成分から接尾辞(拡張子)を取り除きます。 .. For example, $(removesuffix a.c b.foo "c d") expands to a b "c d". 例えば、 ``$(removesuffix a.c b.foo "c d")`` の結果は ``a b "c d"`` となります。 .. index:: single: replacesuffixes() .. _label9.3.24: 9.3.24 replacesuffixes ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(replacesuffixes old-suffixes, new-suffixes, sequence) : Array old-suffixes : Sequence new-suffixes : Sequence sequence : Sequence .. The replacesuffixes function modifies the suffix of each component in sequence. The old-suffixes and new-suffixes sequences should have the same length. ``replacesuffixes`` 関数はシーケンスの各々の成分の接尾辞(拡張子)を置き換えます。 ``old-suffixes`` と ``new-suffixes`` シーケンスは同じ長さである必要があります。 .. For example, $(replacesuffixes .h .c, .o .o, a.c b.h c.z) expands to a.o b.o c.z. 例えば、 ``$(replacesuffixes .h .c, .o .o, a.c b.h c.z)`` の結果は ``a.o b.o c.z`` となります。 .. index:: single: addprefix() .. _label9.3.25: 9.3.25 addprefix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(addprefix prefix, sequence) : Array prefix : String sequence : Sequence .. The addprefix function adds a prefix to each component of a sequence. The number of element in the result array is exactly the same as the number of elements in the argument sequence. ``addprefix`` 関数はシーケンスの各々の成分に接頭辞を付与します。返される配列の長さは、指定されたシーケンスの配列の長さと全く同じです。 .. For example, $(addprefix foo/, a b "c d") evaluates to foo/a foo/b foo/"c d". 例えば、 ``$(addprefix foo/, a b "c d")`` は ``foo/a foo/b foo/"c d"`` と評価されます。 .. index:: single: mapprefix() .. _label9.3.26: 9.3.26 mapprefix ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(mapprefix prefix, sequence) : Array prefix : String sequence : Sequence .. The mapprefix function adds a prefix to each component of a sequence. It is similar to addprefix, but array concatenation is used instead of string concatenation. The result array contains twice as many elements as the argument sequence. ``mapprefix`` 関数はシーケンスの各々の成分に接頭辞を付与します。これは ``addprefix`` 関数と似ていますが、この関数は文字列をくっ付ける代わりに新しく成分を追加します。よって、返される配列の長さは、指定されたシーケンスの配列の長さの2倍です。 .. For example, $(mapprefix foo, a b "c d") expands to foo a foo b foo "c d". 例えば、 ``$(mapprefix foo, a b "c d")`` の結果は ``foo a foo b foo "c d"`` となります。 .. index:: single: add-wrapper() .. _label9.3.27: 9.3.27 add-wrapper ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(add-wrapper prefix, suffix, sequence) : Array prefix : String suffix : String sequence : Sequence .. The add-wrapper functions adds both a prefix and a suffix to each component of a sequence. For example, the expression $(add-wrapper dir/, .c, a b) evaluates to dir/a.c dir/b.c. String concatenation is used. The array result has the same number of elements as the argument sequence. ``add-wrapper`` 関数はシーケンスの各々の成分に接頭辞と接尾辞の両方を付与します。例えば、 ``$(add-wrapper dir/, .c, a b)`` は ``dir/a.c dir/b.c`` と評価されます。文字列は結合されるため、返される配列の長さは、指定されたシーケンスの長さと全く同じです。 .. index:: single: set() .. _label9.3.28: 9.3.28 set ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(set sequence) : Array sequence : Sequence .. The set function sorts a set of string components, eliminating duplicates. ``set`` 関数は文字列の集合をソートします。さらに、重複した成分を除去します。 .. For example, $(set z y z "m n" w a) expands to "m n" a w y z. 例えば、 ``$(set z y z "m n" w a)`` の結果は ``"m n" a w y z`` となります。 .. index:: single: mem() .. _label9.3.29: 9.3.29 mem ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(mem elem, sequence) : Boolean elem : String sequence : Sequence .. The mem function tests for membership in a sequence. ``mem`` 関数はシーケンス中に指定した成分が含まれているかどうか調べます。 .. For example, $(mem "m n", y z "m n" w a) evaluates to true, while $(mem m n, y z "m n" w a) evaluates to false. 例えば、 ``$(mem "m n", y z "m n" w a)`` は ``true`` と評価されて、一方で ``$(mem m n, y z "m n" w a)`` は ``false`` と評価されます。 .. index:: single: intersection() .. _label9.3.30: 9.3.30 intersection ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(intersection sequence1, sequence2) : Array sequence1 : Sequence sequence2 : Sequence .. The intersection function takes two arguments, treats them as sets of strings, and computes their intersection. The order of the result is undefined, and it may contain duplicates. Use the set function to sort the result and eliminate duplicates in the result if desired. ``intersection`` 関数は指定された二つの集合の和をとります。返される配列の長さは不定であり、重複があればそれを含みます。もし結果をソートし、さらに重複を除きたい場合は ``set`` 関数を使ってください。 .. For example, the expression $(intersection c a b a, b a) evaluates to a b a. 例えば、 ``$(intersection c a b a, b a)`` は ``a b a`` と評価されます。 .. index:: single: intersects() .. _label9.3.31: 9.3.31 intersects ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(intersects sequence1, sequence2) : Boolean sequence1 : Sequence sequence2 : Sequence .. The intersects function tests whether two sets have a non-empty intersection. This is slightly more efficient than computing the intersection and testing whether it is empty. ``intersects`` 関数は二つの集合の和が空集合でないかどうか調べます。これは集合の和を計算し、空であるかどうか調べるよりも少しだけ効率的です。 .. For example, the expression $(intersects a b c, d c e) evaluates to true, and $(intersects a b c a, d e f) evaluates to false. 例えば、 ``$(intersects a b c, d c e)`` は ``true`` と評価されて、 ``$(intersects a b c a, d e f)`` は ``false`` と評価されます。 .. index:: single: set-diff() .. _label9.3.32: 9.3.32 set-diff ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(set-diff sequence1, sequence2) : Array sequence1 : Sequence sequence2 : Sequence .. The set-diff function takes two arguments, treats them as sets of strings, and computes their difference (all the elements of the first set that are not present in the second one). The order of the result is undefined and it may contain duplicates. Use the set function to sort the result and eliminate duplicates in the result if desired. ``set-diff`` 関数は二つの集合の差異を計算します。結果は ``sequence1`` には含まれるが ``sequence2`` には含まれていない成分からなる配列です。返される配列の長さは不定であり、重複があればそれを含みます。もし結果をソートし、さらに重複を除きたい場合は ``set`` 関数を使ってください。 .. note:: 訳注: この関数は集合論における ``f(A,B) = A - B`` と等価です。 .. For example, the expression $(set-diff c a b a e, b a) evaluates to c e. 例えば、 ``$(set-diff c a b a e, b a)`` は ``c e`` と評価されます。 .. index:: single: filter() .. _label9.3.33: 9.3.33 filter ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(set-diff sequence1, sequence2) : Array sequence1 : Sequence sequence2 : Sequence .. The filter function picks elements from a sequence. The patterns is a non-empty sequence of patterns, each may contain one occurrence of the wildcard % character. ``filter`` 関数はシーケンスから特定の成分を抜き出します。 ``patterns`` にはパターンを定義した、空でないシーケンスを指定します。また、パターンにはワイルドカード ``%`` を含めることができます。 .. For example $(filter %.h %.o, a.c x.o b.h y.o "hello world".c) evaluates to x.o b.h y.o. 例えば、 ``$(filter %.h %.o, a.c x.o b.h y.o "hello world".c)`` は ``x.o b.h y.o`` と評価されます。 .. index:: single: filter-out() .. _label9.3.34: 9.3.34 filter-out ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(filter-out patterns, sequence) : Array patterns : Sequence sequence : Sequence .. The filter-out function removes elements from a sequence. The patterns is a non-empty sequence of patterns, each may contain one occurrence of the wildcard % character. ``filter-out`` 関数はシーケンスから特定の成分を除去します。 ``patterns`` にはパターンを定義した、空でないシーケンスを指定します。また、パターンにはワイルドカード ``%`` を含めることができます。 .. For example $(filter-out %.c %.h, a.c x.o b.h y.o "hello world".c) evaluates to x.o y.o. 例えば、 ``$(filter-out %.c %.h, a.c x.o b.h y.o "hello world".c)`` は ``x.o y.o`` と評価されます。 .. index:: single: capitalize() .. _label9.3.35: 9.3.35 capitalize ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(capitalize sequence) : Array sequence : Sequence .. The capitalize function capitalizes each word in a sequence. For example, $(capitalize through the looking Glass) evaluates to Through The Looking Glass. ``capitalize`` 関数はシーケンスの各々の成分の単語を大文字化します。例えば、 ``$(capitalize through the looking Glass)`` は ``Through The Looking Glass`` と評価されます。 .. index:: single: uncapitalize() .. _label9.3.36: 9.3.36 uncapitalize ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(uncapitalize sequence) : Array sequence : Sequence .. The uncapitalize function uncapitalizes each word in its argument. ``uncapitalize`` 関数は引数に指定された各々の単語を小文字化します。 .. For example, $(uncapitalize through the looking Glass) evaluates to through the looking glass. 例えば、 ``$(uncapitalize through the looking Glass)`` は ``through the looking glass`` と評価されます。 .. index:: single: uppercase() .. _label9.3.37: 9.3.37 uppercase ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(uppercase sequence) : Array sequence : Sequence .. The uppercase function converts each word in a sequence to uppercase. For example, $(uppercase through the looking Glass) evaluates to THROUGH THE LOOKING GLASS. ``uppercase`` 関数はシーケンス中の文字すべてを大文字化します。例えば、 ``$(uppercase through the looking Glass)`` は ``THROUGH THE LOOKING GLASS`` と評価されます。 .. index:: single: lowercase() .. _label9.3.38: 9.3.38 lowercase ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(lowercase sequence) : Array sequence : Sequence .. The lowercase function reduces each word in its argument to lowercase. ``lowercase`` 関数はシーケンス中の文字すべてを小文字化します。 .. For example, $(lowercase through tHe looking Glass) evaluates to through the looking glass. 例えば、 ``$(lowercase through tHe looking Glass)`` は ``through the looking glass`` と評価されます。 .. index:: single: system() .. _label9.3.39: 9.3.39 system ^^^^^^^^^^^^^^^^^^^^^^^^^ :: system(s) s : Sequence .. The system function is used to evaluate a shell expression. This function is used internally by omake to evaluate shell commands. ``system`` 関数はシェル上のコマンドを評価するために用いられます。シェルコマンドを評価するため、omakeは内部でこの関数を使用しています。 .. For example, the following program is equivalent to the expression system(ls foo). 例えば、以下のプログラムは式 ``system(ls foo)`` と等価です。 :: ls foo .. index:: single: shell() .. _label9.3.40: 9.3.40 shell ^^^^^^^^^^^^^^^^^^^^^^^^^ :: $(shell command) : Array $(shella command) : Array $(shell-code command) : Int command : Sequence .. The shell function evaluates a command using the command shell, and returns the whitespace-separated words of the standard output as the result. ``shell`` 関数はシェルコマンドを用いてコマンドを評価し、さらに標準出力先に出力された、ホワイトスペースで区切ってある出力結果を返します。 .. The shella function acts similarly, but it returns the lines as separate items in the array. ``shella`` 関数は同様に振る舞いますが、この関数では改行をそのまま出力するのではなく、分割された配列として返します。 .. The shell-code function returns the exit code. The output is not diverted. ``shell-code`` は結果として終了コードを返します。出力は返されません。 .. For example, if the current directory contains the files OMakeroot, OMakefile, and hello.c, then $(shell ls) evaluates to hello.c OMakefile OMakeroot (on a Unix system). 例えば、もしカレントディレクトリがファイル ``OMakeroot`` , ``OMakefile`` , ``hello.c`` を含んでいる場合、 ``$(shell ls)`` はUnixシステム上では ``hello.c OMakefile OMakeroot`` と評価されます。 .. index:: single: export() .. _label9.3.41: 9.3.41 export ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The export function allows one to capture the current environment in a variable. ``export`` 関数は現在の環境中の変数の値を保存します。 .. For example, the following code will print 1 1 2. 例えば、以下のコードは ``1 1 2`` と出力されます。 :: A = 1 B = 1 C = 1 SAVE_ENV = $(export A B) A = 2 B = 2 C = 2 export($(SAVE_ENV)) println($A $B $C) .. The arguments to this function are interpreted the exact same way as the arguments to the export special form (see Section 6.3). この関数に引数を指定することは、 ``export`` 文を用いて引数を指定するのと全く等価なものとして解釈されます(詳細は ":ref:`label6.3`" を参照してください)。 .. index:: single: while .. _label9.3.42: 9.3.42 while ^^^^^^^^^^^^^^^^^^^^^^^^^ :: while あるいは :: while case ... case default .. The loop is executed while the test is true. In the first form, the is executed on every loop iteration. In the second form, the body is selected, as the first case where the test is true. If none apply, the optional default case is evaluated. If no cases are true, the loop exits. The environment is automatically exported. ```` が真である間はずっとループの式が実行されます。最初の形では、 ```` はすべてのループにおいて実行されます。二番目の形では、もし ```` が真であった場合は ```` が実行されます。もしなにも当てはまらない場合には ```` が実行されます。もしすべての場合において真でなかったならば、ループは終了します。なお、ループ中の環境は自動的にエクスポートされます。 .. Examples. Iterate for i from 0 to 9. 例えば、 ``i`` を ``0`` から ``9`` まで繰り返します。 :: i = 0 while $(lt $i, 10) echo $i i = $(add $i, 1) .. The following example is equivalent. 上の例は以下の例と等価です。 :: i = 0 while true case $(lt $i, 10) echo $i i = $(add $i, 1) .. The following example is similar, but some special cases are printed. value is printed. 以下の例は似ていますが、いくつかの特殊な場合においてある文字が出力されます。その他は値が出力されます。 :: i = 0 while $(lt $i, 10) case $(equal $i, 0) echo zero case $(equal $i, 1) echo one default echo $i .. The break function can be used to break out of the while loop early. ``break`` 関数は ``while`` ループを早期に抜けたい場合に用いられます。 .. index:: single: break .. _label9.3.43: 9.3.43 break ^^^^^^^^^^^^^^^^^^^^^^^^^ :: break .. Terminate execution of the innermost loop, returning the current state. 最も近いループから抜け出し、現在の状態を返します。 .. index:: single: random() single: random-init() .. _label9.3.44: 9.3.44 random, random-init ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: random-init(i) i : Int random() : Int .. Produce a random number. The numbers are pseudo-random, and are not cryptographically secure. 乱数を生成します。値は疑似乱数で、暗号として用いられるほどセキュアではありません。 .. The generator is initialized form semi-random system data. Subsequent runs should produce different results. The rando-init function can be used to return the generator to a known state. 乱数生成器はシステムの乱数器を用いて初期化します。よって、次にプログラムを実行したときの乱数の値は前回と異なります。 ``ramdom-init`` 関数は特定の値を用いて乱数生成器を初期化します。 .. _label9.4: 9.4 演算 ---------------------------------- .. index:: single: int() .. _label9.4.1: 9.4.1 int ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The int function can be used to create integers. It returns an Int object. ``int`` 関数は整数値を作るために用いられ、 ``Int`` オブジェクトを返します。 :: $(int 17) .. index:: single: float() .. _label9.4.2: 9.4.2 float ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The float function can be used to create floating-point numbers. It returns a Float object. ``float`` 関数は浮動小数点値を作るために用いられ、 ``Float`` オブジェクトを返します。 :: $(float 3.1415926) .. index:: single: neg() single: add() single: sub() single: mul() single: div() single: mod() single: lnot() single: land() single: lor() single: lxor() single: lsl() single: lsr() single: asr() single: min() single: max() .. _label9.4.3: 9.4.3 基本的な演算 ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The following functions can be used to perform basic arithmetic. 以下の関数は基本的な数学の演算を行います。 .. * $(neg ): arithmetic inverse * $(add ): addition. * $(sub ): subtraction. * $(mul ): multiplication. * $(div ): division. * $(mod ): remainder. * $(lnot ): bitwise inverse. * $(land ): bitwise and. * $(lor ): bitwise or. * $(lxor ): bitwise exclusive-or. * $(lsl ): logical shift left. * $(lsr ): logical shift right. * $(asr ): arithmetic shift right. * $(min ): smallest element. * $(max ): largest element. * ``$(neg )`` : 数学的な反転 * ``$(add )`` : 加算 * ``$(sub )`` : 減算 * ``$(mul )`` : 乗算 * ``$(div )`` : 除算 * ``$(mod )`` : 余り * ``$(lnot )`` : ビット単位NOT * ``$(land )`` : ビット単位AND * ``$(lor )`` : ビット単位OR * ``$(lxor )`` : ビット単位XOR * ``$(lsl )`` : 論理左シフト * ``$(lsr )`` : 論理右シフト * ``$(asr )`` : 算術右シフト * ``$(min )`` : 最も小さい成分 * ``$(max )`` : 最も大きい成分 .. index:: single: lt() single: le() single: eq() single: ge() single: gt() single: ult() single: ule() single: uge() single: ugt() .. _label9.4.4: 9.4.4 評価 ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The following functions can be used to perform numerical comparisons. 以下の関数は数学的な評価を行います。 .. * $(lt ): less then. * $(le ): no more than. * $(eq ): equal. * $(ge ): no less than. * $(gt ): greater than. * $(ult ): unsigned less than. * $(ule ): unsigned greater than. * $(uge ): unsigned greater than or equal. * $(ugt ): unsigned greater than. * ``$(lt )`` : ~より少ない (A < B) * ``$(le )`` : ~以下 (A <= B) * ``$(eq )`` : 等しい (A == B) * ``$(ge )`` : ~以上 (A >= B) * ``$(gt )`` : ~より多い (A > B) * ``$(ult )`` : ~より少ない(符号なし) * ``$(ule )`` : ~以下(符号なし) * ``$(uge )`` : ~以上(符号なし) * ``$(ugt )`` : ~より多い(符号なし) .. note:: 訳注: ここでいう(符号なし)とは符号ビットを考慮しないで評価を行うことを表しています。例えば、int型とunsigned int型では同じビット数に対してそれぞれ表している数値が異なります。(符号なし)の演算子はこのような場合に用いられます。 .. _label9.5: 9.5 基本的な関数群 ---------------------------------- .. index:: single: fun() .. _label9.5.1: 9.5.1 fun ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The fun form introduces anonymous functions. ``fun`` 関数は匿名関数を生成します。 :: $(fun , ..., , ) .. The last argument is the body of the function. The other arguments are the parameter names. 最後の引数には関数の内容を記述します。他の引数はパラメータ名を指定します。 .. The three following definitions are equivalent. 例えば、以下の3つの関数定義は等価です。 :: F(X, Y) = return($(addsuffix $(Y), $(X))) F = $(fun X, Y, $(addsuffix $(Y), $(X))) F = fun(X, Y) value $(addsuffix $(Y), $(X)) .. index:: single: apply() .. _label9.5.2: 9.5.2 apply ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The apply operator is used to apply a function. ``apply`` 関数は関数に値を適用します。 :: $(apply , ) .. Suppose we have the following function definition. 以下の関数定義を行った場合について考えてみましょう。 :: F(X, Y) = return($(addsuffix $(Y), $(X))) .. The the two expressions below are equivalent. 以下の2つの式は等価です。 :: X = F(a b c, .c) X = $(apply $(F), a b c, .c) .. index:: single: applya() .. _label9.5.3: 9.5.3 applya ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The applya operator is used to apply a function to an array of arguments. ``applya`` 関数は引数の配列を関数に適用します。 :: $(applya , ) .. For example, in the following program, the value of Z is file.c. 例えば、以下のプログラムでは ``Z`` の値は ``file.c`` となります。 :: F(X, Y) = return($(addsuffix $(Y), $(X))) args[] = file .c Z = $(applya $(F), $(args)) .. index:: single: create-map() single: create-lazy-map() .. _label9.5.4: 9.5.4 create-map, create-lazy-map ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The create-map is a simplified form for creating Map objects. The create-map function takes an even number of arguments that specify key/value pairs. For example, the following values are equivalent. ``create-map`` 関数は簡単に ``Map`` オブジェクトを作る関数です。 ``create-map`` 関数はキー/値のペアを引数によって指定するので、引数の数は等しくなければなりません。例えば、以下の2つの式は等価です。 :: X = $(create-map name1, xxx, name2, yyy) X. = extends $(Map) $|name1| = xxx $|name2| = yyy .. The create-lazy-map function is similar, but the values are computed lazily. The following two definitions are equivalent. ``create-lazy-map`` 関数は ``create-map`` と似ていますが、この関数は値が遅延評価されます。例えば、以下の2つの式は等価です。 :: Y = $(create-lazy-map name1, $(xxx), name2, $(yyy)) Y. = extends $(Map) $|name1| = $`(xxx) $|name2| = $`(yyy) .. The create-lazy-map function is used in rule construction. ``create-lazy-map`` 関数はルールを生成する際に用いられます。 .. _label9.6: 9.6 イテレーションとマッピング ---------------------------------- .. index:: single: foreach() .. _label9.6.1: 9.6.1 foreach ^^^^^^^^^^^^^^^^^^^^^^^^^ .. The foreach function maps a function over a sequence. ``foreach`` 関数はシーケンスすべての成分にわたって関数を適用します。 :: $(foreach , ) foreach(, ) .. For example, the following program defines the variable X as an array a.c b.c c.c. 例えば、以下のプログラムでは変数 ``X`` は配列 ``a.c b.c c.c`` と定義されます。 :: X = foreach(x, a b c) value $(x).c # 等価な式 X = $(foreach $(fun x, $(x).c), abc) .. There is also an abbreviated syntax. これらの表現を省略することもできます。 .. The export form can also be used in a foreach body. The final value of X is a.c b.c c.c. ``export`` 文は ``foreach`` の内容に使うこともできます。例えば、以下の式の ``X`` は最終的に ``a.c b.c c.c`` となります。 :: X = foreach(x, a b c) X += $(x).c export .. The break function can be used to break out of the loop early. ``break`` 関数はこのようなループを早期に抜けたい場合に用いられます。 .. _label9.7: 9.7 ブーリアン関数群 ---------------------------------- .. index:: single: sequence-forall() .. _label9.7.1: 9.7.1 sequence-forall ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The forall function tests whether a predicate halds for each element of a sequence. ``forall`` 関数は ```` がシーケンスのすべての成分に当てはまっているかどうか調べます。 :: $(sequence-forall , ) sequence-forall( => ..., ) .. index:: single: sequence-forall() .. _label9.7.2: 9.7.2 sequence-exists ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The exists function tests whether a predicate holds for some element of a sequence. ``exists`` 関数は ```` がシーケンスのいくつかの成分に当てはまっているかどうか調べます。 :: $(sequence-exists , ) sequence-exists( => ..., ) .. index:: single: sequence-sort() .. _label9.7.3: 9.7.3 sequence-sort ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The sort function sorts the elements in an array, given a comparison function. Given two elements (x, y), the comparison should return a negative number if x < y; a positive number if x > y; and 0 if x = y. ``sort`` 関数は配列の成分を与えられた評価関数を元にソートします。評価関数は二つの引数(x, y)を取ります。もしx < yであった場合、評価関数は負の値を返す必要があります。同様に、x > yの場合は正の値、x = yの場合は0を返します。 :: $(sequence-sort , ) sort(, => ..., ) .. index:: single: compare() .. _label9.7.4: 9.7.4 compare ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. The compare function compares two values (x, y) generically returning a negative number if x < y; a positive number if x > y; and 0 if x = y. ``compare`` 関数は二つの値(x, y)を比較します。もしx < yであった場合、この関数は負の値を返します。同様に、x > yの場合は正の値、x = yの場合は0を返します。 :: $(compare x, y) : Int