5.5.8:Constants
定数
A
constant is a value that has a name. Like a variable, a
constant is set in your script. Unlike variables, constants
cannot be changed.
定数は名前を持った値のことです。変数のように、定数もスクリプト内に設定できます。変数と違うのは、定数の値は変更できません。
When
you use a constant, Transcript substitutes the value of the
constant for its name.
The following example uses a constant named "slash":
定数を使うと、トランスクリプトは、定数の値を定数の名前に置き換えます。次の例では、「slash」と言うなの定数を使っています。
put
slash after field "Expressions" -- displays "/"
(「/」を表示します)
You create a new constant using the constant
command.
constantコマンドを使えば新しい定数を作ることができます。
You cannot put anything into a
constant once it's been created.
定数が一旦作られると、定数には何も入れることができません。
Built-in
constants
組み込み定数
The
Transcript language defines several constants, such
as return,
space,
and comma,
for characters that have special meaning in scripts and
therefore can't be entered literally into an expression.
トランスクリプト言語は幾つかの定数を予め定義しています;例えば、return、space、comma等がそれで、これらの文字はスクリプト内では特別な意味を持っており、それ故に表現式で文字通りには使うことができません。
Tip:
To see a list of
all built-in constants, open the Documentation window,
click Transcript Dictionary, and choose "Constants" from
the menu at the top of the window.
秘訣: 組み込み定数の一覧を確認するには、ドキュメンテーション・ウインドウを開いて、トランスクリプト辞書をクリックし、ウインドウ上部のメニューから「定数」を選びます。
User-defined
constants
利用者が定義する定数
You
can also define your own constants using the
constant
command:
constantコマンドを使って、独自の定数を定義することもできます:
constant
myName="Joe Smith"
Like variables, constants can have different scope
depending on how they are created. A constant can be
defined as either a local constant or a script local
constant:
変数同様、定数は異なる範囲(スコープ)を持っており、定数の作られ方によって影響の及ぶ範囲が違ってきます。定数は、ローカル定数かスクリプト・ローカル定数かのいずれかとして定義することができます。
•
If you place the constant
command in a
handler, the constant can be used only in that handler.
・constantコマンドをハンドラ内に置くと、その定数はそのハンドラ内だけで使うことができます。
•
If you place the constant
command in a
script, but outside any handler, the constant can be used
in any handler in the script.
・constantコマンドをスクリプト内に置き、全てのハンドラの外側に置くと、定数はスクリプトのどのハンドラ内でも使うことができるようになります。