⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reftcl.tex

📁 很不错的tcl编程实例
💻 TEX
📖 第 1 页 / 共 2 页
字号:
\section{Basic Tcl Language Features} 

\begin{enum}{3cm}

\Xi{|;| or {\it newline}} statement separator

\Xi{$\backslash$} statement continuation if last character in line 

\Xi{|\#|} comments out rest of line (if first non$-$whitespace character)

\Xi{|var|} simple variable

\Xi{|var(index)|} associative array variable

\Xi{|var(i,j)|} multi-dimensional array variable

\Xi{|\$var|} variable substitution

\Xi{|\$\{var\}xyz|} variable substitution

\Xi{|[expr 1+2]|} command substitution

\Xi{$\backslash${\it char}} backslash substitution (see below)

\Xi{|"hello \$a"|} quoting with substitution

\Xi{|\{hello \$a\}|} quoting with no substitution (deferred substitution)

\end{enum}

\vskip10pt
The only data type in Tcl is a string. However, some commands will interpret
arguments as numbers in which case the formats are
\\
\quad Integer: |  123 0xff| (hex)|  0377| (octal).
\\
\quad Floating Point: |   2.1   3.   6e4    7.91e+16|

\section{Tcl Special Variables}

\begin{enum}{1cm}

\Xi{|env|} Tcl array where each element name is an enviroment variable.

\Xi{|errorCode|} Error code information from the last Tcl error.

\Xi{|errorInfo|} Describes the stack trace of the last Tcl error.

\Xi{|tcl\_precision|} Number of significant digits to retain when
converting floating-point numbers to strings (default 6).

\end{enum}

\section{Backslash Substitutions}

\begin{tabbing}
|   |\=|                  |\=|        |\= \kill
$\backslash$|a| \> audible alert (0x7)	\> $\backslash${\it space}	\> space \\
$\backslash$|b| \> backspace (0x8)	\> $\backslash${\it newline}	\> space \\
$\backslash$|f| \> form feed (0xC)	\> $\backslash${\it ddd}	\> octal value ({\it d}=0-7) \\
$\backslash$|n| \> newline (0xA)	\> $\backslash$x{\it dd}	\> hexadecimal value ({\it d}=0-9, a-f) \\
$\backslash$|r| \> carriage return (0xD)\> $\backslash${\it c}		\> replace `$\backslash${\it c}' with `{\it c}' \\
$\backslash$|t| \> horizontal tab (0x9) \> $\backslash$$\backslash$	\> a backslash \\
$\backslash$|v| \> vertical tab (0xB)	\>
\end{tabbing}

\section{Operators and Math Functions}

The \kwd{expr} command recognizes the following operators, in
decreasing order of precedence:

\begin{tabbing}
|   |\=|                    |\= \kill
 \> |-  ~  !| \> unary minus, bitwise NOT, logical NOT \\
 \> |*  /  %| \> multiply, divide, remainder \\
 \> |+  -|    \> add, subtract \\
 \> |<<  >>|  \> bitwise shift left, bitwise shift right \\
 \> |<  >  <=  >=| \> boolean comparisons \\
 \> |==  !=|  \> boolean equals, not equals \\
 \> \&        \> bitwise AND \\
 \> ${}^\wedge$ \> bitwise exclusive OR \\
 \> \|        \> bitwise inclusive OR \\
 \> \&\&      \> logical AND \\
 \> \|\|      \> logical OR \\
 \> |x ? y : z| \> if |x != 0|, then |y|, else |z|
\end{tabbing}

All operators support integers. All support floating point except |~|,
\%, \lt\lt, \gt\gt, \&, ${}^\wedge$, and \|. Boolean operators can 
also be used for string operands, in which case string comparison will
be used. This will occur if any of the operands are not valid
numbers. The \&\&, \|\|, and |?:| operators have ``lazy evaluation'',
as in C.

\vskip5pt
The \kwd{expr} command recognizes the following math functions:

\begin{enum}{2cm}

\Xi{|abs|} absolute value
\Xi{|acos|} arc cosine
\Xi{|asin|} arc sine
\Xi{|atan|} arc tangent
\Xi{|atan2|} arc tangent of $x/y$
\Xi{|ceil|} round up to nearest integer
\Xi{|cos|} cosine
\Xi{|cosh|} hyperbolic cosine
\Xi{|double|} convert to floating point
\Xi{|exp|} $e^x$
\Xi{|floor|} round down to nearest integer
\Xi{|fmod|} floating point remainder of $x/y$
\Xi{|hypot|} $\sqrt{x^2+y^2}$
\Xi{|int|} convert to integer by truncation
\Xi{|log|} natural logarithm
\Xi{|log10|} base 10 logarithm
\Xi{|pow|} $x^y$
\Xi{|round|} convert to integer by rounding
\Xi{|sin|} sine
\Xi{|sinh|} hyperbolic sine
\Xi{|sqrt|} square root
\Xi{|tan|} tangent
\Xi{|tanh|} hyperbolic tangent

\end{enum}

\section{Regular Expressions}

\begin{enum}{3.5cm}
\Xi{<regex>\|<regex>} match either expression
\Xi{<regex>*} match zero or more of <regex> 
\Xi{<regex>+} match one or more of <regex> 
\Xi{<regex>?} match zero or one of <regex> 
\Xi{|.|} any single character except newline 
\Xi{${}^\wedge$} match beginning of string 
\Xi{\$} match end of string 
\Xi{$\backslash$<c>} match character <c> 
\Xi{<c>} match character <c> 
\Xi{[abc]} match set of characters 
\Xi{[${}^\wedge$abc]} match characters not in set 
\Xi{[a-z]} match range of characters 
\Xi{[${}^\wedge$a-z]} match characters not in range 
\Xi{(\quad)} group expressions 
\end{enum}

\section{Pattern Globbing}

\begin{enum}{3.5cm}
\Xi{?} match any single character 
\Xi{*} match zero or more characters 
\Xi{[abc]} match set of characters 
\Xi{[a-z]} match range of characters 
\Xi{$\backslash$<c>} match character <c> 
\Xi{$\{$a,b,...$\}$} match any of strings a, b, etc. 
\Xi{\~{}} home directory (for \kwd{glob} command)
\Xi{\~{}<user>} match <user>'s home directory (for \kwd{glob} command)
\end{enum}

{\bf Note:}  for the \kwd{glob} command, a ``.'' at the beginning of a
file's name or just after ``/'' must be matched explicitly and all
``/'' characters must be matched explicitly.

\section{Control Flow} 

\begin{enum}{1cm}

\Xi{\kwd{break}}
Abort innermost containing loop command.

\Xi{\kwd{case}}
Obsolete, see \kwd{switch}.

\Xi{\kwd{continue}}
Skip to the next iteration of innermost containing loop command.

\Xi{\kwd{exit} [ <returnCode> ] }
Terminate  the  process, returning <returnCode> (an integer which
defaults to 0) to the system as the exit  status.

\Xi{\kwd{for} <start> <test> <next> <body>}
Looping command where <start>, <next>, and <body> are
Tcl command strings and test is an expression string to be passed
to \kwd{expr} command.

\Xi{\kwd{foreach} <varname> <list> <body>} 
The Tcl command string <body> is evaluated for each item in
the string <list> where the variable <varname> is
set to the item's value.

\Xi{\kwd{if} <expr1> [ \kwd{then} ] <body1> [ \kwd{elseif} <expr2> [ \kwd{then} ] 
	<body2> ... ] [ [ \kwd{else} ] <bodyN> ] } 
If expression string <expr1> evaluates true, Tcl command string <body1> is
evaluated. Otherwise if <expr2> is true, <body2> is evaluated, and so on.
If none of the expressions evaluate to true then <bodyN> is executed.

\Xi{\kwd{return} [\kwd{-code} <code>] [\kwd{-errorinfo} <info>] [\kwd{-errorcode} <code>] [<string>]}
Return immediately from current procedure with <string> as return value.

\Xi{\kwd{switch} [<options>] <string> <pattern1> <body1> [ <pattern2> <body2> ...] }
The <string> argument is matched against each of the <pattern> arguments in order.
As soon as it finds a pattern that matches <string>, it evaluates the
corresponding Tcl command string <body>. If no match is found and the last pattern
is the keyword |default|, its command string is evaluated.
 

\Xi{\kwd{while} <test> <body>} 
Evalutes the Tcl command string <body> as long as expression string <test>
evaluates to true.

\end{enum}

\section{File Information}

\begin{enum}{1cm}

\Xi{\kwd{file atime} <fileName>}
Time <fileName> was last accessed as seconds since Jan. 1, 1970.

\Xi{\kwd{file dirname} <fileName>}
Returns all characters in <fileName> up to but not including last slash.

\Xi{\kwd{file executable} <fileName>}
Returns 1 if <fileName> is executable by user, 0 otherwise.

\Xi{\kwd{file exists} <fileName>}
Returns 1 if <fileName> exists (and user can read its directory), 0 otherwise.

\Xi{\kwd{file extension} <fileName>}
Returns all characters in <fileName> after and including the last dot.

\Xi{\kwd{file isdirectory} <fileName>}
Returns 1 if <fileName> is a directory, 0 otherwise.

\Xi{\kwd{file isfile} <fileName>}
Returns 1 if <fileName> is a regular file, 0 otherwise.

\Xi{\kwd{file lstat} <fileName> <varName>}
Same as \kwd{file stat} except uses the lstat kernel call.

\Xi{\kwd{file mtime} <fileName>}
Time <fileName> was last modified as seconds since Jan. 1, 1970.

\Xi{\kwd{file owned} <fileName>}
Returns 1 if <fileName> owned by the current user, 0 otherwise.

\Xi{\kwd{file readable} <fileName>}
Returns 1 if <fileName> is readable by current user, 0 otherwise.

\Xi{\kwd{file readlink} <fileName>}
Returns value of symbolic link given by <fileName>.

\Xi{\kwd{file rootname} <fileName>}
Returns all the characters in <fileName> up to but not including last dot.

\Xi{\kwd{file size} <fileName>}
Returns size of <fileName> in bytes.

\Xi{\kwd{file stat} <fileName> <varName>}
Place results of stat kernel call on <fileName> in variable <varName>
as an array with elements |atime|, |ctime|, |dev|, |gid|, |ino|,
|mode|, |mtime|, |nlink|, |size|, |type|, and |uid|.

\Xi{\kwd{file tail} <fileName>}
Return all characters in <fileName> after last slash.

\Xi{\kwd{file type} <fileName>}
Returns string giving type of <fileName>. Possible values are |file|,
|directory|, |characterSpecial|, |blockSpecial|, |fifo|, |link|, or |socket|.

\Xi{\kwd{file writable} <fileName>}
Returns 1 if <fileName> is writable by current user, 0 otherwise.

\end{enum}

\section{Tcl Interpreter Information}

\begin{enum}{1cm}

\Xi{\kwd{info args} <procName>}
Returns list describing in order the names of arguments to <procName>.

\Xi{\kwd{info body} <procName>}
Returns the body of procedure <procName>.

\Xi{\kwd{info cmdcount} }
Returns the total number of commands that have been invoked.

\Xi{\kwd{info commands} [<pattern>]}
Returns list of Tcl commands matching glob <pattern> (default |*|).

\Xi{\kwd{info complete} <command>}
Returns 1 if <command> is a complete Tcl command, 0
otherwise. Complete means having no unclosed quotes, braces, brackets
or array element names

\Xi{\kwd{info default} <procName> <arg> <varName>}
Returns 1 if procedure <procName> has a default for argument <arg> and
places the value in variable <varName>. Returns 0 if there is no default.

\Xi{\kwd{info exists} <varName>}
Returns 1 if the variable <varName> exists in the current context, 0 othewise.

\Xi{\kwd{info globals} [<pattern>]}
Returns list of global variables matching glob <pattern> (default |*|).

\Xi{\kwd{info level}}
Returns the stack level of the invoking procedure.

\Xi{\kwd{info level} <number>}
Returns name and arguments of procedure invoked at stack level <number>.

\Xi{\kwd{info library} }
Returns name of library directory where standard Tcl scripts are stored.

\Xi{\kwd{info locals} [<pattern>]}
Returns list of local variables matching glob <pattern> (default |*|).

\Xi{\kwd{info patchlevel} }
Returns current patch level for Tcl.

\Xi{\kwd{info procs} [<pattern>]}
Returns list of Tcl procedures matching glob <pattern> (default |*|).
Differs from \kwd{info commands} in that built-ins are excluded.

\Xi{\kwd{info script} }
Returns name of Tcl script currently being evaluated.

\Xi{\kwd{info tclversion} }
Returns version number of Tcl in <major>.<minor> form.

\Xi{\kwd{info vars} [<pattern>]}
Returns list of currently-visible variables matching glob <pattern> (default |*|).

\end{enum}

\section{File Input/Output}

\begin{enum}{1cm}

\Xi{\kwd{close} <fileId>}
Close the open file given by <fileId>.

\Xi{\kwd{eof} <fileId>}
Returns 1 if an end-of-file has occurred on <fileId>, 0 otherwise.

\Xi{\kwd{flush} <fileId>}
Flushes any output that has been buffered for <fileId>.

\Xi{\kwd{gets} <fileId> [<varName>]}
Read next line from file given by <fileId>, discarding newline character.
Places characters of line in <varName> if given, otherwise returns them.

\Xi{\kwd{open} <fileName> [<access>] [<perms>]}
Opens <filename> and returns its file id. If a new file is created,
its permission are set to the conjuction of <perms> and the process
umask.  The <access> may be

\begin{enum}{1cm}
\Xi{|r|} Read only. File must exist.
\Xi{|r+|} Read and write. File must exist.
\Xi{|w|} Write only. Truncate if exists.
\Xi{|w+|} Read and write. Truncate if exists.
\Xi{|a|} Write only. File must exist. Access position at end.
\Xi{|a+|} Read and write. Access position at end.
\end{enum}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -