part of Tcl for Web Nerds by Hal Abelson, Philip Greenspun, and Lydia Sandon; updated July 2011
The interpreter can be called explicitly to complete extra rounds of substitutions or simply to interpret an additional time, using the subst and eval instructions respectively. The eval command takes a string argument which is a command, as follows:
% set cmd {puts stdout "Hello, World!"} 
puts stdout "Hello, World!" 

% eval $cmd 
Hello, World!
The subst command does the single round of substitution ordinarily completed by the interpreter, but without invoking any command. It takes one argument, the string to be substituted into.
% set a "foo bar" 
foo bar 

% subst {a=$a date=[exec date]} 
a=foo bar date=Thu Feb 30 1:11:11 EST 1901
While curly braces normally prevent internal substitution, they are not respected by the subst command. In order to prevent the single round of substitution, the backslash must be used before special characters like a dollar sign or square brackets.

More: http://www.tcl.tk/man/tcl8.4/TclCmd/eval.htm

Continue on to exec.
Return to Table of Contents

Add a comment | Add a link