5.5.6:Special Variable Types

特別な変数の形式

Most of the time, you use variables that you create yourself, using the local or global commands, or simply by putting a value into a new variable in order to create it.

レヴォルーションによるアプリケーションの開発時には、大抵localコマンドやglobalコマンドを使ったり、変数を作成するために値をputコマンドで新規の変数に入れたりといった、独自に作った変数を使うのがほとんどです。

Transcript also creates certain types of variables automatically: parameter variables, command-line variables, environment variables, and the special variable it.

トランスクリプトは、ある形式の変数を自動的に作りだしたりもします:パラメータ変数、コマンド・ライン変数、環境変数、特別な変数itなどです。

Parameter variables

パラメータ変数

In a handler for a custom command or custom function, you can define parameters on the first line of the handler. For example, the following handler defines two parameters named "thisThing" and "thatThing":

カスタム・コマンドやカスタム・ファンクション用のハンドラでは、ハンドラの第一行目でパラメータの定義を行うことができます。例えば、次のハンドラでは二つのパラメータ「thisThing」と「thatThing」を定義しています。

  on myHandler thisThing,thatThing
    add thisThing to thatThing
    subtract thatThing from field 2
  end myHandler

When you use the custom command or custom function, you can pass values to it using the parameters:

カスタム・コマンドやカスタム・ファンクションを使う時には、パラメータを使ってそれらコマンドに値をう受け渡しできます:

  myHandler 15,4+1
  -- puts "15" into the parameter "thisThing",(パラメータ「thisThing」に15を入れます)
  -- and puts "5" into the parameter "thatThing"(パラメータ「thatThing」に5を入れます)

When named parameters are used in a handler, they are called parameter variables.
Within the handler, the parameters can be used in the same way as local variables: you can get their value, use them in expressions, and put data into them.

名前のつけられたパラメータがハンドラで使われた場合に、それらはパラメータ変数と呼ばれます。
ハンドラ内では、パラメータはローカル変数と同様に扱われます:つまり、ローカル変数の値を取得したり、表現式で使ったり、データを入れたりできるのです。

Like local variables, parameter variables persist only as long as the handler is executing.

ローカル変数同様、パラメータ変数はハンドラの実行中のみ有効です。

Environment variables

環境変数

Most operating systems that Revolution supports provide information about the operating environment in environment variables.

レヴォルーションがサポートする幾つかのオペーレーティング・システムでは、操作環境に関する情報を環境変数として提供しています。

You can access environment variables by prepending the $ character to the variable's name. For example, the following statement gets the contents of the LOGNAME environment variable, which holds the current user's login name:

環境変数にアクセスするには、変数名の前に$(ドル記号)をつけます。例えば、次のステートメントはLONGNAME環境変数の値、つまり現在ログイン中のユーザー名、を得るのに使われています:

  get $LOGNAME

See your operating system's technical documentation to find out what environment variables are available.

どんな環境変数が提供されているのかを知るには、使用中のオペレーティング・システムの技術解説書を参照してください。

You can also create your own environment variables by prepending the $ character to the new environment variable's name:

新しい環境変数名の前に$をつけることで、自分独自の環境変数を作ることもできます。

  put field 3 into $MYENVVAR

Note: Environment variables behave like global variables and can be used in any handler. However, you do not need to use the global command to declare them before using them.

注釈: 環境変数はグローバル変数のような働きをし、またどのハンドラ内でも使用することができます。とは言え、環境変数を使用する時に、その宣言のためにglobalコマンドを使用する必要はありません。

The environment variables that you create this way are available to the application, and are also exported to processes started up by the shell function or the open process command.

上述した方法で作成した環境変数は、アプリケーション全体で使用することができます。また、shellファンクションやopen processコマンドで開始したプロセスへの引き渡しもできます。

Command-line argument variables

コマンド・ライン・アーギュメント変数

If you start up the application from a command line, the command name is stored in the variable $0 and any arguments passed on the command line are stored in numbered variables starting with the $ character.

アプリケーションをコマンド・ラインから起動した場合、コマンド名は変数$0に格納されており、コマンド・ラインに引き渡された全てのアーギュメントは、先頭に$を付けられた数字による変数に保存されます。

For example, if you start the application by typing the following shell command:

例えば、次のシェル・コマンドを使ってアプリケーションを起動した場合:

  myrevapp -h name

then the variable $0 contains "myrevapp" (the name of the application), $1 contains "-h", and $2 contains "name".

変数$0には(アプリケーション名である)「myrevapp」が格納され、$1には「-h」が、$2には「name」がそれぞれ格納されます。

Note: Command-line argument variables behave like global variables and can be used in any handler. However, you do not need to use the global command to declare them before using them.

注釈: コマンド・ライン・アーギュメント変数は、グローバル変数のような働きをし、どのハンドラ内ででも使用することができます。とは言え、コマンド・ライン・アーギュメント変数を使用する時には、globalコマンドを使って宣言する必要はありません。

The special variable “it”

特別な変数「it」
The it variable is a special local variable used by Revolution to store certain results.

レヴォルーションで使われる変数itは、ある結果を保持する特別なローカル変数です。

Certain commands--such as get, convert, read from file, ask, and answer-- put their results in this special variable. For a complete list of commands that use the it variable, see the entry for it in the Transcript Dictionary. The following example shows how the answer command uses the it variable:

get
convertread rom fileaskanswer等のある種のコマンドは、コマンドの実行結果をこの特別な変数itに引き渡します。変数itを使用するコマンドを網羅した一覧は、トランスクリプト辞書のitの項目にあります。次の例では、answerコマンドが変数itを使っています:


  on mouseUp
    answer "Go where?" with "Backward" or "Forward"
    -- the answer command puts the button the user clicked
    -- into the it variable:
(answerコマンドは、ユーザーがクリックしたボタンを変数itに入れます)
    if it is "Backward" then go back
    else go next
  end mouseUp

You can use the it variable in the same way as any other local variable, using the put command to put things into it and using the variable in expressions to work with the contents.

変数itは他のローカル変数同様の使い方ができます。つまり、何かを変数itに入れる時にはputコマンドを使い、変数itの値を使う時には表現式内でその変数を用います。