@node Library modules - Utilities, C to Scheme mapping, Library modules - SRFIs, Top @chapter Library modules - Utilities @c NODE ライブラリモジュール - ユーティリティ @c ---------------------------------------------------------------------- @menu * Binary I/O:: binary.io * Packing binary data:: binary.pack * Running Chibi-scheme test suite:: compat.chibi-test * Rational-less arithmetic:: compat.norational * Backward-compatible real elementary functions:: compat.real-elementary-functions * Concurrent sequences:: control.cseq * Futures:: control.future * A common job descriptor for control modules:: control.job * Plumbing ports:: control.plumbing * Parallel map:: control.pmap * Scheduler:: control.scheduler * Thread pools:: control.thread-pool * Password hashing:: crypt.bcrypt * Cache:: data.cache * Heap:: data.heap * Immutable deques:: data.ideque * Immutable map:: data.imap * Priority map:: data.priority-map * Queue:: data.queue * Random data generators:: data.random * Range:: data.range * Ring buffer:: data.ring-buffer * Skew binary random-access lists:: data.skew-list * Sparse data containers:: data.sparse * Trie:: data.trie * Universally unique lexicographically sortable identifier:: data.ulid * Database independent access layer:: dbi * Generic DBM interface:: dbm * File-system dbm:: dbm.fsdbm * GDBM interface:: dbm.gdbm * NDBM interface:: dbm.ndbm * Original DBM interface:: dbm.odbm * Filtering file content:: file.filter * Filesystem utilities:: file.util * Mathematical constants:: math.const * Mersenne-Twister random number generator:: math.mt-random * Prime numbers:: math.prime * Simplex solver:: math.simplex * Windows support:: os.windows * PEG parser combinators:: parser.peg * RFC822 message parsing:: rfc.822 * Base64 encoding/decoding:: rfc.base64 * HTTP cookie handling:: rfc.cookie * FTP:: rfc.ftp * HMAC keyed-hashing:: rfc.hmac * HTTP client:: rfc.http * ICMP packets:: rfc.icmp * IP packets:: rfc.ip * JSON parsing and construction:: rfc.json * MD5 message digest:: rfc.md5 * MIME message handling:: rfc.mime * Quoted-printable encoding/decoding:: rfc.quoted-printable * SHA message digest:: rfc.sha * Transport layer security:: rfc.tls * URI parsing and construction:: rfc.uri * UUID:: rfc.uuid * Zlib compression library:: rfc.zlib * SLIB:: slib * Functional XML parser:: sxml.ssax * SXML query language:: sxml.sxpath * Manipulating SXML structure:: sxml.tools * Serializing XML and HTML from SXML:: sxml.serializer * Text terminal control:: text.console * CSV tables:: text.csv * Calculate difference of text streams:: text.diff * EDN parsing and construction:: text.edn * Running external editor:: text.external-editor * Text filling:: text.fill * Gap buffer:: text.gap-buffer * Localized messages:: text.gettext * Simple HTML document construction:: text.html-lite * Accessing info document:: text.info * Multicolumn formatting:: text.multicolumn * Display with pager:: text.pager * Parsing input stream:: text.parse * Showing progress on text terminals:: text.progress * Segmented string matching:: text.segmented-match * Shell text utilities:: text.sh * SQL parsing and construction:: text.sql * Simple template expander:: text.template * Transliterate characters:: text.tr * Lazy text construction:: text.tree * Combination library:: util.combinations * Message digester framework:: util.digest * Calculate dominator tree:: util.dominator * R6RS identifier syntax:: util.identifier-syntax * Determine isomorphism:: util.isomorph * The longest common subsequence:: util.lcs * Levenshtein edit distance:: util.levenshtein * Pattern matching:: util.match * SLIB-compatible record type:: util.record * Relation framework:: util.relation * Stream library:: util.stream * Temporal relation:: util.temporal-relation * Topological sort (legacy):: util.toposort * Unification:: util.unification * CGI utility:: www.cgi * CGI testing:: www.cgi.test * CSS parsing and construction:: www.css @end menu @c ---------------------------------------------------------------------- @node Binary I/O, Packing binary data, Library modules - Utilities, Library modules - Utilities @section @code{binary.io} - Binary I/O @c NODE バイナリI/O, @code{binary.io} - バイナリI/O @deftp {Module} binary.io @mdindex binary.io @c EN This module provides basic procedures to perform binary I/O of numeric data. Each datum can be read from or written to a port, and got from or put to a uniform vector (see @ref{Uniform vectors}). For structured binary data I/O, more convenient @code{pack} utility is implemented on top of this module (see @ref{Packing binary data}). You might want to use this module directly if you need speed or want a flexible control of endianness. See also @ref{Uniform vectors}, which provides binary block I/O. @c JP このモジュールは数値データを読み書きするバイナリ入出力用の基本手続きを提 供します。各データはポートあるいはユニフォームベクタ (@ref{Uniform vectors}参照)から読み込み、あるいはそれらへ書き出すことが できます。 構造をもつバイナリデータの入出力については、便利な @code{pack}ユーティリティがこのモジュールを使って実装されています (@ref{Packing binary data}を参照してください)。 スピードあるいはエンディアンの柔軟な制御などをやりたいときにこのモジュー ルが使えます。 バイナリのブロック入出力については@ref{Uniform vectors}を参照してくだ さい。 @c COMMON @end deftp @c EN @subheading Endianness Most procedures of this module take an optional @var{endian} argument, specifying the byte order of the binary input. It must be either one of symbols @code{big-endian}, @code{little-endian}, or @code{arm-little-endian}. If the endian argument is omitted, the current value of the builtin parameter @code{default-endian} is used (@pxref{Endianness}). (For 8-bit I/O procedures like @code{read-u8} the endian argument has no effect, but is accepted for consistency). @c JP @subheading エンディアン このモジュールのほとんどの手続はオプション引数として@var{endian}引数を とります。これは@code{big-endian}、@code{little-endian}、 @code{arm-little-endian}のいずれかのシンボルでなければなりません。 エンディアン引数が省略された場合には、組込みパラメータ@code{default-endian} の現在値が使われます (@ref{Endianness}参照)。 (@code{read-u8}の ような 8ビット入出力手続ではエンディアン引数は意味がありませんが、 一貫性のため受け入れるようにしてあります。) @c COMMON @c EN @subheading I/O using port @c JP @subheading ポートを用いたI/O @c COMMON @defun read-u8 :optional port endian @defunx read-u16 :optional port endian @defunx read-u32 :optional port endian @defunx read-u64 :optional port endian @c MOD binary.io @c EN Reads 8, 16, 32 or 64 bit unsigned integer from @var{port} with specified endian, respectively. If @var{port} is omitted, current input port is used. If @var{port} reaches EOF before a complete integer is read, EOF is returned. @c JP それぞれ指定したエンディアンで@var{port}から8、16、32、64ビット符号無 整数を読み込みます。@var{port}が省略された場合は、現在の入力ポートが使 われます。@var{port}が整数の読み込みが完了する前にEOFに到達してしまっ た場合にはEOFが返ります。 @c COMMON @end defun @defun read-s8 :optional port endian @defunx read-s16 :optional port endian @defunx read-s32 :optional port endian @defunx read-s64 :optional port endian @c MOD binary.io @c EN Reads 8, 16, 32 or 64 bit 2's complement signed integer from @var{port} with specified endian, respectively. If @var{port} is omitted, current input port is used. If @var{port} reaches EOF before a complete integer is read, EOF is returned. @c JP それぞれ指定したエンディアンで@var{port}から8、16、32、64ビット、2の補 数符号付き整数を読み込みます。@var{port}が省略された場合は、現在の入力 ポートが使われます。@var{port}が整数の読み込みが完了する前にEOFに到 達してしまった場合にはEOFが返ります。 @c COMMON @end defun @defun read-uint size :optional port endian @defunx read-sint size :optional port endian @c MOD binary.io @c EN More flexible version. Reads @var{size}-octet unsigned or signed integer from @var{port} with specified endian. If @var{port} reaches EOF before a complete integer is read, EOF is returned. @c JP さらに柔軟性が高く、@var{size}オクテットの符号無しあるいは符号付き整数 を@var{port}から指定のエンディアンで読み込みます。 @var{port}が整数の読み込みが完了する前にEOFに到 達してしまった場合にはEOFが返ります。 @c COMMON @end defun @defun read-ber-integer :optional port @c MOD binary.io @c EN Reads BER compressed integer a la X.209. A BER compressed integer is an unsigned integer in base 128, most significant digit first, where the high bit is set on all but the final (least significant) byte. @c JP X.209のBER圧縮形式整数を読み込みます。BER圧縮形式整数は128進符号無し整 数です。最上位桁が最初にきます。最下位桁のバイトをのぞき、すべてのバイ トの最上位ビットはオンになっています。 @c COMMON @end defun @defun write-u8 val :optional port endian @defunx write-u16 val :optional port endian @defunx write-u32 val :optional port endian @defunx write-u64 val :optional port endian @c MOD binary.io @c EN Writes a nonnegative integer @var{val} as 8, 16, 32 or 64 bit unsigned integer to @var{port} with specified endian, respectively. @var{Val} must be within the range of integers representable by the specified bits. When @var{port} is omitted, current output port is used. @c JP それぞれ指定したエンディアンで@var{port}へ 8、16、32、64ビット、符号無 し整数として表現されている非負整数@var{val}を書き出します。 @var{val}はそれぞれ指定したビット数の範囲で表現できる値でなければなり ません。@var{port}が省略された場合は、現在の出力ポートが使われます。 @c COMMON @end defun @defun write-s8 val :optional port endian @defunx write-s16 val :optional port endian @defunx write-s32 val :optional port endian @defunx write-s64 val :optional port endian @c MOD binary.io @c EN Writes an integer @var{val} as 8, 16, 32 or 64 bit as 2's complement signed integer to @var{port} with specified endian, respectively. @var{Val} must be within the range of integers representable by the specified bits. When @var{port} is omitted, current output port is used. @c JP それぞれ指定したエンディアンで@var{port}へ 8、16、32、64ビット、2の補 数符号付き整数として表現されている整数@var{val}を書き出します。 @var{val}はそれぞれ指定したビット数の範囲で表現できる値でなければなり ません。@var{port}が省略された場合は、現在の出力ポートが使われます。 @c COMMON @end defun @defun write-uint size val :optional port endian @defunx write-sint size val :optional port endian @c MOD binary.io @c EN More flexible version. Writes an integer @var{val} as unsigned or signed integer of @var{size} bytes to @var{port} with specified endian. When @var{port} is omitted, current output port is used. @c JP さらに柔軟性が高く、@var{size}オクテットの符号無しあるいは符号付き整数 @var{val}を@var{port}へ、指定のエンディアンで書き出します。 @var{port}が省略された場合は、現在の出力ポートが使われます。 @c COMMON @end defun @defun write-ber-integer val :optional port @c MOD binary.io @c EN Writes a nonnegative integer @var{val} in BER compressed integer to @var{port}. See @code{read-ber-integer} above for BER format. @c JP BER圧縮形式の非負整数@var{val}を@var{port}へ書き出します。 BER圧縮形式については前述の@code{read-ber-integer}を見てください。 @c COMMON @end defun @defun read-f16 :optional port endian @defunx read-f32 :optional port endian @defunx read-f64 :optional port endian @c MOD binary.io @c EN Reads 16, 32, or 64-bit floating point numbers, respectively. 32bit is IEEE754 single-precision, and 64bit is IEEE754 double-precision numbers. 16-bit floating point number consists of 1-bit sign, 5-bit exponent and 10-bit mantissa, as used in some HDR image format. If @var{port} is omitted, current input port is used. If @var{port} reaches EOF before a complete number is read, EOF is returned. @c JP それぞれ、16、32、64ビットの浮動小数点数を読み込みます。 32ビットはIEEE754単精度、64ビットは倍精度の浮動小数点数です。 16ビット浮動小数点数は、1ビットの符号、5ビットの指数、10ビットの仮数からなる、 HDRイメージフォーマット等に使われている形式です。 @var{port}が省略された場合には、 現在の入力ポートが使われます。@var{port}が数値の読み込みが完了する前に EOFに到達してしまった場合にはEOFが返ります。 @c COMMON @end defun @defun write-f16 val :optional port endian @defunx write-f32 val :optional port endian @defunx write-f64 val :optional port endian @c MOD binary.io @c EN Writes a real number @var{val} to @var{port} in 16, 32, or 64-bit floating point number, respectively. If @var{port} is omitted, current output port is used. @c JP 実数値@var{val}を、それぞれ16、32、64ビットの浮動小数点数として 書き出します。 @var{port}が省略された場合には、現在の出力ポートが使われます。 @c COMMON @end defun @c EN @subheading I/O using uniform vectors @c JP @subheading ユニフォームベクタを用いたI/O @c COMMON @c EN In the following routines, the argument @var{uv} can be any type of uniform vector; if it is not a @code{u8vector}, it is treated as if @code{(uvector-alias @var{uv})} is called---that is, it reads directly from the memory image that holds the uvector's content. The @var{pos} argument specifies the byte position from the beginning of the memory area (it is always byte position, regardless of the uniform vector's element size). @c JP 以下のルーチンでは、引数 @var{uv} は任意の型のユニフォームベクタをとり えます。@code{u8vector} ではない場合には @code{(uvector-alias @var{uv})} が呼ばれたのと同様の扱いになります。すなわち、 uvectorの内容を保持するメモリイメージから直接読み込まれます。@var{pos} 引数は当該のメモリ領域の最初からのバイト位置を指定するのに使います(こ れはユニフォームベクタの要素のサイズにかかわらず、つねにバイト位置です)。 @c COMMON @defun get-u8 uv pos :optional endian @defunx get-u16 uv pos :optional endian @defunx get-u32 uv pos :optional endian @defunx get-u64 uv pos :optional endian @defunx get-s8 uv pos :optional endian @defunx get-s16 uv pos :optional endian @defunx get-s32 uv pos :optional endian @defunx get-s64 uv pos :optional endian @defunx get-f16 uv pos :optional endian @defunx get-f32 uv pos :optional endian @defunx get-f64 uv pos :optional endian @c MOD binary.io @c EN Reads a number of a specific format from a uniform vector @var{uv}, starting at a byte position @var{pos}. An error is signaled if the specified position makes reference outside of the uniform vector's content. Returns the read number. @c JP ユニフォームベクタ @var{uv} のバイト位置 @var{pos} から指定したフォー マットで数値を読み込み、その数値を返します。指定した位置が当該ユニフォー ムベクタの内容のある範囲外を参照するものであった場合、エラーを示すシグ ナルがあがります。 @c COMMON @end defun @defun get-u16be uv pos @defunx get-u16le uv pos @defunx get-u32be uv pos @defunx get-u32le uv pos @defunx get-u64be uv pos @defunx get-u64le uv pos @defunx get-s16be uv pos @defunx get-s16le uv pos @defunx get-s32be uv pos @defunx get-s32le uv pos @defunx get-s64be uv pos @defunx get-s64le uv pos @defunx get-f16be uv pos @defunx get-f16le uv pos @defunx get-f32be uv pos @defunx get-f32le uv pos @defunx get-f64be uv pos @defunx get-f64le uv pos @c MOD binary.io @c EN These are big-endian (@code{be}) or little-endian (@code{le}) specific versions of @code{get-*} procedures. In speed-sensitive code, you might want to use these to avoid the overhead of optional-argument handling. @c JP これらは、@code{get-*} 手続のエンディアン(ビッグエンディアン @code{be} あるいはリトルエンディアン @code{le})を指定した版です。スピードを要求 されるコードではオプション引数処理のオーバーヘッドを避けるためこちらを 使うのがいいでしょう。 @c COMMON @end defun @defun get-uint size uv pos :optional endian @defunx get-sint size uv pos :optional endian @c MOD binary.io @c EN Read @var{size} octets from uvector @var{uv}, starting from @var{pos}-th octet, as an unsigned or signed integer, respectively. @c JP ユニフォームベクタ@var{uv}の@var{pos}番目のオクテットから@var{size}オクテットを、 それぞれ符号無し、符号つき整数として読み取ります。 @c COMMON @example (get-uint 3 '#u8(1 2 3 4) 1 'big-endian) @result{} 131884 ; @r{#x020304} (get-sint 3 '#u9(1 2 3 #xff) 1 'little-endian) @result{} -64766 ; @r{sign extended #xff0302} @end example @end defun @defun put-u8! uv pos val :optional endian @defunx put-u16! uv pos val :optional endian @defunx put-u32! uv pos val :optional endian @defunx put-u64! uv pos val :optional endian @defunx put-s8! uv pos val :optional endian @defunx put-s16! uv pos val :optional endian @defunx put-s32! uv pos val :optional endian @defunx put-s64! uv pos val :optional endian @defunx put-f16! uv pos val :optional endian @defunx put-f32! uv pos val :optional endian @defunx put-f64! uv pos val :optional endian @c MOD binary.io @c EN Writes a number @var{val} into a uniform vector @var{uv} in a specific format, starting at a byte position @var{pos}. An error is signaled if the specified position makes reference outside of the uniform vector's content. @c JP 数値 @var{val} をユニフォームベクタ @var{uv} のバイト位置 @var{pos} か ら指定されたフォーマットで書き出します。指定した位置が当該ユニフォーム ベクタの内容のある範囲外を参照するものであった場合、エラーを示すシグナ ルがあがります。 @c COMMON @end defun @defun put-u16be! uv pos val @defunx put-u16le! uv pos val @defunx put-u32be! uv pos val @defunx put-u32le! uv pos val @defunx put-u64be! uv pos val @defunx put-u64le! uv pos val @defunx put-s16be! uv pos val @defunx put-s16le! uv pos val @defunx put-s32be! uv pos val @defunx put-s32le! uv pos val @defunx put-s64be! uv pos val @defunx put-s64le! uv pos val @defunx put-f16be! uv pos val @defunx put-f16le! uv pos val @defunx put-f32be! uv pos val @defunx put-f32le! uv pos val @defunx put-f64be! uv pos val @defunx put-f64le! uv pos val @c MOD binary.io @c EN These are big-endian (@code{be}) or little-endian (@code{le}) specific versions of @code{put-*} procedures. In speed-sensitive code, you might want to use these to avoid the overhead of optional-argument handling. @c JP これらは、@code{put-*} 手続のエンディアン(ビッグエンディアン @code{be} あるいはリトルエンディアン @code{le})を指定した版です。スピードを要求 されるコードではオプション引数処理のオーバーヘッドを避けるためこちらを 使うのがいいでしょう。 @c COMMON @end defun @defun put-uint! size uv pos val :optional endian @defunx put-sint! size uv pos val :optional endian @c MOD binary.io @c EN Write an unsigned or signed integer @var{val} into an uvector @var{uv} starting from @var{pos}-th octet, for @var{size} octets, respectively. @c JP それぞれ符号無しまたは符号つき整数@var{val}を、 ユニフォームベクタ@var{uv}の@var{pos}番目のオクテットから@var{size}オクテット分に 書き込みます。 @c COMMON @end defun @c EN @subheading Compatibility notes @c JP @subheading 互換性への注 @c COMMON @c EN @code{read-u8} etc. were called @code{read-binary-uint8} etc., and @code{read-f32} and @code{read-f64} were called @code{read-binary-float} and @code{read-binary-double}, respectively. These old names are still supported for the backward compatibility but their use is deprecated. The reason of the changes is for brevity and for consistency with the uniform vectors. @c JP @code{read-u8} などは @code{read-binary-uint8} と呼ばれていたもので、 @code{read-f32} や @code{read-f64} はそれぞれ @code{read-binary-float}、 @code{read-binary-double} と呼ばれていたものです。 これらの古い名前は後方互換のためいまのところサポートされていますが、使 用については非推奨とします。この変更は名前の短縮とユニフォームベクタと の一貫性維持のために行われました。 @c COMMON @c ---------------------------------------------------------------------- @node Packing binary data, Running Chibi-scheme test suite, Binary I/O, Library modules - Utilities @section @code{binary.pack} - Packing binary data @c NODE バイナリデータのパック, @code{binary.pack} - バイナリデータのパック @deftp {Module} binary.pack @mdindex binary.pack @c EN This module provides an interface for packing and unpacking (writing and reading) binary data with templates. The functionality was inspired largely by the Perl pack/unpack functions, with comparison of similar features from other languages, however an effort was made to make it more general and more efficient, to be usable for database-like processing. To that end, the most notable differences are that any packable value is unpackable (and vice versa), and the default behavior is to pack and unpack using port I/O, so you can seek in a large file and unpack from it. Also, templates may be stored as dispatch closures to pack, unpack or even skip over values without re-parsing the template. @c JP このモジュールは、バイナリデータをテンプレートを使って パック/アンパック(読み書き)するためのインタフェースを提供します。 この機能は、その多くをPerlのpack/unpack関数から着想し、他の言語での 同じような機能と比較しながら、しかし、データベースライクな処理に 便利なように、より一般的でより効率が良くなるように実装しました。 これを受けて、最も大きな相違点は、全てのパック可能な値はアンパック 可能で(逆も同様)、パック/アンパックのデフォルトの振る舞いはポートI/Oを 使うので、巨大なファイルを読みながらそこからアンパックすることが できます。また、テンプレートはディスパッチクロージャとして格納でき、 パック、アンパック、あるいは値のスキップさえも、テンプレートを パーズし直すことなく行えます。 @c COMMON @c See also binary.io - Binary I/O for utilities to read and write @c individual binary values. @end deftp @defun pack template list :key output to-string? @c MOD binary.pack @c EN Writes the values in @var{list} to the current output port, according to the format specified by the string @var{template}. The template string is a series of single character codes, optionally followed by a numeric count (which defaults to 1). @c JP @var{list}にある値を、文字列@var{template}で指定されたフォーマットに したがって、現在の出力ポートに書き出します。テンプレート文字列は、 1文字のコードの連続で、オプションで(デフォルトが1である)カウント用の数字 が続きます。 @c EN The format characters can generally be divided into string types, which interpret the count as a string byte size, and object types, which treat the count as a repetition indicator. The count may be specified as the character @code{*}, which means to use the full size of the string for string types, and use all remaining values for object types. @c JP フォーマット文字は一般的に、カウントを文字のバイト数と解釈する 文字列型と、カウントを繰り返し指示子と解釈するオブジェクト型に 分けられます。カウントは文字@code{*}で指定され、文字列型では 文字列の全体の長さを、オブジェクト型では残りの全ての値を使うことを 意味します。 @c EN Counts may also be specified as a template enclosed in brackets, which means the count is the byte size of the enclosed template. For example, @code{x[L]} skips a long. @c JP カウントは大括弧に囲まれたテンプレートとしても指定でき、その場合 カウントはその大括弧を囲んでいるテンプレートのバイト数を意味します。 例えば、@code{x[L]}はlongをスキップします。 @c EN The special format character @code{/} may be used to indicate a structure where the packed data contains a dynamic count followed by the value itself. The template is written as @code{/}, where @code{} is any template character to be interpreted as a numeric count, and @code{} is any other template character to use this count. If a normal count is given after @code{} it is ignored. @c JP 特別なフォーマット文字@code{/}は、パックされたデータが、値に続く 動的なカウント分を含むという構造を表すために使われます。 テンプレートは、@code{/}のように書かれ、 ここでは@code{}は数値のカウントと解釈されるいかなる テンプレート文字、@code{}はこのカウントを使ういかなる 他のテンプレート文字です。 @code{の後に通常のカウントが与えられても、無視されます。 @c EN The format character @code{@@} may be used with a count to pad to an absolute position since the start of the template. @c JP フォーマット文字@code{@@}は、カウントとともに使われ、テンプレートの 最初からの絶対位置までパディングします。 @c EN Sub-templates may be grouped inside parentheses. If angle-brackets are used, then they also behave as group operators but recursively operate on nested lists. @c JP サブテンプレートは、括弧の中にグループ化されます。<>が使われると、 ネストされたリストに再帰的に適用されるグループ化オペレータとしても 振舞います。 @c EN The string types: @c JP 文字列型: @c COMMON @table @code @item a @c EN An arbitrary incomplete string, null padded. @c JP 任意の不完全文字列。NULLでパディングされます。 @c COMMON @item A @c EN A text string, space padded. @c JP テキスト文字列。空白スペースでパディングされます。 @c COMMON @item Z @c EN A null terminated (ASCIZ) string, null padded. @c JP NULL終端(ASCIZ)文字列。NULLでパディングされます。 @c COMMON @item b @c EN A bit string (ascending bit order inside each byte). @c JP ビット文字列(それぞれのバイトにおけるビットオーダーは昇順)。 @c COMMON @item B @c EN A bit string (descending bit order inside each byte). @c JP ビット文字列(それぞれのバイトにおけるビットオーダーは降順)。 @c COMMON @item h @c EN A hex string (low nybble first). @c JP 16進文字列(低いニブルが先)。 @c COMMON @item H @c EN A hex string (high nybble first). @c JP 16進文字列(高いニブルが先)。 @c COMMON @end table @c EN The object types: @c JP オブジェクト型: @c COMMON @table @code @item c @c EN A signed 8bit integer. @c JP 符号付き8ビット整数。 @c COMMON @item C @c EN An unsigned 8bit integer. @c JP 符号なし8ビット整数。 @c COMMON @item s @c EN A signed short (16 bit) value. @c JP 符号付き16ビット整数。 @c COMMON @item S @c EN An unsigned short (16 bit) value. @c JP 符号なし16ビット整数。 @c COMMON @item i @c EN A signed integer (>= 32 bit) value. @c JP 符号付き整数(>= 32ビット)。 @c COMMON @item I @c EN An unsigned integer (>= 32 bit) value. @c JP 符号なし整数(>= 32ビット)。 @c COMMON @item l @c EN A signed long (32 bit) value. @c JP 符号付きlong(32ビット)。 @c COMMON @item L @c EN An unsigned long (32 bit) value. @c JP 符号なしlong(32ビット)。 @c COMMON @item n, n! @c EN An unsigned and signed short (16 bit) in "network" (big-endian) order. @c JP ネットワークオーダー(ビッグエンディアン)での符号なし/符号つきshort(16ビット)。 @c COMMON @item N, N! @c EN An unsigned and signed long (32 bit) in "network" (big-endian) order. @c JP ネットワークオーダー(ビッグエンディアン)での符号なし/符号つきlong(32ビット)。 @c COMMON @item v, v! @c EN An unsigned and signed short (16 bit) in "VAX" (little-endian) order. @c JP VAXオーダー(リトルエンディアン)での符号なし/符号つきshort(16ビット)。 @c COMMON @item V, V! @c EN An unsigned and signed long (32 bit) in "VAX" (little-endian) order. @c JP VAXオーダー(リトルエンディアン)での符号なし/符号つきlong(32ビット)。 @c COMMON @item q @c EN A signed quad (64 bit) value. @c JP 符号付きquad(64ビット)。 @c COMMON @item Q @c EN An unsigned quad (64 bit) value. @c JP 符号なしquad(64ビット)。 @c COMMON @item f @c EN A single-precision float in the native format. @c JP ネイティブ形式の単精度float。 @c COMMON @item d @c EN A double-precision float in the native format. @c JP ネイティブ形式の倍精度float。 @c COMMON @item w @c EN A BER compressed integer. An unsigned integer in base 128, most significant digit first, where the high bit is set on all but the final (least significant) byte. Thus any size integer can be encoded, but the encoding is efficient and small integers don't take up any more space than they would in normal char/short/int encodings. @c JP BER圧縮された整数。ベース128における符号なし整数で、最も大きな桁が 最初で、高いビットが最後の(一番小さな)バイト以外にセットされる。 したがって、どのような大きさの整数もエンコードできるが、 エンコーディングは効率的で、小さな整数は通常のchar/short/int エンコーディングの場合よりも占有する空間が少ない。 @c COMMON @item x @c EN A null byte. @c JP NULLバイト。 @c COMMON @item o @c EN An sexp, handled with @code{read} and @code{write}. @c JP S式。@code{read}と@code{write}で扱われる。 @c COMMON @end table @c EN If the optional keyword @var{:output} is given that port is used instead of the current output port. If @var{:to-string?} is given and true, then pack accumulates and returns the output as a string. Note that the returned string may be an incomplete string if the packed string contains a byte sequence invalid as a character sequence. @c JP オプションのキーワード@var{:output}が与えられると、 現在の出力ポートの代わりにそのポートが使われます。 @var{:to-string?}が与えられそれが真である場合は、 パックは蓄積され、その出力は文字列として返ります。 @c COMMON @example (pack "CCCC" '(65 66 67 68) :to-string? #t) @result{} "ABCD" (pack "C/a*" '("hello") :to-string? #t) @result{} "\x05hello" @end example @end defun @defun unpack template :key :input :from-string @c MOD binary.pack @c EN The complement of pack, unpack reads values from the current input port assuming they've been packed according to the string template and returns the values as a list. unpack accepts the same format strings as pack. Further, the following tautology holds: @c JP packの逆を行うもので、unpackは現在の入力ポートから、値が文字列の templateでパックされているものとして読み込み、その値をリストとして 返します。unpackはpackと同じフォーマット文字列を受け付けます。 また、いかなるリスト@var{x}とフォーマット文字列@var{fmt}においても、 次のようなトートロジーが維持されます。 @c COMMON @example (equal? x (unpack fmt :from-string (pack fmt x :to-string? #t))) @end example @c EN for any list @var{x} and format string @var{fmt}. The only exceptions to this are when the template includes a @code{*} and when the @code{o} template is used, since Scheme numeric literals cannot be reliably delimited (though future versions of @code{pack} may circumvent this by registering a new read syntax). If the optional keyword @var{:input} is given that port is used instead of the current input port. If @var{:from-string} is given, then pack reads input from that string. @c JP ただ一つの例外は、テンプレートが@code{*}を含み、@code{o}テンプレートが 使われている場合です。これは、Schemeの数値リテラルは確実に区切られる ことができないからです(@code{pack}の将来のバージョンでは、 新しいread構文を登録することによってこれは回避されるでしょう)。 オプションのキーワード@var{:input}が与えられると、現在の入力ポートの 代わりにそのポートが使われます。@var{:from-string}が与えられると、 packはその文字列を入力とします。 @c COMMON @example (unpack "CCCC" :from-string "ABCD") @result{} '(65 66 67 68) (unpack "C/a*" :from-string "\x05hello") @result{} '("hello") @end example @c EN @emph{Note:} in the current version, @code{@@} in @code{unpack} template has a bug and does not work as supposed. It will be fixed in the future version. @c JP @emph{註:} 現在のバージョンには、@code{unpack}のテンプレートの @code{@@}が想定したように動かないというバグがあります。 将来のバージョンでfixされます。 @c COMMON @end defun @defun unpack-skip template :key :input @c MOD binary.pack @c EN unpack-skip is the same as unpack except it does not return the values. In some cases, particularly with fixed-size templates, this can be much more efficient when you just want to skip over a value. @c JP unpack-skipは、値を返さないことを除いてunpackと同じです。 いくつかのケースでは、特に固定サイズのテンプレートを使うときには、 単に値を読み飛ばしたいときにより効率的です。 @c COMMON @end defun @defun make-packer template @c MOD binary.pack @c EN The low-level interface. This function returns a dispatch closure that can be used to pack, unpack and skip over the same cached template. The dispatch closure accepts symbol methods as follows: @c JP 低レベルなインタフェースです。この関数は、pack、unpackやキャッシュ された同じテンプレートを読み飛ばす時に使われるディスパッチクロージャを 返します。ディスパッチクロージャは、以下のようにシンボルメソッドを 受け付けます。 @c COMMON @table @code @item 'pack list @c EN pack the items in list to the current output port. @c JP listにあるアイテムを、現在の出力ポートへpackします。 @c COMMON @item 'unpack @c EN unpack items from the current input port. @c JP 現在の入力ポートからアイテムをunpackします。 @c COMMON @item 'skip @c EN skip items from the current input port. @c JP 現在の入力ポートからのアイテムをスキップします。 @c COMMON @item 'packer @c EN return the cached 'pack closure @c JP キャッシュされた'packクロージャを返します。 @c COMMON @item 'unpacker @c EN return the cached 'unpack closure. @c JP キャッシュされた'unpackクロージャを返します。 @c COMMON @item 'skipper @c EN return the cached 'skip closure. @c JP キャッシュされた'skipクロージャを返します。 @c COMMON @item 'length @c EN return the known fixed length of the template. @c JP テンプレートの知られている固定された長さを返します。 @c COMMON @item 'variable-length? @c EN return #t if the template has variable length elements. @c JP テンプレートが可変長の要素を持っている場合に#tを返します。 @c COMMON @end table @end defun @c ---------------------------------------------------------------------- @node Running Chibi-scheme test suite, Rational-less arithmetic, Packing binary data, Library modules - Utilities @section @code{compat.chibi-test} - Running Chibi-scheme test suite @c NODE Chibi schemeテストの実行, @code{compat.chibi-test} - Chibi schemeテストの実行 @deftp {Module} compat.chibi-test @mdindex compat.chibi-test @c EN Quite a few srfis come with test suites that's to be run with Chibi Scheme test framework. This module enables Gauche to run the test code as is. @c JP 多くのsrfiには、Chibi Schemeのテストフレームワークで実行できるテストコードが 付いてきます。このモジュールはGaucheでそのテストコードを実行できるようにします。 @c COMMON @end deftp @defmac chibi-test code @dots{} @c MOD compat.chibi-test @c EN Run @var{code} @dots{}, while translating Chibi test framework to Gauche's. @c JP ChibiのテストフレームワークをGaucheのそれに置き換えながら、 @code{code} @dots{}を実行します。 @c COMMON @c EN A typical usage is to write a wrapper that includes the original test code (suppose it's called @file{test-suite.scm}): @c JP 典型的な使い方は、元のテストコード(@file{test-suite.scm}とします)を includeするラッパーを書くことです。 @c COMMON @example (use gauche.test) (test-start "running test-suite.scm") (chibi-test (include "test-suite.scm")) (test-end) @end example @c EN Chibi's test directives are translated to Gauche's test directives (@pxref{Unit testing}, for Gauche's test framework). @c JP Chibiのテストディレクティブは、Gaucheのテストフレームワークのテストディレクティブへと 変換されます(@ref{Unit testing}参照)。 @c COMMON @c EN The main thing is that Chibi allows expressions and definitions to be intermingled within a body, while Gauche only allows all definitions before expressions within a body. We expand such body into nested @code{let} by @code{chibi-test} macro. Chibi test macros (e.g. @code{test-assert}) are defined as local macros in @code{chibi-test} expansion, which expand into @code{gauche.test} macros. @c JP Chibiはボディ中に式と定義が交互に現れることを許していますが、Gaucheでは ボディ中で全ての定義が式に先立たねばなりません。そこで、@code{chibi-test}マクロは @code{code} @dots{}をネストした@code{let}に変換します。 また、Chibiテストマクロ(@code{test-assert}等)は変換後のコードではローカルマクロとして 定義され、そのローカルマクロは@code{gauche.test}マクロへと展開されます。 @c COMMON @c EN Note that we ignore @code{use} forms inside @code{chibi-test}; we might want to use different modules that work better in Gauche. Necessary modules need to be @code{use}'d before you call @code{chibi-test}. @c JP なお、@code{chibi-test}中の@code{use}フォームは無視されます。 これは、Gaucheで実行するのに別のモジュールを使った方が良い場合があるからです。 必要なモジュールは@code{chibi-test}を呼ぶ前に@code{use}しておいてください。 @c COMMON @c EN You may want to check out @file{test/srfi.scm} in Gauche source tree for the use case. @c JP Gaucheのソースツリーの@file{test/srfi.scm}に実際の使用例を見ることができます。 @c COMMON @end defmac @c ---------------------------------------------------------------------- @node Rational-less arithmetic, Backward-compatible real elementary functions, Running Chibi-scheme test suite, Library modules - Utilities @section @code{compat.norational} - Rational-less arithmetic @c NODE 有理数のない算術演算, @code{compat.norational} - 有理数のない算術演算 @deftp {Module} compat.norational @mdindex compat.norational @c EN Until release 0.8.7, Gauche didn't have exact rational numbers. It was able to read the rational number literals such as @code{2/3}, but they are immediately coerced to inexact real numbers (except when it represents a whole integer). And if you divided an exact integer by another exact integer, the result could be coerced to an inexact real if the result wasn't a whole integer. @c JP リリース 0.8.7 までは、Gauche は正確な有理数をサポートしていませんでし た。@code{2/3}のような有理数リテラルを読み込むことはできていましたが、 約分して整数になる場合をのぞいては、その場で非正確な実数に変換されてい ました。正確な整数を正確な整数で割った場合も約分して整数になる場合をの ぞき、結果は非正確な実数になりました。 @c COMMON @c EN As of 0.8.8, this is not the case anymore. Exact division always yields exact result, except when the divisor is zero. @c JP リリース 0.8.8 ではもうこのようなことはありません。正確な数同士の割り 算の結果は常に正確な数になります。ゼロで割ったときはもちろん例外です。 @c COMMON @example (/ 2 3) @result{} 2/3 (/ 5) @result{} 1/5 (/ 4 2) @result{} 2 @end example @c EN This is more precise, but has one drawback: exact rational arithmetic is much slower than the integer and inexact real arithmetic. If you inadvertently produce a rational number in the early stage of calculation, and continue to apply exact arithmetic, performance would be degraded miserably. @c JP 計算は正確な値でできますが、ひとつ欠点もあります。正確有理数演算は整 数演算や非正確実数同士の演算にくらべてはるかに遅いのです。意図せず、計 算の初期段階で有理数を生成してしまうとその後の計算にはすべて正確な演算 が適用されてしまい性能は悲惨なことになります。 @c COMMON @c EN The proper way to solve this is to insert @code{exact->inexact} to appropriate places. However, to ease the transition, you can just import this module and the division @code{/} behaves in the way it used to. @c JP この問題を解決する適切は方法は適切な場所に@code{exact->inexact}を挿入 することです。しかし、この変換を簡単におこなうには、このモジュールをイ ンポートし、割り算に@code{/}を使うだけですみます。 @c COMMON @example (use compat.norational) (/ 2 3) @result{} 0.6666666666666666 (/ 5) @result{} 0.2 (/ 4 2) @result{} 2 @end example @c EN The effect is not global, but only to the modules you explicitly import @code{compat.norational}. @c JP 効果はグローバルには起こらず、明示的に@code{compat.norational}をインポー トしたモジュールでのみ有効です。 @c COMMON @c EN This module only redefines @code{/}. So if your code has exact rational literals, they are treated as exact rationals rather than coerced to inexact reals. You should prefix rational literals with @code{#i} to force Gauche to coerce them to inexact reals: @c JP このモジュールは@code{/}を再定義しているだけです。したがって、コードに 正確な有理数のリテラルが含まれていても、それは非正確な実数に変換される ことはなく、正確な有理数としてあつかわれます。Gaucheに非正確な実数とし て有理数リテラルを扱わせるには、@code{#i}という接頭辞を追加しなければ なりません。 @c COMMON @example gosh> 1/3 1/3 gosh> #i1/3 0.3333333333333333 @end example @end deftp @c ---------------------------------------------------------------------- @node Backward-compatible real elementary functions, Concurrent sequences, Rational-less arithmetic, Library modules - Utilities @section @code{compat.real-elementary-functions} - Backward-compatible real elementary functions @c NODE 後方互換な実数初等関数, @code{compat.real-elementary-functions} - 後方互換な実数初等関数 @deftp {Module} compat.real-elementary-functions @mdindex compat.real-elementary-functions @c EN Gauche 0.9.12 and earlier had undocumented real-only elementary functions, such as @code{%sin} and @code{%exp}. They were intended to be a building block of the complex elementary functions, hence prefixed with @code{%}. However, they were visible in @code{gauche} module, and sometimes used directly because they were fast. @c JP Gauche 0.9.12とそれ以前のバージョンでは、正式にドキュメントされていませんでしたが、 実数のみを対象とした@code{%sin}や@code{%exp}といった初等関数が提供されていました。 複素数までを対象にした初等関数はそれらの上に構築されていて、 実数対象バージョンは内部ルーチンという意図でした(なので@code{%}が頭についています)が、 @code{gauche}モジュールで見えるようになっていたのと、複素数バージョンより速かったので、 過去のコードでこれらの関数を直接呼んでいるコードがあります。 @c COMMON @c EN SRFI-94 introduced names for real-only elementary functions such as @code{real-sin}, so we changed built-in @code{%sin} etc. to follow that names. @xref{Arithmetics}, for those real-only elementary functions. @c JP SRFI-94で、実数のみ対象の初等関数に@code{real-sin}などの名前が規定されたので、 0.9.13から@code{%sin}などを@code{real-sin}にリネームした上で正式にドキュメントしました。 @ref{Arithmetics}に説明があります。 @c COMMON @c EN This module is to ease migration from the legacy code that uses old names. Just add the following form at the beginning of old code and the source would work with both versions. @c JP このモジュールは、古い名前を使っている既存のコードからの移行を補助するためのものです。 次のフォームを付け加えてやれば、古いコードはどのバージョンのGaucheでも動きます。 @c COMMON @example (cond-expand [(library (compat real-elementary-functions)) (use compat.real-elementary-functions)] [else]) @end example @c EN New code must use @code{real-sin} etc. instead of the names provided here. @c JP 新規コードは、このモジュールにある名前ではなく@code{real-sin}などの名前を使ってください。 @c COMMON @end deftp @defun %exp x @defunx %sin x @defunx %cos x @defunx %tan x @defunx %sinpi x @defunx %cospi x @defunx %tanpi x @defunx %asin x @defunx %acos x @defunx %atan x @defunx %sinh x @defunx %cosh x @defunx %tanh x @defunx %sqrt x @defunx %expt x a @c MOD compat.real-elementary-functions @c EN These are the same as the built-in procedures replacing preceding @code{%} with @code{real-}; e.g. @code{%exp} @equiv{} @code{real-exp}. @xref{Arithmetics}, for the description of built-in procedures. @c JP これらは、@code{%}を@code{real-}で置き換えた組み込み手続きと同じです。 (例: @code{%exp} @equiv{} @code{real-exp})。 これらの組み込み手続きについては@ref{Arithmetics}を参照してください。 @c COMMON @end defun @defun %log x :optional base @c MOD compat.real-elementary-functions @c EN This is a real-only logarithm of @var{x} base @var{base}. @var{x} must be a non-negative real number, and @var{base} must be a positive real number. If @var{base} is omitted, Napier's number is assumed, that is, it returns a natural logarithm of @var{x}. If @var{x} is 0, @code{-inf.0} is returned. @c JP これは実数のみを対象とした、@var{base}を底とする@var{x}の対数関数です。 @var{x}は非負実数、@var{base}は正の実数でなければなりません @var{base}が省略された時はネイピア数が使われます。 すなわち、@var{x}の自然対数を返します。 @var{x}が0の時は@code{-inf.0}が返されます。 @c COMMON @c EN Gauche does not have built-in @code{real-log}, to avoid conflict with SRFI-94's @code{real-log} which takes @var{base} argument first. For real-only natural logarithm, Gauche has @code{real-ln}. @c JP Gaucheは組み込みでは@code{real-log}を提供しません。 SRFI-94が底を第一引数にする@code{real-logを}を定義しているので、混同を避けるためです。 実数対象の自然対数には、組み込みの@code{real-ln}が使えます。 @c COMMON @c EN @xref{R7RS flonum}, which defines flonum-only version of logarithms sich as @code{fllog}, @code{fllog2}, and @code{fllog10}. @c JP また、@ref{R7RS flonum}には、flonum専用の対数関数である @code{fllog}、@code{fllog2}、@code{fllog10}等が定義されています。 @c COMMON @end defun @c ---------------------------------------------------------------------- @node Concurrent sequences, Futures, Backward-compatible real elementary functions, Library modules - Utilities @section @code{control.cseq} - Concurrent sequences @c NODE 並行シーケンス, @code{control.cseq} - 並行シーケンス @deftp {Module} control.cseq @mdindex control.cseq @c EN Concurrent sequence (cseq) is a lazy sequence (@pxref{Lazy sequences}), but the generator runs in a separate thread. You can use producer-consumer pararellism very easily using cseq; from the consumer side, it just looks like an ordinary list. Synchornization is implicitly taken care of. Internally, it uses mtqueue (@pxref{Queue}) for synchronization. @c JP 並行シーケンス (cseq) はジェネレータが別スレッドで走る遅延シーケンスです (遅延シーケンスについては@ref{Lazy sequences}参照)。 cseqを使うと、生産者-消費者型の並列性を簡単に書けます。 消費者側からは、cseqは単なるリストに見え、同期は自動的に取られます。 内部的には、同期のためにmtqueueが使われています (@ref{Queue}参照)。 @c COMMON @end deftp @defun generator->cseq gen :key queue-length @c MOD control.cseq @c EN Create a lazy sequence from generator, much like @code{generator->lseq}, except that @var{gen} runs in a separate thread. @c JP @code{generator->lseq}のように、ジェネレータから遅延シーケンスを作って返しますが、 ジェネレータ@var{gen}自体は別スレッドで実行されます。 @c COMMON @c EN The returend value looks like an ordinary list, but its cdrs are computed in parallel. If a cdr isn't computed yet, the reader thread waits until a value becomes available. The generator @var{gen} can be called to generate values asynchronously, until the internal queue gets full. (Compare this to an ordinary lseq, in which @var{gen} is called when it is required, and it runs in the same thread as the caller.) @c JP 返される値は通常のリストのように見えますが、cdr方向のリストの要素は 並行して計算されます。cdrを取ろうとしてそれがまだ計算されていなければ、 読み出し側のスレッドはその値が計算されるまで待ちます。 ジェネレータ@var{gen}は別スレッドで非同期に実行され、 内部キューがいっぱいになるまで値を生成し続けます。 (対比として、 通常のlseqでは、@var{gen}は値が必要になった時に、読み出すスレッドで実行されます。) @c COMMON @c EN If @var{gen} raises an error, it is caught, and reraised when the consumer reads to the point when @var{gen} raised the error. @c JP @var{gen}がエラーを投げた場合、それは捕捉され、 消費者がそのエラーが起きたポイントまで読み進めた時に消費者側のスレッドで再度投げられます。 @c COMMON @c EN The optional @var{queue-length} must be a nonnegative exact integer or @code{#f}. If it is an integer, it specifies the length of the internal queue. If it is @code{#f}, an appropriate value is selected by the library (currently 64). @c JP 省略可能な引数@var{queue-length}は非負の正確な整数か@code{#f}でなければなりません。 整数の場合は、内部のキューの長さを指定します。 @code{#f}の場合はライブラリのデフォルトの長さが使われます。 @c COMMON @c EN Note that Gauche's lseq read-ahead one item (@pxref{Lazy sequences}). So even if you set the queue length to 0, @var{gen} is called before the consumer reads out any value. @c JP Gaucheのlseqは一要素先読みすることに注意してください(@ref{Lazy sequences}参照)。 キュー長を0に指定しても、@var{gen}は消費者が値を呼び出す前に一回呼び出されます。 @c COMMON @end defun @defun coroutine->cseq proc :key queue-length @c MOD control.cseq @c EN Returns an lseq, whose value is generated in @var{proc}, which is called in a separate thread. (See also @code{coroutine->lseq}, @ref{Lazy sequence constructors}). The @var{proc} argument is a procedure to be called with one argument, @var{yield}. The @var{yield} argument is a procedure, and whenever it is called with a value, that value becomes the next item of the resulting lseq. When @var{proc} returns, it becomes the end of the lseq. @c JP @code{coroutine->lseq} (@ref{Lazy sequence constructors}) のように、 値が@var{proc}によって生成されるlseqを返しますが、@var{proc}自体は別スレッドで 実行されます。 @var{proc}引数は、引数@var{yield}を取る手続きです。 @var{yield}引数は1引数の手続きで、それが呼び出されると、引数に渡された値が lseqの次の要素になります。 @var{proc}がリターンしたら、lseqはそこで終端となります。 @c COMMON @c EN If @var{proc} raises an error, it is caught, and reraised when the consumer reads to the point when previously generated values are all read and next value is about to read. @c JP @var{proc}がエラーを投げた場合、それは捕捉され、 消費者がその箇所まで読み進めた時に消費者スレッドで再度投げ直されます。 @c COMMON @c EN The optional @var{queue-length} must be a nonnegative exact integer or @code{#f}. If it is an integer, it specifies the length of the internal queue. If it is @code{#f}, an appropriate value is selected by the library (currently 64). @c JP 省略可能な引数@var{queue-length}は非負の正確な整数か@code{#f}でなければなりません。 整数の場合は、内部のキューの長さを指定します。 @code{#f}の場合はライブラリのデフォルトの長さが使われます。 @c COMMON @end defun @c ---------------------------------------------------------------------- @node Futures, A common job descriptor for control modules, Concurrent sequences, Library modules - Utilities @section @code{control.future} - Futures @c NODE Future, @code{control.future} - Future @deftp {Module} control.future @mdindex control.future @c EN A @emph{future} is a simple construct for concurrent computation. It encloses an expression, and compute its value concurrently. The result of computation can be retrieved later with @code{future-get}. @c JP @emph{future}は並行計算を簡単にする構造です。 指定された式の計算を並行して行います。計算結果は@code{future-get}で取り出すことができます。 @c COMMON @c EN Futures are introduced in MultiLisp, in which retrieval of the computed value is implicit---a future is substituted with the result automatically. Racket and Guile have futures as a library, though the primitive to retrieve the result is called @code{touch}. We avoided to use the name since @code{touch} is too generic. @c JP futureはMultiLispで実装されました。 MultiLispのfutureは暗黙的、つまり計算が終わるとその結果に自動的に置き換わるものでした。 RacketとGuileはライブラリでfutureを提供していますが、 結果の取り出しを@code{touch}と呼んでいます。@code{touch}という名前は一般的にすぎるので、 Gaucheでは@code{future-get}と呼ぶことにしました。 @c COMMON @end deftp @defmac future expr @c MOD control.future @c EN Returns a future object, which runs the computation of @var{expr} in a separate thread. The result(s) of @var{expr} can be retrieved by @code{future-get}. Note that @var{expr} can yield multiple values. @c JP @var{expr}を別スレッドで計算するfutureオブジェクトを返します。 @var{expr}の結果は@code{future-get}で取り出せます。 (@var{expr}は多値を生成することもできます)。 @c COMMON @c EN The @var{expr} is evaluated in the same environment as @code{future} appears, though if an exception raised within @var{expr} is not caught, its delivery is delayed until you call @code{future-get}. @c JP @var{expr}は@code{future}式と同じ環境で評価されます。 ただし、@var{expr}が捕捉されない例外を投げた場合は、@code{future-get}が呼ばれるまで その例外の配送は遅延されます。 @c COMMON @c EN The following example runs HTTP access concurrently with other computation, and retrieves the result later. @c JP 次の例では、HTTPアクセスを他の計算と並行して走らせて、後で結果を取り出しています。 @c COMMON @example (use control.future) (use rfc.http) (let1 f (future (http-get "example.com" "/")) ... some computation ... (receive (code headers body) (future-get f) ...)) @end example @end defmac @defun make-future thunk @c MOD control.future @c EN Returns a future that calls @var{thunk} in a separate thread. @c JP @var{thunk}を別スレッドで呼ぶfutureを返します。 @c COMMON @example (future expr) @equiv{} (make-future (lambda () expr)) @end example @end defun @defun future? obj @c MOD control.future @c EN Returns @code{#t} if @var{obj} is a future, @code{#f} otherwise. @c JP @var{obj}がfutureなら@code{#t}を、そうでなければ@code{#t}を返します。 @c COMMON @end defun @defun future-get future :optional timeout timeout-val @c MOD control.future @c EN The argument must be a future. Retrieve the result(s) of @var{future}. @c JP 引数はfutureでなければなりません。@var{future}の結果を取り出します。 @c COMMON @c EN If the result of @var{future} is already available, it is returned immediately. If @var{future} is still computing, @code{future-get} blocks until the result is ready by default. You can limit how long you will wait by @var{timeout} argument, which can be @code{#f} (default, no timeout), a nonnegative real numebr (relative time in seconds), or a @code{