@node Programming in Gauche, Core syntax, Concepts, Top @chapter Programming in Gauche @c NODE Gaucheでのプログラミング @menu * Invoking Gosh:: * Interactive development:: * Writing Scheme scripts:: * Debugging:: * Platform-dependent features:: * Profiling and tuning:: * Auxiliary programs:: * Writing Gauche modules:: * Using extension packages:: * Building standalone executables:: @end menu @node Invoking Gosh, Interactive development, Programming in Gauche, Programming in Gauche @section Invoking Gosh @c NODE Gaucheを起動する @c EN Gauche can be used either as an independent Scheme scripting engine or as an embedded Scheme library. An interactive interpreter which comes with Gauche distribution is a program named @code{gosh}. @c JP Gaucheは独立したSchemeスクリプティングエンジンとしても、組み込みのSchemeライブラリとしても 使うことができます。Gaucheのディストリビューションには、@code{gosh}という インタラクティブなインタプリタが附属しています。 @c COMMON @deftp {Program} gosh [options] [scheme-file arg @dots{}] @c EN Gauche's interpreter. Without @var{scheme-file}, @code{gosh} works interactively, i.e. it reads a Scheme expression from the standard input, evaluates it, and prints the result, and repeat that until it reads EOF or is terminated. @c JP Gaucheのインタプリタです。 @var{scheme-file}が与えられなければ、 @code{gosh}はインタラクティブに動作します。すなわち、標準入力からScheme式を読み込み、 それを評価して結果をプリントするという動作を、EOFを読むか明示的に終了させられるまで 続けます。 @c COMMON @c EN If @code{gosh} is invoked without @var{scheme-file}, but the input is not a terminal, it enters read-eval-print loop but not writes out a prompt while waiting input form. This is useful when you pipe Scheme program into @code{gosh}. You can force this behavior or suppress this behavior by @code{-b} and @code{-i} options. @c JP もし@var{scheme-file}が与えられておらず、しかし入力が端末でない場合、 @code{gosh}はread-eval-printループに入りますが、入力待ちの際にプロンプトを 表示しません。これはScheme式をパイプで@var{gosh}に処理させる場合に便利です。 @code{-b}または@code{-i}オプションでこの動作を強制的にonまたはoffできます。 @c COMMON @c EN If @var{scheme-file} is specified, @code{gosh} runs it as a Scheme program and exit. @xref{Writing Scheme scripts}, for details. @c JP @var{scheme-file}が与えられた場合、@code{gosh}はそれをSchemeプログラムとして ロードし、終了します。この動作に関しては@ref{Writing Scheme scripts}を参照して 下さい。 @c COMMON @end deftp @menu * Gosh command-line options:: * Environment variables:: * Windows-specific executable:: @end menu @node Gosh command-line options, Environment variables, Invoking Gosh, Invoking Gosh @subsection Command-line options @c NODE コマンドラインオプション @c EN The following command line options are recognized by @code{gosh}. The first command line argument which doesn't begin with `@minus{}' is recognized as the script file. If you want to specify a file that begins with a minus sign, use a dummy option `@code{--}'. @c JP @code{gosh}には以下のようなコマンドラインオプションがあります。 `@minus{}' で始まらない最初のコマンドライン引数がスクリプトファイルと認識されます。 スクリプトファイル名が `@minus{}' で始まっている可能性がある場合は、ダミーオプション `@code{--}' をスクリプトファイル名の前に置いて下さい。 @c COMMON @deftp {Command Option} -I path @c EN Prepends @var{path} to the load path list. You can specify this option more than once to add multiple paths. @c JP @var{path}をロードパスのリストの最初に加えます。このオプションは複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -A path @c EN Appends @var{path} to the tail of the load path list. You can specify this option more than once to add multiple paths. @c JP @var{path}をロードパスのリストの末尾に加えます。このオプションは複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -q @c EN Makes @code{gosh} not to load the default initialization file. @c JP @code{gosh}が起動時にシステムの初期化ファイルをロードしないようにします。 @c COMMON @end deftp @deftp {Command Option} -V @c EN Prints the @code{gosh} version, and various configuration information (SRFI-176). See @code{version-alist} for the details of configuration parameters @pxref{Environment inquiry}. You can control what info to be shown by the environment variable @code{GAUCHE_VERSION_INFO_EXCLUSION} (@pxref{Environment variables}). section below. @c JP @code{gosh}のバージョンおよび様々なコンフィグレーション情報を表示します (SRFI-176)。コンフィグレーション情報については@code{version-alist}を見てください (@ref{Environment inquiry})。 どういった情報を表示するかは、環境変数@code{GAUCHE_VERSION_INFO_EXCLUSION}で カスタマイズできます。@ref{Environment variables}参照。 @c COMMON @end deftp @deftp {Command Option} -v version @c EN If @var{version} is not the running @code{gosh}'s version, execute the specified version of @code{gosh} instead if it is installed. This is useful when you want to invoke specific version of Gauche. Note that @var{version} must be 0.9.6 or later. @c JP @var{version}が実行された@code{gosh}のバージョンでなく、かつ指定されたバージョンの Gaucheがシステムにインストールされていた場合、指定バージョンの@code{gosh}をかわりに起動します。 これは、Gaucheのバージョンを特定して実行したい場合に便利です。 なお、この機能で指定できる@var{version}は0.9.6かそれ以降のみです。 @c COMMON @c EN If the specified version isn't installed on the system, @code{gosh} exits with a message. If you add @code{:} before @var{version}, however, @code{gosh} falls back to itself when it can't find the given version. @c JP 指定のバージョンのGaucheがシステムにインストールされていない場合、@code{gosh}は メッセージを出して終了します。これを避けたい場合、@var{version}の前に@code{:}を 加えると、Gaucheは指定バージョンが見つからない場合は自分自身の実行を続けます。 @c COMMON @example # Suppose you don't have version 0.9.13 on your machine. $ gosh -v 0.9.13 No installed Gauche with version 0.9.13 under /usr/lib/. $ gosh -v :0.9.13 WARNING: No installed Gauche with version 0.9.13 under /usr/lib/. Using the current version. gosh$ (gauche-version) "0.9.15" @end example @end deftp @deftp {Command Option} -u module @c EN Use @var{module}. Before starting execution of @var{scheme-file} or entering the read-eval-print loop, the specified module is @var{use}d, i.e. it is loaded and imported (@xref{Defining and selecting modules}, for details of @code{use}). You can specify this option more than once to use multiple modules. @c JP 起動後、インタラクティブなread-eval-printループに入る前、もしくは@var{scheme-file} をロードする前に@var{module}を``use''します。つまりそのモジュールがロードされ インポートされます。(@code{use}の詳細については@ref{Defining and selecting modules}を参照して下さい。) このオプションは複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -l file @c EN Load @var{file} before starting execution of @var{scheme-file} or entering the read-eval-print loop. The file is loaded in the same way as @code{load} (@pxref{Loading Scheme file}). You can specify this option more than once to load multiple files. @c JP 起動後、インタラクティブなread-eval-printループに入る前、もしくは@var{scheme-file} をロードする前に@var{file}をロードします。ロードの詳細については@ref{Loading Scheme file} を参照して下さい。このオプションは複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -L file @c EN Load @var{file} like @code{-l}, but if @var{file} does not exist, this silently ignores it instead of reporting an error. This option can also be specified multiple times. @c JP @code{-l}オプションと同様に@var{file}をロードしますが、 @var{file}が見つからなかった場合はエラーを報告せずに黙って無視します。 このオプションも複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -e scheme-expression @c EN Evaluate @var{scheme-expression} before starting execution of @var{scheme-file} or entering the read-eval-print loop. Evaluation is done in the @var{interaction-environment} (@pxref{Eval and repl}). You can specify this option more than once to evaluate multiple expressions. @c JP 起動後、インタラクティブなread-eval-printループに入る前、もしくは@var{scheme-file} をロードする前に@var{scheme-expression}を評価します。評価は @var{interaction-environment}中で行われます(@ref{Eval and repl}参照)。 このオプションは複数指定できます。 @c COMMON @end deftp @deftp {Command Option} -E scheme-expression @c EN Same as -e, except the @var{scheme-expression} is read as if it is surrounded by parenthesis. For example: @c JP オプション-eとほぼ同じですが、@var{scheme-expression}は それが括弧で囲まれているかのように読まれます。 このオプションは複数指定できます。例: @c COMMON @example % gosh -umath.const -E"print (sin (* pi/180 15))" -Eexit 0.25881904510252074 @end example @end deftp @deftp {Command Option} -b @c EN Batch. Does not print prompts even if the input is a terminal. @c JP バッチ。入力が端末であってもプロンプトを出さないようにします。 @c COMMON @end deftp @deftp {Command Option} -i @c EN Interactive. Print prompts even if the input is not a terminal. @c JP インタラクティブ。入力が端末で無くてもプロンプトを出すようにします。 @c COMMON @end deftp @deftp {Command Option} -m module @c EN When a script file is given, this option makes the module named @var{module} in which the @code{main} procedure is looked for, instead of the @code{user} module. See @ref{Writing Scheme scripts} for the details of executing scripts. If the named module doesn't exist after loading the script, an error is signaled. This is useful to write a Scheme module that can also be executed as a script. @c JP スクリプトファイルが与えられた場合に、@code{main}手続きを 探すモジュールを指定します。デフォルトでは@code{user}モジュールが探されます。 スクリプトの実行について詳しくは@ref{Writing Scheme scripts}を見てください。 @var{module}で指定されたモジュールが、スクリプトファイルのロード後にも 存在しない場合は、エラーが報告されます。 このオプションは、スクリプトとしても使えるようなSchemeモジュールを書く際に便利です。 @c COMMON @end deftp @deftp {Command Option} -f compiler-option @c EN This option controls compiler and runtime behavior. For now we have following options available: @table @asis @item case-fold Ignore case for symbols. @xref{Case-sensitivity}. @item include-verbose Reports whenever a file is included. Useful to check precisely which files are included in what order. @item load-verbose Reports whenever a file is loaded. Useful to check precisely which files are loaded in what order. @item no-inline Prohibits the compiler from inlining procedures and constants. Equivalent to no-inline-globals, no-inline-locals, no-inline-constants and no-inline-setters combined. @item no-inline-constants Prohibits the compiler from inlining constants. @item no-inline-globals Prohibits the compiler from inlining global procedures. @item no-inline-locals Prohibits the compiler from inlining local procedures. @item no-inline-setters Prohibits the compiler from inlining setters. @item no-lambda-lifting-pass Prohibits the compiler from running lambda-lifting pass. @item no-post-inline-pass Prohibits the compiler from running post-inline optimization pass. @item no-source-info Don't keep source information for debugging. Consumes less memory. @item safe-string-cursors String cursors used on wrong strings will raise an error. This may catch bugs but decreases performance because all cursors will be allocated on heap. @xref{String cursors}. @item test This option allows you to run @code{gosh} when you build it, without installing it. If given, this adds @code{../lib}, @code{../libsrc}, and @code{../src}, relative to the place @code{gosh} is, to the load path before loading initialization file. @item warn-legacy-syntax Warns if the reader sees legacy hex-escape syntax in string literals. @xref{Reader lexical mode}. @xref{Case-sensitivity}. @end table @c JP このオプションはコンパイラとランタイムの動作に影響を与えます。 今のところ、次のオプションのみが@var{compiler-option}として有効です。 @table @asis @item case-fold シンボルの大文字小文字を区別しません。 @ref{Case-sensitivity} を参照して下さい。 @item include-verbose ファイルがincludeされる時にそれを報告します。 正確にどのファイルがどういう順序でincludeされているかを調べるのに便利です。 @item load-verbose ファイルがロードされる時にそれを報告します。 正確にどのファイルがどういう順序でロードされているかを調べるのに便利です。 @item no-inline 一切のインライン展開を行いません。このオプションは以下の no-inline-globals、 no-inline-locals、no-inline-constants、no-inline-setters を同時に指定したのと等価です。 @item no-inline-constants 定数のインライン展開を行ないません。 @item no-inline-globals 大域(global)関数のインライン展開を展開を行ないません。 @item no-inline-locals 局所(local)関数のインライン展開を展開を行ないません。 @item no-inline-setters セッター関数のインライン展開を行いません。 @item no-lambda-lifting-pass lambda lifting最適化パスを抑止します。 @item no-post-inline-pass インライン展開後に再び最適化パスを走らせるのを抑止します。 @item no-source-info デバッグのためのソースファイル情報を保持しません。メモリの使用量は小さくなります。 @item safe-string-cursors 文字列カーソルをそのカーソルが作られた文字列以外の文字列に使おうとした時に エラーを投げます。バグを検出できますが、文字列カーソルが常にヒープアロケートされる ので性能は低下します。@ref{String cursors}参照。 @item test Gaucheをソースツリーからコンパイルしたまま、 インストールせずに実行するためのオプションです。 このオプションが指定されると、@code{gosh}は初期化ファイルを読む前に、 @code{gosh}のあるディレクトリからの相対パスで @code{../lib}、@code{../libsrc}、@code{../src} をロードパスに加えます。 @item warn-legacy-syntax 文字列リテラル中に古い形式の16進数エスケープ形式があったら警告します。 @ref{Reader lexical mode} を参照して下さい。 @end table @c COMMON @end deftp @deftp {Command Option} -p profiler-option @c EN Turn on the profiler. The following @var{profiler-option} is recognized: @c JP プロファイラを有効にします。以下のような@var{profiler-option}が 今のところサポートされています。 @c COMMON @table @code @item time @c EN Records and reports time spent on function calls and number of times each function is called. @c JP 関数中で費された時間と、各関数が呼ばれた回数を記録して報告します。 @c COMMON @item load @c EN Records and reports time spent on loading each modules. Useful to tune start-up time of the scripts. (Results are in elapsed time). @c JP 各モジュールをロードするのにかかった時間を記録して報告します。 スクリプトの起動時間をチューンするのに便利です (実経過時間が報告されます)。 @c COMMON @end table @c EN See @ref{Using profiler} for the details of the profiler. @c JP 詳しくは@ref{Using profiler}を参照して下さい。 @c COMMON @end deftp @deftp {Command Option} -r standard-revision @c EN Start @code{gosh} with an environment of the specified revision of Scheme standard. Currently only 7 is supported as @var{standar-revision}. By default, @code{gosh} starts with @code{user} module, which inherits @code{gauche} module. That means you can use whole Gauche core procedures by default without explicitly declaring it. Proper R7RS code always begins with either @code{define-library} or R7RS-style @code{import} form, and Gauche recognizes it and automatically switch to R7RS environments so that R7RS scripts and libraries can be executed by Gauche without special options. However, users who are learning R7RS Scheme may be confused when the initial environment doesn't look like R7RS. By giving @code{-r7} option, @code{gosh} starts with @code{r7rs.user} module that extends the @code{r7rs} module, which defines two R7RS forms, @code{import} and @code{define-library}. If you invoke @code{gosh} into an interactive REPL mode with @code{-r7} option, all standard R7RS-small libraries (except @code{(scheme r5rs)}) are already imported for your convenience. @xref{Library modules - R7RS standard libraries}, for the details on how Gauche supports R7RS. (Note: The @code{-r7} option doesn't change reader lexical mode (@pxref{Reader lexical mode}) to @code{strict-r7}. That's because using @code{strict-r7} mode by default prevents many Gauche code from being loaded.) @c JP @code{gosh}を、指定されたリビジョンのScheme標準環境で起動します。 現在のバージョンでは@var{standard-revision}として7のみがサポートされます。 デフォルトでは、@code{gosh}起動時のモジュールは@code{user}モジュールで、 これは@code{gauche}モジュールを継承しています。すなわち、特に何も指定しないでも Gaucheのコア関数は全て使えるようになっています。 正しいR7RSプログラムは常に@code{define-library}フォームか R7RS式の@code{import}フォームで始まり、Gaucheはそれらを見つけると 自動的にR7RS環境へと切り替えるので、特になにもしなくても R7RSスクリプトやライブラリを使うことはできます。 しかし、R7RS Schemeを勉強中のユーザにとっては、最初に入る環境が R7RSでないと混乱してしまうかもしれません。 @code{-r7}オプションが与えられると、@code{gosh}は起動時のモジュールを @code{r7rs.user}モジュールにします。これは@code{r7rs}モジュールを継承した もので、@code{import}と@code{define-library}だけが定義されています。 @code{-r7}をつけた@code{gosh}を対話REPLとして起動した場合は、簡便のために @code{(scheme r5rs)}を除く全てのR7RS-smallライブラリが importされた状態になっています。 GaucheがR7RSをどのようにサポートしているかの詳細については @ref{Library modules - R7RS standard libraries}を参照してください。 (註: @code{-r7}オプションは、リーダ字句モードを@code{strict-r7}に 替えることはしません。@code{strict-r7}モードをデフォルトにすると、 多くのGaucheコードをロードすることができなくなるからです。リーダ字句モードについては @ref{Reader lexical mode}を参照してください。) @c COMMON @end deftp @deftp {Command Option} @code{--} @c EN When @code{gosh} sees this option, it stops processing the options and takes next command line argument as a script file. It is useful in case if you have a script file that begins with a minus sign, although it is not generally recommended. @c JP このオプションに出会うと、@code{gosh}はオプションの解析を止めて、その次の引数を 無条件に@var{scheme-file}であると見倣します。@var{scheme-file}がマイナス記号で 始まっている場合に必要です。 @c COMMON @end deftp @c EN The options -I, -A, -l, -u, -e and -E are processes in the order of appearance. For example, adding a load path by -I affects the -l and -u option after it but not before it. @c JP オプション-I, -A, -l, -u, -e 及び -E は、それらがコマンドライン引数として 出現した順に処理されます。例えば、-Iにより追加されるロードパスは それ以降の-lや-uオプションに影響を与えますが、それ以前のものには影響を 与えません。 @c COMMON @node Environment variables, Windows-specific executable, Gosh command-line options, Invoking Gosh @subsection Environment variables @c NODE 環境変数 @c EN The following environment variables are recognized: @c JP 以下の環境変数を認識します。 @c COMMON @deftp {Environment variable} GAUCHE_AVAILABLE_PROCESSORS @c EN You can get the number of system's processors by @code{sys-available-processors} (@pxref{Environment inquiry}); libraries/programs may use this info to optimize number of parallel threads. But you might change that, for testing and benchmarking---e.g. a program automatically uses 8 threads if there are 8 cores, but you might want to run it with 1, 2, 4 threads as well to see the effect of parallelization. This environment variable overrides the return value of @code{sys-available-processors}. @c JP @code{sys-available-processors} でシステムのプロセッサ数を 取得できます(@ref{Environment inquiry}参照)。 ライブラリやプログラムの中には、その数に基づいて並行に走るスレッド数を 調整するものがあります。けれども、テストやベンチマークでその数を 変えたいと思うことがあるかもしれません。例えば、8コア上では自動的に 8スレッド使うプログラムがあったとして、並列化の効果を見るためにその プログラムを1,2,4スレッドで走らせてベンチマークを取る、といった場合です。 この環境変数は、@code{sys-available-processors}が返す値を上書きします。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_CHECK_UNDEFINED_TEST @c EN Warn if @code{#} is used in the test expression of branch. In boolean context, @code{#} counts true. It is also often the case that a procedure returns @code{#} when the return value doesn't matter, and you shouldn't rely on the value that is supposed not to matter--the procedure may change the return value in future (which should be ok, since the value shouldn't have mattered), which can cause unintentional and hard-to-track bugs. @xref{Undefined values}, for the details. We strongly recommend users to turn on this warning. In future, we plan to make this default. @c JP @code{#}が条件式のテスト式に使われた場合に警告を出します。 真偽値判定では@code{#}は真とみなされます。しかし、 @code{#}を返す手続きはしばしば、 「戻り値に意味はない」ことを示すためにそれを返しています。 戻り値に意味がないなら、その値に依存したコードを書くべきではありません。 もし、手続きが将来、もともと意味が無いのだからと戻り値を変えた場合に、 @code{#}に依存してたコードは壊れる可能性があります。 詳しくは@ref{Undefined values}を参照してください。 この機能はなるべくONにしておくようにお勧めします。 将来はデフォルトで警告を出すようにする予定です。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_DYNLOAD_PATH @c EN You can specify additional load paths for dynamically loaded objects by this environment variable, delimiting the paths by '@code{:}'. The paths are appended before the system default load paths. @xref{Loading dynamic library}, for the details of how Gauche finds dynamically loadable objects. @c JP この変数によって、動的にロードするオブジェクト用の追加ロードパスを 指定できます。パスは '@code{:}' で区切ります。 この変数によって指定されたパスはシステムのデフォルトのロードパスの前に 連結されます。 Gaucheが動的にロードするオブジェクトファイルを探す方法については @ref{Loading dynamic library}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_EDITOR @deftpx {Environment variable} EDITOR @c EN This is used by @code{ed} procedure in @code{gauche.interactive} module. @xref{Interactive session}, for the details. @c JP これは@code{gauche.interactive}モジュールの@code{ed}手続きで使われます。 詳しくは@ref{Interactive session}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_HISTORY_FILE @c EN Specifies the filename where the REPL history is saved. If this environment variable is not set, history is saved in @file{~/.gosh_history}. If this environment variable is set but an empty string, history isn't saved. If the process is suid/sgid-ed, history won't be saved. @c JP REPLのヒストリがセーブされるファイル名を指定します。 この環境変数が定義されていなければ、ヒストリは@file{~/.gosh_history}にセーブされます。 この環境変数が定義されており、しかし空文字列だった場合はヒストリはセーブされません。 (また、プロセスがsuid/sgidされている場合もヒストリは保存されません)。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_KEYWORD_DISJOINT @deftpx {Environment variable} GAUCHE_KEYWORD_IS_SYMBOL @c EN These two environment variables affect whether keywords are treated as symbols or not. @xref{Keywords}, for the details. @c JP この二つの環境変数は、キーワードがシンボルとして扱われるかどうかに影響します。 詳しくは@ref{Keywords}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_LEGACY_DEFINE @c EN Make the behavior of toplevel @code{define} the same as 0.9.8 and before. It allows certain legacy programs that aren't valid R7RS. @xref{Into the Scheme-Verse}, for the details. @c JP トップレベルの@code{define}の振る舞いを0.9.8およびそれ以前のものに 合わせます。これは、厳密にはR7RSに従わない、古いコードを走らせる必要が ある場合に使ってください。詳しくは @ref{Into the Scheme-Verse}参照。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_LOAD_PATH @c EN You can specify additional load paths by this environment variable, delimiting the paths by '@code{:}'. The paths are appended before the system default load paths. @xref{Loading Scheme file}, for the details of how Gauche finds files to load. @c JP この環境変数によって、追加するロードパスを指定できます。 パスは '@code{:}' で区切ります。 この変数によって指定されたパスはシステムのデフォルトのロードパスの前に 連結されます。 GaucheがロードするSchemeファイルを見つける方法について詳しくは @ref{Loading Scheme file}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_MUTABLE_LITERALS @c EN Allow literal lists and vectors to be mutated. Such code isn't a valid Scheme program and causes an error, but Gauche didn't enforce the restriction on 0.9.9 and before, so some legacy code may accidentally mutates literals. Set this environment variables to run such old programs. @xref{Literals}, for the details. @c JP リテラルリストとリテラルベクタの改変を許します。 そういったコードは正しいSchemeプログラムではなく、今のGaucheはエラーを投げますが、 0.9.9とそれ以前のバージョンではリテラルリストとリテラルベクタの変更はチェックされて いませんでした。うっかりリテラルを変更してしまっている古いコードを走らせたい場合のみ この環境変数をセットしてください。詳しくは@ref{Literals}参照。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_NO_READ_EDIT @c EN Disable line-editor on REPL prompt, even the terminal is capable. You can also turn it off with @code{-fno-read-edit} command-line option, or @code{,edit off} toplevel commands during REPL session. @xref{Interactive development}, for the details of line editing. @c JP REPLプロンプトでの行編集機能をオフにします。 行編集機能はまた、@code{-fno-read-edit}コマンドラインオプションや、 REPLセッション中の @code{,edit off} トップレベルコマンドでも切ることができます。 詳しくは@ref{Interactive development}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_QUASIRENAME_MODE @c EN This affects @code{quasirename} behavior, to keep the backward compatibility with 0.9.7 and before. @xref{Explicit-renaming macro transformer}, for the details. @c JP これは@code{quasirename}の振る舞いに影響を与え、 0.9.7以前との互換性のために使われます。詳しくは @ref{Explicit-renaming macro transformer}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_REPL_NO_PPRINT @c EN This is used by @code{gauche.interactive} module to suppress pretty-printing on REPL prompt. @xref{Interactive development}, for the details. @c JP これはREPLプロンプトでプリティプリントを抑制するために @code{gauche.interactive}で使われます。 詳しくは@ref{Interactive development}を参照してください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_SUPPRESS_WARNING @c EN Suppress system warnings (@code{WARNING: ...}). Not generally recommended; use only if you absolutely need to. @c JP システムの警告(@code{WARNING: ...})を抑止します。気軽に使うべきではありません。 どうしても必要な場合のみ使ってください。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_TEST_RECORD_FILE @c EN This is used by @code{gauche.test} module (@pxref{Unit testing}). If defined, names a file the test processes keep the total statistics. @c JP @code{gauche.test}モジュールで使われます(@ref{Unit testing}参照)。 定義されていた場合、その値を名前とするファイルにテストの統計が記録されます。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_TEST_REPORT_ERROR @c EN This is used by @code{gauche.test} module (@pxref{Unit testing}). If defined, reports stack trace to stderr when the test thunk raises an error (even when it is expected). Useful for diagnosis of unexpected errors. @c JP @code{gauche.test}モジュールで使われます(@ref{Unit testing}参照)。 定義されていた場合、テストのthunkがエラーを報告した場合に、 スタックトレースを標準エラー出力に表示します (エラーがもともと期待されているテストでも出力されます)。 予想外のエラー発生の原因を調べるのに便利です。 @c COMMON @end deftp @deftp {Environment variable} GAUCHE_VERSION_INFO_EXCLSION @c EN The value must be a comma-separated keys in @code{version-alist} (@pxref{Environment inquiry}). The keys listed here are excluded from the output of @code{gosh -V}. For example, the following setting omits @code{scheme.path} and @code{build.configure} from output of @code{gosh -V}. Those values may contain username and/or project names, and there may be cases when you don't want make them to be public accidentally, by attaching output of @code{gosh -V} to a bug report or something. @c JP 値は@code{version-alist}に現れるキーをコンマ区切りで並べたものです (@ref{Environment inquiry}参照)。ここに挙げられたキーは、@code{gosh -V} の出力から除外されます。例えば次の設定は、@code{gosh -V}の出力に @code{scheme.path}と@code{build.configure}を含めません。 これらの値はユーザ名やプロジェクト名を含んでいる場合がありますが、 バグレポート等に@code{gosh -V}の結果を含める時に、 それらをうっかり公開してしまわないようにしたい、という場合などに便利です。 @c COMMON @example GAUCHE_VERSION_INFO_EXCLUSION=scheme.path,build.configure @end example @end deftp @deftp {Environment variable} TMP @deftpx {Environment variable} TMPDIR @deftpx {Environment variable} TEMP @deftpx {Environment variable} USERPROFILE @c EN These may affect the return value of @code{sys-tmpdir}. Different environment variables may be used on different platforms. @xref{Pathnames}, for the details. @c JP これらは@code{sys-tmpdir}の返り値に影響を与えます。プラットフォームによって 参照される環境変数は異なります。@ref{Pathnames}を参照してください。 @c COMMON @end deftp @node Windows-specific executable, , Environment variables, Invoking Gosh @subsection Windows-specific executable @c NODE Windows特有の実行ファイル @c EN On Windows-native platforms (mingw), two interpreter executables are installed. @code{gosh.exe} is compiled as a Windows console application and works just like ordinary @code{gosh}; that is, it primarily uses standard i/o for communication. Another executable, @code{gosh-noconsole.exe}, is compiled as a Windows no-console (GUI) application. It is not attached to a console when it is started. Its standard input is connected to the @code{NUL} device. Its standard output and standard error output are special ports which open a new console when something is written to them for the first time. (NB: This magic only works for output via Scheme ports; direct output from low-level C libraries will be discarded.) @c JP Windowsネイティブ環境(mingw)では、インタプリタとしてふたつの 実行ファイルがインストールされます。 @code{gosh.exe}はWindowsコンソールアプリケーションとしてコンパイルされ、 普通の@code{gosh}のように、標準入出力を第一の通信手段とします。 もう一つの実行ファイル@code{gosh-noconsole.exe}はWindows非コンソールアプリケーション としてコンパイルされています。こちらは起動時にコンソールに接続されません。 標準入力は@code{NUL}デバイスに接続されます。標準出力と標準エラー出力は 特殊なポートに接続され、最初に書き込みがあった時点で新たなコンソールが作られて 出力されます。(このトリックはSchemeポート経由の出力のみで動きます。 低レベルのCライブラリが標準出力や標準エラー出力に直接書き出したデータは捨てられます)。 @c COMMON @c EN The main purpose of @code{gosh-noconsole.exe} is for Windows scripting. If a Scheme script were associated to @code{gosh.exe} and invoked from Explorer, it would always open a new console window, which is extremely annoying. If you associate Scheme scripts to @code{gosh-noconsole.exe} instead, you can avoid console from popping up. @c JP @code{gosh-noconsole.exe}の目的は、Windows上でのスクリプティングです。 Schemeスクリプトがもし@code{gosh.exe}に関連付けられていたとしたら、 Explorerからそのスクリプトを起動するたびに、 必ず新しいコンソールウィンドウが開くので非常に煩わしいです。 Schemeスクリプトを@code{gosh-noconsole.exe}に 関連づけておけば、この煩わしいコンソールの出現を抑制できます。 @c COMMON @c EN If you're using the official Windows installer, Scheme scripts (@file{*.scm}) have already associated to @code{gosh-noconsole.exe} and you can invoke them by double-clicking on Explorer. Check out some examples under @file{C:\Program Files\Gauche\examples}. @c JP Windows版のオフィシャルのインストーラを使ってGaucheをインストールしたなら、 Schemeスクリプト(@file{*.scm})は既に@code{gosh-noconsole.exe}に 関連づけられているので、ExplorerからSchemeスクリプトをダブルクリックすれば Schemeプログラムを走らせることができます。 @file{C:\Program Files\Gauche\examples}の下にいくつかサンプルが あります @c COMMON @c ---------------------------------------------------------------------- @node Interactive development, Writing Scheme scripts, Invoking Gosh, Programming in Gauche @section Interactive development @c NODE インタラクティブな開発 @c EN When @code{gosh} is invoked without any script files, it goes into interactive read-eval-print loop (REPL). @c JP スクリプトファイルが与えられなかった場合、 @code{gosh}はインタラクティブなread-eval-printループ(REPL)に入ります。 @c COMMON @c EN To exit the interpreter, type EOF (usually Control-D in Unix terminals) or evaluate @code{(exit)}. @c JP インタプリタを終了するには、EOF文字(Unix端末では通常Control-D)をタイプするか、 @code{(exit)}を評価します。 @c COMMON @c EN In the interactive session, @code{gosh} loads and imports @code{gauche.interactive} module (@pxref{Interactive session}) into @code{user} module, for the convenience. Also, if there's a file @file{.gaucherc} under the user's home directory. You may put settings there that would help interactive debugging. (As of Gauche release 0.7.3, @file{.gaucherc} is no longer loaded when @code{gosh} is run in script mode.) Note that @file{.gaucherc} is always loaded in the @code{user} module, even if @code{gosh} is invoked with @code{-r7} option. The file itself is a Gauche-specific feature, so you don't need to consider portability in it. @c JP インタラクティブセッションでは、@code{gosh}は @code{gauche.interactive}モジュールをロードして@code{user}モジュールにインポートします (@ref{Interactive session}参照)。 また、ユーザーのホームディレクトリに@file{.gaucherc}という ファイルがあればそれもロードされます。 インタラクティブデバッグに便利な設定をそこに書いておくことができます。 (Gauche release 0.7.3から、@file{.gaucherc}はgoshがスクリプトモードで 起動された時は読まれなくなりました。) @code{.gaucherc}は常に@code{user}モジュールへとロードされます (@code{gosh}が@code{-r7}オプションつきで起動されていてもそうです)。 @code{.gaucherc}を自動で読み込む、という機能自体がGauche特有の機能ですから、 そこでポータビリティを考慮する必要はないわけです。 @c COMMON @c EN I recommend you to run @code{gosh} inside Emacs, for it has rich features useful to interact with internal Scheme process. Put the following line to your @file{.emacs} file: @example (setq scheme-program-name "gosh -i") @end example And you can run @code{gosh} by @key{M-x run-scheme}. @c JP @code{gosh}をEmacs内部で走らせることをお勧めします。 EmacsはSchemeサブプロセスを操作するための豊富な機能を持っています。 次の行を@file{.emacs}に加えておくと、@key{M-x run-scheme} で Emacsのバッファ内で@code{gosh}が走ります。 @example (setq scheme-program-name "gosh -i") @end example @c COMMON @c EN If you run @code{gosh} in the terminal with capability of cursor control, a basic line-editing feature is available in the REPL session. @xref{Input editing}, for the details. @c JP カーソル制御可能な端末で@code{gosh}を走らせた場合、 REPLセッションで簡単な行編集が使えます。 詳しくは@ref{Input editing}を参照してください。 @c COMMON @c EN If you want to use multibyte characters in the interaction, make sure your terminal's settings is in sync with @code{gosh}'s internal character encodings. @c JP 対話環境でマルチバイト文字を使う場合は、端末の文字エンコーディングを@code{gosh}の 内部エンコーディングと合わせるようにして下さい。 @c COMMON @menu * Working in REPL:: * Input editing:: @end menu @node Working in REPL, Input editing, Interactive development, Interactive development @subsection Working in REPL @c NODE REPLでの開発 @c EN When you enter REPL, Gauche prompts you to enter a Scheme expression: @c JP REPLに入ると、Gaucheはプロンプトを出してScheme式の入力を待ちます。 @c COMMON @example gosh> @end example @c EN (If you enable input editing, the prompt shows @code{gosh$} instead of @code{gosh>}. @xref{Input editing}, for the details.) @c JP (入力編集機能をオンにしている場合は、プロンプトが@code{gosh>}ではなく @code{gosh$}になります。詳しくは@ref{Input editing}を参照してください。) @c COMMON @c EN After you complete a Scheme expression and type ENTER, the result of evaluation is printed. @c JP 完全なScheme式を入力してENTERをタイプすると、そのS式の評価結果が表示されます。 @c COMMON @example gosh> @i{(+ 1 2)} 3 gosh> @end example @c EN The REPL session binds the last three results of evaluation in the global variables @code{*1}, @code{*2} and @code{*3}. You can use the previous results via those history variables in subsequent expressions. @c JP REPLセッションは、過去3回分の評価結果をグローバル変数 @code{*1}、@code{*2}、@code{*3} に束縛します。これらのヒストリ変数を 使って、以前の結果を後続の式の中で使えます。 @c COMMON @example gosh> @i{*1} 3 gosh> @i{(+ *2 3)} 6 @end example @c EN If the Scheme expression yields multiple values (@pxref{Multiple values}), they are printed one by one. @c JP Scheme式が複数の値を返した場合 (@ref{Multiple values}参照)は、各値が順に表示されます。 @c COMMON @example gosh> @i{(min&max 1 -1 8 3)} -1 8 gosh> @end example @c EN The history variable @code{*1}, @code{*2} and @code{*3} only binds the first value. A list of all values are bound to @code{*1+}, @code{*2+} and @code{*3+}. @c JP 式が多値を返しても、変数@code{*1}、@code{*2}、@code{*3} に束縛されるのは最初の値のみです。しかし別のグローバル変数 @code{*1+}、@code{*2+}、@code{*3+}に、全ての値をリストにしたものが 束縛されています。 @c COMMON @example gosh> @i{*1} -1 gosh> @i{*2+} (-1 8) @end example @c EN (Note that, when you evaluate @code{*1} in the above example, the history is shifted---so you need to use @code{*2+} to refer to the result of @code{(min&max 1 -1 8 3)}.) @c JP (上の例で、@code{*1}を評価した時点でヒストリがひとつずれてしまっていることに 注意してください。@code{(min&max 1 -1 8 3)}の結果を見るためには @code{*2+}を参照する必要があります。) @c COMMON @c EN The @code{*history} procedure shows the value of history variables: @c JP 手続き@code{*history}はヒストリ変数の値を表示します。 @c COMMON @example gosh> @i{(*history)} *1: (-1 8) *2: -1 *3: -1 gosh> @end example @c EN As a special case, if an evaluation yields zero values, history isn't updated. The @code{*history} procedure returns no values, so merely looking at the history won't change the history itself. @c JP 特別な場合として、式の評価がゼロ個の値を返した場合は、ヒストリ変数は更新されません。 @code{*history}手続きはゼロ個の値を返すので、ヒストリを見るだけでヒストリが 進んでしまうということはありません。 @c COMMON @example gosh> @i{(*history)} *1: (-1 8) *2: -1 *3: -1 gosh> (values) gosh> @i{(*history)} *1: (-1 8) *2: -1 *3: -1 @end example @c EN Finally, a global variable @code{*e} is bound to the last uncaught error condition object. @c JP 最後に、評価途中で捕捉されないエラーが発生した場合は、エラーコンディションオブジェクトが グローバル変数@code{*e}に束縛されます。 @c COMMON @example gosh> @i{(filter odd? '(1 2 x 4 5))} *** ERROR: integer required, but got x Stack Trace: _______________________________________ 0 (eval expr env) At line 173 of "/usr/share/gauche-0.9/0.9.3.3/lib/gauche/interactive.scm" gosh> @i{*e} # @end example @c EN (The error stack trace may differ depending on your installation.) @c JP (エラースタックトレースの表示はインストールの状況によって異なる場合があります。) @c COMMON @c EN In REPL prompt, you can also enter special @emph{top-level commands} for common tasks. Top-level commands are not Scheme expressions, not even S-expressions. They work like traditional line-oriented shell commands instead. @c JP REPLプロンプトではまた、よくある仕事のために、特別な@emph{トップレベルコマンド}を 入力することもできます。トップレベルコマンドはScheme式ではありませんし、S式でさえ ありません。むしろ、伝統的な行指向のシェルコマンドのように動作します。 @c COMMON @c EN Top-level commands are prefixed by comma to be distinguished from ordinary Scheme expressions. To see what commands are available, just type @code{,help} and return. @c JP トップレベルコマンドは通常のScheme式と区別するために、コンマで始まります。 どういったコマンドが使えるかを見るには、@code{,help}とタイプしてリターンを 入力してみてください。 @c COMMON @example gosh> ,help You're in REPL (read-eval-print-loop) of Gauche shell. Type a Scheme expression to evaluate. A word preceded with comma has special meaning. Type ,help to see the detailed help for . Commands can be abbreviated as far as it is not ambiguous. ,apropos|a Show the names of global bindings that match the regexp. ,cd Change the current directory. ,describe|d Describe the object. ,help|h Show the help message of the command. ,history Show REPL history. ,info|doc Show info document for an entry of NAME, or search entries by REGEXP. ,load|l Load the specified file. ,print-all|pa Print previous result (*1) without abbreviation. ,print-mode|pm View/set print-mode of REPL. ,pwd Print working directory. ,reload|r Reload the specified module, using gauche.reload. ,sh Run command via shell. ,source Show source code of the procedure if it's available. ,use|u Use the specified module. Same as (use module option ...). @end example @c EN To see the help of each individual commands, give the command name (without comma) to the @code{help} command: @c JP それぞれのコマンド特有のヘルプを見るには、コンマを含まないコマンド名を @code{help}コマンドに与えてください。 @c COMMON @example gosh> ,help d Usage: d|describe [object] Describe the object. Without arguments, describe the last REPL result. @end example @c EN The @code{,d} (or @code{,describe}) top-level command describes the given Scheme object or the last result if no object is given. Let's try some: @c JP @code{,d} (あるいは@code{,describe})トップレベルコマンドは与えられたSchemeオブジェクト、 または何もオブジェクトが与えられなければ直前の結果のオブジェクトについて、 その説明を表示します。ちょっと試してみましょう。 @c COMMON @example gosh> (sys-stat "/home") #< 0x2d6adc0> gosh> ,d #< 0x2d6adc0> is an instance of class slots: type : directory perm : 493 mode : 16877 ino : 2 dev : 2081 rdev : 0 nlink : 9 uid : 0 gid : 0 size : 208 atime : 1459468837 mtime : 1401239524 ctime : 1401239524 @end example @c EN In the above example, first we evaluated @code{(sys-stat "/home")}, which returns @code{} object. The subsequent @code{,d} top-level command describes the returned @code{} object. @c JP 上の例では、まず@code{(sys-stat "/home")}を評価して、結果として @code{}オブジェクトが返ってきました。続く@code{,d}コマンドによって その@code{}オブジェクトの詳細が表示されています。 @c COMMON @c EN The description depends on the type of objects. Some types of objects shows extra information. If you describe an exact integer, it shows alternative interpretations of the number: @c JP 表示される情報はオブジェクトの型に依存します。型によっては、追加の情報が 表示される場合もあります。例えば正確な整数を@code{describe}すると、 いくつかの異なる解釈が示されます。 @c COMMON @example gosh> ,d 1401239524 1401239524 is an instance of class (#x538537e4, ~ 1.3Gi, 2014-05-28T01:12:04Z as unix-time) gosh> ,d 48 48 is an instance of class (#x30, #\0 as char, 1970-01-01T00:00:48Z as unix-time) @end example @c EN If you describe a symbol, its known bindings is shown. @c JP シンボルを@code{describe}すると、分かっている束縛が示されます。 @c COMMON @example gosh> ,d 'filter filter is an instance of class Known bindings for variable filter: In module `gauche': # In module `gauche.collection': # @end example @c EN If you describe a procedure, and its source code location is known, that is also shown (see the @code{Defined at...} line): @c JP 手続きを@code{describe}した場合、もし分かっていればそのソースコード上の 場所も表示されます(@code{Defined at ...}の行): @c COMMON @example gosh> ,d string-interpolate # is an instance of class Defined at "../lib/gauche/interpolate.scm":64 slots: required : 1 optional : #t optcount : 1 locked : #f currying : #f constant : #f info : (string-interpolate str :optional (legacy? #f)) setter : #f @end example @c EN Let's see a couple of other top-level commands. The @code{,info} command shows the manual entry of the given procedure, variable, syntax, module or a class. (The text is searched from the installed info document of Gauche. If you get an error, check if the info document is properly installed.) @c JP 他のトップレベルコマンドも見てみましょう。@code{,info}コマンドは 手続き、変数、構文、モジュールもしくはクラス名が与えられると、そのドキュメントを 表示します。(テキストはシステムにインストールされたGaucheのinfoドキュメントから 検索されます。もしエラーが出た場合は、infoドキュメントが正しくインストール されているかどうか確認してください。) @c COMMON @example gosh> ,info append -- Function: append list ... [R7RS base] Returns a list consisting of the elements of the first LIST followed by the elements of the other lists. The resulting list is always newly allocated, except that it shares structure with the last list argument. The last argument may actually be any object; an improper list results if the last argument is not a proper list. gosh> ,info srfi.19 -- Module: srfi.19 This SRFI defines various representations of time and date, and conversion methods among them. On Gauche, time object is supported natively by '