6 Jim Tcl v0.78+ - reference manual for the Jim Tcl scripting language
15 jimsh [<scriptfile>|-]
16 jimsh -e '<immediate-script>'
22 * <<CommandIndex,Command Reference>>
23 * <<OperatorPrecedence,Operator Precedence>>
24 * <<BuiltinVariables, Builtin Variables>>
25 * <<BackslashSequences, Backslash Sequences>>
29 Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
30 The core language engine is compatible with Tcl 8.5+, while implementing
31 a significant subset of the Tcl 8.6 command set, plus additional features
32 available only in Jim Tcl.
34 Some notable differences with Tcl 8.5/8.6 are:
36 1. Object-based I/O (aio), but with a Tcl-compatibility layer
37 2. I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
39 4. Support for references (`ref`/`getref`/`setref`) and garbage collection
40 5. Builtin dictionary type (`dict`) with some limitations compared to Tcl 8.6
41 6. `env` command to access environment variables
42 7. Operating system features: `os.fork`, `os.uptime`, `wait`, `signal`, `alarm`, `sleep`
43 8. Much better error reporting. `info stacktrace` as a replacement for '$errorInfo', '$errorCode'
44 9. Support for "static" variables in procedures
45 10. Threads and coroutines are not supported
46 11. Command and variable traces are not supported
47 12. Built-in command line editing
48 13. Expression shorthand syntax: +$(...)+
49 14. Modular build allows many features to be omitted or built as dynamic, loadable modules
50 15. Highly suitable for use in an embedded environment
51 16. Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
57 1. Add `file mtimeus` for high resolution file timestamps
58 2. `aio` now supports datagram Unix-Domain sockets
59 3. Add support for `aio lock -wait`
60 4. Add `signal block` to prevent delivery of signals
62 Changes between 0.77 and 0.78
63 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64 1. Add serial/tty support with `aio tty`
65 2. Add support for 'jimsh -'
66 3. Add hidden '-commands' option to many commands
67 4. Add scriptable autocompletion support in interactive mode with `tcl::autocomplete`
69 6. Add scriptable autocompletion support with `history completion`
70 7. Add support for `tree delete`
71 8. Add support for `defer` and '$jim::defer'
72 9. Renamed `os.wait` to `wait`, now more Tcl-compatible and compatible with `exec ... &`
73 10. `pipe` is now a synonym for `socket pipe`
74 11. Closing a pipe open with `open |...` now returns Tcl-like status
75 12. It is now possible to used `exec` redirection with a pipe opened with `open |...`
76 13. Interactive line editing now supports multiline mode if $::history::multiline is set
78 Changes between 0.76 and 0.77
79 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80 1. Add support for `aio sync`
81 2. Add SSL and TLS support in aio
83 4. Added support for boolean constants in `expr`
84 5. `string is` now supports 'boolean' class
85 6. Add support for `aio lock` and `aio unlock`
86 7. Add new `interp` command
88 Changes between 0.75 and 0.76
89 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90 1. `glob` now supports the +-tails+ option
91 2. Add support for `string cat`
92 3. Allow `info source` to add source info
94 Changes between 0.74 and 0.75
95 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 1. `binary`, `pack` and `unpack` now support floating point
97 2. `file copy` +-force+ handles source and target as the same file
98 3. `format` now supports +%b+ for binary conversion
99 4. `lsort` now supports +-unique+ and +-real+
100 5. Add support for half-close with `aio close` +?r|w?+
101 6. Add `socket pair` for a bidirectional pipe
102 7. Add '--random-hash' to randomise hash tables for greater security
103 8. `dict` now supports 'for', 'values', 'incr', 'append', 'lappend', 'update', 'info' and 'replace'
104 9. `file stat` no longer requires the variable name
105 10. Add support for `file link`
107 Changes between 0.73 and 0.74
108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 1. Numbers with leading zeros are treated as decimal, not octal
111 3. Add LFS (64 bit) support for `aio seek`, `aio tell`, `aio copyto`, `file copy`
112 4. `string compare` and `string equal` now support '-length'
113 5. `glob` now supports '-directory'
115 Changes between 0.72 and 0.73
116 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117 1. Built-in regexp now support non-capturing parentheses: (?:...)
118 2. Add `string replace`
119 3. Add `string totitle`
120 4. Add `info statics`
121 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions)
122 6. `local` now works with any command, not just procs
123 7. Add `info alias` to access the target of an alias
124 8. UTF-8 encoding past the basic multilingual plane (BMP) is supported
127 11. Most extensions are now enabled by default
128 12. Add support for namespaces and the `namespace` command
131 Changes between 0.71 and 0.72
132 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133 1. procs now allow 'args' and optional parameters in any position
134 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
135 3. Add support for the '-force' option to `file delete`
136 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
137 5. New +tcl_platform(pathSeparator)+
138 6. Add support settings the modification time with `file mtime`
139 7. `exec` is now fully supported on win32 (mingw32)
140 8. `file join`, `pwd`, `glob` etc. now work for mingw32
141 9. Line editing is now supported for the win32 console (mingw32)
142 10. Add `aio listen` command
144 Changes between 0.70 and 0.71
145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 1. Allow 'args' to be renamed in procs
147 2. Add +$(...)+ shorthand syntax for expressions
148 3. Add automatic reference variables in procs with +&var+ syntax
149 4. Support +jimsh --version+
150 5. Additional variables in +tcl_platform()+
151 6. `local` procs now push existing commands and `upcall` can call them
152 7. Add `loop` command (TclX compatible)
153 8. Add `aio buffering` command
154 9. `info complete` can now return the missing character
155 10. `binary format` and `binary scan` are now (optionally) supported
156 11. Add `string byterange`
157 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
161 Tcl stands for 'tool command language' and is pronounced
162 'http://www.oxforddictionaries.com/definition/american_english/tickle[tickle]'.
163 It is actually two things: a language and a library.
165 First, Tcl is a simple textual language, intended primarily for
166 issuing commands to interactive programs such as text editors,
167 debuggers, illustrators, and shells. It has a simple syntax and is also
168 programmable, so Tcl users can write command procedures to provide more
169 powerful commands than those in the built-in set.
171 Second, Tcl is a library package that can be embedded in application
172 programs. The Tcl library consists of a parser for the Tcl language,
173 routines to implement the Tcl built-in commands, and procedures that
174 allow each application to extend Tcl with additional commands specific
175 to that application. The application program generates Tcl commands and
176 passes them to the Tcl parser for execution. Commands may be generated
177 by reading characters from an input source, or by associating command
178 strings with elements of the application's user interface, such as menu
179 entries, buttons, or keystrokes.
181 When the Tcl library receives commands it parses them into component
182 fields and executes built-in commands directly. For commands implemented
183 by the application, Tcl calls back to the application to execute the
184 commands. In many cases commands will invoke recursive invocations of the
185 Tcl interpreter by passing in additional strings to execute (procedures,
186 looping commands, and conditional commands all work in this way).
188 An application program gains three advantages by using Tcl for its command
189 language. First, Tcl provides a standard syntax: once users know Tcl,
190 they will be able to issue commands easily to any Tcl-based application.
191 Second, Tcl provides programmability. All a Tcl application needs
192 to do is to implement a few application-specific low-level commands.
193 Tcl provides many utility commands plus a general programming interface
194 for building up complex command procedures. By using Tcl, applications
195 need not re-implement these features.
197 Third, Tcl can be used as a common language for communicating between
198 applications. Inter-application communication is not built into the
199 Tcl core described here, but various add-on libraries, such as the Tk
200 toolkit, allow applications to issue commands to each other. This makes
201 it possible for applications to work together in much more powerful ways
202 than was previously possible.
204 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
205 used to run standalone Tcl scripts, or to run Tcl commands interactively.
207 This manual page focuses primarily on the Tcl language. It describes
208 the language syntax and the built-in commands that will be available
209 in any application based on Tcl. The individual library procedures are
210 described in more detail in separate manual pages, one per procedure.
212 JIMSH COMMAND INTERPRETER
213 -------------------------
214 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
215 It may be invoked in interactive mode as:
219 or to process the Tcl script in a file with:
223 or to process the Tcl script from standard input:
227 It may also be invoked to execute an immediate script with:
233 Interactive mode reads Tcl commands from standard input, evaluates
234 those commands and prints the results.
237 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
240 . lsort [info commands p*]
241 package parray pid popen proc puts pwd
242 . foreach i {a b c} {
249 invalid command name "bad"
253 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
254 terminal is detected, Emacs-style line editing commands are available, including:
255 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
256 in history. Additionally, the +h+ command may be used to display the command history.
258 Command line history is automatically saved and loaded from +~/.jim_history+
260 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
265 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
266 An interpreter consists of a set of command bindings, a set of variable
267 values, and a few other miscellaneous pieces of state. Each Tcl command
268 is interpreted in the context of a particular interpreter.
270 Some Tcl-based applications will maintain multiple interpreters
271 simultaneously, each associated with a different widget or portion of
272 the application. Interpreters are relatively lightweight structures.
273 They can be created and deleted quickly, so application programmers should
274 feel free to use multiple interpreters if that simplifies the application.
278 Tcl supports only one type of data: strings. All commands, all arguments
279 to commands, all command results, and all variable values are strings.
281 Where commands require numeric arguments or return numeric results,
282 the arguments and results are passed as strings. Many commands expect
283 their string arguments to have certain formats, but this interpretation
284 is up to the individual commands. For example, arguments often contain
285 Tcl command strings, which may get executed as part of the commands.
286 The easiest way to understand the Tcl interpreter is to remember that
287 everything is just an operation on a string. In many cases Tcl constructs
288 will look similar to more structured constructs from other languages.
289 However, the Tcl constructs are not structured at all; they are just
290 strings of characters, and this gives them a different behaviour than
291 the structures they may look like.
293 Although the exact interpretation of a Tcl string depends on who is doing
294 the interpretation, there are three common forms that strings take:
295 commands, expressions, and lists. The major sections below discuss
296 these three forms in more detail.
300 The Tcl language has syntactic similarities to both the Unix shells
301 and Lisp. However, the interpretation of commands is different
302 in Tcl than in either of those other two systems.
303 A Tcl command string consists of one or more commands separated
304 by newline characters or semi-colons.
305 Each command consists of a collection of fields separated by
306 white space (spaces or tabs).
307 The first field must be the name of a command, and the
308 additional fields, if any, are arguments that will be passed to
309 that command. For example, the command:
313 has three fields: the first, `set`, is the name of a Tcl command, and
314 the last two, 'a' and '22', will be passed as arguments to
315 the `set` command. The command name may refer either to a built-in
316 Tcl command, an application-specific command bound in with the library
317 procedure 'Jim_CreateCommand', or a command procedure defined with the
318 `proc` built-in command.
320 Arguments are passed literally as text strings. Individual commands may
321 interpret those strings in any fashion they wish. The `set` command,
322 for example, will treat its first argument as the name of a variable
323 and its second argument as a string value to assign to that variable.
324 For other commands arguments may be interpreted as integers, lists,
325 file names, or Tcl commands.
327 Command names should normally be typed completely (e.g. no abbreviations).
328 However, if the Tcl interpreter cannot locate a command it invokes a
329 special command named `unknown` which attempts to find or create the
332 For example, at many sites `unknown` will search through library
333 directories for the desired command and create it as a Tcl procedure if
334 it is found. The `unknown` command often provides automatic completion
335 of abbreviated commands, but usually only for commands that were typed
338 It's probably a bad idea to use abbreviations in command scripts and
339 other forms that will be re-used over time: changes to the command set
340 may cause abbreviations to become ambiguous, resulting in scripts that
345 If the first non-blank character in a command is +\#+, then everything
346 from the +#+ up through the next newline character is treated as
347 a comment and ignored. When comments are embedded inside nested
348 commands (e.g. fields enclosed in braces) they must have properly-matched
349 braces (this is necessary because when Tcl parses the top-level command
350 it doesn't yet know that the nested field will be used as a command so
351 it cannot process the nested comment character as a comment).
353 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
354 -------------------------------------
355 Normally each argument field ends at the next white space, but
356 double-quotes may be used to create arguments with embedded space.
358 If an argument field begins with a double-quote, then the argument isn't
359 terminated by white space (including newlines) or a semi-colon (see below
360 for information on semi-colons); instead it ends at the next double-quote
361 character. The double-quotes are not included in the resulting argument.
362 For example, the command
364 set a "This is a single argument"
366 will pass two arguments to `set`: 'a' and 'This is a single argument'.
368 Within double-quotes, command substitutions, variable substitutions,
369 and backslash substitutions still occur, as described below. If the
370 first character of a command field is not a quote, then quotes receive
371 no special interpretation in the parsing of that field.
373 GROUPING ARGUMENTS WITH BRACES
374 ------------------------------
375 Curly braces may also be used for grouping arguments. They are similar
376 to quotes except for two differences. First, they nest; this makes them
377 easier to use for complicated arguments like nested Tcl command strings.
378 Second, the substitutions described below for commands, variables, and
379 backslashes do *not* occur in arguments enclosed in braces, so braces
380 can be used to prevent substitutions where they are undesirable.
382 If an argument field begins with a left brace, then the argument ends
383 at the matching right brace. Tcl will strip off the outermost layer
384 of braces and pass the information between the braces to the command
385 without any further modification. For example, in the command
387 set a {xyz a {b c d}}
389 the `set` command will receive two arguments: 'a'
392 When braces or quotes are in effect, the matching brace or quote need
393 not be on the same line as the starting quote or brace; in this case
394 the newline will be included in the argument field along with any other
395 characters up to the matching brace or quote. For example, the `eval`
396 command takes one argument, which is a command string; `eval` invokes
397 the Tcl interpreter to execute the command string. The command
404 will assign the value '22' to 'a' and '33' to 'b'.
406 If the first character of a command field is not a left
407 brace, then neither left nor right
408 braces in the field will be treated specially (except as part of
409 variable substitution; see below).
411 COMMAND SUBSTITUTION WITH BRACKETS
412 ----------------------------------
413 If an open bracket occurs in a field of a command, then command
414 substitution occurs (except for fields enclosed in braces). All of the
415 text up to the matching close bracket is treated as a Tcl command and
416 executed immediately. Then the result of that command is substituted
417 for the bracketed text. For example, consider the command
421 When the `set` command has only a single argument, it is the name of a
422 variable and `set` returns the contents of that variable. In this case,
423 if variable 'b' has the value 'foo', then the command above is equivalent
428 Brackets can be used in more complex ways. For example, if the variable
429 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
432 set a xyz[set b].[set c]
434 is equivalent to the command
439 A bracketed command may contain multiple commands separated by newlines
440 or semi-colons in the usual fashion. In this case the value of the last
441 command is used for substitution. For example, the command
446 is equivalent to the command
451 If a field is enclosed in braces then the brackets and the characters
452 between them are not interpreted specially; they are passed through to
453 the argument verbatim.
455 VARIABLE SUBSTITUTION WITH $
456 ----------------------------
457 The dollar sign (+$+) may be used as a special shorthand form for
458 substituting variable values. If +$+ appears in an argument that isn't
459 enclosed in braces then variable substitution will occur. The characters
460 after the +$+, up to the first character that isn't a number, letter,
461 or underscore, are taken as a variable name and the string value of that
462 variable is substituted for the name.
464 For example, if variable 'foo' has the value 'test', then the command
468 is equivalent to the command
472 There are two special forms for variable substitution. If the next
473 character after the name of the variable is an open parenthesis, then
474 the variable is assumed to be an array name, and all of the characters
475 between the open parenthesis and the next close parenthesis are taken as
476 an index into the array. Command substitutions and variable substitutions
477 are performed on the information between the parentheses before it is
480 For example, if the variable 'x' is an array with one element named
481 'first' and value '87' and another element named '14' and value 'more',
484 set a xyz$x(first)zyx
486 is equivalent to the command
490 If the variable 'index' has the value '14', then the command
492 set a xyz$x($index)zyx
494 is equivalent to the command
498 For more information on arrays, see VARIABLES AND ARRAYS below.
500 The second special form for variables occurs when the dollar sign is
501 followed by an open curly brace. In this case the variable name consists
502 of all the characters up to the next curly brace.
504 Array references are not possible in this form: the name between braces
505 is assumed to refer to a scalar variable. For example, if variable
506 'foo' has the value 'test', then the command
510 is equivalent to the command
515 Variable substitution does not occur in arguments that are enclosed in
516 braces: the dollar sign and variable name are passed through to the
519 The dollar sign abbreviation is simply a shorthand form. +$a+ is
520 completely equivalent to +[set a]+; it is provided as a convenience
523 SEPARATING COMMANDS WITH SEMI-COLONS
524 ------------------------------------
525 Normally, each command occupies one line (the command is terminated by a
526 newline character). However, semi-colon (+;+) is treated as a command
527 separator character; multiple commands may be placed on one line by
528 separating them with a semi-colon. Semi-colons are not treated as
529 command separators if they appear within curly braces or double-quotes.
531 BACKSLASH SUBSTITUTION
532 ----------------------
533 Backslashes may be used to insert non-printing characters into command
534 fields and also to insert special characters like braces and brackets
535 into fields without them being interpreted specially as described above.
537 The backslash sequences understood by the Tcl interpreter are
538 listed below. In each case, the backslash
539 sequence is replaced by the given character:
540 [[BackslashSequences]]
551 Carriage-return (0xd).
574 +{backslash}<space>+::
575 Space ( ): doesn't terminate argument.
578 Semi-colon: doesn't terminate command.
583 +{backslash}<newline>+::
584 Nothing: this joins two lines together
585 into a single line. This backslash feature is unique in that
586 it will be applied even when the sequence occurs within braces.
588 +{backslash}{backslash}+::
589 Backslash ('{backslash}').
592 The digits +'ddd'+ (one, two, or three of them) give the octal value of
593 the character. Note that Jim supports null characters in strings.
596 +{backslash}u\{nnn\}+::
597 +{backslash}Unnnnnnnn+::
598 The UTF-8 encoding of the unicode codepoint represented by the hex digits, +'nnnn'+, is inserted.
599 The 'u' form allows for one to four hex digits.
600 The 'U' form allows for one to eight hex digits.
601 The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
602 characters UTF-8 characters which are followed by a hex digit.
604 For example, in the command
608 the second argument to `set` will be +{x[ yza+.
610 If a backslash is followed by something other than one of the options
611 described above, then the backslash is transmitted to the argument
612 field without any special processing, and the Tcl scanner continues
613 normal processing with the next character. For example, in the
618 The first argument to `set` will be +{backslash}*a+ and the second
619 argument will be +{backslash}{foo+.
621 If an argument is enclosed in braces, then backslash sequences inside
622 the argument are parsed but no substitution occurs (except for
623 backslash-newline): the backslash
624 sequence is passed through to the argument as is, without making
625 any special interpretation of the characters in the backslash sequence.
626 In particular, backslashed braces are not counted in locating the
627 matching right brace that terminates the argument.
633 the second argument to `set` will be +{backslash}{abc+.
635 This backslash mechanism is not sufficient to generate absolutely
636 any argument structure; it only covers the
637 most common cases. To produce particularly complicated arguments
638 it is probably easiest to use the `format` command along with
639 command substitution.
641 STRING AND LIST INDEX SPECIFICATIONS
642 ------------------------------------
644 Many string and list commands take one or more 'index' parameters which
645 specify a position in the string relative to the start or end of the string/list.
647 The index may be one of the following forms:
650 A simple integer, where '0' refers to the first element of the string
653 +integer+integer+ or::
655 The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
656 This is useful when used with (e.g.) +$i+1+ rather than the more verbose
660 The last element of the string or list.
663 The 'nth-from-last' element of the string or list.
667 1. A command is just a string.
668 2. Within a string commands are separated by newlines or semi-colons
669 (unless the newline or semi-colon is within braces or brackets
671 3. A command consists of fields. The first field is the name of the command.
672 The other fields are strings that are passed to that command as arguments.
673 4. Fields are normally separated by white space.
674 5. Double-quotes allow white space and semi-colons to appear within
676 Command substitution, variable substitution, and backslash substitution
677 still occur inside quotes.
678 6. Braces defer interpretation of special characters.
679 If a field begins with a left brace, then it consists of everything
680 between the left brace and the matching right brace. The
681 braces themselves are not included in the argument.
682 No further processing is done on the information between the braces
683 except that backslash-newline sequences are eliminated.
684 7. If a field doesn't begin with a brace then backslash,
685 variable, and command substitution are done on the field. Only a
686 single level of processing is done: the results of one substitution
687 are not scanned again for further substitutions or any other
688 special treatment. Substitution can
689 occur on any field of a command, including the command name
690 as well as the arguments.
691 8. If the first non-blank character of a command is a +\#+, everything
692 from the +#+ up through the next newline is treated as a comment
697 The second major interpretation applied to strings in Tcl is
698 as expressions. Several commands, such as `expr`, `for`,
699 and `if`, treat one or more of their arguments as expressions
700 and call the Tcl expression processors ('Jim_ExprLong',
701 'Jim_ExprBoolean', etc.) to evaluate them.
703 The operators permitted in Tcl expressions are a subset of
704 the operators permitted in C expressions, and they have the
705 same meaning and precedence as the corresponding C operators.
706 Expressions almost always yield numeric results
707 (integer or floating-point values).
708 For example, the expression
714 Tcl expressions differ from C expressions in the way that
715 operands are specified, and in that Tcl expressions support
716 non-numeric operands and string comparisons.
718 A Tcl expression consists of a combination of operands, operators,
721 White space may be used between the operands and operators and
722 parentheses; it is ignored by the expression processor.
723 Where possible, operands are interpreted as integer values.
725 Integer values may be specified in decimal (the normal case) or in
726 hexadecimal (if the first two characters of the operand are '0x').
727 Note that Jim Tcl does *not* treat numbers with leading zeros as octal.
729 If an operand does not have one of the integer formats given
730 above, then it is treated as a floating-point number if that is
731 possible. Floating-point numbers may be specified in any of the
732 ways accepted by an ANSI-compliant C compiler (except that the
733 'f', 'F', 'l', and 'L' suffixes will not be permitted in
734 most installations). For example, all of the
735 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.
737 If no numeric interpretation is possible, then an operand is left
738 as a string (and only a limited set of operators may be applied to
741 String constants representing boolean constants
742 (+'0'+, +'1'+, +'false'+, +'off'+, +'no'+, +'true'+, +'on'+, +'yes'+)
743 are also recognized and can be used in logical operations.
745 1. Operands may be specified in any of the following ways:
747 2. As a numeric value, either integer or floating-point.
749 3. As one of valid boolean constants
751 4. As a Tcl variable, using standard '$' notation.
752 The variable's value will be used as the operand.
754 5. As a string enclosed in double-quotes.
755 The expression parser will perform backslash, variable, and
756 command substitutions on the information between the quotes,
757 and use the resulting value as the operand
759 6. As a string enclosed in braces.
760 The characters between the open brace and matching close brace
761 will be used as the operand without any substitutions.
763 7. As a Tcl command enclosed in brackets.
764 The command will be executed and its result will be used as
767 Where substitutions occur above (e.g. inside quoted strings), they
768 are performed by the expression processor.
769 However, an additional layer of substitution may already have
770 been performed by the command parser before the expression
771 processor was called.
773 As discussed below, it is usually best to enclose expressions
774 in braces to prevent the command parser from performing substitutions
777 For some examples of simple expressions, suppose the variable 'a' has
778 the value 3 and the variable 'b' has the value 6. Then the expression
779 on the left side of each of the lines below will evaluate to the value
780 on the right side of the line:
785 {word one} < "word $a" 0
787 The valid operators are listed below, grouped in decreasing order
789 [[OperatorPrecedence]]
790 +int() double() round() abs(), rand(), srand()+::
791 Unary functions (except rand() which takes no arguments)
792 * +'int()'+ converts the numeric argument to an integer by truncating down.
793 * +'double()'+ converts the numeric argument to floating point.
794 * +'round()'+ converts the numeric argument to the closest integer value.
795 * +'abs()'+ takes the absolute value of the numeric argument.
796 * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
797 * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
799 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
800 Unary math functions.
801 If Jim is compiled with math support, these functions are available.
804 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
805 may be applied to string operands, and bit-wise NOT may be
806 applied only to integers.
809 Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
810 integers. Otherwise supports integers only. (Note that the math-function form
811 has the same highest precedence)
814 Multiply, divide, remainder. None of these operands may be
815 applied to string operands, and remainder may be applied only
819 Add and subtract. Valid for any numeric operands.
822 Left and right shift, left and right rotate. Valid for integer operands only.
825 Boolean less, greater, less than or equal, and greater than or equal.
826 Each operator produces 1 if the condition is true, 0 otherwise.
827 These operators may be applied to strings as well as numeric operands,
828 in which case string comparison is used.
831 Boolean equal and not equal. Each operator produces a zero/one result.
832 Valid for all operand types. *Note* that values will be converted to integers
833 if possible, then floating point types, and finally strings will be compared.
834 It is recommended that 'eq' and 'ne' should be used for string comparison.
837 String equal and not equal. Uses the string value directly without
838 attempting to convert to a number first.
841 String in list and not in list. For 'in', result is 1 if the left operand (as a string)
842 is contained in the right operand (as a list), or 0 otherwise. The result for
843 +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
846 Bit-wise AND. Valid for integer operands only.
849 Bit-wise OR. Valid for integer operands only.
852 Bit-wise exclusive OR. Valid for integer operands only.
855 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
856 Valid for numeric operands only (integers or floating-point).
859 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
860 Valid for numeric operands only (integers or floating-point).
863 If-then-else, as in C. If +'x'+
864 evaluates to non-zero, then the result is the value of +'y'+.
865 Otherwise the result is the value of +'z'+.
866 The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
869 See the C manual for more details on the results
870 produced by each operator.
871 All of the binary operators group left-to-right within the same
872 precedence level. For example, the expression
878 The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
879 in C, which means that operands are not evaluated if they are not
880 needed to determine the outcome. For example, in
884 only one of +[a]+ or +[b]+ will actually be evaluated,
885 depending on the value of +$v+.
887 All internal computations involving integers are done with the C
888 type 'long long' if available, or 'long' otherwise, and all internal
889 computations involving floating-point are done with the C type
892 When converting a string to floating-point, exponent overflow is
893 detected and results in a Tcl error.
894 For conversion to integer from string, detection of overflow depends
895 on the behaviour of some routines in the local C library, so it should
896 be regarded as unreliable.
897 In any case, overflow and underflow are generally not detected
898 reliably for intermediate results.
900 Conversion among internal representations for integer, floating-point,
901 string operands is done automatically as needed.
902 For arithmetic computations, integers are used until some
903 floating-point number is introduced, after which floating-point is used.
908 yields the result 1, while
911 5 / ( [string length "abcd"] + 0.0 )
913 both yield the result 1.25.
915 String values may be used as operands of the comparison operators,
916 although the expression evaluator tries to do comparisons as integer
917 or floating-point when it can.
918 If one of the operands of a comparison is a string and the other
919 has a numeric value, the numeric operand is converted back to
920 a string using the C 'sprintf' format specifier
921 '%d' for integers and '%g' for floating-point values.
922 For example, the expressions
927 both evaluate to 1. The first comparison is done using integer
928 comparison, and the second is done using string comparison after
929 the second operand is converted to the string '18'.
931 In general it is safest to enclose an expression in braces when
932 entering it in a command: otherwise, if the expression contains
933 any white space then the Tcl interpreter will split it
934 among several arguments. For example, the command
938 results in three arguments being passed to `expr`: +$a+,
939 \+, and +$b+. In addition, if the expression isn't in braces
940 then the Tcl interpreter will perform variable and command substitution
941 immediately (it will happen in the command parser rather than in
942 the expression parser). In many cases the expression is being
943 passed to a command that will evaluate the expression later (or
944 even many times if, for example, the expression is to be used to
945 decide when to exit a loop). Usually the desired goal is to re-do
946 the variable or command substitutions each time the expression is
947 evaluated, rather than once and for all at the beginning. For example,
950 for {set i 1} $i<=10 {incr i} {...} ** WRONG **
952 is probably intended to iterate over all values of +i+ from 1 to 10.
953 After each iteration of the body of the loop, `for` will pass
954 its second argument to the expression evaluator to see whether or not
955 to continue processing. Unfortunately, in this case the value of +i+
956 in the second argument will be substituted once and for all when the
957 `for` command is parsed. If +i+ was 0 before the `for`
958 command was invoked then the second argument of `for` will be +0\<=10+
959 which will always evaluate to 1, even though +i+ eventually
960 becomes greater than 10. In the above case the loop will never
961 terminate. Instead, the expression should be placed in braces:
963 for {set i 1} {$i<=10} {incr i} {...} ** RIGHT **
965 This causes the substitution of 'i'
966 to be delayed; it will be re-done each time the expression is
967 evaluated, which is the desired result.
971 The third major way that strings are interpreted in Tcl is as lists.
972 A list is just a string with a list-like structure
973 consisting of fields separated by white space. For example, the
978 is a list with four elements or fields.
979 Lists have the same basic structure as command strings, except
980 that a newline character in a list is treated as a field separator
981 just like space or tab. Conventions for braces and quotes
982 and backslashes are the same for lists as for commands. For example,
987 is a list with three elements: +a+, +b c+, and +d e {f g h}+.
989 Whenever an element is extracted from a list, the same rules about
990 braces and quotes and backslashes are applied as for commands. Thus in
991 the example above when the third element is extracted from the list,
996 (when the field was extracted, all that happened was to strip off
997 the outermost layer of braces). Command substitution and
998 variable substitution are never
999 made on a list (at least, not by the list-processing commands; the
1000 list can always be passed to the Tcl interpreter for evaluation).
1002 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
1003 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
1004 you to build lists, extract elements from them, search them, and perform
1005 other list-related functions.
1007 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
1012 A new addition to Tcl 8.5 is the ability to expand a list into separate
1013 arguments. Support for this feature is also available in Jim.
1015 Consider the following attempt to exec a list:
1020 This will attempt to exec a command named "ls -l", which will clearly not
1021 work. Typically eval and concat are required to solve this problem, however
1022 it can be solved much more easily with +\{*\}+.
1026 This will expand the following argument into individual elements and then evaluate
1027 the resulting command.
1029 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
1030 for backward compatibility with experimental versions of this feature.
1034 Tcl provides two commands that support string matching using regular
1035 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
1038 Regular expressions may be implemented one of two ways. Either using the system's C library
1039 POSIX regular expression support, or using the built-in regular expression engine.
1040 The differences between these are described below.
1042 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
1044 POSIX Regular Expressions
1045 ~~~~~~~~~~~~~~~~~~~~~~~~~
1046 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1047 this support will be used by default. The type of regular expressions supported are
1048 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
1049 See REG_EXTENDED in the documentation.
1051 Using the system-supported POSIX regular expressions will typically
1052 make for the smallest code size, but some features such as UTF-8
1053 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported, and null characters
1054 in strings are not supported.
1056 See regex(3) and regex(7) for full details.
1058 Jim built-in Regular Expressions
1059 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1060 The Jim built-in regular expression engine may be selected with +./configure --with-jim-regexp+
1061 or it will be selected automatically if UTF-8 support is enabled.
1063 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
1064 and POSIX are highlighted below.
1066 1. UTF-8 strings and patterns are both supported
1067 2. All Tcl character classes are supported (e.g. +[:alnum:]+, +[:digit:]+, +[:space:]+), but...
1068 3. Character classes apply to ASCII characters only
1069 4. Supported shorthand character classes: +{backslash}w+ = +[:alnum:]+, +{backslash}W+ = +^[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}D+ = +^[:digit:],+ +{backslash}s+ = +[:space:]+, + +{backslash}S+ = +^[:space:]+
1070 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1071 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1072 7. Partially supported constraint escapes: +{backslash}A+ = start of string, +{backslash}Z+ = end of string
1073 8. Support for the +?+ non-greedy quantifier. e.g. +*?+
1074 9. Support for non-capturing parentheses +(?:...)+
1075 10. Jim Tcl considers that both patterns and strings end at a null character (+\x00+)
1079 Each command produces two results: a code and a string. The
1080 code indicates whether the command completed successfully or not,
1081 and the string gives additional information. The valid codes are
1082 defined in jim.h, and are:
1085 This is the normal return code, and indicates that the command completed
1086 successfully. The string gives the command's return value.
1089 Indicates that an error occurred; the string gives a message describing
1093 Indicates that the `return` command has been invoked, and that the
1094 current procedure (or top-level command or `source` command)
1095 should return immediately. The
1096 string gives the return value for the procedure or command.
1099 Indicates that the `break` command has been invoked, so the
1100 innermost loop should abort immediately. The string should always
1104 Indicates that the `continue` command has been invoked, so the
1105 innermost loop should go on to the next iteration. The string
1106 should always be empty.
1109 Indicates that a signal was caught while executing a commands.
1110 The string contains the name of the signal caught.
1111 See the `signal` and `catch` commands.
1114 Indicates that the command called the `exit` command.
1115 The string contains the exit code.
1117 Tcl programmers do not normally need to think about return codes,
1118 since +JIM_OK+ is almost always returned. If anything else is returned
1119 by a command, then the Tcl interpreter immediately stops processing
1120 commands and returns to its caller. If there are several nested
1121 invocations of the Tcl interpreter in progress, then each nested
1122 command will usually return the error to its caller, until eventually
1123 the error is reported to the top-level application code. The
1124 application will then display the error message for the user.
1126 In a few cases, some commands will handle certain `error` conditions
1127 themselves and not return them upwards. For example, the `for`
1128 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1129 stops executing the body of the loop and returns +JIM_OK+ to its
1130 caller. The `for` command also handles +JIM_CONTINUE+ codes and the
1131 procedure interpreter handles +JIM_RETURN+ codes. The `catch`
1132 command allows Tcl programs to catch errors and handle them without
1133 aborting command interpretation any further.
1135 The `info returncodes` command may be used to programmatically map between
1136 return codes and names.
1140 Tcl allows you to extend the command interface by defining
1141 procedures. A Tcl procedure can be invoked just like any other Tcl
1142 command (it has a name and it receives one or more arguments).
1143 The only difference is that its body isn't a piece of C code linked
1144 into the program; it is a string containing one or more other
1147 The `proc` command is used to create a new Tcl command procedure:
1149 +*proc* 'name arglist ?statics? body'+
1151 The new command is named +'name'+, and it replaces any existing command
1152 there may have been by that name. Whenever the new command is
1153 invoked, the contents of +'body'+ will be executed by the Tcl
1156 +'arglist'+ specifies the formal arguments to the procedure.
1157 It consists of a list, possibly empty, of the following
1158 argument specifiers:
1161 Required Argument - A simple argument name.
1164 Optional Argument - A two-element list consisting of the
1165 argument name, followed by the default value, which will
1166 be used if the corresponding argument is not supplied.
1169 Reference Argument - The caller is expected to pass the name of
1170 an existing variable. An implicit +`upvar` 1 origname name+ is done
1171 to make the variable available in the proc scope.
1174 Variable Argument - The special name +'args'+, which is
1175 assigned all remaining arguments (including none) as a list. The
1176 variable argument may only be specified once. Note that
1177 the syntax +{args newname}+ may be used to retain the special
1178 behaviour of +'args'+ with a different local name. In this case,
1179 the variable is named +'newname'+ rather than +'args'+.
1181 When the command is invoked, a local variable will be created for each of
1182 the formal arguments to the procedure; its value will be the value
1183 of corresponding argument in the invoking command or the argument's
1186 Arguments with default values need not be specified in a procedure
1187 invocation. However, there must be enough actual arguments for all
1188 required arguments, and there must not be any extra actual arguments
1189 (unless the Variable Argument is specified).
1191 Actual arguments are assigned to formal arguments as in left-to-right
1192 order with the following precedence.
1194 1. Required Arguments (including Reference Arguments)
1195 2. Optional Arguments
1196 3. Variable Argument
1198 The following example illustrates precedence. Assume a procedure declaration:
1200 proc p {{a A} args b {c C} d} {...}
1202 This procedure requires at least two arguments, but can accept an unlimited number.
1203 The following table shows how various numbers of arguments are assigned.
1204 Values marked as +-+ are assigned the default value.
1206 [width="40%",frame="topbot",options="header"]
1208 |Number of arguments|a|args|b|c|d
1216 When +'body'+ is being executed, variable names normally refer to local
1217 variables, which are created automatically when referenced and deleted
1218 when the procedure returns. One local variable is automatically created
1219 for each of the procedure's arguments. Global variables can be
1220 accessed by invoking the `global` command or via the +::+ prefix.
1224 In addition to procedure arguments, Jim procedures may declare static variables.
1225 These variables scoped to the procedure and initialised at procedure definition.
1226 Either from the static variable definition, or from the enclosing scope.
1228 Consider the following example:
1231 jim> proc a {} {a {b 2}} {
1243 The static variable +'a'+ has no initialiser, so it is initialised from
1244 the enclosing scope with the value 1. (Note that it is an error if there
1245 is no variable with the same name in the enclosing scope). However +'b'+
1246 has an initialiser, so it is initialised to 2.
1248 Unlike a local variable, the value of a static variable is retained across
1249 invocations of the procedure.
1251 See the `proc` command for information on how to define procedures
1252 and what happens when they are invoked. See also NAMESPACES.
1254 VARIABLES - SCALARS AND ARRAYS
1255 ------------------------------
1256 Tcl allows the definition of variables and the use of their values
1257 either through '$'-style variable substitution, the `set`
1258 command, or a few other mechanisms.
1260 Variables need not be declared: a new variable will automatically
1261 be created each time a new variable name is used.
1263 Tcl supports two types of variables: scalars and arrays.
1264 A scalar variable has a single value, whereas an array variable
1265 can have any number of elements, each with a name (called
1266 its 'index') and a value.
1268 Array indexes may be arbitrary strings; they need not be numeric.
1269 Parentheses are used refer to array elements in Tcl commands.
1270 For example, the command
1274 will modify the element of 'x' whose index is 'first'
1275 so that its new value is '44'.
1277 Two-dimensional arrays can be simulated in Tcl by using indexes
1278 that contain multiple concatenated values.
1279 For example, the commands
1284 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1286 In general, array elements may be used anywhere in Tcl that scalar
1287 variables may be used.
1289 If an array is defined with a particular name, then there may
1290 not be a scalar variable with the same name.
1292 Similarly, if there is a scalar variable with a particular
1293 name then it is not possible to make array references to the
1296 To convert a scalar variable to an array or vice versa, remove
1297 the existing variable with the `unset` command.
1299 The `array` command provides several features for dealing
1300 with arrays, such as querying the names of all the elements of
1301 the array and converting between an array and a list.
1303 Variables may be either global or local. If a variable
1304 name is used when a procedure isn't being executed, then it
1305 automatically refers to a global variable. Variable names used
1306 within a procedure normally refer to local variables associated with that
1307 invocation of the procedure. Local variables are deleted whenever
1308 a procedure exits. Either `global` command may be used to request
1309 that a name refer to a global variable for the duration of the current
1310 procedure (this is somewhat analogous to 'extern' in C), or the variable
1311 may be explicitly scoped with the +::+ prefix. For example
1327 ARRAYS AS LISTS IN JIM
1328 ----------------------
1329 Unlike Tcl, Jim can automatically convert between a list (with an even
1330 number of elements) and an array value. This is similar to the way Tcl
1331 can convert between a string and a list.
1342 Thus `array set` is equivalent to `set` when the variable does not
1345 The reverse is also true where an array will be converted into
1348 set a(1) one; set a(2) two
1357 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1358 of this command. Dictionaries provide efficient access to key-value
1359 pairs, just like arrays, but dictionaries are pure values. This
1360 means that you can pass them to a procedure just as a list or a
1361 string. Tcl dictionaries are therefore much more like Tcl lists,
1362 except that they represent a mapping from keys to values, rather
1363 than an ordered sequence.
1365 You can nest dictionaries, so that the value for a particular key
1366 consists of another dictionary. That way you can elegantly build
1367 complicated data structures, such as hierarchical databases. You
1368 can also combine dictionaries with other Tcl data structures. For
1369 instance, you can build a list of dictionaries that themselves
1372 Dictionaries are values that contain an efficient, order-preserving
1373 mapping from arbitrary keys to arbitrary values. Each key in the
1374 dictionary maps to a single value. They have a textual format that
1375 is exactly that of any list with an even number of elements, with
1376 each mapping in the dictionary being represented as two items in
1377 the list. When a command takes a dictionary and produces a new
1378 dictionary based on it (either returning it or writing it back into
1379 the variable that the starting dictionary was read from) the new
1380 dictionary will have the same order of keys, modulo any deleted
1381 keys and with new keys added on to the end. When a string is
1382 interpreted as a dictionary and it would otherwise have duplicate
1383 keys, only the last value for a particular key is used; the others
1384 are ignored, meaning that, "apple banana" and "apple carrot apple
1385 banana" are equivalent dictionaries (with different string
1388 Note that in Jim, arrays are implemented as dictionaries.
1389 Thus automatic conversion between lists and dictionaries applies
1390 as it does for arrays.
1392 jim> dict set a 1 one
1394 jim> dict set a 2 two
1400 jim> dict set a 3 T three
1401 1 one 2 two 3 {T three}
1403 See the `dict` command for more details.
1407 Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
1408 including a number of 3rd party components. While there is less need for namespaces
1409 in Jim Tcl (which does not strive to support large applications), it is convenient to
1410 provide a subset of the support for namespaces to easy porting code from Tcl.
1412 Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
1413 purposes. This feature is currently experimental. See README.namespaces for more information
1414 and the documentation of the `namespace` command.
1416 GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION
1417 -----------------------------------------------
1418 Unlike Tcl, Jim has some sophisticated support for functional programming.
1419 These are described briefly below.
1421 More information may be found at http://wiki.tcl.tk/13847
1425 A reference can be thought of as holding a value with one level of indirection,
1426 where the value may be garbage collected when unreferenced.
1427 Consider the following example:
1429 jim> set r [ref "One String" test]
1430 <reference.<test___>.00000000000000000000>
1434 The operation `ref` creates a references to the value specified by the
1435 first argument. (The second argument is a "type" used for documentation purposes).
1437 The operation `getref` is the dereferencing operation which retrieves the value
1438 stored in the reference.
1440 jim> setref $r "New String"
1445 The operation `setref` replaces the value stored by the reference. If the old value
1446 is no longer accessible by any reference, it will eventually be automatically be garbage
1451 Normally, all values in Tcl are passed by value. As such values are copied and released
1452 automatically as necessary.
1454 With the introduction of references, it is possible to create values whose lifetime
1455 transcend their scope. To support this, case, the Jim system will periodically identify
1456 and discard objects which are no longer accessible by any reference.
1458 The `collect` command may be used to force garbage collection. Consider a reference created
1461 jim> proc f {ref value} { puts "Finaliser called for $ref,$value" }
1462 jim> set r [ref "One String" test f]
1463 <reference.<test___>.00000000000
1468 Finaliser called for <reference.<test___>.00000000000,One String
1471 Note that once the reference, 'r', was modified so that it no longer
1472 contained a reference to the value, the garbage collector discarded
1473 the value (after calling the finalizer).
1475 The finalizer for a reference may be examined or changed with the `finalize` command
1479 jim> finalize $r newf
1484 Jim provides a garbage collected `lambda` function. This is a procedure
1485 which is able to create an anonymous procedure. Consider:
1487 jim> set f [lambda {a} {{x 0}} { incr x $a }]
1494 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1495 which is incremented by the supplied value and the result returned.
1497 Once the procedure name is no longer accessible, it will automatically be deleted
1498 when the garbage collector runs.
1500 The procedure may also be delete immediately by renaming it "". e.g.
1506 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1507 then most string-related commands become UTF-8 aware. These include,
1508 but are not limited to, `string match`, `split`, `glob`, `scan` and
1511 UTF-8 encoding has many advantages, but one of the complications is that
1512 characters can take a variable number of bytes. Thus the addition of
1513 `string bytelength` which returns the number of bytes in a string,
1514 while `string length` returns the number of characters.
1516 If UTF-8 support is not enabled, all commands treat bytes as characters
1517 and `string bytelength` returns the same value as `string length`.
1519 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ and related syntax
1520 is still available to embed UTF-8 sequences.
1522 Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.
1526 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1527 pattern matching rules. These commands support UTF-8. For example:
1529 string match a\[\ua0-\ubf\]b "a\u00a3b"
1533 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1534 a string with two bytes and one character. The same as +{backslash}ub5+
1538 `format` respects widths as character widths, not byte widths. For example, the following will
1539 return a string with three characters, not three bytes.
1541 format %.3s \ub5\ub6\ub7\ub8
1543 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1544 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1546 scan \u00b5A %c%c a b
1548 `scan %s` will also accept a character class, including unicode ranges.
1552 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1553 will return 0, even though the string may be considered to be alphabetic.
1555 string is alpha \ub5Test
1557 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1559 Case Mapping and Conversion
1560 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1561 Jim provides a simplified unicode case mapping. This means that case conversion
1562 and comparison will not increase or decrease the number of characters in a string.
1563 (Although it may change the number of bytes).
1565 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1566 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1567 Similarly for `string tolower` and `string totitle`.
1569 Commands which perform case insensitive matches, such as `string compare -nocase`
1570 and `lsearch -nocase` fold both strings to uppercase before comparison.
1572 Invalid UTF-8 Sequences
1573 ~~~~~~~~~~~~~~~~~~~~~~~
1574 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1575 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1576 and those which end prematurely, such as a lone '0xc2'.
1578 In these situations, the offending bytes are treated as single characters. For example,
1579 the following returns 2.
1581 string bytelength \xff\xff
1585 If UTF-8 support is enabled, the built-in regular expression engine will be
1586 selected which supports UTF-8 strings and patterns.
1588 See REGULAR EXPRESSIONS
1592 The Tcl library provides the following built-in commands, which will
1593 be available in any application using Tcl. In addition to these
1594 built-in commands, there may be additional commands defined by each
1595 application, plus commands defined as Tcl procedures.
1597 In the command syntax descriptions below, words in +*boldface*+ are
1598 literals that you type verbatim to Tcl.
1600 Words in +'italics'+ are meta-symbols; they serve as names for any of
1601 a range of values that you can type.
1603 Optional arguments or groups of arguments are indicated by enclosing them
1604 in +?question-marks?+.
1606 Ellipses (+\...+) indicate that any number of additional
1607 arguments or groups of arguments may appear, in the same format
1608 as the preceding argument(s).
1619 Delivers the +SIGALRM+ signal to the process after the given
1620 number of seconds. If the platform supports 'ualarm(3)' then
1621 the argument may be a floating point value. Otherwise it must
1624 Note that unless a signal handler for +SIGALRM+ has been installed
1625 (see `signal`), the process will exit on this signal.
1629 +*alias* 'name args\...'+
1631 Creates a single word alias (command) for one or more words. For example,
1632 the following creates an alias for the command `info exists`.
1639 `alias` returns +'name'+, allowing it to be used with `local`.
1641 See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`
1645 +*append* 'varName value ?value value ...?'+
1647 Append all of the +'value'+ arguments to the current value
1648 of variable +'varName'+. If +'varName'+ doesn't exist,
1649 it is given a value equal to the concatenation of all the
1650 +'value'+ arguments.
1652 This command provides an efficient way to build up long
1653 variables incrementally.
1654 For example, "`append a $b`" is much more efficient than
1655 "`set a $a$b`" if +$a+ is long.
1659 +*apply* 'lambdaExpr ?arg1 arg2 \...?'+
1661 The command `apply` provides for anonymous procedure calls,
1662 similar to `lambda`, but without command name being created, even temporarily.
1664 The function +'lambdaExpr'+ is a two element list +{args body}+
1665 or a three element list +{args body namespace}+. The first element
1666 args specifies the formal arguments, in the same form as the `proc` and `lambda` commands.
1670 +*array* 'option arrayName ?arg\...?'+
1672 This command performs one of several operations on the
1673 variable given by +'arrayName'+.
1675 Note that in general, if the named array does not exist, the +'array'+ command behaves
1676 as though the array exists but is empty.
1678 The +'option'+ argument determines what action is carried out by the
1679 command. The legal +'options'+ (which may be abbreviated) are:
1681 +*array exists* 'arrayName'+::
1682 Returns 1 if arrayName is an array variable, 0 if there is
1683 no variable by that name.
1685 +*array get* 'arrayName ?pattern?'+::
1686 Returns a list containing pairs of elements. The first
1687 element in each pair is the name of an element in arrayName
1688 and the second element of each pair is the value of the
1689 array element. The order of the pairs is undefined. If
1690 pattern is not specified, then all of the elements of the
1691 array are included in the result. If pattern is specified,
1692 then only those elements whose names match pattern (using
1693 the matching rules of string match) are included. If arrayName
1694 isn't the name of an array variable, or if the array contains
1695 no elements, then an empty list is returned.
1697 +*array names* 'arrayName ?pattern?'+::
1698 Returns a list containing the names of all of the elements
1699 in the array that match pattern. If pattern is omitted then
1700 the command returns all of the element names in the array.
1701 If pattern is specified, then only those elements whose
1702 names match pattern (using the matching rules of string
1703 match) are included. If there are no (matching) elements
1704 in the array, or if arrayName isn't the name of an array
1705 variable, then an empty string is returned.
1707 +*array set* 'arrayName list'+::
1708 Sets the values of one or more elements in arrayName. list
1709 must have a form like that returned by array get, consisting
1710 of an even number of elements. Each odd-numbered element
1711 in list is treated as an element name within arrayName, and
1712 the following element in list is used as a new value for
1713 that array element. If the variable arrayName does not
1714 already exist and list is empty, arrayName is created with
1715 an empty array value.
1717 +*array size* 'arrayName'+::
1718 Returns the number of elements in the array. If arrayName
1719 isn't the name of an array then 0 is returned.
1721 +*array unset* 'arrayName ?pattern?'+::
1722 Unsets all of the elements in the array that match pattern
1723 (using the matching rules of string match). If arrayName
1724 isn't the name of an array variable or there are no matching
1725 elements in the array, no error will be raised. If pattern
1726 is omitted and arrayName is an array variable, then the
1727 command unsets the entire array. The command always returns
1734 This command may be invoked only inside the body of a loop command
1735 such as `for` or `foreach` or `while`. It returns a +JIM_BREAK+ code
1736 to signal the innermost containing loop command to return immediately.
1740 +*case* 'string' ?in? 'patList body ?patList body ...?'+
1742 +*case* 'string' ?in? {'patList body ?patList body ...?'}+
1744 *Note* that the `switch` command should generally be preferred unless compatibility
1745 with Tcl 6.x is desired.
1747 Match +'string'+ against each of the +'patList'+ arguments
1748 in order. If one matches, then evaluate the following +'body'+ argument
1749 by passing it recursively to the Tcl interpreter, and return the result
1750 of that evaluation. Each +'patList'+ argument consists of a single
1751 pattern or list of patterns. Each pattern may contain any of the wild-cards
1752 described under `string match`.
1754 If a +'patList'+ argument is +default+, the corresponding body will be
1755 evaluated if no +'patList'+ matches +'string'+. If no +'patList'+ argument
1756 matches +'string'+ and no default is given, then the `case` command returns
1759 Two syntaxes are provided.
1761 The first uses a separate argument for each of the patterns and commands;
1762 this form is convenient if substitutions are desired on some of the
1763 patterns or commands.
1765 The second form places all of the patterns and commands together into
1766 a single argument; the argument must have proper list structure, with
1767 the elements of the list being the patterns and commands.
1769 The second form makes it easy to construct multi-line case commands,
1770 since the braces around the whole list make it unnecessary to include a
1771 backslash at the end of each line.
1773 Since the +'patList'+ arguments are in braces in the second form,
1774 no command or variable substitutions are performed on them; this makes
1775 the behaviour of the second form different than the first form in some
1778 Below are some examples of `case` commands:
1780 case abc in {a b} {format 1} default {format 2} a* {format 3}
1790 will return '1', and
1805 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1807 The `catch` command may be used to prevent errors from aborting
1808 command interpretation. `catch` evaluates +'command'+, and returns a
1809 +JIM_OK+ code, regardless of any errors that might occur while
1810 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1813 The return value from `catch` is a decimal string giving the code
1814 returned by the Tcl interpreter after executing +'command'+. This
1815 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1816 it will have a non-zero value corresponding to one of the exceptional
1817 return codes (see jim.h for the definitions of code values, or the
1818 `info returncodes` command).
1820 If the +'resultVarName'+ argument is given, then it gives the name
1821 of a variable; `catch` will set the value of the variable to the
1822 string returned from +'command'+ (either a result or an error message).
1824 If the +'optionsVarName'+ argument is given, then it gives the name
1825 of a variable; `catch` will set the value of the variable to a
1826 dictionary. For any return code other than +JIM_RETURN+, the value
1827 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1828 it will be set to the code given in `return -code`. Additionally,
1829 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1830 will contain the current stack trace (the same result as `info stacktrace`),
1831 the value of the key +-errorcode+ will contain the
1832 same value as the global variable $::errorCode, and the value of
1833 the key +-level+ will be the current return level (see `return -level`).
1834 This can be useful to rethrow an error:
1836 if {[catch {...} msg opts]} {
1837 ...maybe do something with the error...
1839 return {*}$opts $msg
1842 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1843 The set of codes which will be caught may be modified by specifying the one more codes before
1846 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1848 catch -exit -nobreak -nocontinue -- { ... }
1850 The use of +--+ is optional. It signifies that no more return code options follow.
1852 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1853 (stored in +'resultVarName'+) is name of the signal caught.
1859 Change the current working directory to +'dirName'+.
1861 Returns an empty string.
1863 This command can potentially be disruptive to an application, so it may
1864 be removed in some applications.
1869 Returns the current time as seconds since the epoch.
1872 Returns the current time in "clicks", a system-dependent, high-resolution time.
1874 +*clock microseconds*+::
1875 Returns the current time in microseconds.
1877 +*clock milliseconds*+::
1878 Returns the current time in milliseconds.
1880 +*clock format* 'seconds' ?*-format* 'format?' ?*-gmt* 'boolean?'+::
1881 Format the given time (seconds since the epoch) according to the given
1882 format. See strftime(3) for supported formats.
1883 If no format is supplied, "%c" is used.
1885 If +'boolean'+ is true, processing is performed in UTC.
1886 If +'boolean'+ is false (the default), processing is performeed in the local time zone.
1888 +*clock scan* 'str' *-format* 'format' ?*-gmt* 'boolean?'+::
1889 Scan the given time string using the given format string.
1890 See strptime(3) for supported formats.
1891 See `clock format` for the handling of '-gmt'.
1899 Closes the file given by +'fileId'+.
1900 +'fileId'+ must be the return value from a previous invocation
1901 of the `open` command; after this command, it should not be
1908 Normally reference garbage collection is automatically performed periodically.
1909 However it may be run immediately with the `collect` command.
1911 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
1915 +*concat* 'arg ?arg \...?'+
1917 This command treats each argument as a list and concatenates them
1918 into a single list. It permits any number of arguments. For example,
1921 concat a b {c d e} {f {g h}}
1933 This command may be invoked only inside the body of a loop command such
1934 as `for` or `foreach` or `while`. It returns a +JIM_CONTINUE+ code to
1935 signal the innermost containing loop command to skip the remainder of
1936 the loop's body but continue with the next iteration of the loop.
1940 +*alias* 'args\...'+
1942 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
1945 the following creates a local, unnamed alias for the command `info exists`.
1947 set e [local curry info exists]
1952 `curry` returns the name of the procedure.
1954 See also `proc`, `alias`, `lambda`, `local`.
1958 +*dict* 'option ?arg\...?'+
1960 Performs one of several operations on dictionary values.
1962 The +'option'+ argument determines what action is carried out by the
1963 command. The legal +'options'+ are:
1965 +*dict create* '?key value \...?'+::
1966 Create and return a new dictionary value that contains each of
1967 the key/value mappings listed as arguments (keys and values
1968 alternating, with each key being followed by its associated
1971 +*dict exists* 'dictionary key ?key \...?'+::
1972 Returns a boolean value indicating whether the given key (or path
1973 of keys through a set of nested dictionaries) exists in the given
1974 dictionary value. This returns a true value exactly when `dict get`
1975 on that path will succeed.
1977 +*dict get* 'dictionary ?key \...?'+::
1978 Given a dictionary value (first argument) and a key (second argument),
1979 this will retrieve the value for that key. Where several keys are
1980 supplied, the behaviour of the command shall be as if the result
1981 of "`dict get $dictVal $key`" was passed as the first argument to
1982 dict get with the remaining arguments as second (and possibly
1983 subsequent) arguments. This facilitates lookups in nested dictionaries.
1984 If no keys are provided, dict would return a list containing pairs
1985 of elements in a manner similar to array get. That is, the first
1986 element of each pair would be the key and the second element would
1987 be the value for that key. It is an error to attempt to retrieve
1988 a value for a key that is not present in the dictionary.
1990 +*dict keys* 'dictionary ?pattern?'+::
1991 Returns a list of the keys in the dictionary.
1992 If pattern is specified, then only those keys whose
1993 names match +'pattern'+ (using the matching rules of string
1994 match) are included.
1996 +*dict merge* ?'dictionary \...'?+::
1997 Return a dictionary that contains the contents of each of the
1998 +'dictionary'+ arguments. Where two (or more) dictionaries
1999 contain a mapping for the same key, the resulting dictionary
2000 maps that key to the value according to the last dictionary on
2001 the command line containing a mapping for that key.
2003 +*dict set* 'dictionaryName key ?key \...? value'+::
2004 This operation takes the +'name'+ of a variable containing a dictionary
2005 value and places an updated dictionary value in that variable
2006 containing a mapping from the given key to the given value. When
2007 multiple keys are present, this operation creates or updates a chain
2008 of nested dictionaries.
2010 +*dict size* 'dictionary'+::
2011 Return the number of key/value mappings in the given dictionary value.
2013 +*dict unset* 'dictionaryName key ?key \...? value'+::
2014 This operation (the companion to `dict set`) takes the name of a
2015 variable containing a dictionary value and places an updated
2016 dictionary value in that variable that does not contain a mapping
2017 for the given key. Where multiple keys are present, this describes
2018 a path through nested dictionaries to the mapping to remove. At
2019 least one key must be specified, but the last key on the key-path
2020 need not exist. All other components on the path must exist.
2022 +*dict with* 'dictionaryName key ?key \...? script'+::
2023 Execute the Tcl script in +'script'+ with the value for each
2024 key in +'dictionaryName'+ mapped to a variable with the same
2025 name. Where one or more keys are given, these indicate a chain
2026 of nested dictionaries, with the innermost dictionary being the
2027 one opened out for the execution of body. Making +'dictionaryName'+
2028 unreadable will make the updates to the dictionary be discarded,
2029 and this also happens if the contents of +'dictionaryName'+ are
2030 adjusted so that the chain of dictionaries no longer exists.
2031 The result of `dict with` is (unless some kind of error occurs)
2032 the result of the evaluation of body.
2034 The variables are mapped in the scope enclosing the `dict with`;
2035 it is recommended that this command only be used in a local
2036 scope (procedure). Because of this, the variables set by
2037 `dict with` will continue to exist after the command finishes (unless
2038 explicitly unset). Note that changes to the contents of +'dictionaryName'+
2039 only happen when +'script'+ terminates.
2041 +*dict for, values, incr, append, lappend, update, info, replace*+ to be documented...
2045 +*env* '?name? ?default?'+
2047 If +'name'+ is supplied, returns the value of +'name'+ from the initial
2048 environment (see getenv(3)). An error is returned if +'name'+ does not
2049 exist in the environment, unless +'default'+ is supplied - in which case
2050 that value is returned instead.
2052 If no arguments are supplied, returns a list of all environment variables
2053 and their values as +{name value \...}+
2055 See also the global variable +::env+
2063 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
2066 +'fileId'+ must have been the return value from a previous call to `open`,
2067 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
2068 standard I/O channels.
2072 +*error* 'message ?stacktrace?'+
2074 Returns a +JIM_ERR+ code, which causes command interpretation to be
2075 unwound. +'message'+ is a string that is returned to the application
2076 to indicate what went wrong.
2078 If the +'stacktrace'+ argument is provided and is non-empty,
2079 it is used to initialize the stacktrace.
2081 This feature is most useful in conjunction with the `catch` command:
2082 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
2083 to return a stack trace reflecting the original point of occurrence
2088 error $errMsg [info stacktrace]
2090 See also `errorInfo`, `info stacktrace`, `catch` and `return`
2094 +*errorInfo* 'error ?stacktrace?'+
2096 Returns a human-readable representation of the given error message and stack trace.
2099 if {[catch {...} error]} {
2100 puts stderr [errorInfo $error [info stacktrace]]
2108 +*eval* 'arg ?arg\...?'+
2110 `eval` takes one or more arguments, which together comprise a Tcl
2111 command (or collection of Tcl commands separated by newlines in the
2112 usual way). `eval` concatenates all its arguments in the same
2113 fashion as the `concat` command, passes the concatenated string to the
2114 Tcl interpreter recursively, and returns the result of that
2115 evaluation (or any error generated by it).
2119 +*exec* 'arg ?arg\...?'+
2121 This command treats its arguments as the specification
2122 of one or more UNIX commands to execute as subprocesses.
2123 The commands take the form of a standard shell pipeline;
2124 +|+ arguments separate commands in the
2125 pipeline and cause standard output of the preceding command
2126 to be piped into standard input of the next command (or +|&+ for
2127 both standard output and standard error).
2129 Under normal conditions the result of the `exec` command
2130 consists of the standard output produced by the last command
2131 in the pipeline followed by the standard error output.
2133 If any of the commands writes to its standard error file,
2134 then this will be included in the result after the standard output
2135 of the last command.
2137 Note that unlike Tcl, data written to standard error does not cause
2138 `exec` to return an error.
2140 If any of the commands in the pipeline exit abnormally or
2141 are killed or suspended, then `exec` will return an error.
2142 If no standard error output was produced, or is redirected,
2143 the error message will include the normal result, as above,
2144 followed by error messages describing the abnormal terminations.
2146 If any standard error output was produced, these abnormal termination
2147 messages are suppressed.
2149 If the last character of the result or error message
2150 is a newline then that character is deleted from the result
2151 or error message for consistency with normal
2154 An +'arg'+ may have one of the following special forms:
2157 The standard output of the last command in the pipeline
2158 is redirected to the file. In this situation `exec`
2159 will normally return an empty string.
2162 As above, but append to the file.
2165 The standard output of the last command in the pipeline is
2166 redirected to the given (writable) file descriptor (e.g. stdout,
2167 stderr, or the result of `open`). In this situation `exec`
2168 will normally return an empty string.
2171 The standard error of the last command in the pipeline
2172 is redirected to the file.
2175 As above, but append to the file.
2178 The standard error of the last command in the pipeline is
2179 redirected to the given (writable) file descriptor.
2182 The standard error of the last command in the pipeline is
2183 redirected to the same file descriptor as the standard output.
2186 Both the standard output and standard error of the last command
2187 in the pipeline is redirected to the file.
2190 As above, but append to the file.
2193 The standard input of the first command in the pipeline
2194 is taken from the file.
2197 The standard input of the first command is taken as the
2198 given immediate value.
2201 The standard input of the first command in the pipeline
2202 is taken from the given (readable) file descriptor.
2204 If there is no redirection of standard input, standard error
2205 or standard output, these are connected to the corresponding
2206 input or output of the application.
2208 If the last +'arg'+ is +&+ then the command will be
2209 executed in background.
2210 In this case the standard output from the last command
2211 in the pipeline will
2212 go to the application's standard output unless
2213 redirected in the command, and error output from all
2214 the commands in the pipeline will go to the application's
2215 standard error file. The return value of exec in this case
2216 is a list of process ids (pids) in the pipeline.
2218 Each +'arg'+ becomes one word for a command, except for
2219 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2220 arguments that follow +<+, +<<+, and +>+.
2222 The first word in each command is taken as the command name;
2223 the directories in the PATH environment variable are searched for
2224 an executable by the given name.
2226 No `glob` expansion or other shell-like substitutions
2227 are performed on the arguments to commands.
2229 If the command fails, the global $::errorCode (and the -errorcode
2230 option in `catch`) will be set to a list, as follows:
2232 +*CHILDKILLED* 'pid sigName msg'+::
2233 This format is used when a child process has been killed
2234 because of a signal. The pid element will be the process's
2235 identifier (in decimal). The sigName element will be the
2236 symbolic name of the signal that caused the process to
2237 terminate; it will be one of the names from the include
2238 file signal.h, such as SIGPIPE. The msg element will be a
2239 short human-readable message describing the signal, such
2240 as "write on pipe with no readers" for SIGPIPE.
2242 +*CHILDSUSP* 'pid sigName msg'+::
2243 This format is used when a child process has been suspended
2244 because of a signal. The pid element will be the process's
2245 identifier, in decimal. The sigName element will be the
2246 symbolic name of the signal that caused the process to
2247 suspend; this will be one of the names from the include
2248 file signal.h, such as SIGTTIN. The msg element will be a
2249 short human-readable message describing the signal, such
2250 as "background tty read" for SIGTTIN.
2252 +*CHILDSTATUS* 'pid code'+::
2253 This format is used when a child process has exited with a
2254 non-zero exit status. The pid element will be the process's
2255 identifier (in decimal) and the code element will be the
2256 exit code returned by the process (also in decimal).
2258 The environment for the executed command is set from $::env (unless
2259 this variable is unset, in which case the original environment is used).
2263 +*exists ?-var|-proc|-command|-alias?* 'name'+
2265 Checks the existence of the given variable, procedure, command
2266 or alias respectively and returns 1 if it exists or 0 if not. This command
2267 provides a more simplified/convenient version of `info exists`,
2268 `info procs` and `info commands`.
2270 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2274 +*exit* '?returnCode?'+
2276 Terminate the process, returning +'returnCode'+ to the
2277 parent as the exit status.
2279 If +'returnCode'+ isn't specified then it defaults
2282 Note that exit can be caught with `catch`.
2288 Calls the expression processor to evaluate +'arg'+, and returns
2289 the result as a string. See the section EXPRESSIONS above.
2291 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2292 The following two are identical.
2294 set x [expr {3 * 2 + 1}]
2299 +*file* 'option name ?arg\...?'+
2301 Operate on a file or a file name. +'name'+ is the name of a file.
2303 +'option'+ indicates what to do with the file name. Any unique
2304 abbreviation for +'option'+ is acceptable. The valid options are:
2306 +*file atime* 'name'+::
2307 Return a decimal string giving the time at which file +'name'+
2308 was last accessed. The time is measured in the standard UNIX
2309 fashion as seconds from a fixed starting time (often January 1, 1970).
2310 If the file doesn't exist or its access time cannot be queried then an
2313 +*file copy ?-force?* 'source target'+::
2314 Copies file +'source'+ to file +'target'+. The source file must exist.
2315 The target file must not exist, unless +-force+ is specified.
2317 +*file delete ?-force? ?--?* 'name\...'+::
2318 Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2319 If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2320 unless the +-force+ options is given. In this case no errors will be generated, even
2321 if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
2322 the first name being +'-force'+.
2324 +*file dirname* 'name'+::
2325 Return all of the characters in +'name'+ up to but not including
2326 the last slash character. If there are no slashes in +'name'+
2327 then return +.+ (a single dot). If the last slash in +'name'+ is its first
2328 character, then return +/+.
2330 +*file executable* 'name'+::
2331 Return '1' if file +'name'+ is executable by
2332 the current user, '0' otherwise.
2334 +*file exists* 'name'+::
2335 Return '1' if file +'name'+ exists and the current user has
2336 search privileges for the directories leading to it, '0' otherwise.
2338 +*file extension* 'name'+::
2339 Return all of the characters in +'name'+ after and including the
2340 last dot in +'name'+. If there is no dot in +'name'+ then return
2343 +*file isdirectory* 'name'+::
2344 Return '1' if file +'name'+ is a directory,
2347 +*file isfile* 'name'+::
2348 Return '1' if file +'name'+ is a regular file,
2351 +*file join* 'arg\...'+::
2352 Joins multiple path components. Note that if any components is
2353 an absolute path, the preceding components are ignored.
2354 Thus +"`file` join /tmp /root"+ returns +"/root"+.
2356 +*file link* ?*-hard|-symbolic*? 'newname target'+::
2357 Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
2358 Note that the sense of this command is the opposite of `file rename` and `file copy`
2359 and also of `ln`, but this is compatible with Tcl.
2360 An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.
2362 +*file lstat* 'name varName'+::
2363 Same as 'stat' option (see below) except uses the +'lstat'+
2364 kernel call instead of +'stat'+. This means that if +'name'+
2365 refers to a symbolic link the information returned in +'varName'+
2366 is for the link rather than the file it refers to. On systems that
2367 don't support symbolic links this option behaves exactly the same
2368 as the 'stat' option.
2370 +*file mkdir* 'dir1 ?dir2\...?'+::
2371 Creates each directory specified. For each pathname +'dir'+ specified,
2372 this command will create all non-existing parent directories
2373 as well as +'dir'+ itself. If an existing directory is specified,
2374 then no action is taken and no error is returned. Trying to
2375 overwrite an existing file with a directory will result in an
2376 error. Arguments are processed in the order specified, halting
2377 at the first error, if any.
2379 +*file mtime* 'name ?time?'+::
2380 Return a decimal string giving the time at which file +'name'+
2381 was last modified. The time is measured in the standard UNIX
2382 fashion as seconds from a fixed starting time (often January 1, 1970).
2383 If the file doesn't exist or its modified time cannot be queried then an
2384 error is generated. If +'time'+ is given, sets the modification time
2385 of the file to the given value.
2387 +*file mtimeus* 'name ?time_us?'+::
2388 As for `file mtime` except the time value is in microseconds
2389 since the epoch (see also `clock microseconds`).
2390 Note that some platforms and some filesystems don't support high
2391 resolution timestamps for files.
2393 +*file normalize* 'name'+::
2394 Return the normalized path of +'name'+. See 'realpath(3)'.
2396 +*file owned* 'name'+::
2397 Return '1' if file +'name'+ is owned by the current user,
2400 +*file readable* 'name'+::
2401 Return '1' if file +'name'+ is readable by
2402 the current user, '0' otherwise.
2404 +*file readlink* 'name'+::
2405 Returns the value of the symbolic link given by +'name'+ (i.e. the
2406 name of the file it points to). If
2407 +'name'+ isn't a symbolic link or its value cannot be read, then
2408 an error is returned. On systems that don't support symbolic links
2409 this option is undefined.
2411 +*file rename* ?*-force*? 'oldname' 'newname'+::
2412 Renames the file from the old name to the new name.
2413 If +'newname'+ already exists, an error is returned unless +'-force'+ is
2416 +*file rootname* 'name'+::
2417 Return all of the characters in +'name'+ up to but not including
2418 the last '.' character in the name. If +'name'+ doesn't contain
2419 a dot, then return +'name'+.
2421 +*file size* 'name'+::
2422 Return a decimal string giving the size of file +'name'+ in bytes.
2423 If the file doesn't exist or its size cannot be queried then an
2426 +*file stat* 'name ?varName?'+::
2427 Invoke the 'stat' kernel call on +'name'+, and return the result
2428 as a dictionary with the following keys: 'atime',
2429 'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2430 'nlink', 'size', 'type', 'uid', 'mtimeus' (if supported - see `file mtimeus`)
2431 Each element except 'type' is a decimal string with the value of
2432 the corresponding field from the 'stat' return structure; see the
2433 manual entry for 'stat' for details on the meanings of the values.
2434 The 'type' element gives the type of the file in the same form
2435 returned by the command `file type`.
2436 If +'varName'+ is specified, it is taken to be the name of an array
2437 variable and the values are also stored into the array.
2439 +*file tail* 'name'+::
2440 Return all of the characters in +'name'+ after the last slash.
2441 If +'name'+ contains no slashes then return +'name'+.
2443 +*file tempfile* '?template?'+::
2444 Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2445 default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2446 the format of the template and security concerns.
2448 +*file type* 'name'+::
2449 Returns a string giving the type of file +'name'+, which will be
2450 one of +file+, +directory+, +characterSpecial+,
2451 +blockSpecial+, +fifo+, +link+, or +socket+.
2453 +*file writable* 'name'+::
2454 Return '1' if file +'name'+ is writable by
2455 the current user, '0' otherwise.
2457 The `file` commands that return 0/1 results are often used in
2458 conditional or looping commands, for example:
2460 if {![file exists foo]} {
2461 error {bad file name}
2468 +*finalize* 'reference ?command?'+
2470 If +'command'+ is omitted, returns the finalizer command for the given reference.
2472 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2473 the empty string to remove the current finalizer.
2475 The reference must be a valid reference create with the `ref`
2478 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2486 Flushes any output that has been buffered for +'fileId'+. +'fileId'+ must
2487 have been the return value from a previous call to `open`, or it may be
2488 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2489 refer to a file that was opened for writing. This command returns an
2494 +*for* 'start test next body'+
2496 `for` is a looping command, similar in structure to the C `for` statement.
2497 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2498 and +'test'+ is an expression string.
2500 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2501 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2502 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2503 interpreter on +'next'+, then repeats the loop. The command terminates
2504 when +'test'+ evaluates to 0.
2506 If a `continue` command is invoked within +'body'+ then any remaining
2507 commands in the current execution of +'body'+ are skipped; processing
2508 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2509 +'test'+, and so on.
2511 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2512 command will return immediately.
2514 The operation of `break` and `continue` are similar to the corresponding
2517 `for` returns an empty string.
2521 +*foreach* 'varName list body'+
2523 +*foreach* 'varList list ?varList2 list2 \...? body'+
2525 In this command, +'varName'+ is the name of a variable, +'list'+
2526 is a list of values to assign to +'varName'+, and +'body'+ is a
2527 collection of Tcl commands.
2529 For each field in +'list'+ (in order from left to right), `foreach` assigns
2530 the contents of the field to +'varName'+ (as if the `lindex` command
2531 had been used to extract the field), then calls the Tcl interpreter to
2534 If instead of being a simple name, +'varList'+ is used, multiple assignments
2535 are made each time through the loop, one for each element of +'varList'+.
2537 For example, if there are two elements in +'varList'+ and six elements in
2538 the list, the loop will be executed three times.
2540 If the length of the list doesn't evenly divide by the number of elements
2541 in +'varList'+, the value of the remaining variables in the last iteration
2542 of the loop are undefined.
2544 The `break` and `continue` statements may be invoked inside +'body'+,
2545 with the same effect as in the `for` command.
2547 `foreach` returns an empty string.
2551 +*format* 'formatString ?arg \...?'+
2553 This command generates a formatted string in the same way as the
2554 C 'sprintf' procedure (it uses 'sprintf' in its
2555 implementation). +'formatString'+ indicates how to format
2556 the result, using +%+ fields as in 'sprintf', and the additional
2557 arguments, if any, provide values to be substituted into the result.
2559 All of the 'sprintf' options are valid; see the 'sprintf'
2560 man page for details. Each +'arg'+ must match the expected type
2561 from the +%+ field in +'formatString'+; the `format` command
2562 converts each argument to the correct type (floating, integer, etc.)
2563 before passing it to 'sprintf' for formatting.
2565 The only unusual conversion is for +%c+; in this case the argument
2566 must be a decimal string, which will then be converted to the corresponding
2567 ASCII (or UTF-8) character value.
2569 In addition, Jim Tcl provides basic support for conversion to binary with +%b+.
2571 `format` does backslash substitution on its +'formatString'+
2572 argument, so backslash sequences in +'formatString'+ will be handled
2573 correctly even if the argument is in braces.
2575 The return value from `format` is the formatted string.
2579 +*getref* 'reference'+
2581 Returns the string associated with +'reference'+. The reference must
2582 be a valid reference create with the `ref` command.
2584 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2588 +*gets* 'fileId ?varName?'+
2590 +'fileId' *gets* '?varName?'+
2592 Reads the next line from the file given by +'fileId'+ and discards
2593 the terminating newline character.
2595 If +'varName'+ is specified, then the line is placed in the variable
2596 by that name and the return value is a count of the number of characters
2597 read (not including the newline).
2599 If the end of the file is reached before reading
2600 any characters then -1 is returned and +'varName'+ is set to an
2603 If +'varName'+ is not specified then the return value will be
2604 the line (minus the newline character) or an empty string if
2605 the end of the file is reached before reading any characters.
2607 An empty string will also be returned if a line contains no characters
2608 except the newline, so `eof` may have to be used to determine
2609 what really happened.
2611 If the last character in the file is not a newline character, then
2612 `gets` behaves as if there were an additional newline character
2613 at the end of the file.
2615 +'fileId'+ must be +stdin+ or the return value from a previous
2616 call to `open`; it must refer to a file that was opened
2621 +*glob* ?*-nocomplain*? ?*-directory* 'dir'? ?*-tails*? ?*--*? 'pattern ?pattern \...?'+
2623 This command performs filename globbing, using csh rules. The returned
2624 value from `glob` is the list of expanded filenames.
2626 If +-nocomplain+ is specified as the first argument then an empty
2627 list may be returned; otherwise an error is returned if the expanded
2628 list is empty. The +-nocomplain+ argument must be provided
2629 exactly: an abbreviation will not be accepted.
2631 If +-directory+ is given, the +'dir'+ is understood to contain a
2632 directory name to search in. This allows globbing inside directories
2633 whose names may contain glob-sensitive characters. The returned names
2634 include the directory name unless +'-tails'+ is specified.
2636 If +'-tails'+ is specified, along with +-directory+, the returned names
2637 are relative to the given directory.
2642 +*global* 'varName ?varName \...?'+
2644 This command is ignored unless a Tcl procedure is being interpreted.
2645 If so, then it declares each given +'varName'+ to be a global variable
2646 rather than a local one. For the duration of the current procedure
2647 (and only while executing in the current procedure), any reference to
2648 +'varName'+ will be bound to a global variable instead
2651 An alternative to using `global` is to use the +::+ prefix
2652 to explicitly name a variable in the global scope.
2656 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2658 The `if` command evaluates +'expr1'+ as an expression (in the same way
2659 that `expr` evaluates its argument). The value of the expression must
2660 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2661 the Tcl interpreter.
2663 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2664 then +'body2'+ is executed, and so on.
2666 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2668 The +then+ and +else+ arguments are optional "noise words" to make the
2669 command easier to read.
2671 There may be any number of +elseif+ clauses, including zero. +'bodyN'+
2672 may also be omitted as long as +else+ is omitted too.
2674 The return value from the command is the result of the body script that
2675 was executed, or an empty string if none of the expressions was non-zero
2676 and there was no +'bodyN'+.
2680 +*incr* 'varName ?increment?'+
2682 Increment the value stored in the variable whose name is +'varName'+.
2683 The value of the variable must be integral.
2685 If +'increment'+ is supplied then its value (which must be an
2686 integer) is added to the value of variable +'varName'+; otherwise
2687 1 is added to +'varName'+.
2689 The new value is stored as a decimal string in variable +'varName'+
2690 and also returned as result.
2692 If the variable does not exist, the variable is implicitly created
2693 and set to +0+ first.
2698 +*info* 'option ?arg\...?'+::
2700 Provide information about various internals to the Tcl interpreter.
2701 The legal +'option'+'s (which may be abbreviated) are:
2703 +*info args* 'procname'+::
2704 Returns a list containing the names of the arguments to procedure
2705 +'procname'+, in order. +'procname'+ must be the name of a
2706 Tcl command procedure.
2708 +*info alias* 'command'+::
2709 +'command'+ must be an alias created with `alias`. In which case the target
2710 command and arguments, as passed to `alias` are returned. See `exists -alias`
2712 +*info body* 'procname'+::
2713 Returns the body of procedure +'procname'+. +'procname'+ must be
2714 the name of a Tcl command procedure.
2717 Returns a list of all open file handles from `open` or `socket`
2719 +*info commands* ?'pattern'?+::
2720 If +'pattern'+ isn't specified, returns a list of names of all the
2721 Tcl commands, including both the built-in commands written in C and
2722 the command procedures defined using the `proc` command.
2723 If +'pattern'+ is specified, only those names matching +'pattern'+
2724 are returned. Matching is determined using the same rules as for
2727 +*info complete* 'command' ?'missing'?+::
2728 Returns 1 if +'command'+ is a complete Tcl command in the sense of
2729 having no unclosed quotes, braces, brackets or array element names,
2730 If the command doesn't appear to be complete then 0 is returned.
2731 This command is typically used in line-oriented input environments
2732 to allow users to type in commands that span multiple lines; if the
2733 command isn't complete, the script can delay evaluating it until additional
2734 lines have been typed to complete the command. If +'varName'+ is specified, the
2735 missing character is stored in the variable with that name.
2737 +*info exists* 'varName'+::
2738 Returns '1' if the variable named +'varName'+ exists in the
2739 current context (either as a global or local variable), returns '0'
2742 +*info frame* ?'number'?+::
2743 If +'number'+ is not specified, this command returns a number
2744 which is the same result as `info level` - the current stack frame level.
2745 If +'number'+ is specified, then the result is a list consisting of the procedure,
2746 filename and line number for the procedure call at level +'number'+ on the stack.
2747 If +'number'+ is positive then it selects a particular stack level (1 refers
2748 to the top-most active procedure, 2 to the procedure it called, and
2749 so on); otherwise it gives a level relative to the current level
2750 (0 refers to the current procedure, -1 to its caller, and so on).
2751 The level has an identical meaning to `info level`.
2753 +*info globals* ?'pattern'?+::
2754 If +'pattern'+ isn't specified, returns a list of all the names
2755 of currently-defined global variables.
2756 If +'pattern'+ is specified, only those names matching +'pattern'+
2757 are returned. Matching is determined using the same rules as for
2761 An alias for `os.gethostname` for compatibility with Tcl 6.x
2763 +*info level* ?'number'?+::
2764 If +'number'+ is not specified, this command returns a number
2765 giving the stack level of the invoking procedure, or 0 if the
2766 command is invoked at top-level. If +'number'+ is specified,
2767 then the result is a list consisting of the name and arguments for the
2768 procedure call at level +'number'+ on the stack. If +'number'+
2769 is positive then it selects a particular stack level (1 refers
2770 to the top-most active procedure, 2 to the procedure it called, and
2771 so on); otherwise it gives a level relative to the current level
2772 (0 refers to the current procedure, -1 to its caller, and so on).
2773 See the `uplevel` command for more information on what stack
2776 +*info locals* ?'pattern'?+::
2777 If +'pattern'+ isn't specified, returns a list of all the names
2778 of currently-defined local variables, including arguments to the
2779 current procedure, if any. Variables defined with the `global`
2780 and `upvar` commands will not be returned. If +'pattern'+ is
2781 specified, only those names matching +'pattern'+ are returned.
2782 Matching is determined using the same rules as for `string match`.
2784 +*info nameofexecutable*+::
2785 Returns the name of the binary file from which the application
2786 was invoked. A full path will be returned, unless the path
2787 can't be determined, in which case the empty string will be returned.
2789 +*info procs* ?'pattern'?+::
2790 If +'pattern'+ isn't specified, returns a list of all the
2791 names of Tcl command procedures.
2792 If +'pattern'+ is specified, only those names matching +'pattern'+
2793 are returned. Matching is determined using the same rules as for
2796 +*info references*+::
2797 Returns a list of all references which have not yet been garbage
2800 +*info returncodes* ?'code'?+::
2801 Returns a list representing the mapping of standard return codes
2802 to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2803 instead returns the name for the given code.
2806 If a Tcl script file is currently being evaluated (i.e. there is a
2807 call to 'Jim_EvalFile' active or there is an active invocation
2808 of the `source` command), then this command returns the name
2809 of the innermost file being processed. Otherwise the command returns an
2812 +*info source* 'script ?filename line?'+::
2813 With a single argument, returns the original source location of the given script as a list of
2814 +{filename linenumber}+. If the source location can't be determined, the
2815 list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
2816 of +'script'+ with the associate source information. This can be useful to produce
2817 useful messages from `eval`, etc. if the original source information may be lost.
2819 +*info stacktrace*+::
2820 After an error is caught with `catch`, returns the stack trace as a list
2821 of +{procedure filename line \...}+.
2823 +*info statics* 'procname'+::
2824 Returns a dictionary of the static variables of procedure
2825 +'procname'+. +'procname'+ must be the name of a Tcl command
2826 procedure. An empty dictionary is returned if the procedure has
2827 no static variables.
2830 Returns the version number for this version of Jim in the form +*x.yy*+.
2832 +*info vars* ?'pattern'?+::
2833 If +'pattern'+ isn't specified,
2834 returns a list of all the names of currently-visible variables, including
2835 both locals and currently-visible globals.
2836 If +'pattern'+ is specified, only those names matching +'pattern'+
2837 are returned. Matching is determined using the same rules as for
2842 +*join* 'list ?joinString?'+
2844 The +'list'+ argument must be a valid Tcl list. This command returns the
2845 string formed by joining all of the elements of +'list'+ together with
2846 +'joinString'+ separating each adjacent pair of elements.
2848 The +'joinString'+ argument defaults to a space character.
2852 +*kill* ?'SIG'|*-0*? 'pid'+
2854 Sends the given signal to the process identified by +'pid'+.
2856 The signal may be specified by name or number in one of the following forms:
2864 The signal name may be in either upper or lower case.
2866 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2868 If no signal is specified, SIGTERM is used.
2870 An error is raised if the signal could not be delivered.
2874 +*lambda* 'args ?statics? body'+
2876 The `lambda` command is identical to `proc`, except rather than
2877 creating a named procedure, it creates an anonymous procedure and returns
2878 the name of the procedure.
2880 See `proc` and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2884 +*lappend* 'varName value ?value value \...?'+
2886 Treat the variable given by +'varName'+ as a list and append each of
2887 the +'value'+ arguments to that list as a separate element, with spaces
2890 If +'varName'+ doesn't exist, it is created as a list with elements given
2891 by the +'value'+ arguments. `lappend` is similar to `append` except that
2892 each +'value'+ is appended as a list element rather than raw text.
2894 This command provides a relatively efficient way to build up large lists.
2899 is much more efficient than
2901 set a [concat $a [list $b]]
2907 +*lassign* 'list varName ?varName \...?'+
2909 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2910 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2911 list elements, the remaining variables are set to the empty string. If there are more list elements
2912 than variables, a list of unassigned elements is returned.
2914 jim> lassign {1 2 3} a b; puts a=$a,b=$b
2920 +*local* 'cmd ?arg\...?'+
2922 First, `local` evaluates +'cmd'+ with the given arguments. The return value must
2923 be the name of an existing command, which is marked as having local scope.
2924 This means that when the current procedure exits, the specified
2925 command is deleted. This can be useful with `lambda`, local procedures or
2926 to automatically close a filehandle.
2928 In addition, if a command already exists with the same name,
2929 the existing command will be kept rather than deleted, and may be called
2930 via `upcall`. The previous command will be restored when the current
2931 procedure exits. See `upcall` for more details.
2933 In this example, a local procedure is created. Note that the procedure
2934 continues to have global scope while it is active.
2937 # proc ... returns "inner" which is marked local
2938 local proc inner {} {
2939 # will be deleted when 'outer' exits
2946 In this example, the lambda is deleted at the end of the procedure rather
2947 than waiting until garbage collection.
2950 set x [lambda inner {args} {
2951 # will be deleted when 'outer' exits
2953 # Use 'function' here which simply returns $x
2962 +*loop* 'var first limit ?incr? body'+
2964 Similar to `for` except simpler and possibly more efficient.
2965 With a positive increment, equivalent to:
2967 for {set var $first} {$var < $limit} {incr var $incr} $body
2969 If +'incr'+ is not specified, 1 is used.
2970 Note that setting the loop variable inside the loop does not
2971 affect the loop count.
2975 +*lindex* 'list ?index ...?'+
2977 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
2978 (0 refers to the first element of the list).
2979 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2981 In extracting the element, +'lindex'+ observes the same rules concerning
2982 braces and quotes and backslashes as the Tcl command interpreter; however,
2983 variable substitution and command substitution do not occur.
2985 If no index values are given, simply returns +'list'+
2987 If +'index'+ is negative or greater than or equal to the number of elements
2988 in +'list'+, then an empty string is returned.
2990 If additional index arguments are supplied, then each argument is
2991 used in turn to select an element from the previous indexing
2992 operation, allowing the script to select elements from sublists.
2996 +*linsert* 'list index element ?element element \...?'+
2998 This command produces a new list from +'list'+ by inserting all
2999 of the +'element'+ arguments just before the element +'index'+
3000 of +'list'+. Each +'element'+ argument will become
3001 a separate element of the new list. If +'index'+ is less than
3002 or equal to zero, then the new elements are inserted at the
3003 beginning of the list. If +'index'+ is greater than or equal
3004 to the number of elements in the list, then the new elements are
3005 appended to the list.
3007 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3012 +*list* 'arg ?arg \...?'+
3014 This command returns a list comprised of all the arguments, +'arg'+. Braces
3015 and backslashes get added as necessary, so that the `lindex` command
3016 may be used on the result to re-extract the original arguments, and also
3017 so that `eval` may be used to execute the resulting list, with
3018 +'arg1'+ comprising the command's name and the other args comprising
3019 its arguments. `list` produces slightly different results than
3020 `concat`: `concat` removes one level of grouping before forming
3021 the list, while `list` works directly from the original arguments.
3022 For example, the command
3024 list a b {c d e} {f {g h}}
3028 a b {c d e} {f {g h}}
3030 while `concat` with the same arguments will return
3038 Treats +'list'+ as a list and returns a decimal string giving
3039 the number of elements in it.
3043 +*lset* 'varName ?index ..? newValue'+
3045 Sets an element in a list.
3047 The `lset` command accepts a parameter, +'varName'+, which it interprets
3048 as the name of a variable containing a Tcl list. It also accepts
3049 zero or more indices into the list. Finally, it accepts a new value
3050 for an element of varName. If no indices are presented, the command
3053 lset varName newValue
3055 In this case, newValue replaces the old value of the variable
3058 When presented with a single index, the `lset` command
3059 treats the content of the varName variable as a Tcl list. It addresses
3060 the index'th element in it (0 refers to the first element of the
3061 list). When interpreting the list, `lset` observes the same rules
3062 concerning braces and quotes and backslashes as the Tcl command
3063 interpreter; however, variable substitution and command substitution
3064 do not occur. The command constructs a new list in which the
3065 designated element is replaced with newValue. This new list is
3066 stored in the variable varName, and is also the return value from
3069 If index is negative or greater than or equal to the number of
3070 elements in $varName, then an error occurs.
3072 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3074 If additional index arguments are supplied, then each argument is
3075 used in turn to address an element within a sublist designated by
3076 the previous indexing operation, allowing the script to alter
3077 elements in sublists. The command,
3081 replaces element 2 of sublist 1 with +'newValue'+.
3083 The integer appearing in each index argument must be greater than
3084 or equal to zero. The integer appearing in each index argument must
3085 be strictly less than the length of the corresponding list. In other
3086 words, the `lset` command cannot change the size of a list. If an
3087 index is outside the permitted range, an error is reported.
3092 +*lmap* 'varName list body'+
3094 +*lmap* 'varList list ?varList2 list2 \...? body'+
3096 `lmap` is a "collecting" `foreach` which returns a list of its results.
3100 jim> lmap i {1 2 3 4 5} {expr $i*$i}
3102 jim> lmap a {1 2 3} b {A B C} {list $a $b}
3105 If the body invokes `continue`, no value is added for this iteration.
3106 If the body invokes `break`, the loop ends and no more values are added.
3112 Loads the dynamic extension, +'filename'+. Generally the filename should have
3113 the extension +.so+. The initialisation function for the module must be based
3114 on the name of the file. For example loading +hwaccess.so+ will invoke
3115 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
3116 should not be used directly. Instead it is invoked automatically by `package require`.
3120 +*lrange* 'list first last'+
3122 +'list'+ must be a valid Tcl list. This command will return a new
3123 list consisting of elements +'first'+ through +'last'+, inclusive.
3125 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3127 If +'last'+ is greater than or equal to the number of elements
3128 in the list, then it is treated as if it were +end+.
3130 If +'first'+ is greater than +'last'+ then an empty string
3133 Note: +"`lrange` 'list first first'"+ does not always produce the
3134 same result as +"`lindex` 'list first'"+ (although it often does
3135 for simple fields that aren't enclosed in braces); it does, however,
3136 produce exactly the same results as +"`list` [`lindex` 'list first']"+
3141 +*lreplace* 'list first last ?element element \...?'+
3143 Returns a new list formed by replacing one or more elements of
3144 +'list'+ with the +'element'+ arguments.
3146 +'first'+ gives the index in +'list'+ of the first element
3149 If +'first'+ is less than zero then it refers to the first
3150 element of +'list'+; the element indicated by +'first'+
3151 must exist in the list.
3153 +'last'+ gives the index in +'list'+ of the last element
3154 to be replaced; it must be greater than or equal to +'first'+.
3156 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3158 The +'element'+ arguments specify zero or more new arguments to
3159 be added to the list in place of those that were deleted.
3161 Each +'element'+ argument will become a separate element of
3164 If no +'element'+ arguments are specified, then the elements
3165 between +'first'+ and +'last'+ are simply deleted.
3169 +*lrepeat* 'number element1 ?element2 \...?'+
3171 Build a list by repeating elements +'number'+ times (which must be
3172 a positive integer).
3181 Returns the list in reverse order.
3183 jim> lreverse {1 2 3}
3188 +*lsearch* '?options? list pattern'+
3190 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3191 command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
3192 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3193 the list are to be matched against pattern and must have one of the values below:
3195 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3198 +'pattern'+ is a literal string that is compared for exact equality against each list element.
3199 This is the default.
3202 +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3203 rules as the string match command.
3206 +'pattern'+ is treated as a regular expression and matched against each list element using
3207 the rules described by `regexp`.
3209 +*-command* 'cmdname'+::
3210 +'cmdname'+ is a command which is used to match the pattern against each element of the
3211 list. It is invoked as +'cmdname' ?*-nocase*? 'pattern listvalue'+ and should return 1
3212 for a match, or 0 for no match.
3215 Changes the result to be the list of all matching indices (or all matching values if
3216 +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3217 order. If values are returned, the order of the values will be the order of those values
3218 within the input list.
3221 The matching value is returned instead of its index (or an empty string if no value
3222 matches). If +-all+ is also specified, then the result of the command is the list of all
3223 values that matched. The +-inline+ and +-bool+ options are mutually exclusive.
3226 Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3227 the result will be a list of '0' and '1' for each element of the list depending upon whether
3228 the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3231 This negates the sense of the match, returning the index (or value
3232 if +-inline+ is specified) of the first non-matching value in the
3233 list. If +-bool+ is also specified, the '0' will be returned if a
3234 match is found, or '1' otherwise. If +-all+ is also specified,
3235 non-matches will be returned rather than matches.
3238 Causes comparisons to be handled in a case-insensitive manner.
3242 +*lsort* ?*-index* 'listindex'? ?*-nocase|-integer|-real|-command* 'cmdname'? ?*-unique*? ?*-decreasing*|*-increasing*? 'list'+
3244 Sort the elements of +'list'+, returning a new list in sorted order.
3245 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.
3247 If +-nocase+ is specified, comparisons are case-insensitive.
3249 If +-integer+ is specified, numeric sorting is used.
3251 If +-real+ is specified, floating point number sorting is used.
3253 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3254 name. For each comparison, +'cmdname $value1 $value2+' is called which
3255 should compare the values and return an integer less than, equal
3256 to, or greater than zero if the +'$value1'+ is to be considered less
3257 than, equal to, or greater than +'$value2'+, respectively.
3259 If +-decreasing+ is specified, the resulting list is in the opposite
3260 order to what it would be otherwise. +-increasing+ is the default.
3262 If +-unique+ is specified, then only the last set of duplicate elements found in the list will be retained.
3263 Note that duplicates are determined relative to the comparison used in the sort. Thus if +-index 0+ is used,
3264 +{1 a}+ and +{1 b}+ would be considered duplicates and only the second element, +{1 b}+, would be retained.
3266 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3267 the given index is extracted from the list for comparison. The list index may
3268 be any valid list index, such as +1+, +end+ or +end-2+.
3274 This command is a simple helper command to add a script to the '+$jim::defer+' variable
3275 that will run when the current proc or interpreter exits. For example:
3277 jim> proc a {} { defer {puts "Leaving a"}; puts "Exit" }
3282 If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
3283 when the proc or interpreter exits.
3287 +*open* 'fileName ?access?'+
3289 +*open* '|command-pipeline ?access?'+
3291 Opens a file and returns an identifier
3292 that may be used in future invocations
3293 of commands like `read`, `puts`, and `close`.
3294 +'fileName'+ gives the name of the file to open.
3296 The +'access'+ argument indicates the way in which the file is to be accessed.
3297 It may have any of the following values:
3300 Open the file for reading only; the file must already exist.
3303 Open the file for both reading and writing; the file must
3307 Open the file for writing only. Truncate it if it exists. If it doesn't
3308 exist, create a new file.
3311 Open the file for reading and writing. Truncate it if it exists.
3312 If it doesn't exist, create a new file.
3315 Open the file for writing only. The file must already exist, and the file
3316 is positioned so that new data is appended to the file.
3319 Open the file for reading and writing. If the file doesn't
3320 exist, create a new empty file. Set the initial access position
3321 to the end of the file.
3323 +'access'+ defaults to 'r'.
3325 If a file is opened for both reading and writing, then `seek`
3326 must be invoked between a read and a write, or vice versa.
3328 If the first character of +'fileName'+ is "|" then the remaining
3329 characters of +'fileName'+ are treated as a list of arguments that
3330 describe a command pipeline to invoke, in the same style as the
3331 arguments for exec. In this case, the channel identifier returned
3332 by open may be used to write to the command's input pipe or read
3333 from its output pipe, depending on the value of +'access'+. If write-only
3334 access is used (e.g. +'access'+ is 'w'), then standard output for the
3335 pipeline is directed to the current standard output unless overridden
3336 by the command. If read-only access is used (e.g. +'access'+ is r),
3337 standard input for the pipeline is taken from the current standard
3338 input unless overridden by the command.
3340 The `pid` command may be used to return the process ids of the commands
3341 forming the command pipeline.
3343 See also `socket`, `pid`, `exec`
3347 +*package provide* 'name ?version?'+
3349 Indicates that the current script provides the package named +'name'+.
3350 If no version is specified, '1.0' is used.
3352 Any script which provides a package may include this statement
3353 as the first statement, although it is not required.
3355 +*package require* 'name ?version?'*+
3357 Searches for the package with the given +'name'+ by examining each path
3358 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3359 or '$path/$name.tcl' as a script package.
3361 The first such file which is found is considered to provide the package.
3362 (The version number is ignored).
3364 If '$name.so' exists, it is loaded with the `load` command,
3365 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3367 If `load` or `source` fails, `package require` will fail immediately.
3368 No further attempt will be made to locate the file.
3376 The first form returns the process identifier of the current process.
3378 The second form accepts a handle returned by `open` and returns a list
3379 of the process ids forming the pipeline in the same form as `exec ... &`.
3380 If 'fileId' represents a regular file handle rather than a command pipeline,
3381 the empty string is returned instead.
3383 See also `open`, `exec`
3387 +*proc* 'name args ?statics? body'+
3389 The `proc` command creates a new Tcl command procedure, +'name'+.
3390 When the new command is invoked, the contents of +'body'+ will be executed.
3391 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3392 If specified, +'statics'+, declares static variables which are bound to the
3395 See PROCEDURES for detailed information about Tcl procedures.
3397 The `proc` command returns +'name'+ (which is useful with `local`).
3399 When a procedure is invoked, the procedure's return value is the
3400 value specified in a `return` command. If the procedure doesn't
3401 execute an explicit `return`, then its return value is the value
3402 of the last command executed in the procedure's body.
3404 If an error occurs while executing the procedure body, then the
3405 procedure-as-a-whole will return that same error.
3409 +*puts* ?*-nonewline*? '?fileId? string'+
3411 +'fileId' *puts* ?*-nonewline*? 'string'+
3413 Writes the characters given by +'string'+ to the file given
3414 by +'fileId'+. +'fileId'+ must have been the return
3415 value from a previous call to `open`, or it may be
3416 +stdout+ or +stderr+ to refer to one of the standard I/O
3417 channels; it must refer to a file that was opened for
3420 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3421 `puts` normally outputs a newline character after +'string'+,
3422 but this feature may be suppressed by specifying the +-nonewline+
3425 Output to files is buffered internally by Tcl; the `flush`
3426 command may be used to force buffered characters to be output.
3430 Creates a pair of `aio` channels and returns the handles as a list: +{read write}+
3434 # Must close $w after exec
3444 Returns the path name of the current working directory.
3448 +*rand* '?min? ?max?'+
3450 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3451 (defaults to the maximum integer).
3453 If only one argument is given, it is interpreted as +'max'+.
3457 +*range* '?start? end ?step?'+
3459 Returns a list of integers starting at +'start'+ (defaults to 0)
3460 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3473 +*read* ?*-nonewline*? 'fileId'+
3475 +'fileId' *read* ?*-nonewline*?+
3477 +*read* 'fileId numBytes'+
3479 +'fileId' *read* 'numBytes'+
3482 In the first form, all of the remaining bytes are read from the file
3483 given by +'fileId'+; they are returned as the result of the command.
3484 If the +-nonewline+ switch is specified then the last
3485 character of the file is discarded if it is a newline.
3487 In the second form, the extra argument specifies how many bytes to read;
3488 exactly this many bytes will be read and returned, unless there are fewer than
3489 +'numBytes'+ bytes left in the file; in this case, all the remaining
3492 +'fileId'+ must be +stdin+ or the return value from a previous call
3493 to `open`; it must refer to a file that was opened for reading.
3497 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3499 Determines whether the regular expression +'exp'+ matches part or
3500 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3502 See REGULAR EXPRESSIONS above for complete information on the
3503 syntax of +'exp'+ and how it is matched against +'string'+.
3505 If additional arguments are specified after +'string'+ then they
3506 are treated as the names of variables to use to return
3507 information about which part(s) of +'string'+ matched +'exp'+.
3508 +'matchVar'+ will be set to the range of +'string'+ that
3509 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3510 the characters in +'string'+ that matched the leftmost parenthesized
3511 subexpression within +'exp'+, the next +'subMatchVar'+ will
3512 contain the characters that matched the next parenthesized
3513 subexpression to the right in +'exp'+, and so on.
3515 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3516 matching characters from `string`, however see +-indices+ and
3519 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3520 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3521 match the string (e.g. because it was in a portion of the expression
3522 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3523 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3526 The following switches modify the behaviour of +'regexp'+
3529 Causes upper-case and lower-case characters to be treated as
3530 identical during the matching process.
3533 Use newline-sensitive matching. By default, newline
3534 is a completely ordinary character with no special meaning in
3535 either REs or strings. With this flag, +[^+ bracket expressions
3536 and +.+ never match newline, an +^+ anchor matches the null
3537 string after any newline in the string in addition to its normal
3538 function, and the +$+ anchor matches the null string before any
3539 newline in the string in addition to its normal function.
3542 Changes what is stored in the subMatchVars. Instead of
3543 storing the matching characters from string, each variable
3544 will contain a list of two decimal strings giving the indices
3545 in string of the first and last characters in the matching
3546 range of characters.
3548 +*-start* 'offset'+::
3549 Specifies a character index offset into the string at which to start
3550 matching the regular expression. If +-indices+ is
3551 specified, the indices will be indexed starting from the
3552 absolute beginning of the input string. +'offset'+ will be
3553 constrained to the bounds of the input string.
3556 Causes the regular expression to be matched as many times as possible
3557 in the string, returning the total number of matches found. If this
3558 is specified with match variables, they will contain information
3559 for the last match only.
3562 Causes the command to return, as a list, the data that would otherwise
3563 be placed in match variables. When using +-inline+, match variables
3564 may not be specified. If used with +-all+, the list will be concatenated
3565 at each iteration, such that a flat list is always returned. For
3566 each match iteration, the command will append the overall match
3567 data, plus one element for each subexpression in the regular
3571 Marks the end of switches. The argument following this one will be
3572 treated as +'exp'+ even if it starts with a +-+.
3576 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3578 This command matches the regular expression +'exp'+ against
3579 +'string'+ using the rules described in REGULAR EXPRESSIONS
3582 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3583 with the substitutions detailed below, and returns the number of
3584 substitutions made (normally 1 unless +-all+ is specified).
3585 This is 0 if there were no matches.
3587 If +'varName'+ is not specified, the substituted string will be returned
3590 When copying +'string'+, the portion of +'string'+ that
3591 matched +'exp'+ is replaced with +'subSpec'+.
3592 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3593 in the substitution with the portion of +'string'+ that
3596 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3597 between 1 and 9, then it is replaced in the substitution with
3598 the portion of +'string'+ that matched the +'n'+\'-th
3599 parenthesized subexpression of +'exp'+.
3600 Additional backslashes may be used in +'subSpec'+ to prevent special
3601 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3604 The use of backslashes in +'subSpec'+ tends to interact badly
3605 with the Tcl parser's use of backslashes, so it's generally
3606 safest to enclose +'subSpec'+ in braces if it includes
3609 The following switches modify the behaviour of +'regsub'+
3612 Upper-case characters in +'string'+ are converted to lower-case
3613 before matching against +'exp'+; however, substitutions
3614 specified by +'subSpec'+ use the original unconverted form
3618 All ranges in +'string'+ that match +'exp'+ are found and substitution
3619 is performed for each of these ranges, rather than only the
3620 first. The +&+ and +{backslash}n+ sequences are handled for
3621 each substitution using the information from the corresponding
3625 Use newline-sensitive matching. By default, newline
3626 is a completely ordinary character with no special meaning in
3627 either REs or strings. With this flag, +[^+ bracket expressions
3628 and +.+ never match newline, an +^+ anchor matches the null
3629 string after any newline in the string in addition to its normal
3630 function, and the +$+ anchor matches the null string before any
3631 newline in the string in addition to its normal function.
3633 +*-start* 'offset'+::
3634 Specifies a character index offset into the string at which to
3635 start matching the regular expression. +'offset'+ will be
3636 constrained to the bounds of the input string.
3639 Marks the end of switches. The argument following this one will be
3640 treated as +'exp'+ even if it starts with a +-+.
3644 +*ref* 'string tag ?finalizer?'+
3646 Create a new reference containing +'string'+ of type +'tag'+.
3647 If +'finalizer'+ is specified, it is a command which will be invoked
3648 when the a garbage collection cycle runs and this reference is
3649 no longer accessible.
3651 The finalizer is invoked as:
3653 finalizer reference string
3655 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3659 +*rename* 'oldName newName'+
3661 Rename the command that used to be called +'oldName'+ so that it
3662 is now called +'newName'+. If +'newName'+ is an empty string
3663 (e.g. {}) then +'oldName'+ is deleted. The `rename` command
3664 returns an empty string as result.
3668 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3670 Return immediately from the current procedure (or top-level command
3671 or `source` command), with +'value'+ as the return value. If +'value'+
3672 is not specified, an empty string will be returned as result.
3674 If +-code+ is specified (as either a number or ok, error, break,
3675 continue, signal, return or exit), this code will be used instead
3676 of +JIM_OK+. This is generally useful when implementing flow of control
3679 If +-level+ is specified and greater than 1, it has the effect of delaying
3680 the new return code from +-code+. This is useful when rethrowing an error
3681 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3682 an example of how this is done.
3684 Note: The following options are only used when +-code+ is JIM_ERR.
3686 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3687 it is used to initialize the stacktrace.
3689 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3693 +*scan* 'string format varName1 ?varName2 \...?'+
3695 This command parses fields from an input string in the same fashion
3696 as the C 'sscanf' procedure. +'string'+ gives the input to be parsed
3697 and +'format'+ indicates how to parse it, using '%' fields as in
3698 'sscanf'. All of the 'sscanf' options are valid; see the 'sscanf'
3699 man page for details. Each +'varName'+ gives the name of a variable;
3700 when a field is scanned from +'string'+, the result is converted back
3701 into a string and assigned to the corresponding +'varName'+. The
3702 only unusual conversion is for '%c'. For '%c' conversions a single
3703 character value is converted to a decimal string, which is then
3704 assigned to the corresponding +'varName'+; no field width may be
3705 specified for this conversion.
3709 +*seek* 'fileId offset ?origin?'+
3711 +'fileId' *seek* 'offset ?origin?'+
3713 Change the current access position for +'fileId'+.
3714 The +'offset'+ and +'origin'+ arguments specify the position at
3715 which the next read or write will occur for +'fileId'+.
3716 +'offset'+ must be a number (which may be negative) and +'origin'+
3717 must be one of the following:
3720 The new access position will be +'offset'+ bytes from the start
3724 The new access position will be +'offset'+ bytes from the current
3725 access position; a negative +'offset'+ moves the access position
3726 backwards in the file.
3729 The new access position will be +'offset'+ bytes from the end of
3730 the file. A negative +'offset'+ places the access position before
3731 the end-of-file, and a positive +'offset'+ places the access position
3732 after the end-of-file.
3734 The +'origin'+ argument defaults to +start+.
3736 +'fileId'+ must have been the return value from a previous call to
3737 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3738 of the standard I/O channels.
3740 This command returns an empty string.
3744 +*set* 'varName ?value?'+
3746 Returns the value of variable +'varName'+.
3748 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3749 creating a new variable if one doesn't already exist, and return
3752 If +'varName'+ contains an open parenthesis and ends with a
3753 close parenthesis, then it refers to an array element: the characters
3754 before the open parenthesis are the name of the array, and the characters
3755 between the parentheses are the index within the array.
3756 Otherwise +'varName'+ refers to a scalar variable.
3758 If no procedure is active, then +'varName'+ refers to a global
3761 If a procedure is active, then +'varName'+ refers to a parameter
3762 or local variable of the procedure, unless the +'global'+ command
3763 has been invoked to declare +'varName'+ to be global.
3765 The +::+ prefix may also be used to explicitly reference a variable
3766 in the global scope.
3770 +*setref* 'reference string'+
3772 Store a new string in +'reference'+, replacing the existing string.
3773 The reference must be a valid reference create with the `ref`
3776 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3780 Command for signal handling.
3782 See `kill` for the different forms which may be used to specify signals.
3784 Commands which return a list of signal names do so using the canonical form:
3787 +*signal handle* ?'signals \...'?+::
3788 If no signals are given, returns a list of all signals which are currently
3790 If signals are specified, these are added to the list of signals currently
3793 +*signal ignore* ?'signals \...'?+::
3794 If no signals are given, returns a lists all signals which are currently
3796 If signals are specified, these are added to the list of signals
3797 currently being ignored. These signals are still delivered, but
3798 are not considered by `catch -signal` or `try -signal`. Use
3799 `signal check` to determine which signals have occurred but
3802 +*signal block* ?'signals \...'?+::
3803 If no signals are given, returns a lists all signals which are currently
3805 If signals are specified, these are added to the list of signals
3806 currently being blocked. These signals are not delivered to the process.
3807 This can be useful for signals such as +SIGPIPE+, especially in conjunction
3808 with `exec` as child processes inherit the parent's signal disposition.
3810 +*signal default* ?'signals \...'?+::
3811 If no signals are given, returns a lists all signals which currently have
3812 the default behaviour.
3813 If signals are specified, these are added to the list of signals which have
3814 the default behaviour.
3816 +*signal check ?-clear?* ?'signals \...'?+::
3817 Returns a list of signals which have been delivered to the process
3818 but are 'ignored'. If signals are specified, only that set of signals will
3819 be checked, otherwise all signals will be checked.
3820 If +-clear+ is specified, any signals returned are removed and will not be
3821 returned by subsequent calls to `signal check` unless delivered again.
3823 +*signal throw* ?'signal'?+::
3824 Raises the given signal, which defaults to +SIGINT+ if not specified.
3825 The behaviour is identical to:
3829 Note that `signal handle` and `signal ignore` represent two forms of signal
3830 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3831 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3832 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3835 Prevent a processing from taking too long
3837 signal handle SIGALRM
3840 .. possibly long running process ..
3843 puts stderr "Process took too long"
3846 Handle SIGHUP to reconfigure:
3848 signal ignore SIGHUP
3850 ... handle configuration/reconfiguration ...
3851 while {[signal check -clear SIGHUP] eq ""} {
3852 ... do processing ..
3854 # Received SIGHUP, so reconfigure
3857 Note: signal handling is currently not supported in child interpreters.
3858 In these interpreters, the signal command does not exist.
3864 Pauses for the given number of seconds, which may be a floating
3865 point value less than one to sleep for less than a second, or an
3866 integer to sleep for one or more seconds.
3870 +*source* 'fileName'+
3872 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3873 as a sequence of commands to execute in the normal fashion. The return
3874 value of `source` is the return value of the last command executed
3875 from the file. If an error occurs in executing the contents of the
3876 file, then the `source` command will return that error.
3878 If a `return` command is invoked from within the file, the remainder of
3879 the file will be skipped and the `source` command will return
3880 normally with the result from the `return` command.
3884 +*split* 'string ?splitChars?'+
3886 Returns a list created by splitting +'string'+ at each character
3887 that is in the +'splitChars'+ argument.
3889 Each element of the result list will consist of the
3890 characters from +'string'+ between instances of the
3891 characters in +'splitChars'+.
3893 Empty list elements will be generated if +'string'+ contains
3894 adjacent characters in +'splitChars'+, or if the first or last
3895 character of +'string'+ is in +'splitChars'+.
3897 If +'splitChars'+ is an empty string then each character of
3898 +'string'+ becomes a separate element of the result list.
3900 +'splitChars'+ defaults to the standard white-space characters.
3903 split "comp.unix.misc" .
3905 returns +'"comp unix misc"'+ and
3907 split "Hello world" {}
3909 returns +'"H e l l o { } w o r l d"'+.
3914 +*stackdump* 'stacktrace'+
3916 Creates a human readable representation of a stack trace.
3923 Returns a live stack trace as a list of +proc file line proc file line \...+.
3924 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
3925 same form as produced by `catch` and `info stacktrace`
3927 See also `stackdump`.
3932 +*string* 'option arg ?arg \...?'+
3934 Perform one of several string operations, depending on +'option'+.
3935 The legal options (which may be abbreviated) are:
3937 +*string bytelength* 'string'+::
3938 Returns the length of the string in bytes. This will return
3939 the same value as `string length` if UTF-8 support is not enabled,
3940 or if the string is composed entirely of ASCII characters.
3941 See UTF-8 AND UNICODE.
3943 +*string byterange* 'string first last'+::
3944 Like `string range` except works on bytes rather than characters.
3945 These commands are identical if UTF-8 support is not enabled.
3947 +*string cat* '?string1 string2 \...?'+::
3948 Concatenates the given strings into a single string.
3950 +*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
3951 Perform a character-by-character comparison of strings +'string1'+ and
3952 +'string2'+ in the same way as the C 'strcmp' procedure. Return
3953 -1, 0, or 1, depending on whether +'string1'+ is lexicographically
3954 less than, equal to, or greater than +'string2'+. If +-length+
3955 is specified, then only the first +'len'+ characters are used
3956 in the comparison. If +'len'+ is negative, it is ignored.
3957 Performs a case-insensitive comparison if +-nocase+ is specified.
3959 +*string equal ?-nocase?* '?*-length* len?' 'string1 string2'+::
3960 Returns 1 if the strings are equal, or 0 otherwise. If +-length+
3961 is specified, then only the first +'len'+ characters are used
3962 in the comparison. If +'len'+ is negative, it is ignored.
3963 Performs a case-insensitive comparison if +-nocase+ is specified.
3965 +*string first* 'string1 string2 ?firstIndex?'+::
3966 Search +'string2'+ for a sequence of characters that exactly match
3967 the characters in +'string1'+. If found, return the index of the
3968 first character in the first such match within +'string2'+. If not
3969 found, return -1. If +'firstIndex'+ is specified, matching will start
3970 from +'firstIndex'+ of +'string1'+.
3972 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'firstIndex'+.
3974 +*string index* 'string charIndex'+::
3975 Returns the +'charIndex'+'th character of the +'string'+
3976 argument. A +'charIndex'+ of 0 corresponds to the first
3977 character of the string.
3978 If +'charIndex'+ is less than 0 or greater than
3979 or equal to the length of the string then an empty string is
3982 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'charIndex'+.
3984 +*string is* 'class' ?*-strict*? 'string'+::
3985 Returns 1 if +'string'+ is a valid member of the specified character
3986 class, otherwise returns 0. If +-strict+ is specified, then an
3987 empty string returns 0, otherwise an empty string will return 1
3988 on any class. The following character classes are recognized
3989 (the class name can be abbreviated):
3991 +alnum+;; Any alphabet or digit character.
3992 +alpha+;; Any alphabet character.
3993 +ascii+;; Any character with a value less than 128 (those that are in the 7-bit ascii range).
3994 +boolean+;; Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
3995 +control+;; Any control character.
3996 +digit+;; Any digit character.
3997 +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
3998 In case of under/overflow in the value, 0 is returned.
3999 +graph+;; Any printing character, except space.
4000 +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
4001 +lower+;; Any lower case alphabet character.
4002 +print+;; Any printing character, including space.
4003 +punct+;; Any punctuation character.
4004 +space+;; Any space character.
4005 +upper+;; Any upper case alphabet character.
4006 +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
4008 Note that string classification does +'not'+ respect UTF-8. See UTF-8 AND UNICODE
4010 Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).
4012 +*string last* 'string1 string2 ?lastIndex?'+::
4013 Search +'string2'+ for a sequence of characters that exactly match
4014 the characters in +'string1'+. If found, return the index of the
4015 first character in the last such match within +'string2'+. If there
4016 is no match, then return -1. If +'lastIndex'+ is specified, only characters
4017 up to +'lastIndex'+ of +'string2'+ will be considered in the match.
4019 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'lastIndex'+.
4021 +*string length* 'string'+::
4022 Returns a decimal string giving the number of characters in +'string'+.
4023 If UTF-8 support is enabled, this may be different than the number of bytes.
4024 See UTF-8 AND UNICODE
4026 +*string map ?-nocase?* 'mapping string'+::
4027 Replaces substrings in +'string'+ based on the key-value pairs in
4028 +'mapping'+, which is a list of +key value key value \...+ as in the form
4029 returned by `array get`. Each instance of a key in the string will be
4030 replaced with its corresponding value. If +-nocase+ is specified, then
4031 matching is done without regard to case differences. Both key and value may
4032 be multiple characters. Replacement is done in an ordered manner, so the
4033 key appearing first in the list will be checked first, and so on. +'string'+ is
4034 only iterated over once, so earlier key replacements will have no affect for
4035 later key matches. For example,
4037 string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
4040 will return the string +01321221+.
4042 Note that if an earlier key is a prefix of a later one, it will completely mask the later
4043 one. So if the previous example is reordered like this,
4045 string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
4048 it will return the string +02c322c222c+.
4050 +*string match ?-nocase?* 'pattern string'+::
4051 See if +'pattern'+ matches +'string'+; return 1 if it does, 0
4052 if it doesn't. Matching is done in a fashion similar to that
4053 used by the C-shell. For the two strings to match, their contents
4054 must be identical except that the following special sequences
4055 may appear in +'pattern'+:
4058 Matches any sequence of characters in +'string'+,
4059 including a null string.
4062 Matches any single character in +'string'+.
4065 Matches any character in the set given by +'chars'+.
4066 If a sequence of the form +'x-y'+ appears in +'chars'+,
4067 then any character between +'x'+ and +'y'+, inclusive,
4071 Matches the single character +'x'+. This provides a way of
4072 avoiding the special interpretation of the characters +{backslash}*?[]+
4075 Performs a case-insensitive comparison if +-nocase+ is specified.
4077 +*string range* 'string first last'+::
4078 Returns a range of consecutive characters from +'string'+, starting
4079 with the character whose index is +'first'+ and ending with the
4080 character whose index is +'last'+. An index of 0 refers to the
4081 first character of the string.
4083 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
4085 If +'first'+ is less than zero then it is treated as if it were zero, and
4086 if +'last'+ is greater than or equal to the length of the string then
4087 it is treated as if it were +end+. If +'first'+ is greater than
4088 +'last'+ then an empty string is returned.
4090 +*string repeat* 'string count'+::
4091 Returns a new string consisting of +'string'+ repeated +'count'+ times.
4093 +*string replace* 'string first last ?newstring?'+::
4094 Removes a range of consecutive characters from +'string'+, starting
4095 with the character whose index is +'first'+ and ending with the
4096 character whose index is +'last'+. If +'newstring'+ is specified,
4097 then it is placed in the removed character range. If +'first'+ is
4098 less than zero then it is treated as if it were zero, and if +'last'+
4099 is greater than or equal to the length of the string then it is
4100 treated as if it were +end+. If +'first'+ is greater than +'last'+
4101 or the length of the initial string, or +'last'+ is less than 0,
4102 then the initial string is returned untouched.
4104 +*string reverse* 'string'+::
4105 Returns a string that is the same length as +'string'+ but
4106 with its characters in the reverse order.
4108 +*string tolower* 'string'+::
4109 Returns a value equal to +'string'+ except that all upper case
4110 letters have been converted to lower case.
4112 +*string totitle* 'string'+::
4113 Returns a value equal to +'string'+ except that the first character
4114 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
4115 and all remaining characters have been converted to lower case.
4117 +*string toupper* 'string'+::
4118 Returns a value equal to +'string'+ except that all lower case
4119 letters have been converted to upper case.
4121 +*string trim* 'string ?chars?'+::
4122 Returns a value equal to +'string'+ except that any leading
4123 or trailing characters from the set given by +'chars'+ are
4125 If +'chars'+ is not specified then white space is removed
4126 (spaces, tabs, newlines, and carriage returns).
4128 +*string trimleft* 'string ?chars?'+::
4129 Returns a value equal to +'string'+ except that any
4130 leading characters from the set given by +'chars'+ are
4132 If +'chars'+ is not specified then white space is removed
4133 (spaces, tabs, newlines, and carriage returns).
4135 +*string trimright* 'string ?chars?'+::
4136 Returns a value equal to +'string'+ except that any
4137 trailing characters from the set given by +'chars'+ are
4139 If +'chars'+ is not specified then white space is removed
4140 (spaces, tabs, newlines, and carriage returns).
4141 Null characters are always removed.
4145 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
4147 This command performs variable substitutions, command substitutions,
4148 and backslash substitutions on its string argument and returns the
4149 fully-substituted result. The substitutions are performed in exactly
4150 the same way as for Tcl commands. As a result, the string argument
4151 is actually substituted twice, once by the Tcl parser in the usual
4152 fashion for Tcl commands, and again by the subst command.
4154 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
4155 specified, then the corresponding substitutions are not performed.
4156 For example, if +-nocommands+ is specified, no command substitution
4157 is performed: open and close brackets are treated as ordinary
4158 characters with no special interpretation.
4160 *Note*: when it performs its substitutions, subst does not give any
4161 special treatment to double quotes or curly braces. For example,
4162 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
4170 +*switch* '?options? string pattern body ?pattern body \...?'+
4172 +*switch* '?options? string {pattern body ?pattern body \...?}'+
4174 The `switch` command matches its string argument against each of
4175 the pattern arguments in order. As soon as it finds a pattern that
4176 matches string it evaluates the following body and returns the
4177 result of that evaluation. If the last pattern argument is default
4178 then it matches anything. If no pattern argument matches string and
4179 no default is given, then the `switch` command returns an empty string.
4180 If the initial arguments to switch start with - then they are treated
4181 as options. The following options are currently supported:
4184 Use exact matching when comparing string to a
4185 pattern. This is the default.
4188 When matching string to the patterns, use glob-style
4189 matching (i.e. the same as implemented by the string
4193 When matching string to the patterns, use regular
4194 expression matching (i.e. the same as implemented
4195 by the regexp command).
4197 +-command 'commandname'+::
4198 When matching string to the patterns, use the given command, which
4199 must be a single word. The command is invoked as
4200 'commandname pattern string', or 'commandname -nocase pattern string'
4201 and must return 1 if matched, or 0 if not.
4204 Marks the end of options. The argument following
4205 this one will be treated as string even if it starts
4208 Two syntaxes are provided for the pattern and body arguments. The
4209 first uses a separate argument for each of the patterns and commands;
4210 this form is convenient if substitutions are desired on some of the
4211 patterns or commands. The second form places all of the patterns
4212 and commands together into a single argument; the argument must
4213 have proper list structure, with the elements of the list being the
4214 patterns and commands. The second form makes it easy to construct
4215 multi-line `switch` commands, since the braces around the whole list
4216 make it unnecessary to include a backslash at the end of each line.
4217 Since the pattern arguments are in braces in the second form, no
4218 command or variable substitutions are performed on them; this makes
4219 the behaviour of the second form different than the first form in
4222 If a body is specified as +-+ it means that the body for the next
4223 pattern should also be used as the body for this pattern (if the
4224 next pattern also has a body of +-+ then the body after that is
4225 used, and so on). This feature makes it possible to share a single
4226 body among several patterns.
4228 Below are some examples of `switch` commands:
4230 switch abc a - b {format 1} abc {format 2} default {format 3}
4234 switch -regexp aaab {
4254 +*tailcall* 'cmd ?arg\...?'+
4256 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4257 the current call frame. This is similar to 'exec' in Bourne Shell.
4259 The following are identical except the first immediately replaces the current call frame.
4263 return [uplevel 1 [list a b c]]
4265 `tailcall` is useful as a dispatch mechanism:
4268 tailcall sub_$cmd {*}$args
4279 Returns a decimal string giving the current access position in
4282 +'fileId'+ must have been the return value from a previous call to
4283 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4284 of the standard I/O channels.
4288 +*throw* 'code ?msg?'+
4290 This command throws an exception (return) code along with an optional message.
4291 This command is mostly for convenient usage with `try`.
4293 The command +throw break+ is equivalent to +break+.
4294 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4298 +*time* 'command ?count?'+
4300 This command will call the Tcl interpreter +'count'+
4301 times to execute +'command'+ (or once if +'count'+ isn't
4302 specified). It will then return a string of the form
4304 503 microseconds per iteration
4306 which indicates the average amount of time required per iteration,
4309 Time is measured in elapsed time, not CPU time.
4313 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4315 The `try` command is provided as a convenience for exception handling.
4317 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4318 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4320 It then evaluates the script for the first matching 'on' handler
4321 (there many be zero or more) based on the return code from the `try`
4322 section. For example a normal +JIM_ERR+ error will be matched by
4323 an 'on error' handler.
4325 Finally, any +'finalscript'+ is evaluated.
4327 The result of this command is the result of +'tryscript'+, except in the
4328 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4329 in which case the result is this new exception.
4331 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4334 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4335 the matching handler.
4342 } on {continue break} {} {
4343 error "Unexpected break/continue"
4344 } on error {msg opts} {
4345 puts "Dealing with error"
4346 return {*}$opts $msg
4348 puts "Got signal: $sig"
4353 If break, continue or error are raised, they are dealt with by the matching
4356 In any case, the file will be closed via the 'finally' clause.
4358 See also `throw`, `catch`, `return`, `error`.
4362 +*unknown* 'cmdName ?arg arg ...?'+
4364 This command doesn't actually exist as part of Tcl, but Tcl will
4365 invoke it if it does exist.
4367 If the Tcl interpreter encounters a command name for which there
4368 is not a defined command, then Tcl checks for the existence of
4369 a command named `unknown`.
4371 If there is no such command, then the interpreter returns an
4374 If the `unknown` command exists, then it is invoked with
4375 arguments consisting of the fully-substituted name and arguments
4376 for the original non-existent command.
4378 The `unknown` command typically does things like searching
4379 through library directories for a command procedure with the name
4380 +'cmdName'+, or expanding abbreviated command names to full-length,
4381 or automatically executing unknown commands as UNIX sub-processes.
4383 In some cases (such as expanding abbreviations) `unknown` will
4384 change the original command slightly and then (re-)execute it.
4385 The result of the `unknown` command is used as the result for
4386 the original non-existent command.
4390 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4393 Each +'name'+ is a variable name, specified in any of the
4394 ways acceptable to the `set` command.
4396 If a +'name'+ refers to an element of an array, then that
4397 element is removed without affecting the rest of the array.
4399 If a +'name'+ consists of an array name with no parenthesized
4400 index, then the entire array is deleted.
4402 The `unset` command returns an empty string as result.
4404 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4405 is specified. The '--' argument may be specified to stop option processing
4406 in case the variable name may be '-nocomplain'.
4410 +*upcall* 'command ?args ...?'+
4412 May be used from within a proc defined as `local` `proc` in order to call
4413 the previous, hidden version of the same command.
4415 If there is no previous definition of the command, an error is returned.
4419 +*uplevel* '?level? command ?command ...?'+
4421 All of the +'command'+ arguments are concatenated as if they had
4422 been passed to `concat`; the result is then evaluated in the
4423 variable context indicated by +'level'+. `uplevel` returns
4424 the result of that evaluation. If +'level'+ is an integer, then
4425 it gives a distance (up the procedure calling stack) to move before
4426 executing the command. If +'level'+ consists of +\#+ followed by
4427 a number then the number gives an absolute level number. If +'level'+
4428 is omitted then it defaults to +1+. +'level'+ cannot be
4429 defaulted if the first +'command'+ argument starts with a digit or +#+.
4431 For example, suppose that procedure 'a' was invoked
4432 from top-level, and that it called 'b', and that 'b' called 'c'.
4433 Suppose that 'c' invokes the `uplevel` command. If +'level'+
4434 is +1+ or +#2+ or omitted, then the command will be executed
4435 in the variable context of 'b'. If +'level'+ is +2+ or +#1+
4436 then the command will be executed in the variable context of 'a'.
4438 If +'level'+ is '3' or +#0+ then the command will be executed
4439 at top-level (only global variables will be visible).
4440 The `uplevel` command causes the invoking procedure to disappear
4441 from the procedure calling stack while the command is being executed.
4442 In the above example, suppose 'c' invokes the command
4444 uplevel 1 {set x 43; d}
4446 where 'd' is another Tcl procedure. The `set` command will
4447 modify the variable 'x' in 'b's context, and 'd' will execute
4448 at level 3, as if called from 'b'. If it in turn executes
4453 then the `set` command will modify the same variable 'x' in 'b's
4454 context: the procedure 'c' does not appear to be on the call stack
4455 when 'd' is executing. The command `info level` may
4456 be used to obtain the level of the current procedure.
4458 `uplevel` makes it possible to implement new control
4459 constructs as Tcl procedures (for example, `uplevel` could
4460 be used to implement the `while` construct as a Tcl procedure).
4464 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4466 This command arranges for one or more local variables in the current
4467 procedure to refer to variables in an enclosing procedure call or
4468 to global variables.
4470 +'level'+ may have any of the forms permitted for the `uplevel`
4471 command, and may be omitted if the first letter of the first +'otherVar'+
4472 isn't +#+ or a digit (it defaults to '1').
4474 For each +'otherVar'+ argument, `upvar` makes the variable
4475 by that name in the procedure frame given by +'level'+ (or at
4476 global level, if +'level'+ is +#0+) accessible
4477 in the current procedure by the name given in the corresponding
4480 The variable named by +'otherVar'+ need not exist at the time of the
4481 call; it will be created the first time +'myVar'+ is referenced, just like
4482 an ordinary variable.
4484 `upvar` may only be invoked from within procedures.
4486 `upvar` returns an empty string.
4488 The `upvar` command simplifies the implementation of call-by-name
4489 procedure calling and also makes it easier to build new control constructs
4491 For example, consider the following procedure:
4498 'add2' is invoked with an argument giving the name of a variable,
4499 and it adds two to the value of that variable.
4500 Although 'add2' could have been implemented using `uplevel`
4501 instead of `upvar`, `upvar` makes it simpler for 'add2'
4502 to access the variable in the caller's procedure frame.
4508 +*wait -nohang* 'pid'+
4510 With no arguments, cleans up any processes started by `exec ... &` that have completed
4511 (reaps zombie processes).
4513 With one or two arguments, waits for a process by id, either returned by `exec ... &`
4514 or by `os.fork` (if supported).
4516 Waits for the process to complete, unless +-nohang+ is specified, in which case returns
4517 immediately if the process is still running.
4519 Returns a list of 3 elements.
4521 +{NONE x x}+ if the process does not exist or has already been waited for, or
4522 if -nohang is specified, and the process is still alive.
4524 +{CHILDSTATUS <pid> <exit-status>}+ if the process exited normally.
4526 +{CHILDKILLED <pid> <signal>}+ if the process terminated on a signal.
4528 +{CHILDSUSP <pid> none}+ if the process terminated for some other reason.
4530 Note that on platforms supporting waitpid(2), +pid+ can also be given special values such
4531 as 0 or -1. See waitpid(2) for more detail.
4535 +*while* 'test body'+
4537 The +'while'+ command evaluates +'test'+ as an expression
4538 (in the same way that `expr` evaluates its argument).
4539 The value of the expression must be numeric; if it is non-zero
4540 then +'body'+ is executed by passing it to the Tcl interpreter.
4542 Once +'body'+ has been executed then +'test'+ is evaluated
4543 again, and the process repeats until eventually +'test'+
4544 evaluates to a zero numeric value. `continue`
4545 commands may be executed inside +'body'+ to terminate the current
4546 iteration of the loop, and `break`
4547 commands may be executed inside +'body'+ to cause immediate
4548 termination of the `while` command.
4550 The `while` command always returns an empty string.
4555 The following extensions may or may not be available depending upon
4556 what options were selected when Jim Tcl was built.
4560 posix: os.fork, os.gethostname, os.getids, os.uptime
4561 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4563 Invokes 'fork(2)' and returns the result.
4565 +*os.gethostname*+::
4566 Invokes 'gethostname(3)' and returns the result.
4569 Returns the various user/group ids for the current process.
4572 uid 1000 euid 1000 gid 100 egid 100
4575 Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4577 ANSI I/O (aio) and EVENTLOOP API
4578 --------------------------------
4579 Jim provides an alternative object-based API for I/O.
4581 See `open` and `socket` for commands which return an I/O handle.
4585 +$handle *accept* ?addrvar?+::
4586 Server socket only: Accept a connection and return stream.
4587 If +'addrvar'+ is specified, the address of the connected client is stored
4588 in the named variable in the form 'addr:port' for IP sockets or 'path' for Unix domain sockets.
4589 See `socket` for details.
4591 +$handle *buffering none|line|full*+::
4592 Sets the buffering mode of the stream.
4594 +$handle *close ?r(ead)|w(rite)|-nodelete?*+::
4596 The +'read'+ and +'write'+ arguments perform a "half-close" on a socket. See the 'shutdown(2)' man page.
4597 The +'-nodelete'+ option is applicable only for Unix domain sockets. It closes the socket
4598 but does not delete the bound path (e.g. after `os.fork`).
4601 +$handle *copyto* 'tofd ?size?'+::
4602 Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4603 that many bytes will be copied. Otherwise copying continues until the end
4604 of the input file. Returns the number of bytes actually copied.
4607 Returns 1 if stream is at eof
4609 +$handle *filename*+::
4610 Returns the original filename associated with the handle.
4611 Handles returned by `socket` give the socket type instead of a filename.
4616 +$handle *gets* '?var?'+::
4617 Read one line and return it or store it in the var
4619 +$handle *isatty*+::
4620 Returns 1 if the stream is a tty device.
4622 +$handle *lock ?-wait?*+::
4623 Apply a POSIX lock to the open file associated with the handle using
4624 'fcntl(F_SETLK)', or 'fcntl(F_SETLKW)' to wait for the lock to be available if +'-wait'+
4626 The handle must be open for write access.
4627 Returns 1 if the lock was successfully obtained, 0 otherwise.
4628 An error occurs if the handle is not suitable for locking (e.g.
4629 if it is not open for write)
4631 +$handle *ndelay ?0|1?*+::
4632 Set O_NDELAY (if arg). Returns current/new setting.
4633 Note that in general ANSI I/O interacts badly with non-blocking I/O.
4636 +$handle *peername*+::
4637 Returns the remote address or path of the connected socket. See 'getpeername(2)'.
4639 +$handle *puts ?-nonewline?* 'str'+::
4640 Write the string, with newline unless -nonewline
4642 +$handle *read ?-nonewline?* '?len?'+::
4643 Read and return bytes from the stream. To eof if no len.
4645 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4646 Receives a message from the handle via recvfrom(2) and returns it.
4647 At most +'maxlen'+ bytes are read. If +'addrvar'+ is specified, the sending address
4648 of the message is stored in the named variable in the form 'addr:port' for IP sockets
4649 or 'path' for Unix domain sockets. See `socket` for details.
4651 +$handle *seek* 'offset' *?start|current|end?*+::
4652 Seeks in the stream (default 'current')
4654 +$handle *sendto* 'str ?address'+::
4655 Sends the string, +'str'+, to the given address (host:port or path) via the socket using 'sendto(2)'.
4656 This is intended for udp/dgram sockets and may give an error or behave in unintended
4657 ways for other handle types.
4658 Returns the number of bytes written.
4660 +$handle *sockname*+::
4661 Returns the bound address or path of the socket. See 'getsockname(2)'.
4663 +$handle *sockopt* '?name value?'+::
4664 With no arguments, returns a dictionary of socket options currently set for the handle
4665 (will be empty for a non-socket). With +'name'+ and +'value'+, sets the socket option
4666 to the given value. Currently supports the following boolean socket options:
4667 +broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay+, and the following
4668 integer socket options: +sndbuf, rcvbuf+
4671 Flush the stream, then 'fsync(2)' to commit any changes to storage.
4672 Only available on platforms that support 'fsync(2)'.
4675 Returns the current seek position
4677 +$handle *tty* ?settings?+::
4678 If no arguments are given, returns a dictionary containing the tty settings for the stream.
4679 If arguments are given, they must either be a dictionary, or +setting value \...+
4680 Abbrevations are supported for both settings and values, so the following is acceptable:
4681 +$f tty parity e input c out raw+.
4682 Only available on platforms that support 'termios(3)'. Supported settings are:
4685 Baud rate. e.g. 115200
4693 +*parity even|odd|none*+;;
4696 +*handshake xonxoff|rtscts|none*+;;
4699 +*input raw|cooked*+;;
4700 Input character processing. In raw mode, the usual key sequences such as ^C do
4701 not generate signals.
4703 +*output raw|cooked*+;;
4704 Output character processing. Typically CR -> CRNL is disabled in raw mode.
4706 +*vmin* 'numchars'+;;
4707 Minimum number of characters to read.
4710 Timeout for noncanonical read (units of 0.1 seconds)
4712 +$handle *ssl* ?*-server* 'cert priv'?+::
4713 Upgrades the stream to a SSL/TLS session and returns the handle.
4715 +$handle *unlock*+::
4716 Release a POSIX lock previously acquired by `aio lock`.
4718 +$handle *verify*+::
4719 Verifies the certificate of a SSL/TLS stream peer
4721 +*load_ssl_certs* 'dir'+::
4722 Loads SSL/TLS CA certificates for use during verification
4726 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4727 For compatibility with Tcl, a limited form of the `fconfigure`
4728 command is supported.
4729 * `fconfigure ... -blocking` maps to `aio ndelay`
4730 * `fconfigure ... -buffering` maps to `aio buffering`
4731 * `fconfigure ... -translation` is accepted but ignored
4734 eventloop: after, vwait, update
4735 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4737 The following commands allow a script to be invoked when the given condition occurs.
4738 If no script is given, returns the current script. If the given script is the empty, the
4741 +$handle *readable* '?readable-script?'+::
4742 Sets or returns the script for when the socket is readable.
4744 +$handle *writable* '?writable-script?'+::
4745 Sets or returns the script for when the socket is writable.
4747 +$handle *onexception* '?exception-script?'+::
4748 Sets or returns the script for when oob data received.
4750 For compatibility with 'Tcl', these may be prefixed with `fileevent`. e.g.
4753 +fileevent $handle *readable* '\...'+
4755 Time-based execution is also available via the eventloop API.
4758 Sleeps for the given number of milliseconds. No events are
4759 processed during this time.
4761 +*after* 'ms'|*idle* 'script ?script \...?'+::
4762 The scripts are concatenated and executed after the given
4763 number of milliseconds have elapsed. If 'idle' is specified,
4764 the script will run the next time the event loop is processed
4765 with `vwait` or `update`. The script is only run once and
4766 then removed. Returns an event id.
4768 +*after cancel* 'id|command'+::
4769 Cancels an `after` event with the given event id or matching
4770 command (script). Returns the number of milliseconds
4771 remaining until the event would have fired. Returns the
4772 empty string if no matching event is found.
4774 +*after info* '?id?'+::
4775 If +'id'+ is not given, returns a list of current `after`
4776 events. If +'id'+ is given, returns a list containing the
4777 associated script and either 'timer' or 'idle' to indicated
4778 the type of the event. An error occurs if +'id'+ does not
4781 +*vwait* 'variable'+::
4782 A call to `vwait` enters the eventloop. `vwait` processes
4783 events until the named (global) variable changes or all
4784 event handlers are removed. The variable need not exist
4785 beforehand. If there are no event handlers defined, `vwait`
4786 returns immediately.
4788 +*update ?idletasks?*+::
4789 A call to `update` enters the eventloop to process expired events, but
4790 no new events. If 'idletasks' is specified, only expired time events are handled,
4792 Returns once handlers have been run for all expired events.
4794 Scripts are executed at the global scope. If an error occurs during a handler script,
4795 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4796 If the `bgerror` command does not exist, the error message details are printed to stderr instead.
4798 If a file event handler script generates an error, the handler is automatically removed
4799 to prevent infinite errors. (A time event handler is always removed after execution).
4802 Called when an event handler script generates an error. Note that the normal command resolution
4803 rules are used for bgerror. First the name is resolved in the current namespace, then in the
4808 Various socket types may be created.
4810 +*socket unix* 'path'+::
4811 A unix domain socket client connected to 'path'
4813 +*socket unix.server* 'path'+::
4814 A unix domain socket server listening on 'path'
4816 +*socket unix.dgram* '?path?'+::
4817 A unix domain socket datagram client, optionally connected to 'path'
4819 +*socket unix.dgram.server* 'path'+::
4820 A unix domain socket datagram server server listening on 'path'
4822 +*socket ?-ipv6? stream* 'addr:port'+::
4823 A TCP socket client. (See the forms for +'addr'+ below)
4825 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4826 A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4828 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4829 A UDP socket client. If the address is not specified,
4830 the client socket will be unbound and 'sendto' must be used
4831 to indicated the destination.
4833 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4834 A UDP socket server.
4837 A synonym for `pipe`
4840 A socketpair (see socketpair(2)). Like `pipe`, this command returns
4841 a list of two channels: {s1 s2}. These channels are both readable and writable.
4843 This command creates a socket connected (client) or bound (server) to the given
4846 The returned value is channel and may generally be used with the various file I/O
4847 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
4849 . set f [socket stream www.google.com:80]
4851 . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
4856 Server sockets, however support only 'accept', which is most useful in conjunction with
4859 set f [socket stream.server 80]
4861 set client [$f accept]
4864 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
4869 The address, +'addr'+, can be given in one of the following forms:
4871 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
4872 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
4875 Note that on many systems, listening on an IPv6 address such as [::] will
4876 also accept requests via IPv4.
4878 Where a hostname is specified, the +'first'+ returned address is used
4879 which matches the socket type is used.
4881 An unconnected dgram socket (either 'dgram' or 'unix.dgram') must use
4882 `sendto` to specify the destination address.
4884 The path for Unix domain sockets is automatically removed when the socket
4885 is closed. Use `close -nodelete` in the rare case where this behaviour
4886 should be avoided (e.g. after `os.fork`).
4890 +*syslog* '?options? ?priority? message'+
4892 This command sends message to system syslog facility with given
4893 priority. Valid priorities are:
4895 emerg, alert, crit, err, error, warning, notice, info, debug
4897 If a message is specified, but no priority is specified, then a
4898 priority of info is used.
4900 By default, facility user is used and the value of global tcl variable
4901 argv0 is used as ident string. However, any of the following options
4902 may be specified before priority to control these parameters:
4904 +*-facility* 'value'+::
4905 Use specified facility instead of user. The following
4906 values for facility are recognized:
4908 authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
4911 +*-ident* 'string'+::
4912 Use given string instead of argv0 variable for ident string.
4914 +*-options* 'integer'+::
4915 Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
4916 use numeric values of those from your system syslog.h file,
4917 because I haven't got time to implement yet another hash
4922 The optional 'pack' extension provides commands to encode and decode binary strings.
4924 +*pack* 'varName value' *-intle|-intbe|-floatle|-floatbe|-str* 'bitwidth ?bitoffset?'+::
4925 Packs the binary representation of +'value'+ into the variable
4926 +'varName'+. The value is packed according to the given type
4927 (integer/floating point/string, big-endian/little-endian), width and bit offset.
4928 The variable is created if necessary (like `append`).
4929 The variable is expanded if necessary.
4931 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str* 'bitpos bitwidth'+::
4932 Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
4933 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
4934 and signed/unsigned) and returns it. For integer types, +'bitwidth'+
4935 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
4936 +'bitwidth'+ may be 32 bits (for single precision numbers) or 64 bits (for double precision).
4937 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
4938 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
4939 or the empty string for the string type.
4943 The optional 'zlib' extension provides a Tcl-compatible subset of the `zlib` command.
4945 +*crc32* 'data' '?startValue?'+::
4946 Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
4947 for calculating the checksum of chunked data read from a stream (for instance, a pipe).
4949 +*deflate* 'string' '?level?'+::
4950 Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
4951 be specified to choose the desired speed vs. compression rate ratio.
4953 +*inflate* 'data' '?bufferSize?'+::
4954 Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
4955 allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
4957 +*gzip* 'string' '?-level level?'+::
4958 Compresses a buffer and adds a gzip header.
4960 +*gunzip* 'data' '?-buffersize size?'+::
4961 Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
4962 which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
4963 systems without a severe memory constraint.
4967 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
4968 commands based on the low-level `pack` and `unpack` commands.
4970 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
4972 Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
4973 in case of overflow.
4977 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
4979 See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.
4981 +*class* 'classname ?baseclasses? classvars'+::
4982 Create a new class, +'classname'+, with the given dictionary
4983 (+'classvars'+) as class variables. These are the initial variables
4984 which all newly created objects of this class are initialised with.
4985 If a list of baseclasses is given, methods and instance variables
4988 +*super* 'method ?args \...?'+::
4989 From within a method, invokes the given method on the base class.
4990 Note that this will only call the last baseclass given.
4994 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
4995 similar to that provided by tcllib ::struct::tree (http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html)
4997 A tree is a collection of nodes, where each node (except the root node) has a single parent
4998 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
5001 Creates and returns a new tree object with a single node named "root".
5002 All operations on the tree are invoked through this object.
5005 Destroy the tree and all it's nodes. (Note that the tree will also
5006 be automatically garbage collected once it goes out of scope).
5008 +$tree *set* 'nodename key value'+::
5009 Set the value for the given attribute key.
5011 +$tree *lappend* 'nodename key value \...'+::
5012 Append to the (list) value(s) for the given attribute key, or set if not yet set.
5014 +$tree *keyexists* 'nodename key'+::
5015 Returns 1 if the given attribute key exists.
5017 +$tree *get* 'nodename key'+::
5018 Returns the value associated with the given attribute key.
5020 +$tree *getall* 'nodename'+::
5021 Returns the entire attribute dictionary associated with the given key.
5023 +$tree *depth* 'nodename'+::
5024 Returns the depth of the given node. The depth of "root" is 0.
5026 +$tree *parent* 'nodename'+::
5027 Returns the node name of the parent node, or "" for the root node.
5029 +$tree *numchildren* 'nodename'+::
5030 Returns the number of child nodes.
5032 +$tree *children* 'nodename'+::
5033 Returns a list of the child nodes.
5035 +$tree *next* 'nodename'+::
5036 Returns the next sibling node, or "" if none.
5038 +$tree *insert* 'nodename ?index?'+::
5039 Add a new child node to the given node. The index is a list index
5040 such as +3+ or +end-2+. The default index is +end+.
5041 Returns the name of the newly added node.
5043 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
5044 Walks the tree starting from the given node, either breadth first (+bfs+)
5045 depth first (+dfs+).
5046 The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
5047 The name of each node is stored in +'nodevar'+.
5048 The script is evaluated twice for each node, on entry and exit.
5051 Dumps the tree contents to stdout
5055 The optional tclprefix extension provides the Tcl8.6-compatible `tcl::prefix` command
5056 (http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm) for matching strings against a table
5057 of possible values (typically commands or options).
5059 +*tcl::prefix all* 'table string'+::
5060 Returns a list of all elements in +'table'+ that begin with the prefix +'string'+.
5062 +*tcl::prefix longest* 'table string'+::
5063 Returns the longest common prefix of all elements in +'table'+ that begin with the prefix +'string'+.
5065 +*tcl::prefix match* '?options? table string'+::
5066 If +'string'+ equals one element in +'table'+ or is a prefix to
5067 exactly one element, the matched element is returned. If not, the
5068 result depends on the +-error+ option.
5070 * +*-exact*+ Accept only exact matches.
5071 * +*-message* 'string'+ Use +'string'+ in the error message at a mismatch. Default is "option".
5072 * +*-error* 'options'+ The options are used when no match is found. If +'options'+ is
5073 empty, no error is generated and an empty string is returned.
5074 Otherwise the options are used as return options when
5075 generating the error message. The default corresponds to
5080 Scriptable command line completion is supported in the interactive shell, 'jimsh', through
5081 the `tcl::autocomplete` callback. A simple implementation is provided, however this may
5082 be replaced with a custom command instead if desired.
5084 In the interactive shell, press <TAB> to activate command line completion.
5086 +*tcl::autocomplete* 'commandline'+::
5087 This command is called with the current command line when the user presses <TAB>.
5088 The command should return a list of all possible command lines that match the current command line.
5089 For example if +*pr*+ is the current command line, the list +*{prefix proc}*+ may be returned.
5093 The optional history extension provides script access to the command line editing
5094 and history support available in 'jimsh'. See 'examples/jtclsh.tcl' for an example.
5095 Note: if line editing support is not available, `history getline` acts like `gets` and
5096 the remaining subcommands do nothing.
5098 +*history load* 'filename'+::
5099 Load history from a (text) file. If the file does not exist or is not readable,
5102 +*history getline* 'prompt ?varname?'+::
5103 Displays the given prompt and allows a line to be entered. Similarly to `gets`,
5104 if +'varname'+ is given, it receives the line and the length of the line is returned,
5105 or -1 on EOF. If +'varname'+ is not given, the line is returned directly.
5107 +*history completion* 'command'+::
5108 Sets an autocompletion command (see `tcl::autocomplete`) that is active during `history getline`.
5109 If the command is empty, autocompletion is disabled.
5111 +*history add* 'line'+::
5112 Adds the given line to the history buffer.
5114 +*history save* 'filename'+::
5115 Saves the current history buffer to the given file.
5118 Displays the current history buffer to standard output.
5122 Provides namespace-related functions. See also: http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
5124 +*namespace code* 'script'+::
5125 Captures the current namespace context for later execution of
5126 the script +'script'+. It returns a new script in which script has
5127 been wrapped in a +*namespace inscope*+ command.
5129 +*namespace current*+::
5130 Returns the fully-qualified name for the current namespace.
5132 +*namespace delete* '?namespace ...?'+::
5133 Deletes all commands and variables with the given namespace prefixes.
5135 +*namespace eval* 'namespace arg ?arg...?'+::
5136 Activates a namespace called +'namespace'+ and evaluates some code in that context.
5138 +*namespace origin* 'command'+::
5139 Returns the fully-qualified name of the original command to which the imported command +'command'+ refers.
5141 +*namespace parent* ?namespace?+::
5142 Returns the fully-qualified name of the parent namespace for namespace +'namespace'+, if given, otherwise
5143 for the current namespace.
5145 +*namespace qualifiers* 'string'+::
5146 Returns any leading namespace qualifiers for +'string'+
5148 +*namespace tail* 'string'+::
5149 Returns the simple name at the end of a qualified string.
5151 +*namespace upvar* 'namespace ?arg...?'+::
5152 This command arranges for zero or more local variables in the current procedure to refer to variables in +'namespace'+
5154 +*namespace which* '?-command|-variable? name'+::
5155 Looks up +'name'+ as either a command (the default) or variable and returns its fully-qualified name.
5159 The optional 'interp' command allows sub-interpreters to be created where commands may be run
5160 independently (but synchronously) of the main interpreter.
5163 Creates and returns a new interpreter object (command).
5164 The created interpeter contains any built-in commands along with static extensions,
5165 but does not include any dynamically loaded commands (package require, load).
5166 These must be reloaded in the child interpreter if required.
5168 +*$interp delete*+::
5169 Deletes the interpeter object.
5171 +*$interp eval* 'script' ...+::
5172 Evaluates a script in the context for the child interpreter, in the same way as 'eval'.
5174 +*$interp alias* 'alias childcmd parentcmd ?arg ...?'+::
5175 Similar to 'alias', but creates a command, +'childcmd'+, in the child interpreter that is an
5176 alias for +'parentcmd'+ in the parent interpreter, with the given, fixed arguments.
5177 The alias may be deleted in the child with 'rename'.
5179 [[BuiltinVariables]]
5183 The following global variables are created automatically
5187 This variable is set by Jim as an array
5188 whose elements are the environment variables for the process.
5189 Reading an element will return the value of the corresponding
5190 environment variable.
5191 This array is initialised at startup from the `env` command.
5192 It may be modified and will affect the environment passed to
5193 commands invoked with `exec`.
5196 This variable is set by Jim as an array containing information
5197 about the platform on which Jim was built. Currently this includes
5198 'os' and 'platform'.
5201 This variable contains a list of paths to search for packages.
5202 It defaults to a location based on where jim is installed
5203 (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
5204 or the embedding application. Note that +jimsh+ will consider
5205 the environment variable +$JIMLIB+ to be a list of colon-separated
5206 list of paths to add to +*auto_path*+.
5209 This variable holds the value of the -errorcode return
5210 option set by the most recent error that occurred in this
5211 interpreter. This list value represents additional information
5212 about the error in a form that is easy to process with
5213 programs. The first element of the list identifies a general
5214 class of errors, and determines the format of the rest of
5215 the list. The following formats for -errorcode return options
5216 are used by the Tcl core; individual applications may define
5217 additional formats. Currently only `exec` sets this variable.
5218 Otherwise it will be +NONE+.
5220 The following global variables are set by jimsh.
5222 +*tcl_interactive*+::
5223 This variable is set to 1 if jimsh is started in interactive mode
5227 This variable is set by Jim as an array containing information
5228 about the platform upon which Jim was built. The following is an
5229 example of the contents of this array.
5231 tcl_platform(byteOrder) = littleEndian
5232 tcl_platform(engine) = Jim
5233 tcl_platform(os) = Darwin
5234 tcl_platform(platform) = unix
5235 tcl_platform(pointerSize) = 8
5236 tcl_platform(threaded) = 0
5237 tcl_platform(wordSize) = 8
5238 tcl_platform(pathSeparator) = :
5241 If jimsh is invoked to run a script, this variable contains the name
5245 If jimsh is invoked to run a script, this variable contains a list
5246 of any arguments supplied to the script.
5249 If jimsh is invoked to run a script, this variable contains the number
5250 of arguments supplied to the script.
5253 The value of argv[0] when jimsh was invoked.
5255 The following variables have special meaning to Jim Tcl:
5258 If this variable is set, it is considered to be a list of scripts to evaluate
5259 when the current proc exits (local variables), or the interpreter exits (global variable).
5262 +*history::multiline*+::
5263 If this variable is set to "1", interactive line editing operates in multiline mode.
5264 That is, long lines will wrap across multiple lines rather than scrolling within a
5267 CHANGES IN PREVIOUS RELEASES
5268 ----------------------------
5272 1. +platform_tcl()+ settings are now automatically determined
5273 2. Add aio `$handle filename`
5274 3. Add `info channels`
5275 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
5276 5. Add `exists` command
5277 6. Add the pure-Tcl 'oo' extension
5278 7. The `exec` command now only uses vfork(), not fork()
5279 8. Unit test framework is less verbose and more Tcl-compatible
5280 9. Optional UTF-8 support
5281 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
5282 11. Command line editing in interactive mode, e.g. 'jimsh'
5286 1. `source` now checks that a script is complete (.i.e. not missing a brace)
5287 2. 'info complete' now uses the real parser and so is 100% accurate
5288 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
5289 4. `tailcall` no longer loses stack trace information
5290 5. Add `alias` and `curry`
5291 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
5292 7. `local` allows procedures to be deleted automatically at the end of the current procedure
5293 8. udp sockets are now supported for both clients and servers.
5294 9. vfork-based exec is now working correctly
5295 10. Add 'file tempfile'
5296 11. Add 'socket pipe'
5297 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
5298 13. It is now possible to `return` from within `try`
5299 14. IPv6 support is now included
5301 16. Event handlers works better if an error occurs. eof handler has been removed.
5302 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
5303 18. Command pipelines via open "|..." are now supported
5304 19. `pid` can now return pids of a command pipeline
5305 20. Add 'info references'
5306 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
5307 22. `exec` now sets environment based on $::env
5309 24. Add support for 'lsort -index'
5313 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
5314 2. Fix `exec` error messages when special token (e.g. '>') is the last token
5315 3. Fix `subst` handling of backslash escapes.
5316 4. Allow abbreviated options for `subst`
5317 5. Add support for `return`, `break`, `continue` in subst
5318 6. Many `expr` bug fixes
5319 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
5320 8. The variable name argument to `regsub` is now optional
5321 9. Add support for 'unset -nocomplain'
5322 10. Add support for list commands: `lassign`, `lrepeat`
5323 11. Fully-functional `lsearch` is now implemented
5324 12. Add 'info nameofexecutable' and 'info returncodes'
5325 13. Allow `catch` to determine what return codes are caught
5326 14. Allow `incr` to increment an unset variable by first setting to 0
5327 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
5329 17. Add 'try ... finally' command
5335 Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5336 Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
5337 Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
5338 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
5339 Copyright 2008 Andrew Lunn <andrew@lunn.ch>
5340 Copyright 2008 Duane Ellis <openocd@duaneellis.com>
5341 Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
5342 Copyright 2009 Steve Bennett <steveb@workware.net.au>
5345 Redistribution and use in source and binary forms, with or without
5346 modification, are permitted provided that the following conditions
5348 1. Redistributions of source code must retain the above copyright
5349 notice, this list of conditions and the following disclaimer.
5350 2. Redistributions in binary form must reproduce the above
5351 copyright notice, this list of conditions and the following
5352 disclaimer in the documentation and/or other materials
5353 provided with the distribution.
5355 THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
5356 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
5357 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5358 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5359 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
5360 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5361 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5362 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5363 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5364 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5365 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5366 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5368 The views and conclusions contained in the software and documentation
5369 are those of the authors and should not be interpreted as representing
5370 official policies, either expressed or implied, of the Jim Tcl Project.