forked from shirok/Gauche
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.texi
3771 lines (3367 loc) · 155 KB
/
program.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@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
@c EN
@subheading Command-line options
@c JP
@subheading コマンドラインオプション
@c COMMON
@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 exits.
@c JP
@code{gosh}のバージョンを表示して終了します。
@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
@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.
@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
cause performance problems because all cursors will be allocated on
heap. @xref{String cursors}.
@item test
Adds "@code{../src}" and "@code{../lib}" to the load path before loading
initialization file. This is useful when you want to test the
compiled @code{gosh} REPL without installing it.
@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 no-inline
一切のインライン展開を行いません。このオプションは以下の no-inline-globals
no-inline-locals および no-inline-constants を同時に指定したのと等価です。
@item no-inline-globals
大域(global)関数のインライン展開を展開を行ないません。
@item no-inline-locals
局所(local)関数のインライン展開を展開を行ないません。
@item no-inline-constants
定数のインライン展開を行ないません。
@item no-post-inline-pass
インライン展開後に再び最適化パスを走らせるのを抑止します。
@item no-lambda-lifting-pass
lambda lifting最適化パスを抑止します。
@item no-source-info
デバッグのためのソースファイル情報を保持しません。メモリの使用量は小さくなります。
@item load-verbose
ファイルがロードされる時にそれを報告します。
正確にどのファイルがどういう順序でロードされているかを調べるのに便利です。
@item include-verbose
ファイルがincludeされる時にそれを報告します。
正確にどのファイルがどういう順序でincludeされているかを調べるのに便利です。
@item warn-legacy-syntax
文字列リテラル中に古い形式の16進数エスケープ形式があったら警告します。
@ref{Reader lexical mode} を参照して下さい。
@item case-fold
シンボルの大文字小文字を区別しません。
@ref{Case-sensitivity} を参照して下さい。
@item test
"@code{../src}" と "@code{../lib}" を、初期化ファイルを読む前に
ロードパスに加えます。これは、作成された@code{gosh}をインストールせずに
実行してみるのに便利です。
@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
@c EN
@subheading Environment variables
@c JP
@subheading 環境変数
@c COMMON
@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{#<undef>} is used in the test expression of branch.
In boolean context, @code{#<undef>} counts true. It is also
often the case that a procedure returns @code{#<undef>} 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{#<undef>}が条件式のテスト式に使われた場合に警告を出します。
真偽値判定では@code{#<undef>}は真とみなされます。しかし、
@code{#<undef>}を返す手続きはしばしば、
「戻り値に意味はない」ことを示すためにそれを返しています。
戻り値に意味がないなら、その値に依存したコードを書くべきではありません。
もし、手続きが将来、もともと意味が無いのだからと戻り値を変えた場合に、
@code{#<undef>}に依存してたコードは壊れる可能性があります。
詳しくは@ref{Undefined values}を参照してください。
この機能はなるべくONtにしておくようにお勧めします。
将来はデフォルトで警告を出すようにする予定です。
@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 varible 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} 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
@c EN
@subheading Windows-specific executable
@c JP
@subheading Windows特有の実行ファイル
@c COMMON
@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)