天天看點

tcl/tk學習筆記(1)

Spaces are not required around the square brackets used for command substitution. For the purposes of grouping, the interpreter considers everything between the square brackets as part of the current group. The following sets x to the concatenation of two command results because there is no space between ] and [.

set x [cmd1][cmd2]

Built-in Math Functions

acos(x)

Arccosine of x.

asin(x)

Arcsine of x.

atan(x)

Arctangent of x.

atan2(y,x)

Rectangular (x,y) to polar (r,th). atan2 gives th.

ceil(x)

Least integral value greater than or equal to x.

cos(x)

Cosine of x.

cosh(x)

Hyperbolic cosine of x.

exp(x)

Exponential, ex.

floor(x)

Greatest integral value less than or equal to x.

fmod(x,y)

Floating point remainder of x/y.

hypot(x,y)

Returns sqrt(x*x + y*y). r part of polar coordinates.

log(x)

Natural log of x.

log10(x)

Log base 10 of x.

pow(x,y)

x to the y power, xy.

sin(x)

Sine of x.

sinh(x)

Hyperbolic sine of x.

sqrt(x)

Square root of x.

tan(x)

Tangent of x.

tanh(x)

Hyperbolic tangent of x.

abs(x)

Absolute value of x.

double(x)

Promote x to floating point.

int(x)

Truncate x to an integer.

round(x)

Round x to an integer.

rand()

Return a random floating point value between 0.0 and 1.0.

srand(x)

Set the seed for the random number generator to the integer x.

wide(x)

Promote x to a wide (64-bit) integer. (Tcl 8.4)

Core TCL Commands

after             Schedule a Tcl command for later execution.

append        Append arguments to a variable's value. No spaces added.

array            Query array state and search through elements.

binary          Convert between strings and binary data.

break           Exit loop prematurely.

catch           Trap errors.

cd                 Change working directory.

clock            Get the time and format date strings.

close           Close an open I/O stream.

concat         Concatenate arguments with spaces between. Splices lists.

console       Control the console used to enter commands interactively.

continue      Continue with next loop iteration.

error             Raise an error.

eof                Check for end of file.

eval              Concatenate arguments and evaluate them as a command.

exec            Fork and execute a UNIX program.

exit               Terminate the process.

expr              Evaluate a math expression.

fblocked       Poll an I/O channel to see if data is ready.

fconfigure    Set and query I/O channel properties.

fcopy             Copy from one I/O channel to another.

file                Query the file system.

fileevent      Register callback for event-driven I/O.

flush              Flush output from an I/O stream's internal buffers.

for                  Loop construct similar to C for statement.

foreach         Loop construct over a list, or lists, of values.

format           Format a string similar to C sprintf.

gets               Read a line of input from an I/O stream.

glob               Expand a pattern to matching file names.

global            Declare global variables.

history           Use command-line history.

if                     Test a condition. Allows else and elseif clauses.

incr                Increment a variable by an integer amount.

info                Query the state of the Tcl interpreter.

interp             Create additional Tcl interpreters.

join                 Concatenate list elements with a given separator string.

lappend         Add elements to the end of a list.

lindex            Fetch an element of a list.

linsert            Insert elements into a list.

list                   Create a list out of the arguments.

llength            Return the number of elements in a list.

load                Load shared libraries that define Tcl commands.

lrange             Return a range of list elements.

lreplace          Replace elements of a list.

lsearch           Search for an element of a list that matches a pattern.

lset                  Set an element in a list. (Tcl 8.4)

lsort                 Sort a list.

namespace   Create and manipulate namespaces.

open                Open a file or process pipeline for I/O.

package           Provide or require code packages.

pid                     return the process ID.

proc                   Define a Tcl procedure.

puts                    Output a string to an I/O stream.

pwd                   Return the current working directory.

read                  Read blocks of characters from an I/O stream.

regexp              Match regular expressions.

regsub              Substitute based on regular expressions.

rename            Change the name of a Tcl command.

return                Return a value from a procedure.

scan                   Parse a string according to a format specification.

seek                  Set the seek offset of an I/O stream.

set                     assign a value to a variable.

socket               Open a TCP/IP network connection.

source              Evaluate the Tcl commands in a file.

split                   Chop a string up into list elements.

string                Operate on strings.

subst                 Substitute embedded commands and variable references.

switch               Test several conditions.

tell                     Return the current seek offset of an I/O stream.

time                  measure the execution time of a command.

trace                  Monitor variable assignments.

unknown          Handle unknown commands.

unset                Delete variables.

uplevel             Execute a command in a different scope.

upvar                 reference a variable in a different scope.

variable            Declare namespace variables.

vwait                  Wait for a variable to be modified.

while                 Loop until a boolean expression is false.

source csh in tcl

exec /bin/csh -c "source $sourceEnv; command; "

Wish command line options

-colormap new

Use a new private colormap.

-display display

Use the specified X display. UNIX only.

-geometry geometry

The size and position of the window.

-name name

Specify the Tk application name.

-sync

Run X synchronously. UNIX only.

-use id

Use the window specified by id for the main window.

-visual visual

Specify the visual for the main window.

--

Terminate options to wish.