## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > eval

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

eval — Tcl 記述譜を評価する Evaluate a Tcl script

### 構文 SYNOPSIS

eval arg ?arg ...?

### 説明 DESCRIPTION

eval は１つ或はそれ以上の引数を取り､それらは､一緒になって､一つ或はそれ以上の命令を含む一つのTcl 記述譜を構成する｡eval は､その全ての引数を､ concat 命令と同等の流儀で連結し､連結された文字列を Tcl 解釈実行機能に再帰的に手渡し､次に､その評価の結果を返す(又は､それにより何かの不具合が生成される)｡ Eval takes one or more arguments, which together comprise a Tcl script containing one or more commands. Eval concatenates all its arguments in the same fashion as the concat command, passes the concatenated string to the Tcl interpreter recursively, and returns the result of that evaluation (or any error generated by it).

註意すべきは､ list 命令は語の並びを､それ以上 eval 命令によって展開されない様な方法で引用する; 如何なる値の$aと$bと$cに於ても､次の二行は効果としては等価である｡ Note that the list command quotes sequences of words in such a way that they are not further expanded by the eval command; for any values, $a, $b, and $c, these two lines are effectively equivalent:

    eval [list $a $b $c]
    $a $b $c

### 用例 EXAMPLES

断片的な記述譜を変数に保存しておき､後にそれに追加された臨時の値と一緒に実行することは有用であることが多い｡この技法は､Tcl の核(譬えば､ fcopy や lsort や trace 命令の呼戻し)の至る処で数多く使われている｡この用例は､Tcl 命令核を如何に使うかを示す｡ Often, it is useful to store a fragment of a script in a variable and execute it later on with extra values appended. This technique is used in a number of places throughout the Tcl core (e.g. in fcopy, lsort and trace command callbacks). This example shows how to do this using core Tcl commands:

    set script {
        puts "logging now"
        lappend $myCurrentLogVar
    }
    set myCurrentLogVar log1
    # 中途での経過状況の変数部分として設定する!
    # Set up a switch of logging variable part way through!
    after 20000 set myCurrentLogVar log2

    for {set i 0} {$i<10} {incr i} {
        # Introduce a random delay
        after [expr {int(5000 * rand())}]
        update    ;# Check for the asynch log switch
        eval $script $i [clock clicks]
    }

註意すべきは､大部分の通常の場合は(即ち､記述譜の断片が実際は命令の前半部分を形成する語のリストである場合)､この種の様式の起動には {*}$script を使う方がよい｡ eval 命令ほど一般的ではないが､容易に実務に適応する[訳註{*}については､ Tcl の項を参照]｡次の手続函数は､ lappend 命令と似かよった様に振舞う､違いは､引数の値を変数内のリストの初めの箇所に挿入することである: Note that in the most common case (where the script fragment is actually just a list of words forming a command prefix), it is better to use {*}$script when doing this sort of invocation pattern. It is less general than the eval command, and hence easier to make robust in practice. The following procedure acts in a way that is analogous to the lappend command, except it inserts the argument values at the start of the list in the variable:

    proc lprepend {varName args} {
        upvar 1 $varName var
        # 変数が実在し､且つリストを有していることを確認する
        # Ensure that the variable exists and contains a list
        lappend var
        # 次に､全引数を其処に入れる
        # Now we insert all the arguments in one go
        set var [eval [list linsert $var 0] $args]
    }

但し､最後の行は､今では[訳註 8.5版以降では]､普通は eval を使わず､この様に書くべき: However, the last line would now normally be written without eval, like this:

    set var [linsert $var 0 {*}$args]

or indeed like this:

    set var [list {*}$args {*}$var]

### SEE ALSO

catch, concat, error, errorCode, errorInfo, interp, list, namespace, subst, uplevel

### KEYWORDS

concatenate, evaluate, script
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.