1, expression
1.1 The operand of the Tcl expression is usually an integer or a real number. An integer is generally in decimal format. However, if the first character of an integer is 0 (zero), TCL regards this Integer as an octal integer, if the first two characters are 0x, the integer is regarded as hexadecimal.
1.2 operator TCL syntax format and usage are similar to ANSI C
1.3 Functions
The mathematical functions supported by TCL are as follows:
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) hyperboliccosine 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.
Many Commands in TCL use expressions as parameters. The most typical is the expr command. In addition, expressions are also used as parameters in the loop control of if, while, for, and other loop control commands.
2, list
2.1 LIST Command
The list concept is used to represent a set in TCl. In TCL, list is an ordered set composed of a bunch of elements. List can be nested and defined.
% List 1 2 {3 4}
1 2 {3 4}
2.2 Concat command (this command does not know how to use it)
Syntax: Concat list? List ...?
This command combines multiple lists into a list, and each list becomes an element of the new list.
2.3 lindex command
Syntax: lindex List Index
Returns the index (0-based) element of the list. Example:
% Lindex {1 2 {3 4} 2
3 4
2.4 llength command
Syntax: llength list
Returns the number of elements in the list. Example
% Llength {1 2 {3 4 }}
3
2.5 linsert command
Syntax: linsert List index value? Value ...?
Returns a new string, which is obtained before inserting all value values into the index (0-based) element of the list.
Example:
% Linsert {1 2 {3 4 }}1 7 8 {9 10}
1 7 8 {9 10} 2 {3 4}
2.6 lreplace command
Syntax: lreplace list first last? Value value ...?
Returns a new string that uses all values for the firs (0-based) T to the last (0-based) element of the list.
Parameter. If the value parameter is not set, the first to last elements are deleted. Example:
% Lreplace {1 7 8 {9 10} 2 {3 4} 3 3
1 7 8 2 {3 4}
% Lreplace {1 7 8 2 {3 4} 4 4 4 5 6
1 7 8 2 4 5 6
2.7 lrange command
Syntax: lrange list first last
Returns a string composed of the first (0-based) of the list to the last (0-based) element. If the last value is end. Yes
From the first to the end of the string.
Example:
% Lrange {1 7 8 2 4 5 6} 2 end
8 2 4 5 6
2.8 lappend command
Syntax: lappend varname value? Value ...?
Attaches the value of each value to the variable varname as an element and returns the new value of the variable.
This variable is generated if it does not exist. Example:
% Set a 9
9
% Lappend a 1 2 3
9 1 2 3
% Set
9 1 2 3
2.9 lsearch command
Syntax: lsearch? -Exact? ? -Glob? ? -Regexp? List Pattern
Returns the index of the first element in the list that matches pattern. If no match is found,-1 is returned. -Exact,-glob,
-Regexp is a technology that matches three modes. -Exact indicates exact match.-glob matches string match.
The matching method of commands is the same. The following section describes the string commands.-Regexp indicates regular expression matching,
This section describes the Regexp commands in section 8. Use-glob matching for lack of time. Example:
% Set a {how are you}
How are you
% Lsearch $ A y *
2
% Lsearch $ A y?
-1
TCL language NOTE 2