@node Library modules - SRFIs, Library modules - Utilities, Library modules - R7RS standard libraries, Top @chapter Library modules - SRFIs @c NODE ライブラリモジュール - SRFI @c EN This chapter lists modules that provides SRFI functionalities. Note that some of SRFI features are built in Gauche core and not listed here. The SRFIs that have been adopted to R7RS-large are described in @ref{Library modules - R7RS standard libraries}. @xref{Standard conformance}, for entire list of supported SRFIs. (Even if a srfi is not listed here, you can still say @code{(use srfi.N)} or @code{(import (srfi N))}, as far as srfi N is supported by Gauche.) @c JP この章ではSRFIの機能を提供するモジュールをリストします。 一部のSRFIはGaucheのコアに組み込まれており、 この章には挙げられていないことに注意して下さい。 また、R7RS-largeに取り入れられたsrfiは@ref{Library modules - R7RS standard libraries}で解説しています。 サポートされている全てのSRFIのリストは@ref{Standard conformance}にあります。 (ここに挙げられていないSRFIでも、サポートされているものについては @code{(use srfi.N)}や@code{(import (srfi N))}と書くことができます。) @c COMMON @c EN Note that we use a hyphen to refer to a SRFI as a specification (e.g. SRFI-13) but use a hierarchical name for the module (e.g. @code{srfi.13} as a Gauche's module, or @code{(srfi 13)} as a R7RS library). @c JP ここで、仕様としてのSRFIを指す場合はハイフンを使い(例: SRFI-13)、 モジュール名としては階層的な名前を使う(例: Gaucheモジュールとしては@code{srfi.13}、 R7RSライブラリとしては@code{(srfi 13)})ということに注意してください。 @c COMMON @c ---------------------------------------------------------------------- @menu * Testing availability of SRFIs:: * SRFIs that have become R7RS-large:: * Homogeneous vectors:: srfi.4 * A compatible let form with signatures and rest arguments:: srfi.5 * Feature-based program configuration language:: srfi.7 * String library:: srfi.13 * Time data types and procedures:: srfi.19 * Sources of random bits:: srfi.27 * Localization:: srfi.29 * A program argument processor:: srfi.37 * Eager comprehensions:: srfi.42 * Vector library (Legacy):: srfi.43 * Requiring extensions:: srfi.55 * Integers as bits:: srfi.60 * A Scheme API for test suites:: srfi.64 * Octet vectors:: srfi.66 * Basic hash tables:: srfi.69 * Octet-addressed binary blocks:: srfi.74 * Lightweight testing:: srfi.78 * Accessing environment variables:: srfi.98 * Purely functional random-access pairs and lists:: srfi.101 * Basic socket interface:: srfi.106 * Portable runtime environment inquiry:: srfi.112 * Comparators:: srfi.114 * Simple adjustable-size strings:: srfi.118 * Timer APIs:: srfi.120 * Titlecase procedures:: srfi.129 * Cursor-based string library:: srfi.130 * String library (reduced):: srfi.152 * First-class dynamic extents:: srfi.154 * Homogeneous numeric vector libraries:: srfi.160 * Comparator sublibrary:: srfi.162 * POSIX API:: srfi.170 * Two safer subsets of R7RS:: srfi.172 * Hooks (srfi):: srfi.173 * POSIX timespecs:: srfi.174 * ASCII character library:: srfi.175 * Bitvector library:: srfi.178 * JSON:: srfi.180 * Custom ports:: srfi.181 * Linear adjustable-length strings:: srfi.185 * Maybe and Either optional container types:: srfi.189 * Coroutine generators:: srfi.190 * Port positioning:: srfi.192 * Command line:: srfi.193 * Random data generators (SRFI):: srfi.194 * Range objects:: srfi.196 * Pipeline operators:: srfi.197 * String-notated bytevectors:: srfi.207 * Enums and enum sets:: srfi.209 * Procedures and syntax for multiple values:: srfi.210 * Central log exchange:: srfi.215 * SICP prerequisites:: srfi.216 * Integer sets:: srfi.217 * Define higher-order lambda:: srfi.219 * Generator/accumulator sub-library:: srfi.221 * Compound objects:: srfi.222 * Control features:: srfi.226 * Optional arguments:: srfi.227 * Composing comparators:: srfi.228 * Tagged procedures:: srfi.229 * Atomic operations:: srfi.230 * Flexible curried procedures:: srfi.232 * Topological sorting:: srfi.234 * Combinators (SRFI):: srfi.235 * Codesets:: srfi.238 * Destructuring lists:: srfi.239 * Syntactic monads:: srfi.247 * Property testing:: srfi.252 @end menu @node Testing availability of SRFIs, SRFIs that have become R7RS-large, Library modules - SRFIs, Library modules - SRFIs @section Testing availability of SRFIs @c NODE SRFIが使えるかどうかテストする @c EN To test availability of a SRFI with @code{cond-expand} (@pxref{Feature conditional}), you can use @code{(library library-name)} feature requirement. You can use both Gauche-style and R7RS-style library name notation. @c JP 特定のSRFIが使えるかどうかを@code{cond-expand}で検査する場合は、機能要請式 @code{(library @code{library-name})}が使えます (@ref{Feature conditional}参照)。 @var{library-name}にはGauche方式のモジュール名もR7RS方式のライブラリ名も使えます。 @c COMMON @example ;; Use 'library' feature requirement with Gauche module name (cond-expand [(library srfi.13) (use srfi.13) ...] [else ...]) ;; Use 'library' feature requirement with R7RS library name (cond-expand [(library (srfi 13)) (import (srfi 13)) ...] [else ...]) @end example @c EN Alternatively you can use a SRFI name as a feature identifier. @emph{This use is deprecated}. This is an old style used before R7RS. With this style, if the feature is fulfilled, the necessary libraries are implicitly imported, so you don't need to have @code{use} or @code{import} forms (but that means you can't control the imports with @code{only}, @code{rename}, @code{prefix} etc.) @c JP 他に、SRFI名を直接機能識別子として使うこともできます。 @emph{ただし、この機能は非推奨です}。これはR7RS以前の方式です。 この指定を使った場合、機能条件が満たされたならば、必要なモジュールは自動的にインポート されているので、@code{use}や@code{import}でインポートする必要はありません。 ただそれは、@code{only}、@code{rename}、@code{prefix}節などでインポートする 識別子を制御できないということでもあります。 @c COMMON @example ;; DEPRECATED. Use 'srfi-N' feature identifier. ;; If the feature is fulfilled, you can assume the module is already 'use'd. (cond-expand [srfi-13 ...] [else ...]) @end example @c EN If @code{srfi-N} is used as a feature identifier, a warning is issued when an environment variable @code{GAUCHE_WARN_SRFI_FEATURE_ID} is set. In future this warning will be the default. We urge the users to update their code to use @code{(library srfi.N)} form. @c JP @code{srfi-N}が機能識別子として使われた場合、 環境変数@code{GAUCHE_WARN_SRFI_FEATURE_ID}がセットされていれば 警告が表示されます。将来はデフォルトで警告するようになります。 @code{srfi-N}機能識別子を使っているユーザは、なるべく早く @code{(library srfi.N)}へと書き換えるようにしてください。 @c COMMON @node SRFIs that have become R7RS-large, Homogeneous vectors, Testing availability of SRFIs, Library modules - SRFIs @section SRFIs that have become R7RS-large @c NODE R7RS-largeになったSRFI @c EN Here's a list of SRFIs that have become a part of R7RS-large, ordered by SRFI numbers. @c JP 以下に、R7RS-largeに取り入れられたSRFIのリストを番号順に示します。 @c COMMON @table @asis @item SRFI-1 List library @code{scheme.list} (@pxref{R7RS lists}). @item SRFI-14 Character-set library @code{scheme.char-set} (@pxref{R7RS character sets}). @item SRFI-41 Streams @code{scheme.stream} (@pxref{R7RS stream}). @item SRFI-101 Purely functional random-access pairs and lists @code{scheme.rlist} (@pxref{R7RS random-access lists}). @item SRFI-111 Boxes @code{scheme.box} (@pxref{R7RS boxes}). @item SRFI-113 Sets and bags @code{scheme.set} (@pxref{R7RS sets}). @item SRFI-115 Scheme Regular Expressions @code{scheme.regex} (@pxref{R7RS regular expressions}). @item SRFI-116 Immutable list library @code{scheme.ilist} (@pxref{R7RS immutable lists}). @item SRFI-117 Queues based on lists @code{scheme.list-queue} (@pxref{R7RS list queues}). @item SRFI-121 Generators @code{scheme.generator} (@pxref{R7RS generators}). @item SRFI-124 Ephemerons @code{scheme.ephemeron} (@pxref{R7RS ephemerons}). @item SRFI-125 Intermediate hash tables @code{scheme.hash-table} (@pxref{R7RS hash tables}). @item SRFI-127 Lazy sequences @code{scheme.lseq} (@pxref{R7RS lazy sequences}). @item SRFI-128 Comparators (reduced) @code{scheme.comparator} (@pxref{R7RS comparators}). @item SRFI-132 Sort library @code{scheme.sort} (@pxref{R7RS sort}). @item SRFI-133 Vector library @code{scheme.vector} (@pxref{R7RS vectors}). @item SRFI-134 Immutable deques @code{scheme.ideque} (@pxref{R7RS immutable deques}). @item SRFI-135 Immutable texts @code{scheme.text} (@pxref{R7RS immutable texts}). @item SRFI-141 Integer division @code{scheme.division} (@pxref{R7RS integer division}). @item SRFI-143 Fixnums @code{scheme.fixnum} (@pxref{R7RS fixnum}). @item SRFI-144 Flonums @code{scheme.flonum} (@pxref{R7RS flonum}). @item SRFI-146 Mappings @code{scheme.mapping}, @code{scheme.mapping.hash} (@pxref{R7RS mappings}). @item SRFI-151 Bitwise operations @code{scheme.bitwise} (@pxref{R7RS bitwise operations}). @item SRFI-158 Generators and accumulators @code{scheme.generator} (@pxref{R7RS generators}). @item SRFI-159 Combinator formatting @code{scheme.show} (@pxref{R7RS combinator formatting}). @item SRFI-160 Homogeneous numeric vector libraries @code{scheme.vector.@@} (@pxref{R7RS uniform vectors}). @end table @c ---------------------------------------------------------------------- @node Homogeneous vectors, A compatible let form with signatures and rest arguments, SRFIs that have become R7RS-large, Library modules - SRFIs @section @code{srfi.4} - Homogeneous vectors @c NODE 単一型のベクタ, @code{srfi.4} - 単一型のベクタ @deftp {Module} srfi.4 @mdindex srfi.4 @c EN SRFI-4 is now implemented in @code{gauche.uvector} module @xref{Uniform vectors}. This module simply inherits @code{gauche.uvector} for backward-compatibility. @c JP SRFI-4は、@code{gauche.uvector}モジュールとして実装されています。 @ref{Uniform vectors}参照。 このモジュールは後方互換性のために単に@code{gauche.uvector}を継承しています。 @c COMMON @end deftp @c ---------------------------------------------------------------------- @node A compatible let form with signatures and rest arguments, Feature-based program configuration language, Homogeneous vectors, Library modules - SRFIs @section @code{srfi.5} - A compatible let form with signatures and rest arguments @c NODE シグネチャとrest引数に互換性のあるlet形式, @code{srfi.5} - シグネチャとrest引数に互換性のあるlet形式 @deftp {Module} srfi.5 @mdindex srfi.5 @c EN This module provides SRFI-5's extended @code{let} syntax. @c JP このモジュールは SRFI-5 の拡張 @code{let} 構文を提供します。 @c COMMON @end deftp @defmac let ((var val) @dots{} [. (rest val @dots{})]) body @dots{} @defmacx let name ((var val) @dots{} [. (rest val @dots{})]) body @dots{} @defmacx let (name (var val) @dots{} [. (rest val @dots{})]) body @dots{} [SRFI-5] @c MOD srfi.5 @c EN The @code{let} syntax is extended in two ways. @c JP @code{let} 構文は 2通りの拡張がされています。 @c COMMON @c EN @itemize @bullet @item The extended @code{let} syntax accepts the @var{name} identifier (for named let syntax) within the list of bindings (as in the third syntax above). @item The extended @code{let} syntax accepts the rest parameter binding which works like the rest parameter in the @code{lambda} syntax. @end itemize See SRFI-5 document for rationale of this extension. @c JP @itemize @bullet @item 拡張 @code{let} 構文は、@var{name} 束縛リスト中で(名前付き let 構文用の) 識別子を許します(上の3つめの構文)。 @item 拡張 @code{let} 構文は、@code{lambda} 構文の rest パラメータと同様の 働きをする rest パラメータ束縛を許します。 @end itemize この拡張に関する理論的根拠については SRFI-5 のドキュメントを参照してください。 @c COMMON @end defmac @c ---------------------------------------------------------------------- @node Feature-based program configuration language, String library, A compatible let form with signatures and rest arguments, Library modules - SRFIs @section @code{srfi.7} - Feature-based program configuration language @c NODE 機能ベースプログラム設定言語, @code{srfi.7} - 機能ベースプログラム設定言語 @deftp {Module} srfi.7 @mdindex srfi.7 @c EN This module provides a program configuration metalanguage (@code{program} form) defined in srfi-7. @c JP このモジュールは、SRFI-7 で定義されている プログラム設定メタ言語(@code{program} フォーム)を提供します。 @c EN Gauche autoloads @code{srfi.7} module, so you don't need to say @code{(use srfi.7)} explicitly. @c JP Gauche は @code{srfi.7} モジュールを autoload するので、@code{(use srfi.7)} と 明示的に書く必要はありません。 @c EN Note that the @code{program} form isn't necessary to be a Scheme expression. SRFI-7 allows an implementation to preprocess the @code{program} form to produce a Scheme program, then executes it with different means. @c JP @code{program} フォームは Scheme の式である必要がないことに注意してください。 SRFI-7 では、この @code{program}フォームを処理して Scheme プログラムを 生成してから、それを別の方法で実行するような実装を許しています。 @c EN Gauche implements @code{program} form as a macro, so it can evaluates the form directly. Nonetheless, it doesn't make sense to mix @code{program} form and other forms in one file, or expecting a return value of @code{program} form. @c JP Gauche @code{program} フォームをマクロとして実装しているので、 フォーム自体を直接、評価することができます。とはいえ、@code{program} フォームと他のフォームを一つのファイル中で混在させたり、@code{program} フォームの返り値を期待するのは、よいことではありません。 @c EN A typical usage of @code{program} form is to prepare a single file which just contains @code{program} form. (It can load other files using @code{files} clause (see below) within the @code{program} form.) To execute such a program file in Gauche, you can just load it. @c JP @code{program}フォームの典型的な使い方は、@code{program} フォームのみを 含む単一のファイルを用意することです。(@code{program}フォーム中で @code{files} 節(後述)を用いて他のファイルをロードすることが可能です。) このようなプログラムファイルを Gauche で実行するには、単にそれを ロードするだけです。 @c COMMON @end deftp @deffn {Configuration Language} program program-clause program-clause2 @dots{} [SRFI-7] @c MOD srfi.7 @c EN This is a configuration language to structure a Scheme program, based on availability of the features. A Scheme program is constructed from the @code{program} form. Gauche evaluates the constructed Scheme program on-the-fly. Each @var{program-clause} needs to be one of the "Program Clauses" below. @c JP これは Scheme プログラムを構成する設定言語で、機能の利用可能性に基づいて います。 Scheme のプログラムは、この @code{program}フォームから構築されます。 Gauche は構築された Scheme のプログラムをそのまま実行します。 各 @var{program-clause} は以下の "Program Clause" のどれか一つである 必要があります。 @c COMMON @end deffn @deffn {Program Clause} requires feature-id feature-id2 @dots{} [SRFI-7] @c EN The @var{feature-id}'s are the same as SRFI-0's (@pxref{Feature conditional}). It tells that the following code requires these @var{feature-id}'s. If a feature-id which is not supported in Gauche is given, an error is signaled. @c JP @var{feature-id} は SRFI-0 のものと同じです (@pxref{Feature conditional})。 あとに続くコードが @var{feature-id} を必要とすることを教えます。 Gauche ではサポートされていない feature-id が与えられた場合には、 エラーシグナルが発生します。 @c COMMON @end deffn @deffn {Program Clause} files filename @dots{} [SRFI-7] @c EN Inserts the content of the @var{filename}s into a program. In Gauche, this clause just causes @var{filename}s to be loaded into the current module. @c JP プログラムに @var{filename}の内容を挿入します。Gauche では 単に、現在のモジュール中への @var{filename} のロードをひきおこします。 @c COMMON @end deffn @deffn {Program Clause} code scheme-expression @dots{} [SRFI-7] @c EN The @var{scheme-expression}s are inserted into a program. @c JP @var{scheme-expression} がプログラムに挿入されます。 @c COMMON @end deffn @deffn {Program Clause} feature-cond clause clause2 @dots{} [SRFI-7] @c EN @var{Clause} is a following form: @c JP @var{clause} は以下のようなフォームです。 @c COMMON @example (@var{requirement} @var{program-clause} @var{program-clause2} @dots{}) @end example @c EN Where @var{requirement} should be one of the following: @c JP ここでは、@var{requirement} は以下のもののどれかひとつでなければなりません。 @c COMMON @itemize @bullet @item @var{feature-id} @item @code{(and @var{requirement} @dots{})} @item @code{(or @var{requirement} @dots{})} @item @code{(not @var{requirement})} @end itemize @c EN The @var{requirement} of the last @var{clause} may be @code{else}. Gauche checks each @var{requirement} one by one, and if it finds a fulfilled @var{requirement}, inserts the @var{program-clause}s in that @var{clause} into the program. @c JP 最後の @var{clause} の @var{requirement} は @code{else} になるでしょう。 Gauche はそれぞれの @var{requirement} をひとつずつチェックし、 満された @var{requirement} が見つかると、その@var{clause}中の @var{program-clause} をプログラムに挿入します。 @c COMMON @end deffn @c ---------------------------------------------------------------------- @node String library, Time data types and procedures, Feature-based program configuration language, Library modules - SRFIs @section @code{srfi.13} - String library @c NODE 文字列ライブラリ, @code{srfi.13} - 文字列ライブラリ @deftp {Module} srfi.13 @mdindex srfi.13 @c EN Defines a large set of string-related procedures. @c JP 文字列に関連する手続きの大きなセットを定義しています。 @c COMMON @c EN It was one of the earliest popular srfis, but some of the procedures were turned out not to align well with recent Scheme developments. @xref{String library (reduced)}, and @ref{Cursor-based string library} adapts this srfis to more ``modern'' form. Consider to use them for newer development. @c JP これは広く使われた初期のsrfiのひとつですが、いくつかの手続きは その後のSchemeの発展と相性が良くないということがわかってきました。 @ref{String library (reduced)}や@ref{Cursor-based string library}では このsrfiをより「現代的」なものにしようとしています。 新規に開発する場合はそれらのsrfiを見てみると良いでしょう。 @c COMMON @c EN Many procedures in this srfi specifies the position of a character in a string with an integer index. Although it's portable, it is not optimal for multibyte strings. Gauche natively supports string cursors, which is more efficient than integer indexes (@pxref{String cursors}). All SRFI-13 procedures that accepts integer indexes can also accept string cursors. @c JP このsrfiの多くの手続きは、文字列中の文字の位置を整数のインデックスで表します。 これはポータブルですが、マルチバイト文字列では効率が悪いです。 Gaucheは組み込みでより効率のよい文字列カーソルをサポートしており(@ref{String cursors})、 SRFI-13の手続きは全て文字列インデックスを受け取るところに文字列カーソルも 渡せるようになっています。 @c COMMON @end deftp @menu * SRFI-13 General conventions:: * SRFI-13 String predicates:: * SRFI-13 String constructors:: * SRFI-13 String selection:: * SRFI-13 String comparison:: * SRFI-13 String prefixes & suffixes:: * SRFI-13 String searching:: * SRFI-13 String case mapping:: * SRFI-13 String reverse & append:: * SRFI-13 String mapping:: * SRFI-13 String rotation:: * SRFI-13 Other string operations:: * SRFI-13 String filtering:: * SRFI-13 Low-level string procedures:: @end menu @node SRFI-13 General conventions, SRFI-13 String predicates, String library, String library @subsection General conventions @c NODE 一般規約 @c EN There are a few common factors in string library API, which I don't repeat in each function description @c JP 文字列ライブラリのAPIにはいくつか共通するものがありますが、 それぞれの関数の説明において繰り返しません。 @c COMMON @table @emph @c EN @item argument convention @c JP @item 引数の仕様 @c EN The following argument names imply their types. @c JP 以下の引数名はその型を暗に表しています。 @c COMMON @table @asis @item @var{s}, @var{s1}, @var{s2} @c EN Those arguments must be strings. @c JP これらの引数は文字列でなければなりません。 @c COMMON @item @var{char/char-set/pred} @c EN This argument can be a character, a character-set object, or a predicate that takes a single character and returns a boolean value. ``Applying @var{char/char-set/pred} to a character'' means, if @var{char/char-set/pred} is a character, it is compared to the given character; if @var{char/char-set/pred} is a character set, it is checked if the character set contains the given character; if @var{char/char-set/pred} is a procedure, it is applied to the given character. ``A character satisfies @var{char/char-set/pred}'' means such application to the character yields true value. @c JP この引数は、文字、文字集合オブジェクト、あるいは1つの文字を引数に取り 真偽値を返す述語のいずれかです。``文字に@var{char/char-set/pred}を適用する'' の意味はそれぞれ、@var{char/char-set/pred}が文字ならば与えられた文字と比較される、 @var{char/char-set/pred}が文字集合ならばその文字集合に与えられた文字が 含まれるかを検査する、@var{char/char-set/pred}が述語ならばそれを与えられた 文字に適用する、となります。``ある文字が@var{char/char-set/pred}を満足する'' とは、その文字への前述のような適用が真値を返すという意味になります。 @c COMMON @item @var{start}, @var{end} @c EN Lots of SRFI-13 functions takes these two optional arguments, which limit the area of input string from @var{start}-th character (inclusive) to @var{end}-th character (exclusive), where the operation is performed. When specified, the condition 0 <= @var{start} <= @var{end} <= @var{length of the string} must be satisfied. Default value of @var{start} and @var{end} is 0 and the length of the string, respectively. @c JP SRFI-13の関数の多くは、その操作が実行される対象入力文字列の 範囲を限定する開始インデックスと終了インデックスをオプショナルな 引数として取ります。開始(@var{start}番目)の文字は含まれ、 終了(@var{end}番目)の文字は含まれません。 これらが指定されるとき、0 <= @var{start} <= @var{end} <= @var{length of the string}が 満たされなければなりません。@var{start}と@var{end}のデフォルト値は、 それぞれ0と文字列の長さです。 @c COMMON @end table @c EN @item @code{shared} variant @c JP @item @code{shared}バージョン @c EN Some functions have variants with ``/shared'' attached to its name. SRFI-13 defines those functions to allow to share the part of input string, for better performance. Gauche doesn't have a concept of shared string, and these functions are mere synonyms of their non-shared variants. However, Gauche @emph{internally} shares the storage of strings, so generally you don't need to worry about the overhead of copying substrings. @c JP いくつかの関数は、その名前に``/shared''が付きます。 SRFI-13では、それらの関数はより良いパフォーマンスのために 入力文字列の一部を共有しても良いと定義しています。 Gaucheは、共有文字列という概念を持っていませんし、 それらの関数は単に共有でないバージョンの変名に過ぎません。 しかし、Gaucheは@emph{内部的には}文字列の保存場所を共有しているので、 一般的には部分文字列をコピーするオーバヘッドについて心配する 必要はありません。 @c COMMON @c EN @item @code{right} variant @c JP @item @code{right}バージョン @c EN Most functions works from left to right of the input string. Some functions have variants with ``-right'' to its name, that works from right to left. @c JP ほとんどの関数は、入力文字列を左から右へと扱います。 いくつかの関数は、その名前に``-right''が付き、右から左へと 扱うものがあります。 @c COMMON @end table @node SRFI-13 String predicates, SRFI-13 String constructors, SRFI-13 General conventions, String library @subsection String predicates @c NODE 文字列についての述語 @defun string-null? s [SRFI-13] @c MOD srfi.13 @c EN Returns @code{#t} if @var{s} is an empty string, @code{""}. @c JP @var{s}が空文字列、@code{""}なら、@code{#t}を返します。 @c COMMON @end defun @defun string-every char/char-set/pred s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Sees if every character in @var{s} satisfies @var{char/char-set/pred}. If so, @code{string-every} returns the value that is returned at the last application of @var{char/char-set/pred}. If any of the application returns @code{#f}, @code{string-every} returns @code{#f} immediately. @c JP @var{s}に含まれる全ての文字が@var{char/char-set/pred}を 満足するかを検査します。満足するならば、@code{string-every}は 最後に適用された@var{char/char-set/pred}が返した値を戻り値とします。 どの適用も@code{#f}を返した場合は、@code{string-every}はすぐに @code{#f}を返します。 @c COMMON @end defun @defun string-any char/char-set/pred s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Sees if any character in @var{s} satisfies @var{char/char-set/pred}. If so, @code{string-any} returns the value that is returned by the application. If no character satisfies @var{char/char-set/pred}, @code{#f} is returned. @c JP @var{s}に含まれるいずれかの文字が@var{char/char-set/pred} を満足するかを検査します。いずれかの文字が満足するならば、 @code{string-any}はその適用が返した値を戻り値とします。 どの文字も@var{char/char-set/pred}を満たさなければ、@code{#f}が返ります。 @c COMMON @end defun @node SRFI-13 String constructors, SRFI-13 String selection, SRFI-13 String predicates, String library @subsection String constructors @c NODE 文字列の構築子 @defun string-tabulate proc len [SRFI-13] @c MOD srfi.13 @c EN @var{proc} must be a procedure that takes an integer argument and returns a character. @code{string-tabulate} creates a string, whose @var{i}-th character is calculated by @code{(proc i)}. @c JP @var{proc}は整数を1つ引数として取り文字を返す手続きで なければなりません。@code{string-tabulate}は、その@var{i}番目の 文字が@code{(proc i)}で計算されるような文字列を返します。 @c COMMON @example (string-tabulate (lambda (i) (integer->char (+ i #x30))) 10) @result{} "0123456789" @end example @end defun @defun string-unfold p f g seed :optional base make-final [SRFI-13] @c MOD srfi.13 @c EN A fundamental string builder. The @var{p}, @var{f} and @var{g} are procedures, taking the current seed value. The stop predicate @var{p} determines when to stop: If it returns a true value, string building stops. The mapping function @var{f} returns a character from the current seed value. The next seed function @var{g} returns a next seed value from the current seed value. The @var{seed} argument gives the initial seed value. @c JP 基本的な文字列構築手続きです。 @var{p}、@var{f}、@var{g}は手続きで、現在のシード値を受けとります。 停止述語@var{p}はいつ繰り返しを止めるかを判断します。それが真の値を返したら、 文字列構築は終了し、それまでに生成された文字が集められて文字列として返されます。 @var{f}はシード値から文字を生成する手続きです。@var{g}はシード値から次のシード値を 生成します。@var{seed}引数はシード値の初期値を指定します。 @c COMMON @example (string-unfold (^n (= n 10)) (^n (integer->char (+ n 48))) (^n (+ n 1)) 0) @result{} "0123456789" @end example @c EN The optional argument @var{base} is, when given, prepended to the result string. Another optional argument @var{make-final} is a procedure that takes the last return value of @var{g} and returns a string that becomes the suffix of the result string. @c JP 省略可能引数@var{base}は、与えられれば生成される文字列のプレフィクスとなります。 @var{make-final}は手続きで、繰り返しが終了した後の最後のシード値を受け取り、 文字列のサフィックスを返します。 @c COMMON @example (string-unfold (^n (= n 10)) (^n (integer->char (+ n 48))) (^n (+ n 1)) 0 "foo" x->string) @result{} "foo012345678910" @end example @end defun @defun string-unfold-right p f g seed :optional base make-final [SRFI-13] @c MOD srfi.13 @c EN Another fundamental string builder. The meanings of arguments are the same as @code{string-unfold}. The only difference is that the string is build right-to-left. The optional @var{base}, if given, becomes the suffix of result, and the result of @var{make-final} becomes the prefix. @c JP もうひとつの基本的な文字列構築器です。引数の意味は@code{string-unfold}と 同じですが、@var{f}の返す文字が右から左へと並べられます。 また、章句可能な@var{base}引数はサフィックスに、 @var{make-final}が返す文字列はプレフィクスになります。 @c COMMON @example (string-unfold-right (^n (= n 10)) (^n (integer->char (+ n 48))) (^n (+ n 1)) 0 "foo" x->string) @result{} "109876543210foo" @end example @end defun @defun reverse-list->string char-list [SRFI-13] @c MOD srfi.13 @equiv{} @code{(list->string (reverse char-list))}. @end defun @node SRFI-13 String selection, SRFI-13 String comparison, SRFI-13 String constructors, String library @subsection String selection @c NODE 文字列の選択 @defun substring/shared s start :optional end [SRFI-13] @c MOD srfi.13 @c EN In Gauche, this is the same as @code{substring}, except that the @var{end} argument is optional. @c JP Gaucheでは、引数@var{end}がオプショナルであることを除いて、 @code{substring}と同じです。 @c COMMON @example (substring/shared "abcde" 2) @result{} "cde" @end example @end defun @defun string-copy! target tstart s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Copies a string @var{s} into a string @var{target} from the position @var{tstart}. The @var{target} string must be mutable. Optional @var{start} and @var{end} arguments limits the range of @var{s}. If the copied string run over the end of @var{target}, an error is signaled. @c JP 文字列@var{s}を、文字列@var{target}の@var{tstart}番目以降へコピーします。 @var{target}文字列は変更可能でなければなりません。 オプションの引数@var{start}と@var{end}は、@var{s}の範囲を制限します。 コピーされた文字列が@var{target}の終端を越えたらエラーが通知されます。 @c COMMON @example (define s (string-copy "abcde")) (string-copy! s 2 "ZZ") s @result{} "abZZe" @end example @c EN It is ok to pass the same string to @var{target} and @var{s}; this always work even if the regions of source and destination are overlapping. @c JP @var{target}と@var{s}に同じ文字列を渡しても構いません。コピー元とコピー先の 領域が重なっていても、コピーは常に正しく行われます。 @c COMMON @c EN Note that Gauche encourages you to treat strings as immutable objects. Internally, a string is an indirect pointer to a immutable entity, and mutating a string means copying the original entity and creating a new one. It doesn't ``save allocations''. Always use the functional version @code{string-copy} unless you absolutely need to replace a string in-place. @xref{String utilities}. @c JP Gaucheでは、文字列を変更不可なオブジェクトとして扱うことを強く推奨しています。 内部的に、文字列オブジェクトは変更不可な文字列の実体へのポインタとなっています。 文字列を変更すると、新たな文字列実体がアロケートされそれが変更されるので、 破壊的手続きを使えばメモリアロケーションが節約できるということはありません。 どうしても文字列そのものを破壊的変更したい場合でない限りは、 非破壊版の@code{string-copy}を使いましょう。@ref{String utilities}参照。 @c COMMON @end defun @defun string-take s nchars @defunx string-drop s nchars @defunx string-take-right s nchars @defunx string-drop-right s nchars [SRFI-13] @c MOD srfi.13 @c EN Returns the first @var{nchars}-character string of @var{s} (@code{string-take}) or the string without first @var{nchars} (@code{string-drop}). The @code{*-right} variation counts from the end of string. It is guaranteed that the returned string is always a copy of @var{s}, even no character is dropped. @c JP @code{string-take}は、@var{s}の最初の@var{nchars}文字からなる文字列を返します。 @code{string-drop}は、@var{s}から最初の@var{nchars}文字からなる文字列を 除いた残りを返します。@code{*-right}バージョンは、文字列の最後から数えます。 返される文字列はいつも@var{s}のコピーであり、どの文字も削除されないことが 保証されています。 @c COMMON @example (string-take "abcde" 2) @result{} "ab" (string-drop "abcde" 2) @result{} "cde" (string-take-right "abcde" 2) @result{} "de" (string-drop-right "abcde" 2) @result{} "abc" @end example @end defun @defun string-pad s len :optional char start end @defunx string-pad-right s len :optional char start end [SRFI-13] @c MOD srfi.13 @c EN If a string @var{s} is shorter than @var{len}, returns a string of @var{len} where @var{char} is padded to the left or right, respectively. If @var{s} is longer than @var{len}, the rightmost or leftmost @var{len} chars are taken. @var{Char} defaults to @code{#\space}. If @var{start} and @var{end} are provided, the substring of @var{s} is used as the source. @c JP 文字列@var{s}が@var{len}より短い場合は、@var{char}がそれぞれ左か 右にパディングされた長さ@var{len}の文字列を返します。 @var{s}が@var{len}よりも長い場合は、@var{len}文字が右端か左端から 取り除かれます。@var{Char}のデフォルト値は@code{#\space}です。 @var{start}と@var{end}が与えられると、@var{s}の部分文字列がソース 文字列として使われます。 @c COMMON @example (string-pad "abc" 10) @result{} " abc" (string-pad "abcdefg" 3) @result{} "efg" (string-pad-right "abc" 10) @result{} "abc " (string-pad "abcdefg" 10 #\+ 2 5) @result{} "+++++++cde" @end example @end defun @defun string-trim s :optional char/char-set/pred start end @defunx string-trim-right s :optional char/char-set/pred start end @defunx string-trim-both s :optional char/char-set/pred start end [SRFI-13] @c MOD srfi.13 @c EN Removes characters that match @var{char/char-set/pred} from @var{s}. @code{String-trim} removes the characters from left of @var{s}, @code{string-trim-right} does from right, and @code{string-trim-both} does from both sides. @c JP @var{s}から@var{char/char-set/pred}にマッチする文字を削除します。 @code{String-trim}は@var{s}の左から文字を削除し、 @code{string-trim-right}は右から、@code{string-trim-both}は 両端から削除します。 @c COMMON @c EN @var{Char/char-set/pred} defaults to @code{#[\s]}, i.e. a char-set of whitespaces. If @var{start} and @var{end} are provided, the substring of @var{s} is used as the source. @c JP @var{Char/char-set/pred}のデフォルト値は@code{#[\s]}、つまり空白文字の 文字集合です。@var{start}と@var{end}が与えられると、@var{s}の部分文字列が ソース文字列として使われます。 @c COMMON @example (string-trim " abc ") @result{} "abc " (string-trim-right " abc ") @result{} " abc" (string-trim-both " abc ") @result{} "abc" @end example @end defun @node SRFI-13 String comparison, SRFI-13 String prefixes & suffixes, SRFI-13 String selection, String library @subsection String comparison @c NODE 文字列の色々な比較 @defun string-compare s1 s2 proc< proc= proc> :optional start1 end1 start2 end2 @defunx string-compare-ci s1 s2 proc< proc= proc> :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Compares two strings @var{s1} and @var{s2} codepoint-wise from left. When mismatch is found at the index @var{k} of @var{s1}, calls @var{proc<} with @var{k} if @var{s1}'s codepoint is smaller than the corresponding @var{s2}'s, or calls @var{proc>} if @var{s1}'s one is greater than @var{s2}'s. If two strings are the same, calls @var{proc=} with the index of the last compared position in @var{s1}. @c JP 文字列@var{s1}と@var{s2}をコードポイント毎に左から比較します。 不一致が@var{s1}のインデックス@var{k}で見つかった場合、対応する@var{s2}の コードポイントより@var{s1}のコードポイントの方が小さければ @var{proc<}を@var{k}を引数にして呼び出し、逆に大きければ @var{proc>}を@var{k}を引数にして呼び出します。 二つの文字列が等しければ、@var{proc=}が、@var{s1}の比較された最後のインデックスを 引数にして呼び出されます。 @c COMMON @example (string-compare "abcd" "abzd" (^i `(< ,i)) (^i `(= ,i)) (^i `(> ,i))) @result{} (< 2) (string-compare "abcd" "abcd" (^i `(< ,i)) (^i `(= ,i)) (^i `(> ,i))) @result{} (= 3) @end example @c EN The optional arguments restricts the range of the input strings; however, the index passed to one of the procedures is always an index from the beginning of @var{s1}. @c JP 省略可能引数は入力の文字列の比較すべき範囲を制限します。 但し、@var{proc<}、@var{proc=}、@var{proc>}に渡されるインデックスは 常に@var{s1}の最初から数えたものになります。 @c COMMON @example (string-compare "zzabcdyy" "abcz" (^i `(< ,i)) (^i `(= ,i)) (^i `(> ,i)) 2 6 0 4) @result{} (< 5) (string-compare "zzabcdyy" "abcz" (^i `(< ,i)) (^i `(= ,i)) (^i `(> ,i)) 2 5 0 3) @result{} (= 4) @end example @c EN The case-insensitive variant, @code{string-compare-ci}, compares each codepoint with character-wise case-folding. It won't consider special case folding such as German eszett. @c JP @code{string-compare-ci}は大文字小文字を区別しない比較です。 文字毎の大文字小文字変換を行って比較するので、文字列の長さが変わる 大文字小文字変換のケース (ドイツ語のエスツェット等) は考慮されません。 @c COMMON @end defun @defun string= s1 s2 :optional start1 end1 start2 end2 @defunx string<> s1 s2 :optional start1 end1 start2 end2 @defunx string< s1 s2 :optional start1 end1 start2 end2 @defunx string<= s1 s2 :optional start1 end1 start2 end2 @defunx string> s1 s2 :optional start1 end1 start2 end2 @defunx string>= s1 s2 :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Compare two strings @var{s1} and @var{s2}. Optional arguments can limit the portion of strings to be compared. Comparison is done by character-wise. Note: The builtin procedures @code{string=?} etc. can also be used for character-wise string comparison, but they take arguments differently. @xref{String comparison}. @c JP 二つの文字列@var{s1}と@var{s2}を比較します。省略可能引数で それぞれの文字列の一部のみを比較するように指定できます。 比較は文字ごとに行われます。 註: 組み込み手続きの@code{string=?}等も文字毎の比較に使えますが、 引数の取り方が違います。@ref{String comparison}参照。 @c COMMON @end defun @defun string-ci= s1 s2 :optional start1 end1 start2 end2 @defunx string-ci<> s1 s2 :optional start1 end1 start2 end2 @defunx string-ci< s1 s2 :optional start1 end1 start2 end2 @defunx string-ci<= s1 s2 :optional start1 end1 start2 end2 @defunx string-ci> s1 s2 :optional start1 end1 start2 end2 @defunx string-ci>= s1 s2 :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Compare two strings @var{s1} and @var{s2} in case-insensitive way. Optional arguments can limit the portion of strings to be compared. Case folding and comparison is done by character-wise, so they don't consider case folding that affects multiple characters. Note: We have two other sets of string comparison operations, both are named as @code{string-ci=?} etc. The builtin version (@pxref{String comparison}) does character-wise comparison. The one in @code{gauche.unicode} uses full-string case conversion (@pxref{Full string case conversion}). R7RS version is the latter. @c JP 二つの文字列@var{s1}と@var{s2}を、大文字小文字を区別せずに比較します。 省略可能引数でそれぞれの文字列の一部のみを比較するように指定できます。 大文字小文字の畳み込みと比較は文字ごとに行われます。複数の文字に 影響を与えるような大文字小文字の畳み込みは考慮しません。 註: Gaucheには他に2種類の大文字小文字を区別しない文字列比較手続き群があります。 どちらも@code{string-ci=?}等のようにクエスチョンマーク付きの名前を持っています。 Gauche組み込みのものは文字毎に大文字小文字を畳み込みます (@ref{String comparison}参照)。一方、@code{gauche.unicode}にあるものは 文字列としての畳み込みを行います(@ref{Full string case conversion}参照)。 R7RS版は後者です。 @c COMMON @end defun @defun string-hash s :optional bound start end @defunx string-hash-ci s :optional bound start end [SRFI-13] @c MOD srfi.13 @c EN (Note: Gauche has builtin @code{string-hash} and @code{string-ci-hash} according to SRFI-128. @xref{Hashing}, for the details. SRFI-13's API is upper-compatible to SRFI-128's. The underlying hash algorithm is the same as the builtin ones, so @code{string-hash} returns the same value as the builtin ones for the same string if optional arguments are omitted. On the other hand, the builtin @code{string-ci-hash} uses string case folding (e.g. German eszett and @code{SS} are the same), while SRFI-13's @code{string-hash-ci} uses character-wise case folding. Unless there's a strong reason, we recommend new code should use builtin SRFI-128 version instead of SRFI-13.) Calculates hash value of a string @var{s}. For @code{string-hash-ci}, character-wise case folding is done before calculating the hash value. If the optional @var{bound} argument is given, it must be a positive exact integer, and the return value is limited below it. The optional @var{start} and @var{end} arguments allows using that portion for calculation. @c JP (註: Gaucheは、SRFI-128に準拠した@code{string-hash}と@code{string-ci-hash}を 組み込みで持っています。詳しくは@ref{Hashing}参照。 SRFI-13のAPIはSRFI-128の上位互換になっています。内部で使っているハッシュ アルゴリズムは一緒なので、省略可能引数を全て省略したSRFI-13の@code{string-hash}は、 組み込みの@code{string-hash}と同じ値を返します。 一方、組み込みの@code{string-ci-hash}は文字列として大文字小文字の畳み込みを 行います(ドイツ語のエスツェットと@code{SS}は等しく扱われます)が、SRFI-13の @code{string-hash-ci}は文字毎に大文字小文字を畳み込むように定められているので、 結果が異なる可能性があります。特に強い理由がなければ、新しいコードは 組み込みのSRFI-128版を使うことをおすすめします。) 文字列@var{s}のハッシュ値を計算して返します。@code{string-hash-ci}では ハッシュ値を計算する前に各文字について大文字小文字を畳み込みを行います。 省略可能引数@var{bound}は、与えられたなら正の正確な整数でなければならず、 返される値は0から@code{(- bound 1)}までの値に制限されます。 @var{start}と@var{end}は、与えられれば@var{s}中の対象となる部分文字列を 指定します。 @c COMMON @end defun @node SRFI-13 String prefixes & suffixes, SRFI-13 String searching, SRFI-13 String comparison, String library @subsection String prefixes & suffixes @c NODE 文字列のプリフィックスとサフィックス @defun string-prefix-length s1 s2 :optional start1 end1 start2 end2 @defunx string-suffix-length s1 s2 :optional start1 end1 start2 end2 @defunx string-prefix-length-ci s1 s2 :optional start1 end1 start2 end2 @defunx string-suffix-length-ci s1 s2 :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Returns the length of the longest common prefix/suffix of two strings, @var{s1} and @var{s2}. The optional arguments restrict the range of search. The @code{*-ci} variations use case folding character comparison. @c JP 二つの文字列@var{s1}と@var{s2}の、共通するプレフィクスもしくはサフィックスの 長さを返します。省略可能引数はそれぞれの文字列の探索範囲を限定します。 @code{*-ci}版は文字ごとに、大文字小文字を区別しない比較を行います。 @c COMMON @example (string-prefix-length "abacus" "abalone") @result{} 3 (string-prefix-length "machine" "umbrella") @result{} 0 (string-suffix-length "peeking" "poking") @result{} 4 (string-prefix-length "obvious" "oblivious" 2 7 4 9) @result{} 5 @end example @end defun @defun string-prefix? s1 s2 :optional start1 end1 start2 end2 @defunx string-suffix? s1 s2 :optional start1 end1 start2 end2 @defunx string-prefix-ci? s1 s2 :optional start1 end1 start2 end2 @defunx string-suffix-ci? s1 s2 :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Returns true iff @var{s1} is a prefix or suffix of @var{s2}, respectively. The optional arguments limit the range of @var{s1} and @var{s2} to look at. The @code{*-ci} variations use case folding character comparison. @c JP それぞれ、@var{s1}が@var{s2}のプレフィクスまたはサフィックスになっていた場合に @code{#t}を、それ以外の場合に@code{#f}を返します。 省略可能引数はそれぞれの文字列の探索範囲を限定します。 @code{*-ci}版は文字ごとに、大文字小文字を区別しない比較を行います。 @c COMMON @example (string-prefix? "sch" "scheme") @result{} #t (string-prefix? "lisp" "scheme") @result{} #f (string-suffix? "eme" "scheme") @result{} #t (string-suffix? "eme" "lisp") @result{} #f (string-prefix? "mit-scheme" "scheme-family" 4) @result{} #t @end example @end defun @node SRFI-13 String searching, SRFI-13 String case mapping, SRFI-13 String prefixes & suffixes, String library @subsection String searching @c NODE 文字列の探索 @defun string-index s char/char-set/pred :optional start end @defunx string-index-right s char/char-set/pred :optional start end [SRFI-13] @c MOD srfi.13 @c EN Looks for the first element in a string @var{s} that matches @var{char/char-set/pred}, and returns its index. If @var{char/char-set/pred} is not found in @var{s}, returns @code{#f}. Optional @var{start} and @var{end} limit the range of @var{s} to search. @c JP 文字列@var{s}の中で、@var{char/char-set/pred}にマッチする 最初の要素を探し、そのインデックスを返します。 @var{s}の中に@var{char/char-set/pred}が見つからない場合は、@code{#f}を 返します。オプションの@var{start}と@var{end}は、@var{s}の中で検索対象と なる範囲を制限します。 @c COMMON @example (string-index "Aloha oe" #\a) @result{} 4 (string-index "Aloha oe" #[Aa]) @result{} 0 (string-index "Aloha oe" #[\s]) @result{} 5 (string-index "Aloha oe" char-lower-case?) @result{} 1 (string-index "Aloha oe" #\o 3) @result{} 6 @end example @c EN See also the Gauche built-in procedure @code{string-scan} (@ref{String utilities}), if you need speed over portability. @c JP ポータビリティよりも速度を重視する場合は、Gaucheのビルトイン手続き @code{string-scan}(@ref{String utilities})を参照して下さい。 @c COMMON @end defun @defun string-skip s char/char-set/pred :optional start end @defunx string-skip-right s char/char-set/pred :optional start end [SRFI-13] @c MOD srfi.13 @c EN Looks for the first element that does not match @var{char/char-set/pred} and returns its index. If such element is not found, returns @code{#f}. Optional @var{start} and @var{end} limit the range of @var{s} to search. @c JP @var{char/char-set/pred}にマッチしない最初の要素を探し、 そのインデックスを返します。そのような要素が見つからない場合、@code{#f}を 返します。オプションの@var{start}と@var{end}は、@var{s}の中で検索対象と なる範囲を制限します。 @c COMMON @end defun @defun string-count s char/char-set/pred :optional start end [SRFI-13] @c MOD srfi.13 @c EN Counts the number of elements in @var{s} that matches @var{char/char-set/pred}. Optional @var{start} and @var{end} limit the range of @var{s} to search. @c JP @var{s}の中で、@var{char/char-set/pred}にマッチする要素の数を カウントします。オプションの@var{start}と@var{end}は、@var{s}の中で検索対象と なる範囲を制限します。 @c COMMON @end defun @defun string-contains s1 s2 :optional start1 end1 start2 end2 @defunx string-contains-ci s1 s2 :optional start1 end1 start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Looks for a string @var{s2} inside another string @var{s1}. If found, returns an index in @var{s1} from where the matching string begins. Returns @code{#f} otherwise. Optional @var{start1}, @var{end1}, @var{start2} and @var{end2} limits the range of @var{s1} and @var{s2}. See also the Gauche built-in procedure @code{string-scan} (@ref{String utilities}), if you need speed over portability. @c JP @var{s1}の中で、文字列@var{s2}を探します。見つかった場合は、 @var{s1}でマッチした文字列が始まるインデックスを返します。そうでなければ、 @code{#f}を返します。 オプションの@var{start1}、@var{end1}、@var{start2}、@var{end2}は、 @var{s1}と@var{s2}の範囲を制限します。 ポータビリティよりも速度を重視する場合は、Gaucheのビルトイン手続き @code{string-scan}(@ref{String utilities})を参照して下さい。 @c COMMON @end defun @node SRFI-13 String case mapping, SRFI-13 String reverse & append, SRFI-13 String searching, String library @subsection String case mapping @c NODE 文字列のケース(大文字小文字)マッピング @defun string-titlecase s :optional start end @defunx string-titlecase! s :optional start end @defunx string-upcase s :optional start end @defunx string-upcase! s :optional start end @defunx string-downcase s :optional start end @defunx string-downcase! s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Converts a string @var{s} to titlecase, upcase or downcase, respectively. These operations uses character-by-character mapping provided by @code{char-upcase} etc. That is, @code{string-upcase} and @code{string-downcase} can be understood as follow: @c JP 文字列@var{s}をタイトルケース、大文字、小文字にそれぞれ変換します。 これらの手続きは、文字ごとに@code{char-upcase}等を使った変換を行います。 すなわち、@code{string-upcase}と@code{string-downcase}は以下の操作と 考えることができます。 @c COMMON @example (string-upcase s) @equiv{} (string-map char-upcase s) (string-downcase s) @equiv{} (string-map char-downcase s) @end example @c EN If you need full case mapping that handles the case when a character is mapped to more than one characters, use the procedures with the same name in @code{gauche.unicode} module (@pxref{Full string case conversion}). @c JP 一文字がケース変換によって複数文字になるような場合も考慮したい場合は、 @code{gauche.unicode}モジュールに定義されている同名の手続きを使ってください (@ref{Full string case conversion}参照)。 @c COMMON @c EN The linear-update version @code{string-titlecase!}, @code{string-upcase!} and @code{string-downcase!} destroys @var{s} to store the result. Note that in Gauche, using those procedures doesn't save anything, since string mutation is expensive by design. They are provided merely for completeness. @c JP @code{string-titlecase!}、@code{string-upcase!}、 @code{string-downcase!}はその場で更新するバージョンで、@var{s}を破壊的に 変更します。ただし、Gaucheでは文字列の変更は新たな文字列を作るのと効率的に 何ら変わりがありません。これらの手続きは互換性のためだけに用意されています。 @c COMMON @end defun @node SRFI-13 String reverse & append, SRFI-13 String mapping, SRFI-13 String case mapping, String library @subsection String reverse & append @c NODE 文字列の反転と追加 @defun string-reverse s :optional start end @defunx string-reverse! s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Returns a string in which the character positions are reversed from @var{s}. @code{string-reverse!} modifies @var{s}. @c JP @var{s}の文字の位置を逆順にした文字列を返します。 @code{string-reverse!}は@var{s}そのものを変更します。 @c COMMON @example (string-reverse "mahalo") @result{} "olaham" (string-reverse "mahalo" 3) @result{} "ola" (string-reverse "mahalo" 1 4) @result{} "aha" (let ((s (string-copy "mahalo"))) (string-reverse! s 1 5) s) @result{} "mlahao" @end example @end defun @defun string-concatenate string-list [SRFI-13] @c MOD srfi.13 @c EN Concatenates list of strings. @c JP 文字列のリストを連結します。 @c COMMON @example (string-concatenate '("humuhumu" "nukunuku" "apua" "`a")) @result{} "humuhumunukunukuapua`a" @end example @end defun @defun string-concatenate/shared string-list @defunx string-append/shared s @dots{} [SRFI-13] @c MOD srfi.13 @c EN ``Shared'' version of @code{string-concatenate} and @code{string-append}. In Gauche, these are just synonyms of them. @c JP @code{string-concatenate}と@code{string-append}の``共有'' バージョンです。Gaucheでは、これらは単に別名です。 @c COMMON @end defun @defun string-concatenate-reverse string-list @defunx string-concatenate-reverse/shared string-list [SRFI-13] @c MOD srfi.13 @c EN Reverses @var{string-list} before concatenation. ``Shared'' version works the same in Gauche. @c JP @var{string-list}を連結する前に逆順にします。 Gaucheでは、``共有''バージョンは全く同じ動作をします。 @c COMMON @end defun @node SRFI-13 String mapping, SRFI-13 String rotation, SRFI-13 String reverse & append, String library @subsection String mapping @c NODE 文字列のマッピング @defun string-map! proc s :optional start end [SRFI-13] @c MOD srfi.13 @c EN @code{string-map!} applies @var{proc} on every character of @var{s}, and stores the results into @var{s}. It is an error if @var{proc} returns non-character. @c JP @code{string-map!}は、@var{s}の全ての文字に対して@var{proc}を 適用し、その結果を@var{s}に格納します。 @var{proc}は文字を返さねばなりません。 @c COMMON @example (let ((s (string-copy "wikiwiki"))) (string-map! char-upcase s 4) s) @result{} "wikiWIKI" @end example @end defun @defun string-fold kons knil s :optional start end @defunx string-fold-right kons knil s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Like @var{fold} and @var{fold-right} (@pxref{Walking over lists}), but works on a string instead of a list. @c JP 文字列に対して動作する@var{fold}や@var{fold-right} (@ref{Walking over lists}参照) です。 @c COMMON @example (string-fold cons '() "abcde") @result{} (#\e #\d #\c #\b #\a) (string-fold-right cons '() "abcde") @result{} (#\a #\b #\c #\d #\e) @end example @end defun @defun string-for-each-index proc s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Call @var{proc} on each index of the string @var{s}, from left to right. The result of @var{proc} is discarded. The optional @var{start} and @var{end} arguments can be an integer index or a string cursor, restricting the range of the input string to be traversed. @c JP @var{proc}を@var{s}の各文字について、左から右の順に呼びます。@var{proc}の結果は 捨てられます。 省略可能な@var{start}と@var{end}引数は整数の文字インデックスか 文字列カーソルで、対象となる文字列の範囲を制限します。 @c COMMON @end defun @node SRFI-13 String rotation, SRFI-13 Other string operations, SRFI-13 String mapping, String library @subsection String rotation @c NODE 文字列のローテーション @defun xsubstring s from :optional to start end [SRFI-13] @c MOD srfi.13 @c EN Takes a substring of infinite repetition of string @var{s} between index @var{from} (inclusive) and index @var{to} (exclusive). If @var{to} is omitted, the length of @var{s} is assumed. @c JP @var{s}が左右に無限に繰り替えされているとみなし、その整数インデックス の@var{from}から@var{to}までを切り出して返します。 @var{to}が省略された場合は@var{s}の長さが使われます。 @c COMMON @c EN For example, if @var{s} is @code{"abcde"}, we repeat it infinitely to both sides. So @var{5n}-th character for integer @var{n} is always @code{#\a}, which extends negative @var{n} as well. @c JP 例えば、@var{s}が@code{abcde}の場合、まずそれを無限の 文字列@code{...abcdeabcdeabcde...}とみなします。 つまり整数@var{n}に対して@var{5n}番目の文字は常に@code{#\a}です。 これは@var{n}が負の領域にも拡張されます。 @c COMMON @example (xsubstring "abcde" 2 10) @result{} "cdeabcde" (xsubstring "abcde" -9 -2) @result{} "bcdeabc" @end example @c EN The optional @var{start} and @var{end} arguments can be an integer index or a string cursor, it works as @code{(xsubstring (substring s start end) from to)}. @c JP 省略可能な@var{start}と@var{end}引数は整数の文字インデックスか 文字列カーソルで、与えられた場合、 @code{(xsubstring (substring s start end) from to)}と同じ動作となります。 @c COMMON @end defun @defun string-xcopy! target tstart s sfrom :optional sto start end [SRFI-13] @c MOD srfi.13 @c EN It works as @code{(string-copy! target tstart (xsubstring s sfrom sto start end))}. @c JP @code{(string-copy! target tstart (xsubstring s sfrom sto start end))} と同じ動作をします。 @c COMMON @end defun @node SRFI-13 Other string operations, SRFI-13 String filtering, SRFI-13 String rotation, String library @subsection Other string operations @c NODE 他の文字列操作 @defun string-replace s1 s2 start1 end1 :optional start2 end2 [SRFI-13] @c MOD srfi.13 @c EN Returns a new string whose content is a copy of a string @var{s1}, except the part beginning from the index @var{start1} (inclusive) and ending at the index @var{end1} (exclusive) is replaced by a string @var{s2}. When optional @var{start2} and @var{end2} arguments are given, @var{s2} is trimmed first according to them. The size of the @emph{gap}, @code{(- @var{end1} @var{start1})}, doesn't need to be the same as the size of the inserted string. Effectively, this is the same as the following code. @c JP 文字列@var{s1}の@var{start1}文字目(inclusive)から@var{end1}文字目(exclusive) までを文字列@var{s2}に置き換えた文字列を新たに作って返します。@var{s1}, @var{s2}は 変更されません。 オプショナルな引数@var{start2}、@var{end2}が与えられた場合は、 @var{s2}がまずそれらによって切り取られて置換文字列として使われます。 置き換える隙間の大きさ、つまり@code{(- @var{end1} @var{start1})}は @var{s2}と同じ長さである必要はありません。 実質的に、この手続きは次のコードと等価です。 @c COMMON @example (string-append (substring s1 0 start1) (substring s2 start2 end2) (substring s1 end1 (string-length s1))) @end example @end defun @defun string-tokenize s :optional token-set start end [SRFI-13] @c MOD srfi.13 @c EN Splits the string @var{s} into a list of substrings, where each substring is a maximal non-empty contiguous sequence of characters from the character set @var{token-set}. The default of @var{token-set} is @code{char-set:graphic} (@pxref{Predefined character sets}). See also Gauche's built-in @code{string-split} (@pxref{String utilities}), which provides similar features but different criteria. @c JP 文字列 @var{s} を、@var{token-set} で指定される文字集合で 構成される、空でない最大限連続した文字のシーケンスのそれぞれを 要素とするリストを返します。 @var{token-set} のデフォルト値は @code{char-set:graphic} (@ref{Predefined character sets}参照)。 同様の機能を提供する、しかし異なる基準を持つ、Gauche の組み込み手続き @code{string-split} (@ref{String utilities} 参照) も見て下さい。 @c COMMON @end defun @node SRFI-13 String filtering, SRFI-13 Low-level string procedures, SRFI-13 Other string operations, String library @subsection String filtering @c NODE 文字列のフィルタリング @defun string-filter char/char-set/pred s :optional start end @defunx string-delete char/char-set/pred s :optional start end [SRFI-13] @c MOD srfi.13 @c EN Returns a string consists of characters in a string @var{s} that passes (or don't pass) the test indicated by @var{char/char-set/pred}, respectively. @c JP それぞれ、文字列@var{s}中の文字のうち@var{char/char-set/pred}で示される テストを通る、または通らない文字からなる文字列を返します。 @c COMMON @example (string-filter char-upper-case? "Hello, World!") @result{} "HW" (string-delete char-upper-case? "Hello, World!") @result{} "ello, orld!" (string-delete #\l "Hello, World!") @result{} "Heo, Word!" (string-filter #[\w] "Hello, World!") @result{} "HelloWorld" @end example @c EN Note: SRFI-13 was revised after finalization to switch the order of arguments @var{char/char-set/pred} and @var{s} was. At the time of finalization, the order was @code{(string-filter s pred)} and Gauche implemented it accordingly. However, most existing implementations follows the revised order, since that was what the SRFI-13 reference implementation had. So, from 0.9.4, we revised the API to comply the current SRFI-13 spec, but we also accept the old order as well not to break the old code. We recommend the new code to use the new order. @c JP 註: SRFI-13は制定後に改訂され、引数@var{char/char-set/pred}と@var{s}の 順序が逆になりました。制定時点では引数順は @code{(string-filter s pred)}で、Gaucheもそれに従って実装していました。 しかし既存の実装のほとんどは@code{(string-filter pred s)}という順序に なっています。SRFI-13の参照実装がそうだったからです。 0.9.4からGaucheも現在のSRFI-13の実装に合わせましたが、 以前の仕様で書かれたコードとの互換性を保つため、 引数順を逆にしても動作するようになっています。 新しく書かれるコードは、現在のSRFI-13の引数順を使うのが良いでしょう。 @c COMMON @end defun @node SRFI-13 Low-level string procedures, , SRFI-13 String filtering, String library @subsection Low-level string procedures @c NODE 低レベルな文字列に関する手続き @c EN Here are some helper procedures useful to write other string-processing utilities similar to SRFI-13: @c JP SRFI-13に似せた他の文字列処理ユーティリティを書くのに便利なヘルパー関数です。 @c COMMON @defun string-parse-start+end proc s args @defunx string-parse-final-start+end proc s args [SRFI-13] @c MOD srfi.13 @c EN Most SRFI-13 procedures takes optional start and end arguments. These procedures looks for them in the rest arguments @var{args}, and if they're not provided, gives the default values. @c JP 多くのSRFI-13の手続きは、省略可能引数としてstartとend引数を取ります。 この手続きは、残余引数リスト@var{args}にstartとendが指定されているかを調べ、 指定されていればそれらを、されていなければ適切なデフォルト値を返します。 @c COMMON @c EN The @var{proc} argument is the name (symbol) of the procedure, to be used in the error condition, and @var{s} is the string to be processed. @c JP @var{proc}はエラー通知に使われる手続きの名前 (シンボル)、 @var{s}は処理すべき文字列です。 @c COMMON @c EN Both expects an optional @var{start} argument at the beginning of @var{args}, followed by an optional @var{end} argument. If the @var{end} argument is missing, the length of @var{s} is assumed. If the @var{start} argument is also missing, @code{0} is assumed. If arguments are provided, they must be exact integers, and @code{0} <= @var{start} <= @code{end} <= @code{(string-length @var{s})} must be satisfied; otherwise, an error is signaled. @c JP どちらの手続きも、@var{args}の最初に@var{start}引数があり、その次に@var{end}引数が あることを期待します。@var{end}引数が省略されていた場合は@var{s}の長さが、 @var{start}引数も省略されていた場合は@code{0}が使われます。 引数が与えられた場合は、それらは正確な整数で @code{0} <= @var{start} <= @code{end} <= @code{(string-length @var{s})} を満たしていなければなりません。そうでなければエラーが投げられます。 @c COMMON @c EN If more than two arguments are in @var{args}, @code{string-parse-final-start+end} raises an error (in other words, it requires that the argument list end with the @var{end} argument at most), while @code{string-parse-start+end} permits it and returns the result of arguments, along with start and end indexes. @c JP @var{args}に二つ以上の引数が含まれていた場合、 @code{string-parse-final-start+end}はエラーを通知します (つまり、最長でも引数リストが@var{end}引数で終わる場合に使えます)。 一方、@code{string-parse-start+end}は、余分な引数を許し、それを start/endの値とともに返します。 @c COMMON @c EN Both function return three values: The rest of the argument list, the start index, and the end index. @c JP どちらの関数も3つの値を返します。余分な引数のリスト、startの値、endの値です。 @c COMMON @end defun @defmac let-string-start+end (start end [rest]) proc-exp s-exp args-exp body @dots{} [SRFI-13] @c MOD srfi.13 @end defmac @defun check-substring-spec proc s start end @defunx substring-spec-ok? s start end [SRFI-13] @c MOD srfi.13 @end defun @defun make-kmp-restart-vector s :optional c= start end [SRFI-13] @c MOD srfi.13 @end defun @defun kmp-step pat rv c i c= p-start [SRFI-13] @c MOD srfi.13 @end defun @defun string-kmp-partial-search pat rv s i :optional c= p-start s-start s-end [SRFI-13] @c MOD srfi.13 @end defun @c ---------------------------------------------------------------------- @node Time data types and procedures, Sources of random bits, String library, Library modules - SRFIs @section @code{srfi.19} - Time data types and procedures @c NODE 時間のデータ型と手続き, @code{srfi.19} - 時間のデータ型と手続き @deftp {Module} srfi.19 @mdindex srfi.19 @c EN This SRFI defines various representations of time and date, and conversion methods among them. @c JP このSRFIは、時間と日付に関する様々な表現と、それらの間の変換メソッドを提供します。 @c COMMON @c EN On Gauche, time object is supported natively by @code{