常用命令记录:
set------最多使用
unset ------删除变量,它后面可以有任意多个参数
set a monday
puts $a
unset a
puts $a
monday
can’t read “a”: no such variable
while executing
“puts $a”
(file “arr.tcl” line 6)
append------把文本加到一个变量的后面
% set txt hello
hello
% append txt "! How are you"
hello! How are you
incr------把一个变量值加上一个整数。incr要求变量原来的值和新加的值都必须是整数
%set b 2
2
%incr b 3
5
运算符和优先级
按优先级从高到低往下排列的。同一格中的运算符优先级相同
函数
数学函数并不是命令,只在表达式(expr)中出现才有意义
%set x 2
2
% expr 2* sin($x<3)
1.68294196962
TCL中支持的数学函数如下
abs( x)------Absolute value of x.
acos( x)------ Arc cosine of x, in the range 0 to p.
asin( x)------ Arc sine of x, in the range -p/2 to p/2.
atan( x)------ Arc tangent of x, in the range -p/2 to p/2.
atan2( x, y)------ Arc tangent of x/ y, in the range -p/2 to p/2.
ceil( x) ------Smallest integer not less than x.
cos( x)------Cosine of x ( x in radians).
cosh( x)------ Hyperbolic cosine of x.
double( i) ------Real value equal to integer i.
exp( x) ------e raised to the power x.
floor( x) ------Largest integer not greater than x.
fmod( x, y) ------Floating-point remainder of x divided by y.
hypot( x, y) ------Square root of ( x 2 + y 2 ).
int( x) ------Integer value produced by truncating x.
log( x)------ Natural logarithm of x.
log10( x) ------Base 10 logarithm of x.
pow( x, y) ------x raised to the power y.
round( x) ------Integer value produced by rounding x.
sin( x) ------Sine of x ( x in radians).
sinh( x) ------Hyperbolic sine of x.
sqrt( x)------ Square root of x.
tan( x) ------Tangent of x ( x in radians).
tanh( x)------ Hyperbolic tangent of x.
加粗样式### 集合(List)
语法: list ? value value…?
% list 1 2 {3 4}
1 2 {3 4}
命令:
concat -------把多个list合成一个list,每个list变成新list的一个元素。
lindex---------返回list的第index个元素
llength--------返回list的元素个数
linsert---------返回一个新串,新串是把所有的value参数值插入list的第index个元素之前得到
lreplace-------返回一个新串,新串是把list的第first到第last个元素用所有的value参数替换得到的。如果没有value参数,就表示删除第first到第last个元素
lrange---------返回list的第first (0-based)到第last 元素组成的串,如果last的值是end。就是从第first个直到串的最后。
lappend-------把每个value的值作为一个元素附加到变量varname后面,并返回变量的新值,如果varname不存在,就生成这个变量。
lsearch
lsort
split
join
流程控制:
if–elseif----
while
for
foreach
switch
break/continue