Next: , Previous: , Up: Defining Words   [Contents][Index]


6.10.8 Quotations

引用(quotation)は、 別のコロン定義内の匿名コロン定義です。 引用(quotation)は、 catchoutfile-execute など、 実行トークンを消費するワードを扱うときに便利です。 例えば、 以下の outfile-execute (see Redirection) の使用例を考えてみましょう:

: some-warning ( n -- )
    cr ." warning# " . ;

: print-some-warning ( n -- )
    ['] some-warning stderr outfile-execute ;

上記のように、 some-warning をヘルパー・ワードとして定義し、 その xt を outfile-execute に渡すことができます。 その代わりに、 引用(quotation)を使用して print-some-warning 内でそのようなワードを匿名で定義できます:

: print-some-warning ( n -- )
  [: cr ." warning# " . ;] stderr outfile-execute ;

引用(quotation)は [:;] で囲まれています。 それは実行時に実行トークンを生成します。

[: ( compile-time: – quotation-sys flag colon-sys  ) gforth-1.0 “bracket-colon”

引用(quotation)を開始します

;] ( compile-time: quotation-sys – ; run-time: – xt  ) gforth-1.0 “semi-bracket”

引用(quotation)を終了します