docs: make it clear that the package version is ignored
[jimtcl.git] / jim_tcl.txt
blob4c9553b14f1dbee2dbac25e31b9ff4c9ad41f4b6
1 Jim Tcl(n)
2 ==========
4 NAME
5 ----
6 Jim Tcl v0.79 - reference manual for the Jim Tcl scripting language
8 SYNOPSIS
9 --------
11   cc <source> -ljim
15   jimsh [<scriptfile>|-]
16   jimsh -e '<immediate-script>'
17   jimsh --version
18   jimsh --help
21 .Quick Index
22 * <<CommandIndex,Command Reference>>
23 * <<OperatorPrecedence,Operator Precedence>>
24 * <<BuiltinVariables, Builtin Variables>>
25 * <<BackslashSequences, Backslash Sequences>>
27 INTRODUCTION
28 ------------
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
38 3. Integers are 64bit
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
53 RECENT CHANGES
54 --------------
55 Changes between 0.78 and 0.79
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
61 5. Add support for `file split`
62 6. Add support for `json::encode` and `json::decode`
63 7. `aio tty` now allows setting +echo+ without full +raw+ mode
65 Changes between 0.77 and 0.78
66 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 1. Add serial/tty support with `aio tty`
68 2. Add support for 'jimsh -'
69 3. Add hidden '-commands' option to many commands
70 4. Add scriptable autocompletion support in interactive mode with `tcl::autocomplete`
71 5. Add `aio sockopt`
72 6. Add scriptable autocompletion support with `history completion`
73 7. Add support for `tree delete`
74 8. Add support for `defer` and '$jim::defer'
75 9. Renamed `os.wait` to `wait`, now more Tcl-compatible and compatible with `exec ... &`
76 10. `pipe` is now a synonym for `socket pipe`
77 11. Closing a pipe open with `open |...` now returns Tcl-like status
78 12. It is now possible to used `exec` redirection with a pipe opened with `open |...`
79 13. Interactive line editing now supports multiline mode if $::history::multiline is set
81 Changes between 0.76 and 0.77
82 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83 1. Add support for `aio sync`
84 2. Add SSL and TLS support in aio
85 3. Added `zlib`
86 4. Added support for boolean constants in `expr`
87 5. `string is` now supports 'boolean' class
88 6. Add support for `aio lock` and `aio unlock`
89 7. Add new `interp` command
91 Changes between 0.75 and 0.76
92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93 1. `glob` now supports the +-tails+ option
94 2. Add support for `string cat`
95 3. Allow `info source` to add source info
97 Changes between 0.74 and 0.75
98 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99 1. `binary`, `pack` and `unpack` now support floating point
100 2. `file copy` +-force+ handles source and target as the same file
101 3. `format` now supports +%b+ for binary conversion
102 4. `lsort` now supports +-unique+ and +-real+
103 5. Add support for half-close with `aio close` +?r|w?+
104 6. Add `socket pair` for a bidirectional pipe
105 7. Add '--random-hash' to randomise hash tables for greater security
106 8. `dict` now supports 'for', 'values', 'incr', 'append', 'lappend', 'update', 'info' and 'replace'
107 9. `file stat` no longer requires the variable name
108 10. Add support for `file link`
110 TCL INTRODUCTION
111 -----------------
112 Tcl stands for 'tool command language' and is pronounced
113 'http://www.oxforddictionaries.com/definition/american_english/tickle[tickle]'.
114 It is actually two things: a language and a library.
116 First, Tcl is a simple textual language, intended primarily for
117 issuing commands to interactive programs such as text editors,
118 debuggers, illustrators, and shells.  It has a simple syntax and is also
119 programmable, so Tcl users can write command procedures to provide more
120 powerful commands than those in the built-in set.
122 Second, Tcl is a library package that can be embedded in application
123 programs.  The Tcl library consists of a parser for the Tcl language,
124 routines to implement the Tcl built-in commands, and procedures that
125 allow each application to extend Tcl with additional commands specific
126 to that application.  The application program generates Tcl commands and
127 passes them to the Tcl parser for execution.  Commands may be generated
128 by reading characters from an input source, or by associating command
129 strings with elements of the application's user interface, such as menu
130 entries, buttons, or keystrokes.
132 When the Tcl library receives commands it parses them into component
133 fields and executes built-in commands directly.  For commands implemented
134 by the application, Tcl calls back to the application to execute the
135 commands.  In many cases commands will invoke recursive invocations of the
136 Tcl interpreter by passing in additional strings to execute (procedures,
137 looping commands, and conditional commands all work in this way).
139 An application program gains three advantages by using Tcl for its command
140 language.  First, Tcl provides a standard syntax:  once users know Tcl,
141 they will be able to issue commands easily to any Tcl-based application.
142 Second, Tcl provides programmability.  All a Tcl application needs
143 to do is to implement a few application-specific low-level commands.
144 Tcl provides many utility commands plus a general programming interface
145 for building up complex command procedures.  By using Tcl, applications
146 need not re-implement these features.
148 Third, Tcl can be used as a common language for communicating between
149 applications.  Inter-application communication is not built into the
150 Tcl core described here, but various add-on libraries, such as the Tk
151 toolkit, allow applications to issue commands to each other.  This makes
152 it possible for applications to work together in much more powerful ways
153 than was previously possible.
155 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
156 used to run standalone Tcl scripts, or to run Tcl commands interactively.
158 This manual page focuses primarily on the Tcl language.  It describes
159 the language syntax and the built-in commands that will be available
160 in any application based on Tcl.  The individual library procedures are
161 described in more detail in separate manual pages, one per procedure.
163 JIMSH COMMAND INTERPRETER
164 -------------------------
165 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
166 It may be invoked in interactive mode as:
168   jimsh
170 or to process the Tcl script in a file with:
172   jimsh filename
174 or to process the Tcl script from standard input:
176   jimsh -
178 It may also be invoked to execute an immediate script with:
180   jimsh -e "script"
182 Interactive Mode
183 ~~~~~~~~~~~~~~~~
184 Interactive mode reads Tcl commands from standard input, evaluates
185 those commands and prints the results.
187   $ jimsh
188   Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
189   . info version
190   0.73
191   . lsort [info commands p*]
192   package parray pid popen proc puts pwd
193   . foreach i {a b c} {
194   {> puts $i
195   {> }
196   a
197   b
198   c
199   . bad
200   invalid command name "bad"
201   [error] . exit
202   $
204 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
205 terminal is detected, Emacs-style line editing commands are available, including:
206 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
207 in history. Additionally, the +h+ command may be used to display the command history.
209 Command line history is automatically saved and loaded from +~/.jim_history+
211 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
212 if it exists.
214 INTERPRETERS
215 ------------
216 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
217 An interpreter consists of a set of command bindings, a set of variable
218 values, and a few other miscellaneous pieces of state.  Each Tcl command
219 is interpreted in the context of a particular interpreter.
221 Some Tcl-based applications will maintain multiple interpreters
222 simultaneously, each associated with a different widget or portion of
223 the application.  Interpreters are relatively lightweight structures.
224 They can be created and deleted quickly, so application programmers should
225 feel free to use multiple interpreters if that simplifies the application.
227 DATA TYPES
228 ----------
229 Tcl supports only one type of data:  strings.  All commands, all arguments
230 to commands, all command results, and all variable values are strings.
232 Where commands require numeric arguments or return numeric results,
233 the arguments and results are passed as strings.  Many commands expect
234 their string arguments to have certain formats, but this interpretation
235 is up to the individual commands.  For example, arguments often contain
236 Tcl command strings, which may get executed as part of the commands.
237 The easiest way to understand the Tcl interpreter is to remember that
238 everything is just an operation on a string.  In many cases Tcl constructs
239 will look similar to more structured constructs from other languages.
240 However, the Tcl constructs are not structured at all; they are just
241 strings of characters, and this gives them a different behaviour than
242 the structures they may look like.
244 Although the exact interpretation of a Tcl string depends on who is doing
245 the interpretation, there are three common forms that strings take:
246 commands, expressions, and lists.  The major sections below discuss
247 these three forms in more detail.
249 BASIC COMMAND SYNTAX
250 --------------------
251 The Tcl language has syntactic similarities to both the Unix shells
252 and Lisp.  However, the interpretation of commands is different
253 in Tcl than in either of those other two systems.
254 A Tcl command string consists of one or more commands separated
255 by newline characters or semi-colons.
256 Each command consists of a collection of fields separated by
257 white space (spaces or tabs).
258 The first field must be the name of a command, and the
259 additional fields, if any, are arguments that will be passed to
260 that command.  For example, the command:
262 ----
263     set a 22
264 ----
266 has three fields:  the first, `set`, is the name of a Tcl command, and
267 the last two, 'a' and '22', will be passed as arguments to
268 the `set` command.  The command name may refer either to a built-in
269 Tcl command, an application-specific command bound in with the library
270 procedure 'Jim_CreateCommand', or a command procedure defined with the
271 `proc` built-in command.
273 Arguments are passed literally as text strings.  Individual commands may
274 interpret those strings in any fashion they wish.  The `set` command,
275 for example, will treat its first argument as the name of a variable
276 and its second argument as a string value to assign to that variable.
277 For other commands arguments may be interpreted as integers, lists,
278 file names, or Tcl commands.
280 Command names should normally be typed completely (e.g. no abbreviations).
281 However, if the Tcl interpreter cannot locate a command it invokes a
282 special command named `unknown` which attempts to find or create the
283 command.
285 For example, at many sites `unknown` will search through library
286 directories for the desired command and create it as a Tcl procedure if
287 it is found.  The `unknown` command often provides automatic completion
288 of abbreviated commands, but usually only for commands that were typed
289 interactively.
291 It's probably a bad idea to use abbreviations in command scripts and
292 other forms that will be re-used over time:  changes to the command set
293 may cause abbreviations to become ambiguous, resulting in scripts that
294 no longer work.
296 COMMENTS
297 --------
298 If the first non-blank character in a command is +\#+, then everything
299 from the +#+ up through the next newline character is treated as
300 a comment and ignored.  When comments are embedded inside nested
301 commands (e.g. fields enclosed in braces) they must have properly-matched
302 braces (this is necessary because when Tcl parses the top-level command
303 it doesn't yet know that the nested field will be used as a command so
304 it cannot process the nested comment character as a comment).
306 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
307 -------------------------------------
308 Normally each argument field ends at the next white space, but
309 double-quotes may be used to create arguments with embedded space.
311 If an argument field begins with a double-quote, then the argument isn't
312 terminated by white space (including newlines) or a semi-colon (see below
313 for information on semi-colons); instead it ends at the next double-quote
314 character.  The double-quotes are not included in the resulting argument.
315 For example, the command
317 ----
318     set a "This is a single argument"
319 ----
321 will pass two arguments to `set`:  'a' and 'This is a single argument'.
323 Within double-quotes, command substitutions, variable substitutions,
324 and backslash substitutions still occur, as described below.  If the
325 first character of a command field is not a quote, then quotes receive
326 no special interpretation in the parsing of that field.
328 GROUPING ARGUMENTS WITH BRACES
329 ------------------------------
330 Curly braces may also be used for grouping arguments.  They are similar
331 to quotes except for two differences.  First, they nest; this makes them
332 easier to use for complicated arguments like nested Tcl command strings.
333 Second, the substitutions described below for commands, variables, and
334 backslashes do *not* occur in arguments enclosed in braces, so braces
335 can be used to prevent substitutions where they are undesirable.
337 If an argument field begins with a left brace, then the argument ends
338 at the matching right brace.  Tcl will strip off the outermost layer
339 of braces and pass the information between the braces to the command
340 without any further modification.  For example, in the command
342 ----
343     set a {xyz a {b c d}}
344 ----
346 the `set` command will receive two arguments: 'a'
347 and 'xyz a {b c d}'.
349 When braces or quotes are in effect, the matching brace or quote need
350 not be on the same line as the starting quote or brace; in this case
351 the newline will be included in the argument field along with any other
352 characters up to the matching brace or quote.  For example, the `eval`
353 command takes one argument, which is a command string; `eval` invokes
354 the Tcl interpreter to execute the command string.  The command
356 ----
357     eval {
358       set a 22
359       set b 33
360     }
361 ----
363 will assign the value '22' to 'a' and '33' to 'b'.
365 If the first character of a command field is not a left
366 brace, then neither left nor right
367 braces in the field will be treated specially (except as part of
368 variable substitution; see below).
370 COMMAND SUBSTITUTION WITH BRACKETS
371 ----------------------------------
372 If an open bracket occurs in a field of a command, then command
373 substitution occurs (except for fields enclosed in braces).  All of the
374 text up to the matching close bracket is treated as a Tcl command and
375 executed immediately.  Then the result of that command is substituted
376 for the bracketed text.  For example, consider the command
378 ----
379     set a [set b]
380 ----
382 When the `set` command has only a single argument, it is the name of a
383 variable and `set` returns the contents of that variable.  In this case,
384 if variable 'b' has the value 'foo', then the command above is equivalent
385 to the command
387 ----
388     set a foo
389 ----
391 Brackets can be used in more complex ways.  For example, if the variable
392 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
393 then the command
395 ----
396     set a xyz[set b].[set c]
397 ----
399 is equivalent to the command
401 ----
402     set a xyzfoo.gorp
403 ----
405 A bracketed command may contain multiple commands separated by newlines
406 or semi-colons in the usual fashion.  In this case the value of the last
407 command is used for substitution.  For example, the command
409 ----
410     set a x[set b 22
411     expr $b+2]x
412 ----
414 is equivalent to the command
416 ----
417     set a x24x
418 ----
420 If a field is enclosed in braces then the brackets and the characters
421 between them are not interpreted specially; they are passed through to
422 the argument verbatim.
424 VARIABLE SUBSTITUTION WITH $
425 ----------------------------
426 The dollar sign (+$+) may be used as a special shorthand form for
427 substituting variable values.  If +$+ appears in an argument that isn't
428 enclosed in braces then variable substitution will occur.  The characters
429 after the +$+, up to the first character that isn't a number, letter,
430 or underscore, are taken as a variable name and the string value of that
431 variable is substituted for the name.
433 For example, if variable 'foo' has the value 'test', then the command
435 ----
436     set a $foo.c
437 ----
439 is equivalent to the command
441 ----
442     set a test.c
443 ----
445 There are two special forms for variable substitution.  If the next
446 character after the name of the variable is an open parenthesis, then
447 the variable is assumed to be an array name, and all of the characters
448 between the open parenthesis and the next close parenthesis are taken as
449 an index into the array.  Command substitutions and variable substitutions
450 are performed on the information between the parentheses before it is
451 used as an index.
453 For example, if the variable 'x' is an array with one element named
454 'first' and value '87' and another element named '14' and value 'more',
455 then the command
457 ----
458     set a xyz$x(first)zyx
459 ----
461 is equivalent to the command
463 ----
464     set a xyz87zyx
465 ----
467 If the variable 'index' has the value '14', then the command
469 ----
470     set a xyz$x($index)zyx
471 ----
473 is equivalent to the command
475 ----
476     set a xyzmorezyx
477 ----
479 For more information on arrays, see <<_variables_scalars_and_arrays,VARIABLES - SCALARS AND ARRAYS>> below.
481 The second special form for variables occurs when the dollar sign is
482 followed by an open curly brace.  In this case the variable name consists
483 of all the characters up to the next curly brace.
485 Array references are not possible in this form:  the name between braces
486 is assumed to refer to a scalar variable.  For example, if variable
487 'foo' has the value 'test', then the command
489 ----
490     set a abc${foo}bar
491 ----
493 is equivalent to the command
495 ----
496     set a abctestbar
497 ----
500 Variable substitution does not occur in arguments that are enclosed in
501 braces:  the dollar sign and variable name are passed through to the
502 argument verbatim.
504 The dollar sign abbreviation is simply a shorthand form.  +$a+ is
505 completely equivalent to +[set a]+; it is provided as a convenience
506 to reduce typing.
508 SEPARATING COMMANDS WITH SEMI-COLONS
509 ------------------------------------
510 Normally, each command occupies one line (the command is terminated by a
511 newline character).  However, semi-colon (+;+) is treated as a command
512 separator character; multiple commands may be placed on one line by
513 separating them with a semi-colon.  Semi-colons are not treated as
514 command separators if they appear within curly braces or double-quotes.
516 BACKSLASH SUBSTITUTION
517 ----------------------
518 Backslashes may be used to insert non-printing characters into command
519 fields and also to insert special characters like braces and brackets
520 into fields without them being interpreted specially as described above.
522 The backslash sequences understood by the Tcl interpreter are
523 listed below.  In each case, the backslash
524 sequence is replaced by the given character:
525 [[BackslashSequences]]
526 +{backslash}b+::
527     Backspace (0x8)
529 +{backslash}f+::
530     Form feed (0xc)
532 +{backslash}n+::
533     Newline (0xa)
535 +{backslash}r+::
536     Carriage-return (0xd).
538 +{backslash}t+::
539     Tab (0x9).
541 +{backslash}v+::
542     Vertical tab (0xb).
544 +{backslash}{+::
545     Left brace ({).
547 +{backslash}}+::
548     Right brace (}).
550 +{backslash}[+::
551     Open bracket ([).
553 +{backslash}]+::
554     Close bracket (]).
556 +{backslash}$+::
557     Dollar sign ($).
559 +{backslash}<space>+::
560     Space ( ): doesn't terminate argument.
562 +{backslash};+::
563     Semi-colon: doesn't terminate command.
565 +{backslash}"+::
566     Double-quote.
568 +{backslash}<newline>+::
569     Nothing:  this joins two lines together
570     into a single line.  This backslash feature is unique in that
571     it will be applied even when the sequence occurs within braces.
573 +{backslash}{backslash}+::
574     Backslash ('{backslash}').
576 +{backslash}ddd+::
577     The digits +'ddd'+ (one, two, or three of them) give the octal value of
578     the character.  Note that Jim supports null characters in strings.
580 +{backslash}unnnn+::
581 +{backslash}u\{nnn\}+::
582 +{backslash}Unnnnnnnn+::
583     The UTF-8 encoding of the unicode codepoint represented by the hex digits, +'nnnn'+, is inserted.
584     The 'u' form allows for one to four hex digits.
585     The 'U' form allows for one to eight hex digits.
586     The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
587     characters UTF-8 characters which are followed by a hex digit.
589 For example, in the command
591 ----
592     set a \{x\[\ yz\141
593 ----
595 the second argument to `set` will be +{x[ yza+.
597 If a backslash is followed by something other than one of the options
598 described above, then the backslash is transmitted to the argument
599 field without any special processing, and the Tcl scanner continues
600 normal processing with the next character.  For example, in the
601 command
603 ----
604     set \*a \\\{foo
605 ----
607 The first argument to `set` will be +{backslash}*a+ and the second
608 argument will be +{backslash}{foo+.
610 If an argument is enclosed in braces, then backslash sequences inside
611 the argument are parsed but no substitution occurs (except for
612 backslash-newline):  the backslash
613 sequence is passed through to the argument as is, without making
614 any special interpretation of the characters in the backslash sequence.
615 In particular, backslashed braces are not counted in locating the
616 matching right brace that terminates the argument.
617 For example, in the
618 command
620 ----
621     set a {\{abc}
622 ----
624 the second argument to `set` will be +{backslash}{abc+.
626 This backslash mechanism is not sufficient to generate absolutely
627 any argument structure; it only covers the
628 most common cases.  To produce particularly complicated arguments
629 it is probably easiest to use the `format` command along with
630 command substitution.
632 STRING AND LIST INDEX SPECIFICATIONS
633 ------------------------------------
635 Many string and list commands take one or more 'index' parameters which
636 specify a position in the string relative to the start or end of the string/list.
638 The index may be one of the following forms:
640 +integer+::
641     A simple integer, where '0' refers to the first element of the string
642     or list.
644 +integer+integer+ or::
645 +integer-integer+::
646     The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
647     This is useful when used with (e.g.) +$i+1+ rather than the more verbose
648     +[expr {$i+1\}]+
650 +end+::
651     The last element of the string or list.
653 +end-integer+::
654     The 'nth-from-last' element of the string or list.
656 COMMAND SUMMARY
657 ---------------
658 1. A command is just a string.
659 2. Within a string commands are separated by newlines or semi-colons
660    (unless the newline or semi-colon is within braces or brackets
661    or is backslashed).
662 3. A command consists of fields.  The first field is the name of the command.
663    The other fields are strings that are passed to that command as arguments.
664 4. Fields are normally separated by white space.
665 5. Double-quotes allow white space and semi-colons to appear within
666    a single argument.
667    Command substitution, variable substitution, and backslash substitution
668    still occur inside quotes.
669 6. Braces defer interpretation of special characters.
670    If a field begins with a left brace, then it consists of everything
671    between the left brace and the matching right brace. The
672    braces themselves are not included in the argument.
673    No further processing is done on the information between the braces
674    except that backslash-newline sequences are eliminated.
675 7. If a field doesn't begin with a brace then backslash,
676    variable, and command substitution are done on the field.  Only a
677    single level of processing is done:  the results of one substitution
678    are not scanned again for further substitutions or any other
679    special treatment.  Substitution can
680    occur on any field of a command, including the command name
681    as well as the arguments.
682 8. If the first non-blank character of a command is a +\#+, everything
683    from the +#+ up through the next newline is treated as a comment
684    and ignored.
686 EXPRESSIONS
687 -----------
688 The second major interpretation applied to strings in Tcl is
689 as expressions.  Several commands, such as `expr`, `for`,
690 and `if`, treat one or more of their arguments as expressions
691 and call the Tcl expression processors ('Jim_ExprLong',
692 'Jim_ExprBoolean', etc.) to evaluate them.
694 The operators permitted in Tcl expressions are a subset of
695 the operators permitted in C expressions, and they have the
696 same meaning and precedence as the corresponding C operators.
697 Expressions almost always yield numeric results
698 (integer or floating-point values).
699 For example, the expression
701 ----
702     8.2 + 6
703 ----
705 evaluates to 14.2.
707 Tcl expressions differ from C expressions in the way that
708 operands are specified, and in that Tcl expressions support
709 non-numeric operands and string comparisons.
711 A Tcl expression consists of a combination of operands, operators,
712 and parentheses.
714 White space may be used between the operands and operators and
715 parentheses; it is ignored by the expression processor.
716 Where possible, operands are interpreted as integer values.
718 Integer values may be specified in decimal (the normal case) or in
719 hexadecimal (if the first two characters of the operand are '0x').
720 Note that Jim Tcl does *not* treat numbers with leading zeros as octal.
722 If an operand does not have one of the integer formats given
723 above, then it is treated as a floating-point number if that is
724 possible.  Floating-point numbers may be specified in any of the
725 ways accepted by an ANSI-compliant C compiler (except that the
726 'f', 'F', 'l', and 'L' suffixes will not be permitted in
727 most installations).  For example, all of the
728 following are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
730 If no numeric interpretation is possible, then an operand is left
731 as a string (and only a limited set of operators may be applied to
732 it).
734 String constants representing boolean constants
735 (+'0'+, +'1'+, +'false'+, +'off'+, +'no'+, +'true'+, +'on'+, +'yes'+)
736 are also recognized and can be used in logical operations.
738 1. Operands may be specified in any of the following ways:
740 2. As a numeric value, either integer or floating-point.
742 3. As one of valid boolean constants
744 4. As a Tcl variable, using standard '$' notation.
745 The variable's value will be used as the operand.
747 5. As a string enclosed in double-quotes.
748 The expression parser will perform backslash, variable, and
749 command substitutions on the information between the quotes,
750 and use the resulting value as the operand
752 6. As a string enclosed in braces.
753 The characters between the open brace and matching close brace
754 will be used as the operand without any substitutions.
756 7. As a Tcl command enclosed in brackets.
757 The command will be executed and its result will be used as
758 the operand.
760 Where substitutions occur above (e.g. inside quoted strings), they
761 are performed by the expression processor.
762 However, an additional layer of substitution may already have
763 been performed by the command parser before the expression
764 processor was called.
766 As discussed below, it is usually best to enclose expressions
767 in braces to prevent the command parser from performing substitutions
768 on the contents.
770 For some examples of simple expressions, suppose the variable 'a' has
771 the value 3 and the variable 'b' has the value 6.  Then the expression
772 on the left side of each of the lines below will evaluate to the value
773 on the right side of the line:
775 ----
776     $a + 3.1                6.1
777     2 + "$a.$b"             5.6
778     4*[llength "6 2"]       8
779     {word one} < "word $a"  0
780 ----
782 The valid operators are listed below, grouped in decreasing order
783 of precedence:
784 [[OperatorPrecedence]]
785 +int() double() round() abs(), rand(), srand()+::
786     Unary functions (except rand() which takes no arguments)
787     * +'int()'+ converts the numeric argument to an integer by truncating down.
788     * +'double()'+ converts the numeric argument to floating point.
789     * +'round()'+ converts the numeric argument to the closest integer value.
790     * +'abs()'+ takes the absolute value of the numeric argument.
791     * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
792     * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
794 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
795     Unary math functions.
796     If Jim is compiled with math support, these functions are available.
798 +- + ~ !+::
799     Unary minus, unary plus, bit-wise NOT, logical NOT.  None of these operands
800     may be applied to string operands, and bit-wise NOT may be
801     applied only to integers.
803 +** pow(x,y)+::
804     Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
805     integers. Otherwise supports integers only. (Note that the math-function form
806     has the same highest precedence)
808 +* / %+::
809     Multiply, divide, remainder.  None of these operands may be
810     applied to string operands, and remainder may be applied only
811     to integers.
813 ++ -+::
814     Add and subtract.  Valid for any numeric operands.
816 +<<  >> <<< >>>+::
817     Left and right shift, left and right rotate.  Valid for integer operands only.
819 +<  >  \<=  >=+::
820     Boolean less, greater, less than or equal, and greater than or equal.
821     Each operator produces 1 if the condition is true, 0 otherwise.
822     These operators may be applied to strings as well as numeric operands,
823     in which case string comparison is used.
825 +==  !=+::
826     Boolean equal and not equal.  Each operator produces a zero/one result.
827     Valid for all operand types. *Note* that values will be converted to integers
828     if possible, then floating point types, and finally strings will be compared.
829     It is recommended that 'eq' and 'ne' should be used for string comparison.
831 +eq ne+::
832     String equal and not equal.  Uses the string value directly without
833     attempting to convert to a number first.
835 +in ni+::
836     String in list and not in list. For 'in', result is 1 if the left operand (as a string)
837     is contained in the right operand (as a list), or 0 otherwise. The result for
838     +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
840 +&+::
841     Bit-wise AND.  Valid for integer operands only.
843 +|+::
844     Bit-wise OR.  Valid for integer operands only.
846 +^+::
847     Bit-wise exclusive OR.  Valid for integer operands only.
849 +&&+::
850     Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
851     Valid for numeric operands only (integers or floating-point).
853 +||+::
854     Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
855     Valid for numeric operands only (integers or floating-point).
857 +x ? y : z+::
858     If-then-else, as in C.  If +'x'+
859     evaluates to non-zero, then the result is the value of +'y'+.
860     Otherwise the result is the value of +'z'+.
861     The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
862     be of any type.
864 See the C manual for more details on the results
865 produced by each operator.
866 All of the binary operators group left-to-right within the same
867 precedence level.  For example, the expression
869 ----
870     4*2 < 7
871 ----
873 evaluates to 0.
875 The +&&+, +||+, and +?:+ operators have 'lazy evaluation', just as
876 in C, which means that operands are not evaluated if they are not
877 needed to determine the outcome.  For example, in
879 ----
880     $v ? [a] : [b]
881 ----
883 only one of +[a]+ or +[b]+ will actually be evaluated,
884 depending on the value of +$v+.
886 All internal computations involving integers are done with the C
887 type 'long long' if available, or 'long' otherwise, and all internal
888 computations involving floating-point are done with the C type
889 'double'.
891 When converting a string to floating-point, exponent overflow is
892 detected and results in a Tcl error.
893 For conversion to integer from string, detection of overflow depends
894 on the behaviour of some routines in the local C library, so it should
895 be regarded as unreliable.
896 In any case, overflow and underflow are generally not detected
897 reliably for intermediate results.
899 Conversion among internal representations for integer, floating-point,
900 string operands is done automatically as needed.
901 For arithmetic computations, integers are used until some
902 floating-point number is introduced, after which floating-point is used.
903 For example,
905 ----
906     5 / 4
907 ----
909 yields the result 1, while
911 ----
912     5 / 4.0
913     5 / ( [string length "abcd"] + 0.0 )
914 ----
916 both yield the result 1.25.
918 String values may be used as operands of the comparison operators,
919 although the expression evaluator tries to do comparisons as integer
920 or floating-point when it can.
921 If one of the operands of a comparison is a string and the other
922 has a numeric value, the numeric operand is converted back to
923 a string using the C 'sprintf' format specifier
924 '%d' for integers and '%g' for floating-point values.
925 For example, the expressions
927 ----
928     "0x03" > "2"
929     "0y" < "0x12"
930 ----
932 both evaluate to 1.  The first comparison is done using integer
933 comparison, and the second is done using string comparison after
934 the second operand is converted to the string '18'.
936 In general it is safest to enclose an expression in braces when
937 entering it in a command:  otherwise, if the expression contains
938 any white space then the Tcl interpreter will split it
939 among several arguments.  For example, the command
941 ----
942     expr $a + $b
943 ----
945 results in three arguments being passed to `expr`:  +$a+,
946 \+, and +$b+.  In addition, if the expression isn't in braces
947 then the Tcl interpreter will perform variable and command substitution
948 immediately (it will happen in the command parser rather than in
949 the expression parser).  In many cases the expression is being
950 passed to a command that will evaluate the expression later (or
951 even many times if, for example, the expression is to be used to
952 decide when to exit a loop).  Usually the desired goal is to re-do
953 the variable or command substitutions each time the expression is
954 evaluated, rather than once and for all at the beginning.  For example,
955 the command
957 ----
958     for {set i 1} $i<=10 {incr i} {...}        ** WRONG **
959 ----
961 is probably intended to iterate over all values of +i+ from 1 to 10.
962 After each iteration of the body of the loop, `for` will pass
963 its second argument to the expression evaluator to see whether or not
964 to continue processing.  Unfortunately, in this case the value of +i+
965 in the second argument will be substituted once and for all when the
966 `for` command is parsed.  If +i+ was 0 before the `for`
967 command was invoked then the second argument of `for` will be +0\<=10+
968 which will always evaluate to 1, even though +i+ eventually
969 becomes greater than 10.  In the above case the loop will never
970 terminate.  Instead, the expression should be placed in braces:
972 ----
973     for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **
974 ----
976 This causes the substitution of 'i'
977 to be delayed; it will be re-done each time the expression is
978 evaluated, which is the desired result.
980 LISTS
981 -----
982 The third major way that strings are interpreted in Tcl is as lists.
983 A list is just a string with a list-like structure
984 consisting of fields separated by white space.  For example, the
985 string
987 ----
988     Al Sue Anne John
989 ----
991 is a list with four elements or fields.
992 Lists have the same basic structure as command strings, except
993 that a newline character in a list is treated as a field separator
994 just like space or tab.  Conventions for braces and quotes
995 and backslashes are the same for lists as for commands.  For example,
996 the string
998 ----
999     a b\ c {d e {f g h}}
1000 ----
1002 is a list with three elements:  +a+, +b c+, and +d e {f g h}+.
1004 Whenever an element is extracted from a list, the same rules about
1005 braces and quotes and backslashes are applied as for commands.  Thus in
1006 the example above when the third element is extracted from the list,
1007 the result is
1009 ----
1010     d e {f g h}
1011 ----
1013 (when the field was extracted, all that happened was to strip off
1014 the outermost layer of braces).  Command substitution and
1015 variable substitution are never
1016 made on a list (at least, not by the list-processing commands; the
1017 list can always be passed to the Tcl interpreter for evaluation).
1019 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
1020 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
1021 you to build lists, extract elements from them, search them, and perform
1022 other list-related functions.
1024 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
1026 LIST EXPANSION
1027 --------------
1029 A new addition to Tcl 8.5 is the ability to expand a list into separate
1030 arguments. Support for this feature is also available in Jim.
1032 Consider the following attempt to exec a list:
1034 ----
1035     set cmd {ls -l}
1036     exec $cmd
1037 ----
1039 This will attempt to exec a command named "ls -l", which will clearly not
1040 work. Typically eval and concat are required to solve this problem, however
1041 it can be solved much more easily with +\{*\}+.
1043 ----
1044     exec {*}$cmd
1045 ----
1047 This will expand the following argument into individual elements and then evaluate
1048 the resulting command.
1050 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
1051 for backward compatibility with experimental versions of this feature.
1053 REGULAR EXPRESSIONS
1054 -------------------
1055 Tcl provides two commands that support string matching using regular
1056 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
1057 `lsearch -regexp`.
1059 Regular expressions may be implemented one of two ways. Either using the system's C library
1060 POSIX regular expression support, or using the built-in regular expression engine.
1061 The differences between these are described below.
1063 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
1065 POSIX Regular Expressions
1066 ~~~~~~~~~~~~~~~~~~~~~~~~~
1067 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1068 this support will be used by default. The type of regular expressions supported are
1069 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
1070 See REG_EXTENDED in the documentation.
1072 Using the system-supported POSIX regular expressions will typically
1073 make for the smallest code size, but some features such as UTF-8
1074 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported, and null characters
1075 in strings are not supported.
1077 See regex(3) and regex(7) for full details.
1079 Jim built-in Regular Expressions
1080 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1081 The Jim built-in regular expression engine may be selected with +./configure --with-jim-regexp+
1082 or it will be selected automatically if UTF-8 support is enabled.
1084 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
1085 and POSIX are highlighted below.
1087 1. UTF-8 strings and patterns are both supported
1088 2. All Tcl character classes are supported (e.g. +[:alnum:]+, +[:digit:]+, +[:space:]+), but...
1089 3. Character classes apply to ASCII characters only
1090 4. Supported shorthand character classes: +{backslash}w+ = +[:alnum:]+, +{backslash}W+ = +^[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}D+ = +^[:digit:],+ +{backslash}s+ = +[:space:]+, + +{backslash}S+ = +^[:space:]+
1091 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1092 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1093 7. Partially supported constraint escapes: +{backslash}A+ = start of string, +{backslash}Z+ = end of string
1094 8. Support for the +?+ non-greedy quantifier. e.g. +*?+
1095 9. Support for non-capturing parentheses +(?:...)+
1096 10. Jim Tcl considers that both patterns and strings end at a null character (+\x00+)
1098 COMMAND RESULTS
1099 ---------------
1100 Each command produces two results:  a code and a string.  The
1101 code indicates whether the command completed successfully or not,
1102 and the string gives additional information.  The valid codes are
1103 defined in jim.h, and are:
1105 +JIM_OK(0)+::
1106     This is the normal return code, and indicates that the command completed
1107     successfully.  The string gives the command's return value.
1109 +JIM_ERR(1)+::
1110     Indicates that an error occurred; the string gives a message describing
1111     the error.
1113 +JIM_RETURN(2)+::
1114     Indicates that the `return` command has been invoked, and that the
1115     current procedure (or top-level command or `source` command)
1116     should return immediately.  The
1117     string gives the return value for the procedure or command.
1119 +JIM_BREAK(3)+::
1120     Indicates that the `break` command has been invoked, so the
1121     innermost loop should abort immediately.  The string should always
1122     be empty.
1124 +JIM_CONTINUE(4)+::
1125     Indicates that the `continue` command has been invoked, so the
1126     innermost loop should go on to the next iteration.  The string
1127     should always be empty.
1129 +JIM_SIGNAL(5)+::
1130     Indicates that a signal was caught while executing a commands.
1131     The string contains the name of the signal caught.
1132     See the `signal` and `catch` commands.
1134 +JIM_EXIT(6)+::
1135     Indicates that the command called the `exit` command.
1136     The string contains the exit code.
1138 Tcl programmers do not normally need to think about return codes,
1139 since +JIM_OK+ is almost always returned.  If anything else is returned
1140 by a command, then the Tcl interpreter immediately stops processing
1141 commands and returns to its caller.  If there are several nested
1142 invocations of the Tcl interpreter in progress, then each nested
1143 command will usually return the error to its caller, until eventually
1144 the error is reported to the top-level application code.  The
1145 application will then display the error message for the user.
1147 In a few cases, some commands will handle certain `error` conditions
1148 themselves and not return them upwards.  For example, the `for`
1149 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1150 stops executing the body of the loop and returns +JIM_OK+ to its
1151 caller.  The `for` command also handles +JIM_CONTINUE+ codes and the
1152 procedure interpreter handles +JIM_RETURN+ codes.  The `catch`
1153 command allows Tcl programs to catch errors and handle them without
1154 aborting command interpretation any further.
1156 The `info returncodes` command may be used to programmatically map between
1157 return codes and names.
1159 PROCEDURES
1160 ----------
1161 Tcl allows you to extend the command interface by defining
1162 procedures.  A Tcl procedure can be invoked just like any other Tcl
1163 command (it has a name and it receives one or more arguments).
1164 The only difference is that its body isn't a piece of C code linked
1165 into the program; it is a string containing one or more other
1166 Tcl commands.
1168 The `proc` command is used to create a new Tcl command procedure:
1170 +*proc* 'name arglist ?statics? body'+
1172 The new command is named +'name'+, and it replaces any existing command
1173 there may have been by that name. Whenever the new command is
1174 invoked, the contents of +'body'+ will be executed by the Tcl
1175 interpreter.
1177 +'arglist'+ specifies the formal arguments to the procedure.
1178 It consists of a list, possibly empty, of the following
1179 argument specifiers:
1181 +name+::
1182     Required Argument - A simple argument name.
1184 +{name default}+::
1185     Optional Argument - A two-element list consisting of the
1186     argument name, followed by the default value, which will
1187     be used if the corresponding argument is not supplied.
1189 +&name+::
1190     Reference Argument - The caller is expected to pass the name of
1191     an existing variable. An implicit +`upvar` 1 origname name+ is done
1192     to make the variable available in the proc scope.
1194 +*args*+::
1195     Variable Argument - The special name +'args'+, which is
1196     assigned all remaining arguments (including none) as a list. The
1197     variable argument may only be specified once. Note that
1198     the syntax +{args newname}+ may be used to retain the special
1199     behaviour of +'args'+ with a different local name. In this case,
1200     the variable is named +'newname'+ rather than +'args'+.
1202 When the command is invoked, a local variable will be created for each of
1203 the formal arguments to the procedure; its value will be the value
1204 of corresponding argument in the invoking command or the argument's
1205 default value.
1207 Arguments with default values need not be specified in a procedure
1208 invocation.  However, there must be enough actual arguments for all
1209 required arguments, and there must not be any extra actual arguments
1210 (unless the Variable Argument is specified).
1212 Actual arguments are assigned to formal arguments as in left-to-right
1213 order with the following precedence.
1215 1. Required Arguments (including Reference Arguments)
1216 2. Optional Arguments
1217 3. Variable Argument
1219 The following example illustrates precedence. Assume a procedure declaration:
1221 ----
1222     proc p {{a A} args b {c C} d} {...}
1223 ----
1225 This procedure requires at least two arguments, but can accept an unlimited number.
1226 The following table shows how various numbers of arguments are assigned.
1227 Values marked as +-+ are assigned the default value.
1229 [width="40%",frame="topbot",options="header"]
1230 |==============
1231 |Number of arguments|a|args|b|c|d
1232 |2|-|-|1|-|2
1233 |3|1|-|2|-|3
1234 |4|1|-|2|3|4
1235 |5|1|2|3|4|5
1236 |6|1|2,3|4|5|6
1237 |==============
1239 When +'body'+ is being executed, variable names normally refer to local
1240 variables, which are created automatically when referenced and deleted
1241 when the procedure returns.  One local variable is automatically created
1242 for each of the procedure's arguments.  Global variables can be
1243 accessed by invoking the `global` command or via the +::+ prefix.
1245 New in Jim
1246 ~~~~~~~~~~
1247 In addition to procedure arguments, Jim procedures may declare static variables.
1248 These variables scoped to the procedure and initialised at procedure definition.
1249 Either from the static variable definition, or from the enclosing scope.
1251 Consider the following example:
1253 ----
1254     . set a 1
1255     . proc a {} {a {b 2}} {
1256         set c 1
1257         puts "$a $b $c"
1258         incr a
1259         incr b
1260         incr c
1261     }
1262     . a
1263     1 2 1
1264     . a
1265     2 3 1
1266 ----
1268 The static variable +'a'+ has no initialiser, so it is initialised from
1269 the enclosing scope with the value 1. (Note that it is an error if there
1270 is no variable with the same name in the enclosing scope). However +'b'+
1271 has an initialiser, so it is initialised to 2.
1273 Unlike a local variable, the value of a static variable is retained across
1274 invocations of the procedure.
1276 See the `proc` command for information on how to define procedures
1277 and what happens when they are invoked. See also <<_namespaces,NAMESPACES>>.
1279 VARIABLES - SCALARS AND ARRAYS
1280 ------------------------------
1281 Tcl allows the definition of variables and the use of their values
1282 either through '$'-style variable substitution, the `set`
1283 command, or a few other mechanisms.
1285 Variables need not be declared:  a new variable will automatically
1286 be created each time a new variable name is used.
1288 Tcl supports two types of variables:  scalars and arrays.
1289 A scalar variable has a single value, whereas an array variable
1290 can have any number of elements, each with a name (called
1291 its 'index') and a value.
1293 Array indexes may be arbitrary strings; they need not be numeric.
1294 Parentheses are used refer to array elements in Tcl commands.
1295 For example, the command
1297 ----
1298     set x(first) 44
1299 ----
1301 will modify the element of 'x' whose index is 'first'
1302 so that its new value is '44'.
1304 Two-dimensional arrays can be simulated in Tcl by using indexes
1305 that contain multiple concatenated values.
1306 For example, the commands
1308 ----
1309     set a(2,3) 1
1310     set a(3,6) 2
1311 ----
1313 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1315 In general, array elements may be used anywhere in Tcl that scalar
1316 variables may be used.
1318 If an array is defined with a particular name, then there may
1319 not be a scalar variable with the same name.
1321 Similarly, if there is a scalar variable with a particular
1322 name then it is not possible to make array references to the
1323 variable.
1325 To convert a scalar variable to an array or vice versa, remove
1326 the existing variable with the `unset` command.
1328 The `array` command provides several features for dealing
1329 with arrays, such as querying the names of all the elements of
1330 the array and converting between an array and a list.
1332 Variables may be either global or local.  If a variable
1333 name is used when a procedure isn't being executed, then it
1334 automatically refers to a global variable.  Variable names used
1335 within a procedure normally refer to local variables associated with that
1336 invocation of the procedure.  Local variables are deleted whenever
1337 a procedure exits.  Either `global` command may be used to request
1338 that a name refer to a global variable for the duration of the current
1339 procedure (this is somewhat analogous to 'extern' in C), or the variable
1340 may be explicitly scoped with the +::+ prefix. For example
1342 ----
1343     . set a 1
1344     . set b 2
1345     . proc p {} {
1346         set c 3
1347         global a
1349         puts "$a $::b $c"
1350     }
1351     . p
1352 ----
1354 will output:
1356     1 2 3
1358 ARRAYS AS LISTS IN JIM
1359 ----------------------
1360 Unlike Tcl, Jim can automatically convert between a list (with an even
1361 number of elements) and an array value. This is similar to the way Tcl
1362 can convert between a string and a list.
1364 For example:
1366 ----
1367   set a {1 one 2 two}
1368   puts $a(2)
1369 ----
1371 will output:
1373 ----
1374   two
1375 ----
1377 Thus `array set` is equivalent to `set` when the variable does not
1378 exist or is empty.
1380 The reverse is also true where an array will be converted into
1381 a list.
1383 ----
1384   set a(1) one; set a(2) two
1385   puts $a
1386 ----
1388 will output:
1390 ----
1391   1 one 2 two
1392 ----
1394 DICTIONARY VALUES
1395 -----------------
1396 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1397 of this command. Dictionaries provide efficient access to key-value
1398 pairs, just like arrays, but dictionaries are pure values. This
1399 means that you can pass them to a procedure just as a list or a
1400 string. Tcl dictionaries are therefore much more like Tcl lists,
1401 except that they represent a mapping from keys to values, rather
1402 than an ordered sequence.
1404 You can nest dictionaries, so that the value for a particular key
1405 consists of another dictionary. That way you can elegantly build
1406 complicated data structures, such as hierarchical databases. You
1407 can also combine dictionaries with other Tcl data structures. For
1408 instance, you can build a list of dictionaries that themselves
1409 contain lists.
1411 Dictionaries are values that contain an efficient, order-preserving
1412 mapping from arbitrary keys to arbitrary values. Each key in the
1413 dictionary maps to a single value. They have a textual format that
1414 is exactly that of any list with an even number of elements, with
1415 each mapping in the dictionary being represented as two items in
1416 the list. When a command takes a dictionary and produces a new
1417 dictionary based on it (either returning it or writing it back into
1418 the variable that the starting dictionary was read from) the new
1419 dictionary will have the same order of keys, modulo any deleted
1420 keys and with new keys added on to the end. When a string is
1421 interpreted as a dictionary and it would otherwise have duplicate
1422 keys, only the last value for a particular key is used; the others
1423 are ignored, meaning that, "apple banana" and "apple carrot apple
1424 banana" are equivalent dictionaries (with different string
1425 representations).
1427 Note that in Jim, arrays are implemented as dictionaries.
1428 Thus automatic conversion between lists and dictionaries applies
1429 as it does for arrays.
1431 ----
1432   . dict set a 1 one
1433   1 one
1434   . dict set a 2 two
1435   1 one 2 two
1436   . puts $a
1437   1 one 2 two
1438   . puts $a(2)
1439   two
1440   . dict set a 3 T three
1441   1 one 2 two 3 {T three}
1442 ----
1444 See the `dict` command for more details.
1446 NAMESPACES
1447 ----------
1448 Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
1449 including a number of 3rd party components. While there is less need for namespaces
1450 in Jim Tcl (which does not strive to support large applications), it is convenient to
1451 provide a subset of the support for namespaces to easy porting code from Tcl.
1453 Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
1454 purposes. This feature is currently experimental. See README.namespaces for more information
1455 and the documentation of the `namespace` command.
1457 GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION
1458 -----------------------------------------------
1459 Unlike Tcl, Jim has some sophisticated support for functional programming.
1460 These are described briefly below.
1462 More information may be found at http://wiki.tcl.tk/13847
1464 References
1465 ~~~~~~~~~~
1466 A reference can be thought of as holding a value with one level of indirection,
1467 where the value may be garbage collected when unreferenced.
1468 Consider the following example:
1470 ----
1471     . set r [ref "One String" test]
1472     <reference.<test___>.00000000000000000000>
1473     . getref $r
1474     One String
1475 ----
1477 The operation `ref` creates a references to the value specified by the
1478 first argument. (The second argument is a "type" used for documentation purposes).
1480 The operation `getref` is the dereferencing operation which retrieves the value
1481 stored in the reference.
1483 ----
1484     . setref $r "New String"
1485     New String
1486     . getref $r
1487     New String
1488 ----
1490 The operation `setref` replaces the value stored by the reference. If the old value
1491 is no longer accessible by any reference, it will eventually be automatically be garbage
1492 collected.
1494 Garbage Collection
1495 ~~~~~~~~~~~~~~~~~~
1496 Normally, all values in Tcl are passed by value. As such values are copied and released
1497 automatically as necessary.
1499 With the introduction of references, it is possible to create values whose lifetime
1500 transcend their scope. To support this, case, the Jim system will periodically identify
1501 and discard objects which are no longer accessible by any reference.
1503 The `collect` command may be used to force garbage collection.  Consider a reference created
1504 with a finalizer:
1506 ----
1507     . proc f {ref value} { puts "Finaliser called for $ref,$value" }
1508     . set r [ref "One String" test f]
1509     <reference.<test___>.00000000000
1510     . collect
1511     0
1512     . set r ""
1513     . collect
1514     Finaliser called for <reference.<test___>.00000000000,One String
1515     1
1516 ----
1518 Note that once the reference, 'r', was modified so that it no longer
1519 contained a reference to the value, the garbage collector discarded
1520 the value (after calling the finalizer).
1522 The finalizer for a reference may be examined or changed with the `finalize` command
1524 ----
1525     . finalize $r
1526     f
1527     . finalize $r newf
1528     newf
1529 ----
1531 Lambda Function
1532 ~~~~~~~~~~~~~~~
1533 Jim provides a garbage collected `lambda` function. This is a procedure
1534 which is able to create an anonymous procedure.  Consider:
1536 ----
1537     . set f [lambda {a} {{x 0}} { incr x $a }]
1538     . $f 1
1539     1
1540     . $f 2
1541     3
1542     . set f ""
1543 ----
1545 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1546 which is incremented by the supplied value and the result returned.
1548 Once the procedure name is no longer accessible, it will automatically be deleted
1549 when the garbage collector runs.
1551 The procedure may also be delete immediately by renaming it "". e.g.
1553 ----
1554     . rename $f ""
1555 ----
1557 UTF-8 AND UNICODE
1558 -----------------
1559 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1560 then most string-related commands become UTF-8 aware.  These include,
1561 but are not limited to, `string match`, `split`, `glob`, `scan` and
1562 `format`.
1564 UTF-8 encoding has many advantages, but one of the complications is that
1565 characters can take a variable number of bytes. Thus the addition of
1566 `string bytelength` which returns the number of bytes in a string,
1567 while `string length` returns the number of characters.
1569 If UTF-8 support is not enabled, all commands treat bytes as characters
1570 and `string bytelength` returns the same value as `string length`.
1572 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ and related syntax
1573 is still available to embed UTF-8 sequences.
1575 Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.
1577 String Matching
1578 ~~~~~~~~~~~~~~~
1579 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1580 pattern matching rules. These commands support UTF-8. For example:
1582 ----
1583   string match a\[\ua0-\ubf\]b "a\u00a3b"
1584 ----
1586 format and scan
1587 ~~~~~~~~~~~~~~~
1588 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1589 a string with two bytes and one character. The same as +{backslash}ub5+
1591 ----
1592   format %c 0xb5
1593 ----
1595 `format` respects widths as character widths, not byte widths. For example, the following will
1596 return a string with three characters, not three bytes.
1598 ----
1599   format %.3s \ub5\ub6\ub7\ub8
1600 ----
1602 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1603 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1605 ----
1606   scan \u00b5A %c%c a b
1607 ----
1609 `scan %s` will also accept a character class, including unicode ranges.
1611 String Classes
1612 ~~~~~~~~~~~~~~
1613 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1614 will return 0, even though the string may be considered to be alphabetic.
1616 ----
1617   string is alpha \ub5Test
1618 ----
1620 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1622 Case Mapping and Conversion
1623 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1624 Jim provides a simplified unicode case mapping. This means that case conversion
1625 and comparison will not increase or decrease the number of characters in a string.
1626 (Although it may change the number of bytes).
1628 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1629 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1630 Similarly for `string tolower` and `string totitle`.
1632 Commands which perform case insensitive matches, such as `string compare -nocase`
1633 and `lsearch -nocase` fold both strings to uppercase before comparison.
1635 Invalid UTF-8 Sequences
1636 ~~~~~~~~~~~~~~~~~~~~~~~
1637 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1638 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1639 and those which end prematurely, such as a lone '0xc2'.
1641 In these situations, the offending bytes are treated as single characters. For example,
1642 the following returns 2.
1644 ----
1645   string bytelength \xff\xff
1646 ----
1648 Regular Expressions
1649 ~~~~~~~~~~~~~~~~~~~
1650 If UTF-8 support is enabled, the built-in regular expression engine will be
1651 selected which supports UTF-8 strings and patterns.
1653 See <<_regular_expressions,REGULAR EXPRESSIONS>>
1655 BUILT-IN COMMANDS
1656 -----------------
1657 The Tcl library provides the following built-in commands, which will
1658 be available in any application using Tcl.  In addition to these
1659 built-in commands, there may be additional commands defined by each
1660 application, plus commands defined as Tcl procedures.
1662 In the command syntax descriptions below, words in +*boldface*+ are
1663 literals that you type verbatim to Tcl.
1665 Words in +'italics'+ are meta-symbols; they serve as names for any of
1666 a range of values that you can type.
1668 Optional arguments or groups of arguments are indicated by enclosing them
1669 in +?question-marks?+.
1671 Ellipses (+\...+) indicate that any number of additional
1672 arguments or groups of arguments may appear, in the same format
1673 as the preceding argument(s).
1675 [[CommandIndex]]
1676 Command Index
1677 ~~~~~~~~~~~~~
1678 @INSERTINDEX@
1680 alarm
1681 ~~~~~
1682 +*alarm* 'seconds'+
1684 Delivers the +SIGALRM+ signal to the process after the given
1685 number of seconds. If the platform supports 'ualarm(3)' then
1686 the argument may be a floating point value. Otherwise it must
1687 be an integer.
1689 Note that unless a signal handler for +SIGALRM+ has been installed
1690 (see `signal`), the process will exit on this signal.
1692 alias
1693 ~~~~~
1694 +*alias* 'name args\...'+
1696 Creates a single word alias (command) for one or more words. For example,
1697 the following creates an alias for the command `info exists`.
1699 ----
1700     alias e info exists
1701     if {[e var]} {
1702       ...
1703     }
1704 ----
1706 `alias` returns +'name'+, allowing it to be used with `local`.
1708 See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`
1710 append
1711 ~~~~~~
1712 +*append* 'varName value ?value value ...?'+
1714 Append all of the +'value'+ arguments to the current value
1715 of variable +'varName'+.  If +'varName'+ doesn't exist,
1716 it is given a value equal to the concatenation of all the
1717 +'value'+ arguments.
1719 This command provides an efficient way to build up long
1720 variables incrementally.
1721 For example, "`append a $b`" is much more efficient than
1722 "`set a $a$b`" if +$a+ is long.
1724 apply
1725 ~~~~~~
1726 +*apply* 'lambdaExpr ?arg1 arg2 \...?'+
1728 The command `apply` provides for anonymous procedure calls,
1729 similar to `lambda`, but without command name being created, even temporarily.
1731 The function  +'lambdaExpr'+ is a two element list +{args body}+
1732 or a three element list +{args body namespace}+. The first element
1733 args specifies the formal arguments, in the same form as the `proc` and `lambda` commands.
1735 array
1736 ~~~~~
1737 +*array* 'option arrayName ?arg\...?'+
1739 This command performs one of several operations on the
1740 variable given by +'arrayName'+.
1742 Note that in general, if the named array does not exist, the +'array'+ command behaves
1743 as though the array exists but is empty.
1745 The +'option'+ argument determines what action is carried out by the
1746 command.  The legal +'options'+ (which may be abbreviated) are:
1748 +*array exists* 'arrayName'+::
1749     Returns 1 if arrayName is an array variable, 0 if there is
1750     no variable by that name.
1752 +*array get* 'arrayName ?pattern?'+::
1753     Returns a list containing pairs of elements. The first
1754     element in each pair is the name of an element in arrayName
1755     and the second element of each pair is the value of the
1756     array element. The order of the pairs is undefined. If
1757     pattern is not specified, then all of the elements of the
1758     array are included in the result. If pattern is specified,
1759     then only those elements whose names match pattern (using
1760     the matching rules of string match) are included. If arrayName
1761     isn't the name of an array variable, or if the array contains
1762     no elements, then an empty list is returned.
1764 +*array names* 'arrayName ?pattern?'+::
1765     Returns a list containing the names of all of the elements
1766     in the array that match pattern. If pattern is omitted then
1767     the command returns all of the element names in the array.
1768     If pattern is specified, then only those elements whose
1769     names match pattern (using the matching rules of string
1770     match) are included. If there are no (matching) elements
1771     in the array, or if arrayName isn't the name of an array
1772     variable, then an empty string is returned.
1774 +*array set* 'arrayName list'+::
1775     Sets the values of one or more elements in arrayName. list
1776     must have a form like that returned by array get, consisting
1777     of an even number of elements. Each odd-numbered element
1778     in list is treated as an element name within arrayName, and
1779     the following element in list is used as a new value for
1780     that array element. If the variable arrayName does not
1781     already exist and list is empty, arrayName is created with
1782     an empty array value.
1784 +*array size* 'arrayName'+::
1785     Returns the number of elements in the array. If arrayName
1786     isn't the name of an array then 0 is returned.
1788 +*array unset* 'arrayName ?pattern?'+::
1789     Unsets all of the elements in the array that match pattern
1790     (using the matching rules of string match). If arrayName
1791     isn't the name of an array variable or there are no matching
1792     elements in the array, no error will be raised. If pattern
1793     is omitted and arrayName is an array variable, then the
1794     command unsets the entire array. The command always returns
1795     an empty string.
1797 break
1798 ~~~~~
1799 +*break*+
1801 This command may be invoked only inside the body of a loop command
1802 such as `for` or `foreach` or `while`.  It returns a +JIM_BREAK+ code
1803 to signal the innermost containing loop command to return immediately.
1805 case
1806 ~~~~
1807 The obsolete '+*case*+' command has been removed from Jim Tcl since v0.75.
1808 Use `switch` instead.
1810 catch
1811 ~~~~~
1812 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1814 The `catch` command may be used to prevent errors from aborting
1815 command interpretation.  `catch` evaluates +'command'+, and returns a
1816 +JIM_OK+ code, regardless of any errors that might occur while
1817 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1818 see below).
1820 The return value from `catch` is a decimal string giving the code
1821 returned by the Tcl interpreter after executing +'command'+.  This
1822 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1823 it will have a non-zero value corresponding to one of the exceptional
1824 return codes (see jim.h for the definitions of code values, or the
1825 `info returncodes` command).
1827 If the +'resultVarName'+ argument is given, then it gives the name
1828 of a variable; `catch` will set the value of the variable to the
1829 string returned from +'command'+ (either a result or an error message).
1831 If the +'optionsVarName'+ argument is given, then it gives the name
1832 of a variable; `catch` will set the value of the variable to a
1833 dictionary. For any return code other than +JIM_RETURN+, the value
1834 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1835 it will be set to the code given in `return -code`. Additionally,
1836 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1837 will contain the current stack trace (the same result as `info stacktrace`),
1838 the value of the key +-errorcode+ will contain the
1839 same value as the global variable $::errorCode, and the value of
1840 the key +-level+ will be the current return level (see `return -level`).
1841 This can be useful to rethrow an error:
1843 ----
1844     if {[catch {...} msg opts]} {
1845         ...maybe do something with the error...
1846         incr opts(-level)
1847         return {*}$opts $msg
1848     }
1849 ----
1851 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1852 The set of codes which will be caught may be modified by specifying the one more codes before
1853 +'command'+.
1855 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1857 ----
1858     catch -exit -nobreak -nocontinue -- { ... }
1859 ----
1861 The use of +--+ is optional. It signifies that no more return code options follow.
1863 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1864 (stored in +'resultVarName'+) is name of the signal caught.
1868 +*cd* 'dirName'+
1870 Change the current working directory to +'dirName'+.
1872 Returns an empty string.
1874 This command can potentially be disruptive to an application, so it may
1875 be removed in some applications.
1877 clock
1878 ~~~~~
1879 +*clock seconds*+::
1880     Returns the current time as seconds since the epoch.
1882 +*clock clicks*+::
1883     Returns the current time in "clicks", a system-dependent, high-resolution time.
1885 +*clock microseconds*+::
1886     Returns the current time in microseconds.
1888 +*clock milliseconds*+::
1889     Returns the current time in milliseconds.
1891 +*clock format* 'seconds' ?*-format* 'format?' ?*-gmt* 'boolean?'+::
1892     Format the given time (seconds since the epoch) according to the given
1893     format. See strftime(3) for supported formats.
1894     If no format is supplied, "%c" is used.
1895   ::
1896     If +'boolean'+ is true, processing is performed in UTC.
1897     If +'boolean'+ is false (the default), processing  is performeed in the local time zone.
1899 +*clock scan* 'str' *-format* 'format' ?*-gmt* 'boolean?'+::
1900     Scan the given time string using the given format string.
1901     See strptime(3) for supported formats.
1902     See `clock format` for the handling of '-gmt'.
1904 close
1905 ~~~~~
1906 +*close* 'fileId'+
1908 +'fileId' *close*+
1910 Closes the file given by +'fileId'+.
1911 +'fileId'+ must be the return value from a previous invocation
1912 of the `open` command; after this command, it should not be
1913 used anymore.
1915 collect
1916 ~~~~~~~
1917 +*collect*+
1919 Normally reference garbage collection is automatically performed periodically.
1920 However it may be run immediately with the `collect` command.
1922 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
1924 concat
1925 ~~~~~~
1926 +*concat* 'arg ?arg \...?'+
1928 This command treats each argument as a list and concatenates them
1929 into a single list.  It permits any number of arguments.  For example,
1930 the command
1932 ----
1933     concat a b {c d e} {f {g h}}
1934 ----
1936 will return
1938 ----
1939     a b c d e f {g h}
1940 ----
1942 as its result.
1944 continue
1945 ~~~~~~~~
1946 +*continue*+
1948 This command may be invoked only inside the body of a loop command such
1949 as `for` or `foreach` or `while`.  It returns a  +JIM_CONTINUE+ code to
1950 signal the innermost containing loop command to skip the remainder of
1951 the loop's body but continue with the next iteration of the loop.
1953 curry
1954 ~~~~~
1955 +*alias* 'args\...'+
1957 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
1958 a named procedure.
1960 the following creates a local, unnamed alias for the command `info exists`.
1962 ----
1963     set e [local curry info exists]
1964     if {[$e var]} {
1965       ...
1966     }
1967 ----
1969 `curry` returns the name of the procedure.
1971 See also `proc`, `alias`, `lambda`, `local`.
1973 dict
1974 ~~~~
1975 +*dict* 'option ?arg\...?'+
1977 Performs one of several operations on dictionary values.
1979 The +'option'+ argument determines what action is carried out by the
1980 command.  The legal +'options'+ are:
1982 +*dict create* '?key value \...?'+::
1983     Create and return a new dictionary value that contains each of
1984     the key/value mappings listed as  arguments (keys and values
1985     alternating, with each key being followed by its associated
1986     value.)
1988 +*dict exists* 'dictionary key ?key \...?'+::
1989     Returns a boolean value indicating whether the given key (or path
1990     of keys through a set of nested dictionaries) exists in the given
1991     dictionary value.  This returns a true value exactly when `dict get`
1992     on that path will succeed.
1994 +*dict get* 'dictionary ?key \...?'+::
1995     Given a dictionary value (first argument) and a key (second argument),
1996     this will retrieve the value for that key. Where several keys are
1997     supplied, the behaviour of the command shall be as if the result
1998     of "`dict get $dictVal $key`" was passed as the first argument to
1999     dict get with the remaining arguments as second (and possibly
2000     subsequent) arguments. This facilitates lookups in nested dictionaries.
2001     If no keys are provided, dict would return a list containing pairs
2002     of elements in a manner similar to array get. That is, the first
2003     element of each pair would be the key and the second element would
2004     be the value for that key.  It is an error to attempt to retrieve
2005     a value for a key that is not present in the dictionary.
2007 +*dict keys* 'dictionary ?pattern?'+::
2008     Returns a list of the keys in the dictionary.
2009     If pattern is specified, then only those keys whose
2010     names match +'pattern'+ (using the matching rules of string
2011     match) are included.
2013 +*dict merge* ?'dictionary \...'?+::
2014     Return a dictionary that contains the contents of each of the
2015     +'dictionary'+ arguments. Where two (or more) dictionaries
2016     contain a mapping for the same key, the resulting dictionary
2017     maps that key to the value according to the last dictionary on
2018     the command line containing a mapping for that key.
2020 +*dict set* 'dictionaryName key ?key \...? value'+::
2021     This operation takes the +'name'+ of a variable containing a dictionary
2022     value and places an updated dictionary value in that variable
2023     containing a mapping from the given key to the given value. When
2024     multiple keys are present, this operation creates or updates a chain
2025     of nested dictionaries.
2027 +*dict size* 'dictionary'+::
2028     Return the number of key/value mappings in the given dictionary value.
2030 +*dict unset* 'dictionaryName key ?key \...? value'+::
2031     This operation (the companion to `dict set`) takes the name of a
2032     variable containing a dictionary value and places an updated
2033     dictionary value in that variable that does not contain a mapping
2034     for the given key. Where multiple keys are present, this describes
2035     a path through nested dictionaries to the mapping to remove. At
2036     least one key must be specified, but the last key on the key-path
2037     need not exist. All other components on the path must exist.
2039 +*dict with* 'dictionaryName key ?key \...? script'+::
2040     Execute the Tcl script in +'script'+ with the value for each
2041     key in +'dictionaryName'+ mapped to a variable with the same
2042     name. Where one or more keys are given, these indicate a chain
2043     of nested dictionaries, with the innermost dictionary being the
2044     one opened out for the execution of body. Making +'dictionaryName'+
2045     unreadable will make the updates to the dictionary be discarded,
2046     and this also happens if the contents of +'dictionaryName'+ are
2047     adjusted so that the chain of dictionaries no longer exists.
2048     The result of `dict with` is (unless some kind of error occurs)
2049     the result of the evaluation of body.
2050  ::
2051     The variables are mapped in the scope enclosing the `dict with`;
2052     it is recommended that this command only be used in a local
2053     scope (procedure). Because of this, the variables set by
2054     `dict with` will continue to exist after the command finishes (unless
2055     explicitly unset). Note that changes to the contents of +'dictionaryName'+
2056     only happen when +'script'+ terminates.
2058 +*dict for, values, incr, append, lappend, update, info, replace*+ to be documented...
2062 +*env* '?name? ?default?'+
2064 If +'name'+ is supplied, returns the value of +'name'+ from the initial
2065 environment (see getenv(3)). An error is returned if +'name'+ does not
2066 exist in the environment, unless +'default'+ is supplied - in which case
2067 that value is returned instead.
2069 If no arguments are supplied, returns a list of all environment variables
2070 and their values as +{name value \...}+
2072 See also the global variable +::env+
2076 +*eof* 'fileId'+
2078 +'fileId' *eof*+
2080 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
2081 0 otherwise.
2083 +'fileId'+ must have been the return value from a previous call to `open`,
2084 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
2085 standard I/O channels.
2087 error
2088 ~~~~~
2089 +*error* 'message ?stacktrace?'+
2091 Returns a +JIM_ERR+ code, which causes command interpretation to be
2092 unwound.  +'message'+ is a string that is returned to the application
2093 to indicate what went wrong.
2095 If the +'stacktrace'+ argument is provided and is non-empty,
2096 it is used to initialize the stacktrace.
2098 This feature is most useful in conjunction with the `catch` command:
2099 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
2100 to return a stack trace reflecting the original point of occurrence
2101 of the error:
2103 ----
2104     catch {...} errMsg
2105     ...
2106     error $errMsg [info stacktrace]
2107 ----
2109 See also `errorInfo`, `info stacktrace`, `catch` and `return`
2111 errorInfo
2112 ~~~~~~~~~
2113 +*errorInfo* 'error ?stacktrace?'+
2115 Returns a human-readable representation of the given error message and stack trace.
2116 Typical usage is:
2118 ----
2119     if {[catch {...} error]} {
2120         puts stderr [errorInfo $error [info stacktrace]]
2121         exit 1
2122     }
2123 ----
2125 See also `error`.
2127 eval
2128 ~~~~
2129 +*eval* 'arg ?arg\...?'+
2131 `eval` takes one or more arguments, which together comprise a Tcl
2132 command (or collection of Tcl commands separated by newlines in the
2133 usual way).  `eval` concatenates all its arguments in the same
2134 fashion as the `concat` command, passes the concatenated string to the
2135 Tcl interpreter recursively, and returns the result of that
2136 evaluation (or any error generated by it).
2138 exec
2139 ~~~~
2140 +*exec* 'arg ?arg\...?'+
2142 This command treats its arguments as the specification
2143 of one or more UNIX commands to execute as subprocesses.
2144 The commands take the form of a standard shell pipeline;
2145 +|+ arguments separate commands in the
2146 pipeline and cause standard output of the preceding command
2147 to be piped into standard input of the next command (or +|&+ for
2148 both standard output and standard error).
2150 Under normal conditions the result of the `exec` command
2151 consists of the standard output produced by the last command
2152 in the pipeline followed by the standard error output.
2154 If any of the commands writes to its standard error file,
2155 then this will be included in the result after the standard output
2156 of the last command.
2158 Note that unlike Tcl, data written to standard error does not cause
2159 `exec` to return an error.
2161 If any of the commands in the pipeline exit abnormally or
2162 are killed or suspended, then `exec` will return an error.
2163 If no standard error output was produced, or is redirected,
2164 the error message will include the normal result, as above,
2165 followed by error messages describing the abnormal terminations.
2167 If any standard error output was produced, these abnormal termination
2168 messages are suppressed.
2170 If the last character of the result or error message
2171 is a newline then that character is deleted from the result
2172 or error message for consistency with normal
2173 Tcl return values.
2175 An +'arg'+ may have one of the following special forms:
2177 +>filename+::
2178     The standard output of the last command in the pipeline
2179     is redirected to the file.  In this situation `exec`
2180     will normally return an empty string.
2182 +>>filename+::
2183     As above, but append to the file.
2185 +>@fileId+::
2186     The standard output of the last command in the pipeline is
2187     redirected to the given (writable) file descriptor (e.g. stdout,
2188     stderr, or the result of `open`). In this situation `exec`
2189     will normally return an empty string.
2191 +2>filename+::
2192     The standard error of the last command in the pipeline
2193     is redirected to the file.
2195 +2>>filename+::
2196     As above, but append to the file.
2198 +2>@fileId+::
2199     The standard error of the last command in the pipeline is
2200     redirected to the given (writable) file descriptor.
2202 +2>@1+::
2203     The standard error of the last command in the pipeline is
2204     redirected to the same file descriptor as the standard output.
2206 +>&filename+::
2207     Both the standard output and standard error of the last command
2208     in the pipeline is redirected to the file.
2210 +>>&filename+::
2211     As above, but append to the file.
2213 +<filename+::
2214     The standard input of the first command in the pipeline
2215     is taken from the file.
2217 +<<string+::
2218     The standard input of the first command is taken as the
2219     given immediate value.
2221 +<@fileId+::
2222     The standard input of the first command in the pipeline
2223     is taken from the given (readable) file descriptor.
2225 If there is no redirection of standard input, standard error
2226 or standard output, these are connected to the corresponding
2227 input or output of the application.
2229 If the last +'arg'+ is +&+ then the command will be
2230 executed in background.
2231 In this case the standard output from the last command
2232 in the pipeline will
2233 go to the application's standard output unless
2234 redirected in the command, and error output from all
2235 the commands in the pipeline will go to the application's
2236 standard error file. The return value of exec in this case
2237 is a list of process ids (pids) in the pipeline.
2239 Each +'arg'+ becomes one word for a command, except for
2240 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2241 arguments that follow +<+, +<<+, and +>+.
2243 The first word in each command is taken as the command name;
2244 the directories in the PATH environment variable are searched for
2245 an executable by the given name.
2247 No `glob` expansion or other shell-like substitutions
2248 are performed on the arguments to commands.
2250 If the command fails, the global $::errorCode (and the -errorcode
2251 option in `catch`) will be set to a list, as follows:
2253 +*CHILDKILLED* 'pid sigName msg'+::
2254         This format is used when a child process has been killed
2255         because of a signal. The pid element will be the process's
2256         identifier (in decimal). The sigName element will be the
2257         symbolic name of the signal that caused the process to
2258         terminate; it will be one of the names from the include
2259         file signal.h, such as SIGPIPE. The msg element will be a
2260         short human-readable message describing the signal, such
2261         as "write on pipe with no readers" for SIGPIPE.
2263 +*CHILDSUSP* 'pid sigName msg'+::
2264         This format is used when a child process has been suspended
2265         because of a signal. The pid element will be the process's
2266         identifier, in decimal. The sigName element will be the
2267         symbolic name of the signal that caused the process to
2268         suspend; this will be one of the names from the include
2269         file signal.h, such as SIGTTIN. The msg element will be a
2270         short human-readable message describing the signal, such
2271         as "background tty read" for SIGTTIN.
2273 +*CHILDSTATUS* 'pid code'+::
2274         This format is used when a child process has exited with a
2275         non-zero exit status. The pid element will be the process's
2276         identifier (in decimal) and the code element will be the
2277         exit code returned by the process (also in decimal).
2279 The environment for the executed command is set from $::env (unless
2280 this variable is unset, in which case the original environment is used).
2282 exists
2283 ~~~~~~
2284 +*exists ?-var|-proc|-command|-alias?* 'name'+
2286 Checks the existence of the given variable, procedure, command
2287 or alias respectively and returns 1 if it exists or 0 if not.  This command
2288 provides a more simplified/convenient version of `info exists`,
2289 `info procs` and `info commands`.
2291 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2293 exit
2294 ~~~~
2295 +*exit* '?returnCode?'+
2297 Terminate the process, returning +'returnCode'+ to the
2298 parent as the exit status.
2300 If +'returnCode'+ isn't specified then it defaults
2301 to 0.
2303 Note that exit can be caught with `catch`.
2305 expr
2306 ~~~~
2307 +*expr* 'arg'+
2309 Calls the expression processor to evaluate +'arg'+, and returns
2310 the result as a string.  See the section <<_expressions,EXPRESSIONS>> above.
2312 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2313 The following two are identical.
2315 ----
2316   set x [expr {3 * 2 + 1}]
2317   set x $(3 * 2 + 1)
2318 ----
2320 file
2321 ~~~~
2322 +*file* 'option name ?arg\...?'+
2324 Operate on a file or a file name.  +'name'+ is the name of a file.
2326 +'option'+ indicates what to do with the file name.  Any unique
2327 abbreviation for +'option'+ is acceptable.  The valid options are:
2329 +*file atime* 'name'+::
2330     Return a decimal string giving the time at which file +'name'+
2331     was last accessed.  The time is measured in the standard UNIX
2332     fashion as seconds from a fixed starting time (often January 1, 1970).
2333     If the file doesn't exist or its access time cannot be queried then an
2334     error is generated.
2336 +*file copy ?-force?* 'source target'+::
2337     Copies file +'source'+ to file +'target'+. The source file must exist.
2338     The target file must not exist, unless +-force+ is specified.
2340 +*file delete ?-force? ?--?* 'name\...'+::
2341     Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2342     If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2343     unless the +-force+ options is given. In this case no errors will be generated, even
2344     if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
2345     the first name being +'-force'+.
2347 +*file dirname* 'name'+::
2348     Return all of the characters in +'name'+ up to but not including
2349     the last slash character.  If there are no slashes in +'name'+
2350     then return +.+ (a single dot).  If the last slash in +'name'+ is its first
2351     character, then return +/+.
2353 +*file executable* 'name'+::
2354     Return '1' if file +'name'+ is executable by
2355     the current user, '0' otherwise.
2357 +*file exists* 'name'+::
2358     Return '1' if file +'name'+ exists and the current user has
2359     search privileges for the directories leading to it, '0' otherwise.
2361 +*file extension* 'name'+::
2362     Return all of the characters in +'name'+ after and including the
2363     last dot in +'name'+.  If there is no dot in +'name'+ then return
2364     the empty string.
2366 +*file isdirectory* 'name'+::
2367     Return '1' if file +'name'+ is a directory,
2368     '0' otherwise.
2370 +*file isfile* 'name'+::
2371     Return '1' if file +'name'+ is a regular file,
2372     '0' otherwise.
2374 +*file join* 'arg\...'+::
2375     Joins multiple path components. Note that if any components is
2376     an absolute path, the preceding components are ignored.
2377     Thus +"`file` join /tmp /root"+ returns +"/root"+.
2379 +*file link* ?*-hard|-symbolic*? 'newname target'+::
2380     Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
2381     Note that the sense of this command is the opposite of `file rename` and `file copy`
2382     and also of `ln`, but this is compatible with Tcl.
2383     An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.
2385 +*file lstat* 'name varName'+::
2386     Same as 'stat' option (see below) except uses the +'lstat'+
2387     kernel call instead of +'stat'+.  This means that if +'name'+
2388     refers to a symbolic link the information returned in +'varName'+
2389     is for the link rather than the file it refers to.  On systems that
2390     don't support symbolic links this option behaves exactly the same
2391     as the 'stat' option.
2393 +*file mkdir* 'dir1 ?dir2\...?'+::
2394     Creates each directory specified. For each pathname +'dir'+ specified,
2395     this command will create all non-existing parent directories
2396     as well as +'dir'+ itself. If an existing directory is specified,
2397     then no action is taken and no error is returned. Trying to
2398     overwrite an existing file with a directory will result in an
2399     error.  Arguments are processed in the order specified, halting
2400     at the first error, if any.
2402 +*file mtime* 'name ?time?'+::
2403     Return a decimal string giving the time at which file +'name'+
2404     was last modified.  The time is measured in the standard UNIX
2405     fashion as seconds from a fixed starting time (often January 1, 1970).
2406     If the file doesn't exist or its modified time cannot be queried then an
2407     error is generated. If +'time'+ is given, sets the modification time
2408     of the file to the given value.
2410 +*file mtimeus* 'name ?time_us?'+::
2411     As for `file mtime` except the time value is in microseconds
2412     since the epoch (see also `clock microseconds`).
2413     Note that some platforms and some filesystems don't support high
2414     resolution timestamps for files.
2416 +*file normalize* 'name'+::
2417     Return the normalized path of +'name'+. See 'realpath(3)'.
2419 +*file owned* 'name'+::
2420     Return '1' if file +'name'+ is owned by the current user,
2421     '0' otherwise.
2423 +*file readable* 'name'+::
2424     Return '1' if file +'name'+ is readable by
2425     the current user, '0' otherwise.
2427 +*file readlink* 'name'+::
2428     Returns the value of the symbolic link given by +'name'+ (i.e. the
2429     name of the file it points to).  If
2430     +'name'+ isn't a symbolic link or its value cannot be read, then
2431     an error is returned.  On systems that don't support symbolic links
2432     this option is undefined.
2434 +*file rename* ?*-force*? 'oldname' 'newname'+::
2435     Renames the file from the old name to the new name.
2436     If +'newname'+ already exists, an error is returned unless +'-force'+ is
2437     specified.
2439 +*file rootname* 'name'+::
2440     Return all of the characters in +'name'+ up to but not including
2441     the last '.' character in the name.  If +'name'+ doesn't contain
2442     a dot, then return +'name'+.
2444 +*file split* 'name'+::
2445     Returns a list whose elements are the path components in +'name'+.
2446     The first element of the list will have the same path type as
2447     +'name'+. All other elements will be relative. Path separators
2448     will be discarded.
2450 +*file stat* 'name ?varName?'+::
2451     Invoke the 'stat' kernel call on +'name'+, and return the result
2452     as a dictionary with the following keys: 'atime',
2453     'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2454     'nlink', 'size', 'type', 'uid', 'mtimeus' (if supported - see `file mtimeus`)
2455     Each element except 'type' is a decimal string with the value of
2456     the corresponding field from the 'stat' return structure; see the
2457     manual entry for 'stat' for details on the meanings of the values.
2458     The 'type' element gives the type of the file in the same form
2459     returned by the command `file type`.
2460     If +'varName'+ is specified, it is taken to be the name of an array
2461     variable and the values are also stored into the array.
2463 +*file tail* 'name'+::
2464     Return all of the characters in +'name'+ after the last slash.
2465     If +'name'+ contains no slashes then return +'name'+.
2467 +*file tempfile* '?template?'+::
2468     Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2469     default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2470     the format of the template and security concerns.
2472 +*file type* 'name'+::
2473     Returns a string giving the type of file +'name'+, which will be
2474     one of +file+, +directory+, +characterSpecial+,
2475     +blockSpecial+, +fifo+, +link+, or +socket+.
2477 +*file writable* 'name'+::
2478     Return '1' if file +'name'+ is writable by
2479     the current user, '0' otherwise.
2481 The `file` commands that return 0/1 results are often used in
2482 conditional or looping commands, for example:
2484 ----
2485     if {![file exists foo]} {
2486         error {bad file name}
2487     } else {
2488         ...
2489     }
2490 ----
2492 finalize
2493 ~~~~~~~~
2494 +*finalize* 'reference ?command?'+
2496 If +'command'+ is omitted, returns the finalizer command for the given reference.
2498 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2499 the empty string to remove the current finalizer.
2501 The reference must be a valid reference create with the `ref`
2502 command.
2504 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2506 flush
2507 ~~~~~
2508 +*flush* 'fileId'+
2510 +'fileId' *flush*+
2512 Flushes any output that has been buffered for +'fileId'+.  +'fileId'+ must
2513 have been the return value from a previous call to `open`, or it may be
2514 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2515 refer to a file that was opened for writing.  This command returns an
2516 empty string.
2520 +*for* 'start test next body'+
2522 `for` is a looping command, similar in structure to the C `for` statement.
2523 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2524 and +'test'+ is an expression string.
2526 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2527 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2528 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2529 interpreter on +'next'+, then repeats the loop.  The command terminates
2530 when +'test'+ evaluates to 0.
2532 If a `continue` command is invoked within +'body'+ then any remaining
2533 commands in the current execution of +'body'+ are skipped; processing
2534 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2535 +'test'+, and so on.
2537 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2538 command will return immediately.
2540 The operation of `break` and `continue` are similar to the corresponding
2541 statements in C.
2543 `for` returns an empty string.
2545 foreach
2546 ~~~~~~~
2547 +*foreach* 'varName list body'+
2549 +*foreach* 'varList list ?varList2 list2 \...? body'+
2551 In this command, +'varName'+ is the name of a variable, +'list'+
2552 is a list of values to assign to +'varName'+, and +'body'+ is a
2553 collection of Tcl commands.
2555 For each field in +'list'+ (in order from left to right), `foreach` assigns
2556 the contents of the field to +'varName'+ (as if the `lindex` command
2557 had been used to extract the field), then calls the Tcl interpreter to
2558 execute +'body'+.
2560 If instead of being a simple name, +'varList'+ is used, multiple assignments
2561 are made each time through the loop, one for each element of +'varList'+.
2563 For example, if there are two elements in +'varList'+ and six elements in
2564 the list, the loop will be executed three times.
2566 If the length of the list doesn't evenly divide by the number of elements
2567 in +'varList'+, the value of the remaining variables in the last iteration
2568 of the loop are undefined.
2570 The `break` and `continue` statements may be invoked inside +'body'+,
2571 with the same effect as in the `for` command.
2573 `foreach` returns an empty string.
2575 format
2576 ~~~~~~
2577 +*format* 'formatString ?arg \...?'+
2579 This command generates a formatted string in the same way as the
2580 C 'sprintf' procedure (it uses 'sprintf' in its
2581 implementation).  +'formatString'+ indicates how to format
2582 the result, using +%+ fields as in 'sprintf', and the additional
2583 arguments, if any, provide values to be substituted into the result.
2585 All of the 'sprintf' options are valid; see the 'sprintf'
2586 man page for details.  Each +'arg'+ must match the expected type
2587 from the +%+ field in +'formatString'+; the `format` command
2588 converts each argument to the correct type (floating, integer, etc.)
2589 before passing it to 'sprintf' for formatting.
2591 The only unusual conversion is for +%c+; in this case the argument
2592 must be a decimal string, which will then be converted to the corresponding
2593 ASCII (or UTF-8) character value.
2595 In addition, Jim Tcl provides basic support for conversion to binary with +%b+.
2597 `format` does backslash substitution on its +'formatString'+
2598 argument, so backslash sequences in +'formatString'+ will be handled
2599 correctly even if the argument is in braces.
2601 The return value from `format` is the formatted string.
2603 getref
2604 ~~~~~~
2605 +*getref* 'reference'+
2607 Returns the string associated with +'reference'+. The reference must
2608 be a valid reference create with the `ref` command.
2610 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2612 gets
2613 ~~~~
2614 +*gets* 'fileId ?varName?'+
2616 +'fileId' *gets* '?varName?'+
2618 Reads the next line from the file given by +'fileId'+ and discards
2619 the terminating newline character.
2621 If +'varName'+ is specified, then the line is placed in the variable
2622 by that name and the return value is a count of the number of characters
2623 read (not including the newline).
2625 If the end of the file is reached before reading
2626 any characters then -1 is returned and +'varName'+ is set to an
2627 empty string.
2629 If +'varName'+ is not specified then the return value will be
2630 the line (minus the newline character) or an empty string if
2631 the end of the file is reached before reading any characters.
2633 An empty string will also be returned if a line contains no characters
2634 except the newline, so `eof` may have to be used to determine
2635 what really happened.
2637 If the last character in the file is not a newline character, then
2638 `gets` behaves as if there were an additional newline character
2639 at the end of the file.
2641 +'fileId'+ must be +stdin+ or the return value from a previous
2642 call to `open`; it must refer to a file that was opened
2643 for reading.
2645 glob
2646 ~~~~
2647 +*glob* ?*-nocomplain*? ?*-directory* 'dir'? ?*-tails*? ?*--*? 'pattern ?pattern \...?'+
2649 This command performs filename globbing, using csh rules.  The returned
2650 value from `glob` is the list of expanded filenames.
2652 If +-nocomplain+ is specified as the first argument then an empty
2653 list may be returned;  otherwise an error is returned if the expanded
2654 list is empty.  The +-nocomplain+ argument must be provided
2655 exactly: an abbreviation will not be accepted.
2657 If +-directory+ is given, the +'dir'+ is understood to contain a
2658 directory name to search in. This allows globbing inside directories
2659 whose names may contain glob-sensitive characters. The returned names
2660 include the directory name unless +'-tails'+ is specified.
2662 If +'-tails'+ is specified, along with +-directory+, the returned names
2663 are relative to the given directory.
2665 global
2666 ~~~~~~
2668 +*global* 'varName ?varName \...?'+
2670 This command is ignored unless a Tcl procedure is being interpreted.
2671 If so, then it declares each given +'varName'+ to be a global variable
2672 rather than a local one.  For the duration of the current procedure
2673 (and only while executing in the current procedure), any reference to
2674 +'varName'+ will be bound to a global variable instead
2675 of a local one.
2677 An alternative to using `global` is to use the +::+ prefix
2678 to explicitly name a variable in the global scope.
2682 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2684 The `if` command evaluates +'expr1'+ as an expression (in the same way
2685 that `expr` evaluates its argument).  The value of the expression must
2686 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2687 the Tcl interpreter.
2689 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2690 then +'body2'+ is executed, and so on.
2692 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2694 The +then+ and +else+ arguments are optional "noise words" to make the
2695 command easier to read.
2697 There may be any number of +elseif+ clauses, including zero.  +'bodyN'+
2698 may also be omitted as long as +else+ is omitted too.
2700 The return value from the command is the result of the body script that
2701 was executed, or an empty string if none of the expressions was non-zero
2702 and there was no +'bodyN'+.
2704 incr
2705 ~~~~
2706 +*incr* 'varName ?increment?'+
2708 Increment the value stored in the variable whose name is +'varName'+.
2709 The value of the variable must be integral.
2711 If +'increment'+ is supplied then its value (which must be an
2712 integer) is added to the value of variable +'varName'+;  otherwise
2713 1 is added to +'varName'+.
2715 The new value is stored as a decimal string in variable +'varName'+
2716 and also returned as result.
2718 If the variable does not exist, the variable is implicitly created
2719 and set to +0+ first.
2721 info
2722 ~~~~
2724 +*info* 'option ?arg\...?'+::
2726 Provide information about various internals to the Tcl interpreter.
2727 The legal +'option'+'s (which may be abbreviated) are:
2729 +*info args* 'procname'+::
2730     Returns a list containing the names of the arguments to procedure
2731     +'procname'+, in order.  +'procname'+ must be the name of a
2732     Tcl command procedure.
2734 +*info alias* 'command'+::
2735     +'command'+ must be an alias created with `alias`. In which case the target
2736     command and arguments, as passed to `alias` are returned. See `exists -alias`
2738 +*info body* 'procname'+::
2739     Returns the body of procedure +'procname'+.  +'procname'+ must be
2740     the name of a Tcl command procedure.
2742 +*info channels*+::
2743     Returns a list of all open file handles from `open` or `socket`
2745 +*info commands* ?'pattern'?+::
2746     If +'pattern'+ isn't specified, returns a list of names of all the
2747     Tcl commands, including both the built-in commands written in C and
2748     the command procedures defined using the `proc` command.
2749     If +'pattern'+ is specified, only those names matching +'pattern'+
2750     are returned.  Matching is determined using the same rules as for
2751     `string match`.
2753 +*info complete* 'command' ?'missing'?+::
2754     Returns 1 if +'command'+ is a complete Tcl command in the sense of
2755     having no unclosed quotes, braces, brackets or array element names,
2756     If the command doesn't appear to be complete then 0 is returned.
2757     This command is typically used in line-oriented input environments
2758     to allow users to type in commands that span multiple lines;  if the
2759     command isn't complete, the script can delay evaluating it until additional
2760     lines have been typed to complete the command. If +'varName'+ is specified, the
2761     missing character is stored in the variable with that name.
2763 +*info exists* 'varName'+::
2764     Returns '1' if the variable named +'varName'+ exists in the
2765     current context (either as a global or local variable), returns '0'
2766     otherwise.
2768 +*info frame* ?'number'?+::
2769     If +'number'+ is not specified, this command returns a number
2770     which is the same result as `info level` - the current stack frame level.
2771     If +'number'+ is specified, then the result is a list consisting of the procedure,
2772     filename and line number for the procedure call at level +'number'+ on the stack.
2773     If +'number'+ is positive then it selects a particular stack level (1 refers
2774     to the top-most active procedure, 2 to the procedure it called, and
2775     so on); otherwise it gives a level relative to the current level
2776     (0 refers to the current procedure, -1 to its caller, and so on).
2777     The level has an identical meaning to `info level`.
2779 +*info globals* ?'pattern'?+::
2780     If +'pattern'+ isn't specified, returns a list of all the names
2781     of currently-defined global variables.
2782     If +'pattern'+ is specified, only those names matching +'pattern'+
2783     are returned.  Matching is determined using the same rules as for
2784     `string match`.
2786 +*info hostname*+::
2787     An alias for `os.gethostname` for compatibility with Tcl 6.x
2789 +*info level* ?'number'?+::
2790     If +'number'+ is not specified, this command returns a number
2791     giving the stack level of the invoking procedure, or 0 if the
2792     command is invoked at top-level.  If +'number'+ is specified,
2793     then the result is a list consisting of the name and arguments for the
2794     procedure call at level +'number'+ on the stack.  If +'number'+
2795     is positive then it selects a particular stack level (1 refers
2796     to the top-most active procedure, 2 to the procedure it called, and
2797     so on); otherwise it gives a level relative to the current level
2798     (0 refers to the current procedure, -1 to its caller, and so on).
2799     See the `uplevel` command for more information on what stack
2800     levels mean.
2802 +*info locals* ?'pattern'?+::
2803     If +'pattern'+ isn't specified, returns a list of all the names
2804     of currently-defined local variables, including arguments to the
2805     current procedure, if any.  Variables defined with the `global`
2806     and `upvar` commands will not be returned.  If +'pattern'+ is
2807     specified, only those names matching +'pattern'+ are returned.
2808     Matching is determined using the same rules as for `string match`.
2810 +*info nameofexecutable*+::
2811     Returns the name of the binary file from which the application
2812     was invoked. A full path will be returned, unless the path
2813     can't be determined, in which case the empty string will be returned.
2815 +*info procs* ?'pattern'?+::
2816     If +'pattern'+ isn't specified, returns a list of all the
2817     names of Tcl command procedures.
2818     If +'pattern'+ is specified, only those names matching +'pattern'+
2819     are returned.  Matching is determined using the same rules as for
2820     `string match`.
2822 +*info references*+::
2823     Returns a list of all references which have not yet been garbage
2824     collected.
2826 +*info returncodes* ?'code'?+::
2827     Returns a list representing the mapping of standard return codes
2828     to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2829     instead returns the name for the given code.
2831 +*info script*+::
2832     If a Tcl script file is currently being evaluated (i.e. there is a
2833     call to 'Jim_EvalFile' active or there is an active invocation
2834     of the `source` command), then this command returns the name
2835     of the innermost file being processed.  Otherwise the command returns an
2836     empty string.
2838 +*info source* 'script ?filename line?'+::
2839     With a single argument, returns the original source location of the given script as a list of
2840     +{filename linenumber}+. If the source location can't be determined, the
2841     list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
2842     of +'script'+ with the associate source information. This can be useful to produce
2843     useful messages from `eval`, etc. if the original source information may be lost.
2845 +*info stacktrace*+::
2846     After an error is caught with `catch`, returns the stack trace as a list
2847     of +{procedure filename line \...}+.
2849 +*info statics* 'procname'+::
2850     Returns a dictionary of the static variables of procedure
2851     +'procname'+.  +'procname'+ must be the name of a Tcl command
2852     procedure. An empty dictionary is returned if the procedure has
2853     no static variables.
2855 +*info version*+::
2856     Returns the version number for this version of Jim in the form +*x.yy*+.
2858 +*info vars* ?'pattern'?+::
2859     If +'pattern'+ isn't specified,
2860     returns a list of all the names of currently-visible variables, including
2861     both locals and currently-visible globals.
2862     If +'pattern'+ is specified, only those names matching +'pattern'+
2863     are returned.  Matching is determined using the same rules as for
2864     `string match`.
2866 join
2867 ~~~~
2868 +*join* 'list ?joinString?'+
2870 The +'list'+ argument must be a valid Tcl list.  This command returns the
2871 string formed by joining all of the elements of +'list'+ together with
2872 +'joinString'+ separating each adjacent pair of elements.
2874 The +'joinString'+ argument defaults to a space character.
2876 kill
2877 ~~~~
2878 +*kill* ?'SIG'|*-0*? 'pid'+
2880 Sends the given signal to the process identified by +'pid'+.
2882 The signal may be specified by name or number in one of the following forms:
2884 * +TERM+
2885 * +SIGTERM+
2886 * +-TERM+
2887 * +15+
2888 * +-15+
2890 The signal name may be in either upper or lower case.
2892 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2894 If no signal is specified, SIGTERM is used.
2896 An error is raised if the signal could not be delivered.
2898 lambda
2899 ~~~~~~
2900 +*lambda* 'args ?statics? body'+
2902 The `lambda` command is identical to `proc`, except rather than
2903 creating a named procedure, it creates an anonymous procedure and returns
2904 the name of the procedure.
2906 See `proc` and <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
2908 lappend
2909 ~~~~~~~
2910 +*lappend* 'varName value ?value value \...?'+
2912 Treat the variable given by +'varName'+ as a list and append each of
2913 the +'value'+ arguments to that list as a separate element, with spaces
2914 between elements.
2916 If +'varName'+ doesn't exist, it is created as a list with elements given
2917 by the +'value'+ arguments. `lappend` is similar to `append` except that
2918 each +'value'+ is appended as a list element rather than raw text.
2920 This command provides a relatively efficient way to build up large lists.
2921 For example,
2923 ----
2924     lappend a $b
2925 ----
2927 is much more efficient than
2929 ----
2930     set a [concat $a [list $b]]
2931 ----
2933 when +$a+ is long.
2935 lassign
2936 ~~~~~~~
2937 +*lassign* 'list varName ?varName \...?'+
2939 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2940 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2941 list elements, the remaining variables are set to the empty string. If there are more list elements
2942 than variables, a list of unassigned elements is returned.
2944 ----
2945     . lassign {1 2 3} a b; puts a=$a,b=$b
2946     3
2947     a=1,b=2
2948 ----
2950 local
2951 ~~~~~
2952 +*local* 'cmd ?arg\...?'+
2954 First, `local` evaluates +'cmd'+ with the given arguments. The return value must
2955 be the name of an existing command, which is marked as having local scope.
2956 This means that when the current procedure exits, the specified
2957 command is deleted. This can be useful with `lambda`, local procedures or
2958 to automatically close a filehandle.
2960 In addition, if a command already exists with the same name,
2961 the existing command will be kept rather than deleted, and may be called
2962 via `upcall`. The previous command will be restored when the current
2963 procedure exits. See `upcall` for more details.
2965 In this example, a local procedure is created. Note that the procedure
2966 continues to have global scope while it is active.
2968 ----
2969     proc outer {} {
2970       # proc ... returns "inner" which is marked local
2971       local proc inner {} {
2972         # will be deleted when 'outer' exits
2973       }
2975       inner
2976       ...
2977     }
2978 ----
2980 In this example, the lambda is deleted at the end of the procedure rather
2981 than waiting until garbage collection.
2983 ----
2984     proc outer {} {
2985       set x [lambda inner {args} {
2986         # will be deleted when 'outer' exits
2987       }]
2988       # Use 'function' here which simply returns $x
2989       local function $x
2991       $x ...
2992       ...
2993     }
2994 ----
2996 loop
2997 ~~~~
2998 +*loop* 'var first limit ?incr? body'+
3000 Similar to `for` except simpler and possibly more efficient.
3001 With a positive increment, equivalent to:
3003 ----
3004     for {set var $first} {$var < $limit} {incr var $incr} $body
3005 ----
3007 If +'incr'+ is not specified, 1 is used.
3008 Note that setting the loop variable inside the loop does not
3009 affect the loop count.
3011 lindex
3012 ~~~~~~
3013 +*lindex* 'list ?index ...?'+
3015 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
3016 (0 refers to the first element of the list).
3017 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3019 In extracting the element, +'lindex'+ observes the same rules concerning
3020 braces and quotes and backslashes as the Tcl command interpreter; however,
3021 variable substitution and command substitution do not occur.
3023 If no index values are given, simply returns +'list'+
3025 If +'index'+ is negative or greater than or equal to the number of elements
3026 in +'list'+, then an empty string is returned.
3028 If additional index arguments are supplied, then each argument is
3029 used in turn to select an element from the previous indexing
3030 operation, allowing the script to select elements from sublists.
3032 linsert
3033 ~~~~~~~
3034 +*linsert* 'list index element ?element element \...?'+
3036 This command produces a new list from +'list'+ by inserting all
3037 of the +'element'+ arguments just before the element +'index'+
3038 of +'list'+. Each +'element'+ argument will become
3039 a separate element of the new list. If +'index'+ is less than
3040 or equal to zero, then the new elements are inserted at the
3041 beginning of the list. If +'index'+ is greater than or equal
3042 to the number of elements in the list, then the new elements are
3043 appended to the list.
3045 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3047 list
3048 ~~~~
3050 +*list* 'arg ?arg \...?'+
3052 This command returns a list comprised of all the arguments, +'arg'+. Braces
3053 and backslashes get added as necessary, so that the `lindex` command
3054 may be used on the result to re-extract the original arguments, and also
3055 so that `eval` may be used to execute the resulting list, with
3056 +'arg1'+ comprising the command's name and the other args comprising
3057 its arguments. `list` produces slightly different results than
3058 `concat`:  `concat` removes one level of grouping before forming
3059 the list, while `list` works directly from the original arguments.
3060 For example, the command
3062 ----
3063     list a b {c d e} {f {g h}}
3064 ----
3066 will return
3068 ----
3069     a b {c d e} {f {g h}}
3070 ----
3072 while `concat` with the same arguments will return
3074 ----
3075     a b c d e f {g h}
3076 ----
3078 llength
3079 ~~~~~~~
3080 +*llength* 'list'+
3082 Treats +'list'+ as a list and returns a decimal string giving
3083 the number of elements in it.
3085 lset
3086 ~~~~
3087 +*lset* 'varName ?index ..? newValue'+
3089 Sets an element in a list.
3091 The `lset` command accepts a parameter, +'varName'+, which it interprets
3092 as the name of a variable containing a Tcl list. It also accepts
3093 zero or more indices into the list. Finally, it accepts a new value
3094 for an element of varName. If no indices are presented, the command
3095 takes the form:
3097 ----
3098     lset varName newValue
3099 ----
3101 In this case, newValue replaces the old value of the variable
3102 varName.
3104 When presented with a single index, the `lset` command
3105 treats the content of the varName variable as a Tcl list. It addresses
3106 the index'th element in it (0 refers to the first element of the
3107 list). When interpreting the list, `lset` observes the same rules
3108 concerning braces and quotes and backslashes as the Tcl command
3109 interpreter; however, variable substitution and command substitution
3110 do not occur. The command constructs a new list in which the
3111 designated element is replaced with newValue. This new list is
3112 stored in the variable varName, and is also the return value from
3113 the `lset` command.
3115 If index is negative or greater than or equal to the number of
3116 elements in $varName, then an error occurs.
3118 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'index'+.
3120 If additional index arguments are supplied, then each argument is
3121 used in turn to address an element within a sublist designated by
3122 the previous indexing operation, allowing the script to alter
3123 elements in sublists. The command,
3125 ----
3126     lset a 1 2 newValue
3127 ----
3129 replaces element 2 of sublist 1 with +'newValue'+.
3131 The integer appearing in each index argument must be greater than
3132 or equal to zero. The integer appearing in each index argument must
3133 be strictly less than the length of the corresponding list. In other
3134 words, the `lset` command cannot change the size of a list. If an
3135 index is outside the permitted range, an error is reported.
3137 lmap
3138 ~~~~
3140 +*lmap* 'varName list body'+
3142 +*lmap* 'varList list ?varList2 list2 \...? body'+
3144 `lmap` is a "collecting" `foreach` which returns a list of its results.
3146 For example:
3148 ----
3149     . lmap i {1 2 3 4 5} {expr $i*$i}
3150     1 4 9 16 25
3151     . lmap a {1 2 3} b {A B C} {list $a $b}
3152     {1 A} {2 B} {3 C}
3153 ----
3155 If the body invokes `continue`, no value is added for this iteration.
3156 If the body invokes `break`, the loop ends and no more values are added.
3158 load
3159 ~~~~
3160 +*load* 'filename'+
3162 Loads the dynamic extension, +'filename'+. Generally the filename should have
3163 the extension +.so+. The initialisation function for the module must be based
3164 on the name of the file. For example loading +hwaccess.so+ will invoke
3165 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
3166 should not be used directly. Instead it is invoked automatically by `package require`.
3168 lrange
3169 ~~~~~~
3170 +*lrange* 'list first last'+
3172 +'list'+ must be a valid Tcl list. This command will return a new
3173 list consisting of elements +'first'+ through +'last'+, inclusive.
3175 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
3177 If +'last'+ is greater than or equal to the number of elements
3178 in the list, then it is treated as if it were +end+.
3180 If +'first'+ is greater than +'last'+ then an empty string
3181 is returned.
3183 Note: +"`lrange` 'list first first'"+ does not always produce the
3184 same result as +"`lindex` 'list first'"+ (although it often does
3185 for simple fields that aren't enclosed in braces); it does, however,
3186 produce exactly the same results as +"`list` [`lindex` 'list first']"+
3188 lreplace
3189 ~~~~~~~~
3191 +*lreplace* 'list first last ?element element \...?'+
3193 Returns a new list formed by replacing one or more elements of
3194 +'list'+ with the +'element'+ arguments.
3196 +'first'+ gives the index in +'list'+ of the first element
3197 to be replaced.
3199 If +'first'+ is less than zero then it refers to the first
3200 element of +'list'+;  the element indicated by +'first'+
3201 must exist in the list.
3203 +'last'+ gives the index in +'list'+ of the last element
3204 to be replaced;  it must be greater than or equal to +'first'+.
3206 See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
3208 The +'element'+ arguments specify zero or more new arguments to
3209 be added to the list in place of those that were deleted.
3211 Each +'element'+ argument will become a separate element of
3212 the list.
3214 If no +'element'+ arguments are specified, then the elements
3215 between +'first'+ and +'last'+ are simply deleted.
3217 lrepeat
3218 ~~~~~~~~
3219 +*lrepeat* 'number element1 ?element2 \...?'+
3221 Build a list by repeating elements +'number'+ times (which must be
3222 a positive integer).
3224 ----
3225     . lrepeat 3 a b
3226     a b a b a b
3227 ----
3229 lreverse
3230 ~~~~~~~~
3231 +*lreverse* 'list'+
3233 Returns the list in reverse order.
3235 ----
3236     . lreverse {1 2 3}
3237     3 2 1
3238 ----
3240 lsearch
3241 ~~~~~~~
3242 +*lsearch* '?options? list pattern'+
3244 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3245 command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
3246 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3247 the list are to be matched against pattern and must have one of the values below:
3249 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3251 +*-exact*+::
3252     +'pattern'+ is a literal string that is compared for exact equality against each list element.
3253     This is the default.
3255 +*-glob*+::
3256     +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3257     rules as the string match command.
3259 +*-regexp*+::
3260     +'pattern'+ is treated as a regular expression and matched against each list element using
3261     the rules described by `regexp`.
3263 +*-command* 'cmdname'+::
3264     +'cmdname'+ is a command which is used to match the pattern against each element of the
3265     list. It is invoked as +'cmdname' ?*-nocase*? 'pattern listvalue'+ and should return 1
3266     for a match, or 0 for no match.
3268 +*-all*+::
3269     Changes the result to be the list of all matching indices (or all matching values if
3270     +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3271     order. If values are returned, the order of the values will be the order of those values
3272     within the input list.
3274 +*-inline*+::
3275     The matching value is returned instead of its index (or an empty string if no value
3276     matches). If +-all+ is also specified, then the result of the command is the list of all
3277     values that matched. The +-inline+ and +-bool+ options are mutually exclusive.
3279 +*-bool*+::
3280     Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3281     the result will be a list of '0' and '1' for each element of the list depending upon whether
3282     the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3284 +*-not*+::
3285     This negates the sense of the match, returning the index (or value
3286     if +-inline+ is specified) of the first non-matching value in the
3287     list. If +-bool+ is also specified, the '0' will be returned if a
3288     match is found, or '1' otherwise. If +-all+ is also specified,
3289     non-matches will be returned rather than matches.
3291 +*-nocase*+::
3292     Causes comparisons to be handled in a case-insensitive manner.
3294 lsort
3295 ~~~~~
3296 +*lsort* ?*-index* 'listindex'? ?*-nocase|-integer|-real|-command* 'cmdname'? ?*-unique*? ?*-decreasing*|*-increasing*? 'list'+
3298 Sort the elements of +'list'+, returning a new list in sorted order.
3299 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.
3301 If +-nocase+ is specified, comparisons are case-insensitive.
3303 If +-integer+ is specified, numeric sorting is used.
3305 If +-real+ is specified, floating point number sorting is used.
3307 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3308 name. For each comparison, +'cmdname $value1 $value2+' is called which
3309 should compare the values and return an integer less than, equal
3310 to, or greater than zero if the +'$value1'+ is to be considered less
3311 than, equal to, or greater than +'$value2'+, respectively.
3313 If +-decreasing+ is specified, the resulting list is in the opposite
3314 order to what it would be otherwise. +-increasing+ is the default.
3316 If +-unique+ is specified, then only the last set of duplicate elements found in the list will be retained.
3317 Note that duplicates are determined relative to the comparison used in the sort. Thus if +-index 0+ is used,
3318 +{1 a}+ and +{1 b}+ would be considered duplicates and only the second element, +{1 b}+, would be retained.
3320 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3321 the given index is extracted from the list for comparison. The list index may
3322 be any valid list index, such as +1+, +end+ or +end-2+.
3324 defer
3325 ~~~~~
3326 +*defer* 'script'+
3328 This command is a simple helper command to add a script to the '+$jim::defer+' variable
3329 that will run when the current proc or interpreter exits. For example:
3331 ----
3332     . proc a {} { defer {puts "Leaving a"}; puts "Exit" }
3333     . a
3334     Exit
3335     Leaving a
3336 ----
3338 If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
3339 when the proc or interpreter exits.
3341 open
3342 ~~~~
3343 +*open* 'fileName ?access?'+
3345 +*open* '|command-pipeline ?access?'+
3347 Opens a file and returns an identifier
3348 that may be used in future invocations
3349 of commands like `read`, `puts`, and `close`.
3350 +'fileName'+ gives the name of the file to open.
3352 The +'access'+ argument indicates the way in which the file is to be accessed.
3353 It may have any of the following values:
3355 +r+::
3356     Open the file for reading only; the file must already exist.
3358 +r++::
3359     Open the file for both reading and writing; the file must
3360     already exist.
3362 +w+::
3363     Open the file for writing only. Truncate it if it exists. If it doesn't
3364     exist, create a new file.
3366 +w++::
3367     Open the file for reading and writing. Truncate it if it exists.
3368     If it doesn't exist, create a new file.
3370 +a+::
3371     Open the file for writing only. The file must already exist, and the file
3372     is positioned so that new data is appended to the file.
3374 +a++::
3375     Open the file for reading and writing. If the file doesn't
3376     exist, create a new empty file. Set the initial access position
3377     to the end of the file.
3379 +'access'+ defaults to 'r'.
3381 If a file is opened for both reading and writing, then `seek`
3382 must be invoked between a read and a write, or vice versa.
3384 If the first character of +'fileName'+ is "|" then the remaining
3385 characters of +'fileName'+ are treated as a list of arguments that
3386 describe a command pipeline to invoke, in the same style as the
3387 arguments for exec. In this case, the channel identifier returned
3388 by open may be used to write to the command's input pipe or read
3389 from its output pipe, depending on the value of +'access'+. If write-only
3390 access is used (e.g. +'access'+ is 'w'), then standard output for the
3391 pipeline is directed to the current standard output unless overridden
3392 by the command. If read-only access is used (e.g. +'access'+ is r),
3393 standard input for the pipeline is taken from the current standard
3394 input unless overridden by the command.
3396 The `pid` command may be used to return the process ids of the commands
3397 forming the command pipeline.
3399 See also `socket`, `pid`, `exec`
3401 package
3402 ~~~~~~~
3403 +*package provide* 'name ?version?'+
3405 Indicates that the current script provides the package named +'name'+.
3406 *Note*: The supplied version is ignored. All packages are registered as version 1.0
3407 (it is simply accepted for compatibility purposes).
3409 Any script that provides a package may include this statement
3410 as the first statement, although it is not required.
3412 +*package require* 'name ?version?'+
3414 Searches for the package with the given +'name'+ by examining each path
3415 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3416 or '$path/$name.tcl' as a script package.
3418 The first such file which is found is considered to provide the package.
3419 (The version number is ignored).
3421 If '$name.so' exists, it is loaded with the `load` command,
3422 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3424 If `load` or `source` fails, `package require` will fail immediately.
3425 No further attempt will be made to locate the file.
3429 +*pid*+
3431 +*pid* 'fileId'+
3433 The first form returns the process identifier of the current process.
3435 The second form accepts a handle returned by `open` and returns a list
3436 of the process ids forming the pipeline in the same form as `exec ... &`.
3437 If 'fileId' represents a regular file handle rather than a command pipeline,
3438 the empty string is returned instead.
3440 See also `open`, `exec`
3442 proc
3443 ~~~~
3444 +*proc* 'name args ?statics? body'+
3446 The `proc` command creates a new Tcl command procedure, +'name'+.
3447 When the new command is invoked, the contents of +'body'+ will be executed.
3448 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3449 If specified, +'statics'+, declares static variables which are bound to the
3450 procedure.
3452 See <<_procedures,PROCEDURES> for detailed information about Tcl procedures.
3454 The `proc` command returns +'name'+ (which is useful with `local`).
3456 When a procedure is invoked, the procedure's return value is the
3457 value specified in a `return` command.  If the procedure doesn't
3458 execute an explicit `return`, then its return value is the value
3459 of the last command executed in the procedure's body.
3461 If an error occurs while executing the procedure body, then the
3462 procedure-as-a-whole will return that same error.
3464 puts
3465 ~~~~
3466 +*puts* ?*-nonewline*? '?fileId? string'+
3468 +'fileId' *puts* ?*-nonewline*? 'string'+
3470 Writes the characters given by +'string'+ to the file given
3471 by +'fileId'+. +'fileId'+ must have been the return
3472 value from a previous call to `open`, or it may be
3473 +stdout+ or +stderr+ to refer to one of the standard I/O
3474 channels; it must refer to a file that was opened for
3475 writing.
3477 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3478 `puts` normally outputs a newline character after +'string'+,
3479 but this feature may be suppressed by specifying the +-nonewline+
3480 switch.
3482 Output to files is buffered internally by Tcl; the `flush`
3483 command may be used to force buffered characters to be output.
3485 pipe
3486 ~~~~
3487 Creates a pair of `aio` channels and returns the handles as a list: +{read write}+
3489 ----
3490     lassign [pipe] r w
3492     # Must close $w after exec
3493     exec ps >@$w &
3494     $w close
3496     $r readable ...
3497 ----
3501 +*pwd*+
3503 Returns the path name of the current working directory.
3505 rand
3506 ~~~~
3507 +*rand* '?min? ?max?'+
3509 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3510 (defaults to the maximum integer).
3512 If only one argument is given, it is interpreted as +'max'+.
3514 range
3515 ~~~~
3516 +*range* '?start? end ?step?'+
3518 Returns a list of integers starting at +'start'+ (defaults to 0)
3519 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3521 ----
3522     . range 5
3523     0 1 2 3 4
3524     . range 2 5
3525     2 3 4
3526     . range 2 10 4
3527     2 6
3528     . range 7 4 -2
3529     7 5
3530 ----
3532 read
3533 ~~~~
3534 +*read* ?*-nonewline*? 'fileId'+
3536 +'fileId' *read* ?*-nonewline*?+
3538 +*read* 'fileId numBytes'+
3540 +'fileId' *read* 'numBytes'+
3542 In the first form, all of the remaining bytes are read from the file
3543 given by +'fileId'+; they are returned as the result of the command.
3544 If the +-nonewline+ switch is specified then the last
3545 character of the file is discarded if it is a newline.
3547 In the second form, the extra argument specifies how many bytes to read;
3548 exactly this many bytes will be read and returned, unless there are fewer than
3549 +'numBytes'+ bytes left in the file; in this case, all the remaining
3550 bytes are returned.
3552 +'fileId'+ must be +stdin+ or the return value from a previous call
3553 to `open`; it must refer to a file that was opened for reading.
3555 regexp
3556 ~~~~~~
3557 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3559 Determines whether the regular expression +'exp'+ matches part or
3560 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3562 See <<_regular_expressions,REGULAR EXPRESSIONS>> above for complete information on the
3563 syntax of +'exp'+ and how it is matched against +'string'+.
3565 If additional arguments are specified after +'string'+ then they
3566 are treated as the names of variables to use to return
3567 information about which part(s) of +'string'+ matched +'exp'+.
3568 +'matchVar'+ will be set to the range of +'string'+ that
3569 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3570 the characters in +'string'+ that matched the leftmost parenthesized
3571 subexpression within +'exp'+, the next +'subMatchVar'+ will
3572 contain the characters that matched the next parenthesized
3573 subexpression to the right in +'exp'+, and so on.
3575 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3576 matching characters from `string`, however see +-indices+ and
3577 +-inline+ below.
3579 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3580 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3581 match the string (e.g. because it was in a portion of the expression
3582 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3583 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3584 string otherwise.
3586 The following switches modify the behaviour of +'regexp'+
3588 +*-nocase*+::
3589     Causes upper-case and lower-case characters to be treated as
3590     identical during the matching process.
3592 +*-line*+::
3593     Use newline-sensitive matching. By default, newline
3594     is a completely ordinary character with no special meaning in
3595     either REs or strings. With this flag, +[^+ bracket expressions
3596     and +.+ never match newline, an +^+ anchor matches the null
3597     string after any newline in the string in addition to its normal
3598     function, and the +$+ anchor matches the null string before any
3599     newline in the string in addition to its normal function.
3601 +*-indices*+::
3602     Changes what is stored in the subMatchVars. Instead of
3603     storing the matching characters from string, each variable
3604     will contain a list of two decimal strings giving the indices
3605     in string of the first and last characters in the matching
3606     range of characters.
3608 +*-start* 'offset'+::
3609     Specifies a character index offset into the string at which to start
3610     matching the regular expression. If +-indices+ is
3611     specified, the indices will be indexed starting from the
3612     absolute beginning of the input string. +'offset'+ will be
3613     constrained to the bounds of the input string.
3615 +*-all*+::
3616     Causes the regular expression to be matched as many times as possible
3617     in the string, returning the total number of matches found. If this
3618     is specified with match variables, they will contain information
3619     for the last match only.
3621 +*-inline*+::
3622     Causes the command to return, as a list, the data that would otherwise
3623     be placed in match variables. When using +-inline+, match variables
3624     may not be specified. If used with +-all+, the list will be concatenated
3625     at each iteration, such that a flat list is always returned. For
3626     each match iteration, the command will append the overall match
3627     data, plus one element for each subexpression in the regular
3628     expression.
3630 +*--*+::
3631     Marks the end of switches. The argument following this one will be
3632     treated as +'exp'+ even if it starts with a +-+.
3634 regsub
3635 ~~~~~~
3636 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3638 This command matches the regular expression +'exp'+ against
3639 +'string'+ using the rules described in REGULAR EXPRESSIONS
3640 above.
3642 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3643 with the substitutions detailed below, and returns the number of
3644 substitutions made (normally 1 unless +-all+ is specified).
3645 This is 0 if there were no matches.
3647 If +'varName'+ is not specified, the substituted string will be returned
3648 instead.
3650 When copying +'string'+, the portion of +'string'+ that
3651 matched +'exp'+ is replaced with +'subSpec'+.
3652 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3653 in the substitution with the portion of +'string'+ that
3654 matched +'exp'+.
3656 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3657 between 1 and 9, then it is replaced in the substitution with
3658 the portion of +'string'+ that matched the +'n'+\'-th
3659 parenthesized subexpression of +'exp'+.
3660 Additional backslashes may be used in +'subSpec'+ to prevent special
3661 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3662 backslash.
3664 The use of backslashes in +'subSpec'+ tends to interact badly
3665 with the Tcl parser's use of backslashes, so it's generally
3666 safest to enclose +'subSpec'+ in braces if it includes
3667 backslashes.
3669 The following switches modify the behaviour of +'regsub'+
3671 +*-nocase*+::
3672     Upper-case characters in +'string'+ are converted to lower-case
3673     before matching against +'exp'+;  however, substitutions
3674     specified by +'subSpec'+ use the original unconverted form
3675     of +'string'+.
3677 +*-all*+::
3678     All ranges in +'string'+ that match +'exp'+ are found and substitution
3679     is performed for each of these ranges, rather than only the
3680     first. The +&+ and +{backslash}n+ sequences are handled for
3681     each substitution using the information from the corresponding
3682     match.
3684 +*-line*+::
3685     Use newline-sensitive matching. By default, newline
3686     is a completely ordinary character with no special meaning in
3687     either REs or strings.  With this flag, +[^+ bracket expressions
3688     and +.+ never match newline, an +^+ anchor matches the null
3689     string after any newline in the string in addition to its normal
3690     function, and the +$+ anchor matches the null string before any
3691     newline in the string in addition to its normal function.
3693 +*-start* 'offset'+::
3694     Specifies a character index offset into the string at which to
3695     start matching the regular expression. +'offset'+ will be
3696     constrained to the bounds of the input string.
3698 +*--*+::
3699     Marks the end of switches. The argument following this one will be
3700     treated as +'exp'+ even if it starts with a +-+.
3704 +*ref* 'string tag ?finalizer?'+
3706 Create a new reference containing +'string'+ of type +'tag'+.
3707 If +'finalizer'+ is specified, it is a command which will be invoked
3708 when the a garbage collection cycle runs and this reference is
3709 no longer accessible.
3711 The finalizer is invoked as:
3713 ----
3714     finalizer reference string
3715 ----
3717 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
3719 rename
3720 ~~~~~~
3721 +*rename* 'oldName newName'+
3723 Rename the command that used to be called +'oldName'+ so that it
3724 is now called +'newName'+.  If +'newName'+ is an empty string
3725 (e.g. {}) then +'oldName'+ is deleted.  The `rename` command
3726 returns an empty string as result.
3728 return
3729 ~~~~~~
3730 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3732 Return immediately from the current procedure (or top-level command
3733 or `source` command), with +'value'+ as the return value.  If +'value'+
3734 is not specified, an empty string will be returned as result.
3736 If +-code+ is specified (as either a number or ok, error, break,
3737 continue, signal, return or exit), this code will be used instead
3738 of +JIM_OK+. This is generally useful when implementing flow of control
3739 commands.
3741 If +-level+ is specified and greater than 1, it has the effect of delaying
3742 the new return code from +-code+. This is useful when rethrowing an error
3743 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3744 an example of how this is done.
3746 Note: The following options are only used when +-code+ is JIM_ERR.
3748 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3749 it is used to initialize the stacktrace.
3751 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3753 scan
3754 ~~~~
3755 +*scan* 'string format varName1 ?varName2 \...?'+
3757 This command parses fields from an input string in the same fashion
3758 as the C 'sscanf' procedure.  +'string'+ gives the input to be parsed
3759 and +'format'+ indicates how to parse it, using '%' fields as in
3760 'sscanf'.  All of the 'sscanf' options are valid; see the 'sscanf'
3761 man page for details.  Each +'varName'+ gives the name of a variable;
3762 when a field is scanned from +'string'+, the result is converted back
3763 into a string and assigned to the corresponding +'varName'+.  The
3764 only unusual conversion is for '%c'.  For '%c' conversions a single
3765 character value is converted to a decimal string, which is then
3766 assigned to the corresponding +'varName'+; no field width may be
3767 specified for this conversion.
3769 seek
3770 ~~~~
3771 +*seek* 'fileId offset ?origin?'+
3773 +'fileId' *seek* 'offset ?origin?'+
3775 Change the current access position for +'fileId'+.
3776 The +'offset'+ and +'origin'+ arguments specify the position at
3777 which the next read or write will occur for +'fileId'+.
3778 +'offset'+ must be a number (which may be negative) and +'origin'+
3779 must be one of the following:
3781 +*start*+::
3782     The new access position will be +'offset'+ bytes from the start
3783     of the file.
3785 +*current*+::
3786     The new access position will be +'offset'+ bytes from the current
3787     access position; a negative +'offset'+ moves the access position
3788     backwards in the file.
3790 +*end*+::
3791     The new access position will be +'offset'+ bytes from the end of
3792     the file.  A negative +'offset'+ places the access position before
3793     the end-of-file, and a positive +'offset'+ places the access position
3794     after the end-of-file.
3796 The +'origin'+ argument defaults to +start+.
3798 +'fileId'+ must have been the return value from a previous call to
3799 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3800 of the standard I/O channels.
3802 This command returns an empty string.
3806 +*set* 'varName ?value?'+
3808 Returns the value of variable +'varName'+.
3810 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3811 creating a new variable if one doesn't already exist, and return
3812 its value.
3814 If +'varName'+ contains an open parenthesis and ends with a
3815 close parenthesis, then it refers to an array element:  the characters
3816 before the open parenthesis are the name of the array, and the characters
3817 between the parentheses are the index within the array.
3818 Otherwise +'varName'+ refers to a scalar variable.
3820 If no procedure is active, then +'varName'+ refers to a global
3821 variable.
3823 If a procedure is active, then +'varName'+ refers to a parameter
3824 or local variable of the procedure, unless the +'global'+ command
3825 has been invoked to declare +'varName'+ to be global.
3827 The +::+ prefix may also be used to explicitly reference a variable
3828 in the global scope.
3830 setref
3831 ~~~~~~
3832 +*setref* 'reference string'+
3834 Store a new string in +'reference'+, replacing the existing string.
3835 The reference must be a valid reference create with the `ref`
3836 command.
3838 See <<_garbage_collection_references_lambda_function,GARBAGE COLLECTION>> for more detail.
3840 signal
3841 ~~~~~~
3842 Command for signal handling.
3844 See `kill` for the different forms which may be used to specify signals.
3846 Commands which return a list of signal names do so using the canonical form:
3847 "+SIGINT SIGTERM+".
3849 +*signal handle* ?'signals \...'?+::
3850     If no signals are given, returns a list of all signals which are currently
3851     being handled.
3852     If signals are specified, these are added to the list of signals currently
3853     being handled.
3855 +*signal ignore* ?'signals \...'?+::
3856     If no signals are given, returns a lists all signals which are currently
3857     being ignored.
3858     If signals are specified, these are added to the list of signals
3859     currently being ignored. These signals are still delivered, but
3860     are not considered by `catch -signal` or `try -signal`. Use
3861     `signal check` to determine which signals have occurred but
3862     been ignored.
3864 +*signal block* ?'signals \...'?+::
3865     If no signals are given, returns a lists all signals which are currently
3866     being blocked.
3867     If signals are specified, these are added to the list of signals
3868     currently being blocked. These signals are not delivered to the process.
3869     This can be useful for signals such as +SIGPIPE+, especially in conjunction
3870     with `exec` as child processes inherit the parent's signal disposition.
3872 +*signal default* ?'signals \...'?+::
3873     If no signals are given, returns a lists all signals which currently have
3874     the default behaviour.
3875     If signals are specified, these are added to the list of signals which have
3876     the default behaviour.
3878 +*signal check ?-clear?* ?'signals \...'?+::
3879     Returns a list of signals which have been delivered to the process
3880     but are 'ignored'. If signals are specified, only that set of signals will
3881     be checked, otherwise all signals will be checked.
3882     If +-clear+ is specified, any signals returned are removed and will not be
3883     returned by subsequent calls to `signal check` unless delivered again.
3885 +*signal throw* ?'signal'?+::
3886     Raises the given signal, which defaults to +SIGINT+ if not specified.
3887     The behaviour is identical to:
3889 ----
3890     kill signal [pid]
3891 ----
3893 Note that `signal handle` and `signal ignore` represent two forms of signal
3894 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3895 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3896 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3897 two examples below.
3899 Prevent a processing from taking too long
3901 ----
3902     signal handle SIGALRM
3903     alarm 20
3904     try -signal {
3905         .. possibly long running process ..
3906         alarm 0
3907     } on signal {sig} {
3908         puts stderr "Process took too long"
3909     }
3910 ----
3912 Handle SIGHUP to reconfigure:
3914 ----
3915     signal ignore SIGHUP
3916     while {1} {
3917         ... handle configuration/reconfiguration ...
3918         while {[signal check -clear SIGHUP] eq ""} {
3919             ... do processing ..
3920         }
3921         # Received SIGHUP, so reconfigure
3922     }
3923 ----
3925 Note: signal handling is currently not supported in child interpreters.
3926 In these interpreters, the signal command does not exist.
3928 sleep
3929 ~~~~~
3930 +*sleep* 'seconds'+
3932 Pauses for the given number of seconds, which may be a floating
3933 point value less than one to sleep for less than a second, or an
3934 integer to sleep for one or more seconds.
3936 source
3937 ~~~~~~
3938 +*source* 'fileName'+
3940 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3941 as a sequence of commands to execute in the normal fashion.  The return
3942 value of `source` is the return value of the last command executed
3943 from the file.  If an error occurs in executing the contents of the
3944 file, then the `source` command will return that error.
3946 If a `return` command is invoked from within the file, the remainder of
3947 the file will be skipped and the `source` command will return
3948 normally with the result from the `return` command.
3950 split
3951 ~~~~~
3952 +*split* 'string ?splitChars?'+
3954 Returns a list created by splitting +'string'+ at each character
3955 that is in the +'splitChars'+ argument.
3957 Each element of the result list will consist of the
3958 characters from +'string'+ between instances of the
3959 characters in +'splitChars'+.
3961 Empty list elements will be generated if +'string'+ contains
3962 adjacent characters in +'splitChars'+, or if the first or last
3963 character of +'string'+ is in +'splitChars'+.
3965 If +'splitChars'+ is an empty string then each character of
3966 +'string'+ becomes a separate element of the result list.
3968 +'splitChars'+ defaults to the standard white-space characters.
3969 For example,
3971 ----
3972     split "comp.unix.misc" .
3973 ----
3975 returns +'"comp unix misc"'+ and
3977 ----
3978     split "Hello world" {}
3979 ----
3981 returns +'"H e l l o { } w o r l d"'+.
3983 stackdump
3984 ~~~~~~~~~
3986 +*stackdump* 'stacktrace'+
3988 Creates a human readable representation of a stack trace.
3990 stacktrace
3991 ~~~~~~~~~~
3993 +*stacktrace*+
3995 Returns a live stack trace as a list of +proc file line proc file line \...+.
3996 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
3997 same form as produced by `catch` and `info stacktrace`
3999 See also `stackdump`.
4001 string
4002 ~~~~~~
4004 +*string* 'option arg ?arg \...?'+
4006 Perform one of several string operations, depending on +'option'+.
4007 The legal options (which may be abbreviated) are:
4009 +*string bytelength* 'string'+::
4010     Returns the length of the string in bytes. This will return
4011     the same value as `string length` if UTF-8 support is not enabled,
4012     or if the string is composed entirely of ASCII characters.
4013     See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4015 +*string byterange* 'string first last'+::
4016     Like `string range` except works on bytes rather than characters.
4017     These commands are identical if UTF-8 support is not enabled.
4019 +*string cat* '?string1 string2 \...?'+::
4020     Concatenates the given strings into a single string.
4022 +*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
4023     Perform a character-by-character comparison of strings +'string1'+ and
4024     +'string2'+ in the same way as the C 'strcmp' procedure.  Return
4025     -1, 0, or 1, depending on whether +'string1'+ is lexicographically
4026     less than, equal to, or greater than +'string2'+. If +-length+
4027     is specified, then only the first +'len'+ characters are used
4028     in the comparison.  If +'len'+ is negative, it is ignored.
4029     Performs a case-insensitive comparison if +-nocase+ is specified.
4031 +*string equal ?-nocase?* '?*-length* len?' 'string1 string2'+::
4032     Returns 1 if the strings are equal, or 0 otherwise. If +-length+
4033     is specified, then only the first +'len'+ characters are used
4034     in the comparison.  If +'len'+ is negative, it is ignored.
4035     Performs a case-insensitive comparison if +-nocase+ is specified.
4037 +*string first* 'string1 string2 ?firstIndex?'+::
4038     Search +'string2'+ for a sequence of characters that exactly match
4039     the characters in +'string1'+.  If found, return the index of the
4040     first character in the first such match within +'string2'+.  If not
4041     found, return -1. If +'firstIndex'+ is specified, matching will start
4042     from +'firstIndex'+ of +'string1'+.
4043  ::
4044     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'firstIndex'+.
4046 +*string index* 'string charIndex'+::
4047     Returns the +'charIndex'+'th character of the +'string'+
4048     argument.  A +'charIndex'+ of 0 corresponds to the first
4049     character of the string.
4050     If +'charIndex'+ is less than 0 or greater than
4051     or equal to the length of the string then an empty string is
4052     returned.
4053  ::
4054     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'charIndex'+.
4056 +*string is* 'class' ?*-strict*? 'string'+::
4057     Returns 1 if +'string'+ is a valid member of the specified character
4058     class, otherwise returns 0. If +-strict+ is specified, then an
4059     empty string returns 0, otherwise an empty string will return 1
4060     on any class. The following character classes are recognized
4061     (the class name can be abbreviated):
4062   ::
4063   +alnum+;;  Any alphabet or digit character.
4064   +alpha+;;  Any alphabet character.
4065   +ascii+;;  Any character with a value less than 128 (those that are in the 7-bit ascii range).
4066   +boolean+;;  Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
4067   +control+;; Any control character.
4068   +digit+;;  Any digit character.
4069   +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
4070              In case of under/overflow in the value, 0 is returned.
4071   +graph+;;  Any printing character, except space.
4072   +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
4073   +lower+;;  Any lower case alphabet character.
4074   +print+;;  Any printing character, including space.
4075   +punct+;;  Any punctuation character.
4076   +space+;;  Any space character.
4077   +upper+;;  Any upper case alphabet character.
4078   +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
4079  ::
4080     Note that string classification does +'not'+ respect UTF-8. See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4081  ::
4082     Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).
4084 +*string last* 'string1 string2 ?lastIndex?'+::
4085     Search +'string2'+ for a sequence of characters that exactly match
4086     the characters in +'string1'+.  If found, return the index of the
4087     first character in the last such match within +'string2'+.  If there
4088     is no match, then return -1. If +'lastIndex'+ is specified, only characters
4089     up to +'lastIndex'+ of +'string2'+ will be considered in the match.
4090  ::
4091     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'lastIndex'+.
4093 +*string length* 'string'+::
4094     Returns a decimal string giving the number of characters in +'string'+.
4095     If UTF-8 support is enabled, this may be different than the number of bytes.
4096     See <<_utf_8_and_unicode,UTF-8 AND UNICODE>>.
4098 +*string map ?-nocase?* 'mapping string'+::
4099     Replaces substrings in +'string'+ based on the key-value pairs in
4100     +'mapping'+, which is a list of +key value key value \...+ as in the form
4101     returned by `array get`. Each instance of a key in the string will be
4102     replaced with its corresponding value.  If +-nocase+ is specified, then
4103     matching is done without regard to case differences. Both key and value may
4104     be multiple characters.  Replacement is done in an ordered manner, so the
4105     key appearing first in the list will be checked first, and so on. +'string'+ is
4106     only iterated over once, so earlier key replacements will have no affect for
4107     later key matches. For example,
4109 ----
4110       string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
4111 ----
4113  ::
4114     will return the string +01321221+.
4115  ::
4116     Note that if an earlier key is a prefix of a later one, it will completely mask the later
4117     one.  So if the previous example is reordered like this,
4119 ----
4120       string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
4121 ----
4123  ::
4124     it will return the string +02c322c222c+.
4126 +*string match ?-nocase?* 'pattern string'+::
4127     See if +'pattern'+ matches +'string'+; return 1 if it does, 0
4128     if it doesn't.  Matching is done in a fashion similar to that
4129     used by the C-shell.  For the two strings to match, their contents
4130     must be identical except that the following special sequences
4131     may appear in +'pattern'+:
4133     +*+;;
4134         Matches any sequence of characters in +'string'+,
4135         including a null string.
4137     +?+;;
4138         Matches any single character in +'string'+.
4140     +['chars']+;;
4141         Matches any character in the set given by +'chars'+.
4142         If a sequence of the form +'x-y'+ appears in +'chars'+,
4143         then any character between +'x'+ and +'y'+, inclusive,
4144         will match.
4146     +{backslash}x+;;
4147         Matches the single character +'x'+.  This provides a way of
4148         avoiding the special interpretation of the characters +{backslash}*?[]+
4149         in +'pattern'+.
4150  ::
4151     Performs a case-insensitive comparison if +-nocase+ is specified.
4153 +*string range* 'string first last'+::
4154     Returns a range of consecutive characters from +'string'+, starting
4155     with the character whose index is +'first'+ and ending with the
4156     character whose index is +'last'+.  An index of 0 refers to the
4157     first character of the string.
4158  ::
4159     See <<_string_and_list_index_specifications,STRING AND LIST INDEX SPECIFICATIONS>> for all allowed forms for +'first'+ and +'last'+.
4160  ::
4161     If +'first'+ is less than zero then it is treated as if it were zero, and
4162     if +'last'+ is greater than or equal to the length of the string then
4163     it is treated as if it were +end+.  If +'first'+ is greater than
4164     +'last'+ then an empty string is returned.
4166 +*string repeat* 'string count'+::
4167     Returns a new string consisting of +'string'+ repeated +'count'+ times.
4169 +*string replace* 'string first last ?newstring?'+::
4170     Removes a range of consecutive characters from +'string'+, starting
4171     with the character whose index is +'first'+ and ending with the
4172     character whose index is +'last'+.  If +'newstring'+ is specified,
4173     then it is placed in the removed character range. If +'first'+ is
4174     less than zero then it is treated as if it were zero, and if +'last'+
4175     is greater than or equal to the length of the string then it is
4176     treated as if it were +end+. If +'first'+ is greater than +'last'+
4177     or the length of the initial string, or +'last'+ is less than 0,
4178     then the initial string is returned untouched.
4180 +*string reverse* 'string'+::
4181     Returns a string that is the same length as +'string'+ but
4182     with its characters in the reverse order.
4184 +*string tolower* 'string'+::
4185     Returns a value equal to +'string'+ except that all upper case
4186     letters have been converted to lower case.
4188 +*string totitle* 'string'+::
4189     Returns a value equal to +'string'+ except that the first character
4190     is converted to title case (or upper case if there is no UTF-8 titlecase variant)
4191     and all remaining characters have been converted to lower case.
4193 +*string toupper* 'string'+::
4194     Returns a value equal to +'string'+ except that all lower case
4195     letters have been converted to upper case.
4197 +*string trim* 'string ?chars?'+::
4198     Returns a value equal to +'string'+ except that any leading
4199     or trailing characters from the set given by +'chars'+ are
4200     removed.
4201     If +'chars'+ is not specified then white space is removed
4202     (spaces, tabs, newlines, and carriage returns).
4204 +*string trimleft* 'string ?chars?'+::
4205     Returns a value equal to +'string'+ except that any
4206     leading characters from the set given by +'chars'+ are
4207     removed.
4208     If +'chars'+ is not specified then white space is removed
4209     (spaces, tabs, newlines, and carriage returns).
4211 +*string trimright* 'string ?chars?'+::
4212     Returns a value equal to +'string'+ except that any
4213     trailing characters from the set given by +'chars'+ are
4214     removed.
4215     If +'chars'+ is not specified then white space is removed
4216     (spaces, tabs, newlines, and carriage returns).
4217     Null characters are always removed.
4219 subst
4220 ~~~~~
4221 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
4223 This command performs variable substitutions, command substitutions,
4224 and backslash substitutions on its string argument and returns the
4225 fully-substituted result. The substitutions are performed in exactly
4226 the same way as for Tcl commands. As a result, the string argument
4227 is actually substituted twice, once by the Tcl parser in the usual
4228 fashion for Tcl commands, and again by the subst command.
4230 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
4231 specified, then the corresponding substitutions are not performed.
4232 For example, if +-nocommands+ is specified, no command substitution
4233 is performed: open and close brackets are treated as ordinary
4234 characters with no special interpretation.
4236 *Note*: when it performs its substitutions, subst does not give any
4237 special treatment to double quotes or curly braces. For example,
4238 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
4240 ----
4241     set a 44
4242     subst {xyz {$a}}
4243 ----
4246 switch
4247 ~~~~~~
4248 +*switch* '?options? string pattern body ?pattern body \...?'+
4250 +*switch* '?options? string {pattern body ?pattern body \...?}'+
4252 The `switch` command matches its string argument against each of
4253 the pattern arguments in order. As soon as it finds a pattern that
4254 matches string it evaluates the following body and returns the
4255 result of that evaluation. If the last pattern argument is default
4256 then it matches anything. If no pattern argument matches string and
4257 no default is given, then the `switch` command returns an empty string.
4258 If the initial arguments to switch start with - then they are treated
4259 as options. The following options are currently supported:
4261     +-exact+::
4262         Use exact matching when comparing string to a
4263         pattern. This is the default.
4265     +-glob+::
4266         When matching string to the patterns, use glob-style
4267         matching (i.e. the same as implemented by the string
4268         match command).
4270     +-regexp+::
4271         When matching string to the patterns, use regular
4272         expression matching (i.e. the same as implemented
4273         by the regexp command).
4275     +-command 'commandname'+::
4276         When matching string to the patterns, use the given command, which
4277         must be a single word. The command is invoked as
4278         'commandname pattern string', or 'commandname -nocase pattern string'
4279         and must return 1 if matched, or 0 if not.
4281     +--+::
4282         Marks the end of options. The argument following
4283         this one will be treated as string even if it starts
4284         with a +-+.
4286 Two syntaxes are provided for the pattern and body arguments. The
4287 first uses a separate argument for each of the patterns and commands;
4288 this form is convenient if substitutions are desired on some of the
4289 patterns or commands. The second form places all of the patterns
4290 and commands together into a single argument; the argument must
4291 have proper list structure, with the elements of the list being the
4292 patterns and commands. The second form makes it easy to construct
4293 multi-line `switch` commands, since the braces around the whole list
4294 make it unnecessary to include a backslash at the end of each line.
4295 Since the pattern arguments are in braces in the second form, no
4296 command or variable substitutions are performed on them; this makes
4297 the behaviour of the second form different than the first form in
4298 some cases.
4300 If a body is specified as +-+ it means that the body for the next
4301 pattern should also be used as the body for this pattern (if the
4302 next pattern also has a body of +-+ then the body after that is
4303 used, and so on). This feature makes it possible to share a single
4304 body among several patterns.
4306 Below are some examples of `switch` commands:
4308 ----
4309     switch abc a - b {format 1} abc {format 2} default {format 3}
4310 ----
4312 will return 2,
4314 ----
4315     switch -regexp aaab {
4316            ^a.*b$ -
4317            b {format 1}
4318            a* {format 2}
4319            default {format 3}
4320     }
4321 ----
4323 will return 1, and
4325 ----
4326     switch xyz {
4327            a -
4328            b {format 1}
4329            a* {format 2}
4330            default {format 3}
4331     }
4332 ----
4334 will return 3.
4336 tailcall
4337 ~~~~~~~~
4338 +*tailcall* 'cmd ?arg\...?'+
4340 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4341 the current call frame. This is similar to 'exec' in Bourne Shell.
4343 The following are identical except the first immediately replaces the current call frame.
4345 ----
4346   tailcall a b c
4347 ----
4349 ----
4350   return [uplevel 1 [list a b c]]
4351 ----
4353 `tailcall` is useful as a dispatch mechanism:
4355 ----
4356   proc a {cmd args} {
4357     tailcall sub_$cmd {*}$args
4358   }
4359   proc sub_cmd1 ...
4360   proc sub_cmd2 ...
4361 ----
4363 tell
4364 ~~~~
4365 +*tell* 'fileId'+
4367 +'fileId' *tell*+
4369 Returns a decimal string giving the current access position in
4370 +'fileId'+.
4372 +'fileId'+ must have been the return value from a previous call to
4373 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4374 of the standard I/O channels.
4376 throw
4377 ~~~~~
4378 +*throw* 'code ?msg?'+
4380 This command throws an exception (return) code along with an optional message.
4381 This command is mostly for convenient usage with `try`.
4383 The command +throw break+ is equivalent to +break+.
4384 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4386 time
4387 ~~~~
4388 +*time* 'command ?count?'+
4390 This command will call the Tcl interpreter +'count'+
4391 times to execute +'command'+ (or once if +'count'+ isn't
4392 specified).  It will then return a string of the form
4394 ----
4395     503 microseconds per iteration
4396 ----
4398 which indicates the average amount of time required per iteration,
4399 in microseconds.
4401 Time is measured in elapsed time, not CPU time.
4405 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4407 The `try` command is provided as a convenience for exception handling.
4409 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4410 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4412 It then evaluates the script for the first matching 'on' handler
4413 (there many be zero or more) based on the return code from the `try`
4414 section. For example a normal +JIM_ERR+ error will be matched by
4415 an 'on error' handler.
4417 Finally, any +'finalscript'+ is evaluated.
4419 The result of this command is the result of +'tryscript'+, except in the
4420 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4421 in which case the result is this new exception.
4423 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4424 or as integers.
4426 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4427 the matching handler.
4429 For example:
4431 ----
4432     set f [open input]
4433     try -signal {
4434         process $f
4435     } on {continue break} {} {
4436         error "Unexpected break/continue"
4437     } on error {msg opts} {
4438         puts "Dealing with error"
4439         return {*}$opts $msg
4440     } on signal sig {
4441         puts "Got signal: $sig"
4442     } finally {
4443         $f close
4444     }
4445 ----
4447 If break, continue or error are raised, they are dealt with by the matching
4448 handler.
4450 In any case, the file will be closed via the 'finally' clause.
4452 See also `throw`, `catch`, `return`, `error`.
4454 unknown
4455 ~~~~~~~
4456 +*unknown* 'cmdName ?arg arg ...?'+
4458 This command doesn't actually exist as part of Tcl, but Tcl will
4459 invoke it if it does exist.
4461 If the Tcl interpreter encounters a command name for which there
4462 is not a defined command, then Tcl checks for the existence of
4463 a command named `unknown`.
4465 If there is no such command, then the interpreter returns an
4466 error.
4468 If the `unknown` command exists, then it is invoked with
4469 arguments consisting of the fully-substituted name and arguments
4470 for the original non-existent command.
4472 The `unknown` command typically does things like searching
4473 through library directories for a command procedure with the name
4474 +'cmdName'+, or expanding abbreviated command names to full-length,
4475 or automatically executing unknown commands as UNIX sub-processes.
4477 In some cases (such as expanding abbreviations) `unknown` will
4478 change the original command slightly and then (re-)execute it.
4479 The result of the `unknown` command is used as the result for
4480 the original non-existent command.
4482 unset
4483 ~~~~~
4484 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4486 Remove variables.
4487 Each +'name'+ is a variable name, specified in any of the
4488 ways acceptable to the `set` command.
4490 If a +'name'+ refers to an element of an array, then that
4491 element is removed without affecting the rest of the array.
4493 If a +'name'+ consists of an array name with no parenthesized
4494 index, then the entire array is deleted.
4496 The `unset` command returns an empty string as result.
4498 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4499 is specified. The '--' argument may be specified to stop option processing
4500 in case the variable name may be '-nocomplain'.
4502 upcall
4503 ~~~~~~~
4504 +*upcall* 'command ?args ...?'+
4506 May be used from within a proc defined as `local` `proc` in order to call
4507 the previous, hidden version of the same command.
4509 If there is no previous definition of the command, an error is returned.
4511 uplevel
4512 ~~~~~~~
4513 +*uplevel* '?level? command ?command ...?'+
4515 All of the +'command'+ arguments are concatenated as if they had
4516 been passed to `concat`; the result is then evaluated in the
4517 variable context indicated by +'level'+.  `uplevel` returns
4518 the result of that evaluation.  If +'level'+ is an integer, then
4519 it gives a distance (up the procedure calling stack) to move before
4520 executing the command.  If +'level'+ consists of +\#+ followed by
4521 a number then the number gives an absolute level number.  If +'level'+
4522 is omitted then it defaults to +1+.  +'level'+ cannot be
4523 defaulted if the first +'command'+ argument starts with a digit or +#+.
4525 For example, suppose that procedure 'a' was invoked
4526 from top-level, and that it called 'b', and that 'b' called 'c'.
4527 Suppose that 'c' invokes the `uplevel` command.  If +'level'+
4528 is +1+ or +#2+  or omitted, then the command will be executed
4529 in the variable context of 'b'.  If +'level'+ is +2+ or +#1+
4530 then the command will be executed in the variable context of 'a'.
4532 If +'level'+ is '3' or +#0+ then the command will be executed
4533 at top-level (only global variables will be visible).
4534 The `uplevel` command causes the invoking procedure to disappear
4535 from the procedure calling stack while the command is being executed.
4536 In the above example, suppose 'c' invokes the command
4538 ----
4539     uplevel 1 {set x 43; d}
4540 ----
4542 where 'd' is another Tcl procedure.  The `set` command will
4543 modify the variable 'x' in 'b's context, and 'd' will execute
4544 at level 3, as if called from 'b'.  If it in turn executes
4545 the command
4547 ----
4548     uplevel {set x 42}
4549 ----
4551 then the `set` command will modify the same variable 'x' in 'b's
4552 context:  the procedure 'c' does not appear to be on the call stack
4553 when 'd' is executing.  The command `info level` may
4554 be used to obtain the level of the current procedure.
4556 `uplevel` makes it possible to implement new control
4557 constructs as Tcl procedures (for example, `uplevel` could
4558 be used to implement the `while` construct as a Tcl procedure).
4560 upvar
4561 ~~~~~
4562 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4564 This command arranges for one or more local variables in the current
4565 procedure to refer to variables in an enclosing procedure call or
4566 to global variables.
4568 +'level'+ may have any of the forms permitted for the `uplevel`
4569 command, and may be omitted if the first letter of the first +'otherVar'+
4570 isn't +#+ or a digit (it defaults to '1').
4572 For each +'otherVar'+ argument, `upvar` makes the variable
4573 by that name in the procedure frame given by +'level'+ (or at
4574 global level, if +'level'+ is +#0+) accessible
4575 in the current procedure by the name given in the corresponding
4576 +'myVar'+ argument.
4578 The variable named by +'otherVar'+ need not exist at the time of the
4579 call;  it will be created the first time +'myVar'+ is referenced, just like
4580 an ordinary variable.
4582 `upvar` may only be invoked from within procedures.
4584 `upvar` returns an empty string.
4586 The `upvar` command simplifies the implementation of call-by-name
4587 procedure calling and also makes it easier to build new control constructs
4588 as Tcl procedures.
4589 For example, consider the following procedure:
4591 ----
4592     proc add2 name {
4593         upvar $name x
4594         set x [expr $x+2]
4595     }
4596 ----
4598 'add2' is invoked with an argument giving the name of a variable,
4599 and it adds two to the value of that variable.
4600 Although 'add2' could have been implemented using `uplevel`
4601 instead of `upvar`, `upvar` makes it simpler for 'add2'
4602 to access the variable in the caller's procedure frame.
4604 wait
4605 ~~~~
4606 +*wait*+
4608 +*wait -nohang* 'pid'+
4610 With no arguments, cleans up any processes started by `exec ... &` that have completed
4611 (reaps zombie processes).
4613 With one or two arguments, waits for a process by id, either returned by `exec ... &`
4614 or by `os.fork` (if supported).
4616 Waits for the process to complete, unless +-nohang+ is specified, in which case returns
4617 immediately if the process is still running.
4619 Returns a list of 3 elements.
4621 +{NONE x x}+ if the process does not exist or has already been waited for, or
4622 if -nohang is specified, and the process is still alive.
4624 +{CHILDSTATUS <pid> <exit-status>}+ if the process exited normally.
4626 +{CHILDKILLED <pid> <signal>}+ if the process terminated on a signal.
4628 +{CHILDSUSP <pid> none}+ if the process terminated for some other reason.
4630 Note that on platforms supporting waitpid(2), +pid+ can also be given special values such
4631 as 0 or -1. See waitpid(2) for more detail.
4633 while
4634 ~~~~~
4635 +*while* 'test body'+
4637 The +'while'+ command evaluates +'test'+ as an expression
4638 (in the same way that `expr` evaluates its argument).
4639 The value of the expression must be numeric; if it is non-zero
4640 then +'body'+ is executed by passing it to the Tcl interpreter.
4642 Once +'body'+ has been executed then +'test'+ is evaluated
4643 again, and the process repeats until eventually +'test'+
4644 evaluates to a zero numeric value.  `continue`
4645 commands may be executed inside +'body'+ to terminate the current
4646 iteration of the loop, and `break`
4647 commands may be executed inside +'body'+ to cause immediate
4648 termination of the `while` command.
4650 The `while` command always returns an empty string.
4652 OPTIONAL-EXTENSIONS
4653 -------------------
4655 The following extensions may or may not be available depending upon
4656 what options were selected when Jim Tcl was built.
4659 [[cmd_1]]
4660 posix: os.fork, os.gethostname, os.getids, os.uptime
4661 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4662 +*os.fork*+::
4663     Invokes 'fork(2)' and returns the result.
4665 +*os.gethostname*+::
4666     Invokes 'gethostname(3)' and returns the result.
4668 +*os.getids*+::
4669     Returns the various user/group ids for the current process.
4671 ----
4672     . os.getids
4673     uid 1000 euid 1000 gid 100 egid 100
4674 ----
4676 +*os.uptime*+::
4677     Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4679 ANSI I/O (aio) and EVENTLOOP API
4680 --------------------------------
4681 Jim provides an alternative object-based API for I/O.
4683 See `open` and `socket` for commands which return an I/O handle.
4687 +$handle *accept* ?addrvar?+::
4688     Server socket only: Accept a connection and return stream.
4689     If +'addrvar'+ is specified, the address of the connected client is stored
4690     in the named variable in the form 'addr:port' for IP sockets or 'path' for Unix domain sockets.
4691     See `socket` for details.
4693 +$handle *buffering none|line|full*+::
4694     Sets the buffering mode of the stream.
4696 +$handle *close ?r(ead)|w(rite)|-nodelete?*+::
4697     Closes the stream.
4698     The +'read'+ and +'write'+ arguments perform a "half-close" on a socket. See the 'shutdown(2)' man page.
4699     The +'-nodelete'+ option is applicable only for Unix domain sockets. It closes the socket
4700     but does not delete the bound path (e.g. after `os.fork`).
4703 +$handle *copyto* 'tofd ?size?'+::
4704     Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4705     that many bytes will be copied. Otherwise copying continues until the end
4706     of the input file. Returns the number of bytes actually copied.
4708 +$handle *eof*+::
4709     Returns 1 if stream is at eof
4711 +$handle *filename*+::
4712     Returns the original filename associated with the handle.
4713     Handles returned by `socket` give the socket type instead of a filename.
4715 +$handle *flush*+::
4716     Flush the stream
4718 +$handle *gets* '?var?'+::
4719     Read one line and return it or store it in the var
4721 +$handle *isatty*+::
4722     Returns 1 if the stream is a tty device.
4724 +$handle *lock ?-wait?*+::
4725     Apply a POSIX lock to the open file associated with the handle using
4726     'fcntl(F_SETLK)', or 'fcntl(F_SETLKW)' to wait for the lock to be available if +'-wait'+
4727     is specified.
4728     The handle must be open for write access.
4729     Returns 1 if the lock was successfully obtained, 0 otherwise.
4730     An error occurs if the handle is not suitable for locking (e.g.
4731     if it is not open for write)
4733 +$handle *ndelay ?0|1?*+::
4734     Set O_NDELAY (if arg). Returns current/new setting.
4735     Note that in general ANSI I/O interacts badly with non-blocking I/O.
4736     Use with care.
4738 +$handle *peername*+::
4739     Returns the remote address or path of the connected socket. See 'getpeername(2)'.
4741 +$handle *puts ?-nonewline?* 'str'+::
4742     Write the string, with newline unless -nonewline
4744 +$handle *read ?-nonewline?* '?len?'+::
4745     Read and return bytes from the stream. To eof if no len.
4747 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4748     Receives a message from the handle via recvfrom(2) and returns it.
4749     At most +'maxlen'+ bytes are read. If +'addrvar'+ is specified, the sending address
4750     of the message is stored in the named variable in the form 'addr:port' for IP sockets
4751     or 'path' for Unix domain sockets. See `socket` for details.
4753 +$handle *seek* 'offset' *?start|current|end?*+::
4754     Seeks in the stream (default 'current')
4756 +$handle *sendto* 'str ?address'+::
4757     Sends the string, +'str'+, to the given address (host:port or path) via the socket using 'sendto(2)'.
4758     This is intended for udp/dgram sockets and may give an error or behave in unintended
4759     ways for other handle types.
4760     Returns the number of bytes written.
4762 +$handle *sockname*+::
4763     Returns the bound address or path of the socket. See 'getsockname(2)'.
4765 +$handle *sockopt* '?name value?'+::
4766     With no arguments, returns a dictionary of socket options currently set for the handle
4767     (will be empty for a non-socket). With +'name'+ and +'value'+, sets the socket option
4768     to the given value. Currently supports the following boolean socket options:
4769     +broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay+, and the following
4770     integer socket options: +sndbuf, rcvbuf+
4772 +$handle *sync*+::
4773     Flush the stream, then 'fsync(2)' to commit any changes to storage.
4774     Only available on platforms that support 'fsync(2)'.
4776 +$handle *tell*+::
4777     Returns the current seek position
4779 +$handle *tty* ?settings?+::
4780     If no arguments are given, returns a dictionary containing the tty settings for the stream.
4781     If arguments are given, they must either be a dictionary, or +setting value \...+
4782     Abbrevations are supported for both settings and values, so the following is acceptable:
4783     +$f tty parity e input c out raw+.
4784     Only available on platforms that support 'termios(3)'. Supported settings are:
4786     +*baud* 'rate'+;;
4787         Baud rate. e.g. 115200
4789     +*data 5|6|7|8*+;;
4790         Number of data bits
4792     +*stop 1|2*+;;
4793         Number of stop bits
4795     +*parity even|odd|none*+;;
4796         Parity setting
4798     +*handshake xonxoff|rtscts|none*+;;
4799         Handshaking type
4801     +*input raw|cooked*+;;
4802         Input character processing. In raw mode, the usual key sequences such as ^C do
4803         not generate signals.
4805     +*output raw|cooked*+;;
4806         Output character processing. Typically CR -> CRNL is disabled in raw mode.
4808     +*echo 0|1*+;;
4809         Disable or enable echo on input. Note that this is a set-only value.
4810         Setting +input+ to +raw+ or +cooked+ will overwrite this setting.
4812     +*vmin* 'numchars'+;;
4813         Minimum number of characters to read.
4815     +*vtime* 'time'+;;
4816         Timeout for noncanonical read (units of 0.1 seconds)
4818 +$handle *ssl* ?*-server* 'cert priv'?+::
4819     Upgrades the stream to a SSL/TLS session and returns the handle.
4821 +$handle *unlock*+::
4822     Release a POSIX lock previously acquired by `aio lock`.
4824 +$handle *verify*+::
4825     Verifies the certificate of a SSL/TLS stream peer
4827 +*load_ssl_certs* 'dir'+::
4828     Loads SSL/TLS CA certificates for use during verification
4830 fconfigure
4831 ~~~~~~~~~~
4832 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4833     For compatibility with Tcl, a limited form of the `fconfigure`
4834     command is supported.
4835     * `fconfigure ... -blocking` maps to `aio ndelay`
4836     * `fconfigure ... -buffering` maps to `aio buffering`
4837     * `fconfigure ... -translation` is accepted but ignored
4839 [[cmd_2]]
4840 eventloop: after, vwait, update
4841 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4843 The following commands allow a script to be invoked when the given condition occurs.
4844 If no script is given, returns the current script. If the given script is the empty, the
4845 handler is removed.
4847 +$handle *readable* '?readable-script?'+::
4848     Sets or returns the script for when the socket is readable.
4850 +$handle *writable* '?writable-script?'+::
4851     Sets or returns the script for when the socket is writable.
4853 +$handle *onexception* '?exception-script?'+::
4854     Sets or returns the script for when oob data received.
4856 For compatibility with 'Tcl', these may be prefixed with `fileevent`.  e.g.
4858  ::
4859     +fileevent $handle *readable* '\...'+
4861 Time-based execution is also available via the eventloop API.
4863 +*after* 'ms'+::
4864     Sleeps for the given number of milliseconds. No events are
4865     processed during this time.
4867 +*after* 'ms'|*idle* 'script ?script \...?'+::
4868     The scripts are concatenated and executed after the given
4869     number of milliseconds have elapsed.  If 'idle' is specified,
4870     the script will run the next time the event loop is processed
4871     with `vwait` or `update`. The script is only run once and
4872     then removed.  Returns an event id.
4874 +*after cancel* 'id|command'+::
4875     Cancels an `after` event with the given event id or matching
4876     command (script).  Returns the number of milliseconds
4877     remaining until the event would have fired.  Returns the
4878     empty string if no matching event is found.
4880 +*after info* '?id?'+::
4881     If +'id'+ is not given, returns a list of current `after`
4882     events.  If +'id'+ is given, returns a list containing the
4883     associated script and either 'timer' or 'idle' to indicated
4884     the type of the event. An error occurs if +'id'+ does not
4885     match an event.
4887 +*vwait* 'variable'+::
4888     A call to `vwait` enters the eventloop. `vwait` processes
4889     events until the named (global) variable changes or all
4890     event handlers are removed. The variable need not exist
4891     beforehand.  If there are no event handlers defined, `vwait`
4892     returns immediately.
4894 +*update ?idletasks?*+::
4895     A call to `update` enters the eventloop to process expired events, but
4896     no new events. If 'idletasks' is specified, only expired time events are handled,
4897     not file events.
4898     Returns once handlers have been run for all expired events.
4900 Scripts are executed at the global scope. If an error occurs during a handler script,
4901 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4902 If the `bgerror` command does not exist, the error message details are printed to stderr instead.
4904 If a file event handler script generates an error, the handler is automatically removed
4905 to prevent infinite errors. (A time event handler is always removed after execution).
4907 +*bgerror* 'msg'+::
4908     Called when an event handler script generates an error. Note that the normal command resolution
4909     rules are used for bgerror. First the name is resolved in the current namespace, then in the
4910     global scope.
4912 socket
4913 ~~~~~~
4914 Various socket types may be created.
4916 +*socket unix* 'path'+::
4917     A unix domain socket client connected to 'path'
4919 +*socket unix.server* 'path'+::
4920     A unix domain socket server listening on 'path'
4922 +*socket unix.dgram* '?path?'+::
4923     A unix domain socket datagram client, optionally connected to 'path'
4925 +*socket unix.dgram.server* 'path'+::
4926     A unix domain socket datagram server server listening on 'path'
4928 +*socket ?-ipv6? stream* 'addr:port'+::
4929     A TCP socket client. (See the forms for +'addr'+ below)
4931 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4932     A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4934 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4935     A UDP socket client. If the address is not specified,
4936     the client socket will be unbound and 'sendto' must be used
4937     to indicated the destination.
4939 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4940     A UDP socket server.
4942 +*socket pipe*+::
4943     A synonym for `pipe`
4945 +*socket pair*+::
4946     A socketpair (see socketpair(2)). Like `pipe`, this command returns
4947     a list of two channels: {s1 s2}. These channels are both readable and writable.
4949 This command creates a socket connected (client) or bound (server) to the given
4950 address.
4952 The returned value is channel and may generally be used with the various file I/O
4953 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
4955 ----
4956     . set f [socket stream www.google.com:80]
4957     aio.sockstream1
4958     . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
4959     . $f gets
4960     HTTP/1.0 302 Found
4961     . $f close
4962 ----
4964 Server sockets, however support only 'accept', which is most useful in conjunction with
4965 the EVENTLOOP API.
4967 ----
4968     set f [socket stream.server 80]
4969     $f readable {
4970         set client [$f accept]
4971         $client gets $buf
4972         ...
4973         $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
4974         $client close
4975     }
4976     vwait done
4977 ----
4979 The address, +'addr'+, can be given in one of the following forms:
4981 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
4982 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
4983 3. A hostname
4985 Note that on many systems, listening on an IPv6 address such as [::] will
4986 also accept requests via IPv4.
4988 Where a hostname is specified, the +'first'+ returned address is used
4989 which matches the socket type is used.
4991 An unconnected dgram socket (either 'dgram' or 'unix.dgram') must use
4992 `sendto` to specify the destination address.
4994 The path for Unix domain sockets is automatically removed when the socket
4995 is closed. Use `close -nodelete` in the rare case where this behaviour
4996 should be avoided (e.g. after `os.fork`).
4998 syslog
4999 ~~~~~~
5000 +*syslog* '?options? ?priority? message'+
5002 This  command sends message to system syslog facility with given
5003 priority. Valid priorities are:
5005     emerg, alert, crit, err, error, warning, notice, info, debug
5007 If a message is specified, but no priority is specified, then a
5008 priority of info is used.
5010 By default, facility user is used and the value of global tcl variable
5011 argv0 is used as ident string. However, any of the following options
5012 may be specified before priority to control these parameters:
5014 +*-facility* 'value'+::
5015     Use specified facility instead of user. The following
5016     values for facility are recognized:
5018     authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
5019     uucp, local0-local7
5021 +*-ident* 'string'+::
5022     Use given string instead of argv0 variable for ident string.
5024 +*-options* 'integer'+::
5025     Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
5026     use numeric values of those from your system syslog.h file,
5027     because I haven't got time to implement yet another hash
5028     table.
5030 pack: pack, unpack
5031 ~~~~~~~~~~~~~~~~~~
5032 The optional 'pack' extension provides commands to encode and decode binary strings.
5034 +*pack* 'varName value' *-intle|-intbe|-floatle|-floatbe|-str* 'bitwidth ?bitoffset?'+::
5035     Packs the binary representation of +'value'+ into the variable
5036     +'varName'+. The value is packed according to the given type
5037     (integer/floating point/string, big-endian/little-endian), width and bit offset.
5038     The variable is created if necessary (like `append`).
5039     The variable is expanded if necessary.
5041 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str* 'bitpos bitwidth'+::
5042     Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
5043     Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
5044     and signed/unsigned) and returns it. For integer types, +'bitwidth'+
5045     may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
5046     +'bitwidth'+ may be 32 bits (for single precision numbers) or 64 bits (for double precision).
5047     For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
5048     access outside the length of the value will return 0 for integer types, 0.0 for floating point types
5049     or the empty string for the string type.
5051 zlib
5052 ~~~~
5053 The optional 'zlib' extension provides a Tcl-compatible subset of the `zlib` command.
5055 +*crc32* 'data' '?startValue?'+::
5056     Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
5057     for calculating the checksum of chunked data read from a stream (for instance, a pipe).
5059 +*deflate* 'string' '?level?'+::
5060     Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
5061     be specified to choose the desired speed vs. compression rate ratio.
5063 +*inflate* 'data' '?bufferSize?'+::
5064     Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
5065     allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
5067 +*gzip* 'string' '?-level level?'+::
5068     Compresses a buffer and adds a gzip header.
5070 +*gunzip* 'data' '?-buffersize size?'+::
5071     Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
5072     which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
5073     systems without a severe memory constraint.
5075 binary
5076 ~~~~~~
5077 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
5078 commands based on the low-level `pack` and `unpack` commands.
5080 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
5082 Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
5083 in case of overflow.
5085 oo: class, super
5086 ~~~~~~~~~~~~~~~~
5087 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
5089 See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.
5091 +*class* 'classname ?baseclasses? classvars'+::
5092     Create a new class, +'classname'+, with the given dictionary
5093     (+'classvars'+) as class variables. These are the initial variables
5094     which all newly created objects of this class are initialised with.
5095     If a list of baseclasses is given, methods and instance variables
5096     are inherited.
5098 +*super* 'method ?args \...?'+::
5099     From within a method, invokes the given method on the base class.
5100     Note that this will only call the last baseclass given.
5102 tree
5103 ~~~~
5104 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
5105 similar to that provided by tcllib ::struct::tree (http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html)
5107 A tree is a collection of nodes, where each node (except the root node) has a single parent
5108 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
5110 +*tree*+::
5111     Creates and returns a new tree object with a single node named "root".
5112     All operations on the tree are invoked through this object.
5114 +$tree *destroy*+::
5115     Destroy the tree and all it's nodes. (Note that the tree will also
5116     be automatically garbage collected once it goes out of scope).
5118 +$tree *set* 'nodename key value'+::
5119     Set the value for the given attribute key.
5121 +$tree *lappend* 'nodename key value \...'+::
5122     Append to the (list) value(s) for the given attribute key, or set if not yet set.
5124 +$tree *keyexists* 'nodename key'+::
5125     Returns 1 if the given attribute key exists.
5127 +$tree *get* 'nodename key'+::
5128     Returns the value associated with the given attribute key.
5130 +$tree *getall* 'nodename'+::
5131     Returns the entire attribute dictionary associated with the given key.
5133 +$tree *depth* 'nodename'+::
5134     Returns the depth of the given node. The depth of "root" is 0.
5136 +$tree *parent* 'nodename'+::
5137     Returns the node name of the parent node, or "" for the root node.
5139 +$tree *numchildren* 'nodename'+::
5140     Returns the number of child nodes.
5142 +$tree *children* 'nodename'+::
5143     Returns a list of the child nodes.
5145 +$tree *next* 'nodename'+::
5146     Returns the next sibling node, or "" if none.
5148 +$tree *insert* 'nodename ?index?'+::
5149     Add a new child node to the given node. The index is a list index
5150     such as +3+ or +end-2+. The default index is +end+.
5151     Returns the name of the newly added node.
5153 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
5154     Walks the tree starting from the given node, either breadth first (+bfs+)
5155     depth first (+dfs+).
5156     The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
5157     The name of each node is stored in +'nodevar'+.
5158     The script is evaluated twice for each node, on entry and exit.
5160 +$tree *dump*+::
5161     Dumps the tree contents to stdout
5163 tcl::prefix
5164 ~~~~~~~~~~~
5165 The optional tclprefix extension provides the Tcl8.6-compatible `tcl::prefix` command
5166 (http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm) for matching strings against a table
5167 of possible values (typically commands or options).
5169 +*tcl::prefix all* 'table string'+::
5170     Returns a list of all elements in +'table'+ that begin with the prefix +'string'+.
5172 +*tcl::prefix longest* 'table string'+::
5173     Returns the longest common prefix of all elements in +'table'+ that begin with the prefix +'string'+.
5175 +*tcl::prefix match* '?options? table string'+::
5176     If +'string'+ equals one element in +'table'+ or is a prefix to
5177     exactly one element, the matched element is returned. If not, the
5178     result depends on the +-error+ option.
5180     * +*-exact*+ Accept only exact matches.
5181     * +*-message* 'string'+ Use +'string'+ in the error message at a mismatch. Default is "option".
5182     * +*-error* 'options'+ The options are used when no match is found. If +'options'+ is
5183       empty, no error is generated and an empty string is returned.
5184       Otherwise the options are used as return options when
5185       generating the error message. The default corresponds to
5186       setting +-level 0+.
5188 tcl::autocomplete
5189 ~~~~~~~~~~~~~~~~~
5190 Scriptable command line completion is supported in the interactive shell, 'jimsh', through
5191 the `tcl::autocomplete` callback. A simple implementation is provided, however this may
5192 be replaced with a custom command instead if desired.
5194 In the interactive shell, press <TAB> to activate command line completion.
5196 +*tcl::autocomplete* 'commandline'+::
5197     This command is called with the current command line when the user presses <TAB>.
5198     The command should return a list of all possible command lines that match the current command line.
5199     For example if +*pr*+ is the current command line, the list +*{prefix proc}*+ may be returned.
5201 history
5202 ~~~~~~~
5203 The optional history extension provides script access to the command line editing
5204 and history support available in 'jimsh'. See 'examples/jtclsh.tcl' for an example.
5205 Note: if line editing support is not available, `history getline` acts like `gets` and
5206 the remaining subcommands do nothing.
5208 +*history load* 'filename'+::
5209     Load history from a (text) file. If the file does not exist or is not readable,
5210     it is ignored.
5212 +*history getline* 'prompt ?varname?'+::
5213     Displays the given prompt and allows a line to be entered. Similarly to `gets`,
5214     if +'varname'+ is given, it receives the line and the length of the line is returned,
5215     or -1 on EOF. If +'varname'+ is not given, the line is returned directly.
5217 +*history completion* 'command'+::
5218     Sets an autocompletion command (see `tcl::autocomplete`) that is active during `history getline`.
5219     If the command is empty, autocompletion is disabled.
5221 +*history add* 'line'+::
5222     Adds the given line to the history buffer.
5224 +*history save* 'filename'+::
5225     Saves the current history buffer to the given file.
5227 +*history show*+::
5228     Displays the current history buffer to standard output.
5230 namespace
5231 ~~~~~~~~~
5232 Provides namespace-related functions. See also: http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
5234 +*namespace code* 'script'+::
5235     Captures the current namespace context for later execution of
5236     the script +'script'+. It returns a new script in which script has
5237     been wrapped in a +*namespace inscope*+ command.
5239 +*namespace current*+::
5240     Returns the fully-qualified name for the current namespace.
5242 +*namespace delete* '?namespace ...?'+::
5243     Deletes all commands and variables with the given namespace prefixes.
5245 +*namespace eval* 'namespace arg ?arg...?'+::
5246     Activates a namespace called +'namespace'+ and evaluates some code in that context.
5248 +*namespace origin* 'command'+::
5249     Returns the fully-qualified name of the original command to which the imported command +'command'+ refers.
5251 +*namespace parent* ?namespace?+::
5252     Returns the fully-qualified name of the parent namespace for namespace +'namespace'+, if given, otherwise
5253     for the current namespace.
5255 +*namespace qualifiers* 'string'+::
5256     Returns any leading namespace qualifiers for +'string'+
5258 +*namespace tail* 'string'+::
5259     Returns the simple name at the end of a qualified string.
5261 +*namespace upvar* 'namespace ?arg...?'+::
5262     This command arranges for zero or more local variables in the current procedure to refer to variables in +'namespace'+
5264 +*namespace which* '?-command|-variable? name'+::
5265     Looks up +'name'+ as either a command (the default) or variable and returns its fully-qualified name.
5267 interp
5268 ~~~~~~
5269 The optional 'interp' command allows sub-interpreters to be created where commands may be run
5270 independently (but synchronously) of the main interpreter.
5272 +*interp*+::
5273     Creates and returns a new interpreter object (command).
5274     The created interpeter contains any built-in commands along with static extensions,
5275     but does not include any dynamically loaded commands (package require, load).
5276     These must be reloaded in the child interpreter if required.
5278 +*$interp delete*+::
5279     Deletes the interpeter object.
5281 +*$interp eval* 'script' ...+::
5282     Evaluates a script in the context for the child interpreter, in the same way as 'eval'.
5284 +*$interp alias* 'alias childcmd parentcmd ?arg ...?'+::
5285     Similar to 'alias', but creates a command, +'childcmd'+, in the child interpreter that is an
5286     alias for +'parentcmd'+ in the parent interpreter, with the given, fixed arguments.
5287     The alias may be deleted in the child with 'rename'.
5289 json::encode
5290 ~~~~~~~~~~~~
5292 The Tcl -> JSON encoder is part of the optional 'json' package.
5294 +*json::encode* 'value ?schema?'+::
5296 Encode a Tcl value as JSON according to the schema (defaults to +'str'+). The following schema types are supported:
5297 * 'str' - Tcl string -> JSON string
5298 * 'num' - Tcl value -> bare numeric value or null
5299 * 'bool' - Tcl boolean value -> true, false
5300 * 'obj ?name subschema ...?' - Tcl dict -> JSON object. For each dict key matching 'name', the corresponding 'subschema'
5301 is applied. The special name +'*'+ matches any keys not otherwise matched, otherwise the default +'str'+ is used.
5302 * 'list ?subschema?' - Tcl list -> JSON array. The 'subschema' (default +'str'+) is applied for each element of the list/array.
5303 * 'mixed ?subschema ...?' = Tcl list -> JSON array. Each 'subschema' is applied for the corresponding element of the list/array.
5304   ::
5305 The following are examples:
5306 ----
5307     . json::encode {1 2 true false null 5.0} list
5308     [ "1", "2", "true", "false", "null", "5.0" ]
5309     . json::encode {1 2 true false null 5.0} {list num}
5310     [ 1, 2, true, false, null, 5.0 ]
5311     . json::encode {0 1 2 true false 5.0 off} {list bool}
5312     [ false, true, true, true, false, true, false ]
5313     . json::encode {a 1 b hello c {3 4}} obj
5314     { "a":"1", "b":"hello", "c":"3 4" }
5315     . json::encode {a 1 b hello c {3 4}} {obj a num c {list num}}
5316     { "a":1, "b":"hello", "c":[ 3, 4 ] }
5317     . json::encode {true true {abc def}} {mixed str num obj}
5318     [ "true", true, { "abc":"def" } ]
5319     . json::encode {a 1 b 3.0 c hello d null} {obj c str * num}
5320     { "a":1, "b":3.0, "c":"hello", "d":null }
5321 ----
5323 json::decode
5324 ~~~~~~~~~~~~
5326 The JSON -> Tcl decoder is part of the optional 'json' package.
5328 +*json::decode* ?*-index*? ?*-null* 'string'? ?*-schema*? 'json-string'+::
5330 Decodes the given JSON string (must be array or object) into a Tcl data structure. If '+-index+' is specified,
5331 decodes JSON arrays as dictionaries with numeric keys. This makes it possible to retrieve data from nested
5332 arrays and dictionaries with just '+dict get+'. With the option '+-schema+' returns a list of +'{data schema}'+
5333 where the schema is compatible with `json::encode`. Otherwise just returns the data.
5334 Decoding is as follows (with schema types listed in parentheses):
5335 * object -> dict ('obj')
5336 * array -> list ('mixed' or 'list')
5337 * number -> as-is ('num')
5338 * boolean -> as-is ('bool')
5339 * string -> string ('str')
5340 * null -> supplied null string or the default +'"null"'+ ('num')
5341  ::
5342  Note that an object decoded into a dict will return the keys in the same order as the original string.
5343 ----
5344     . json::decode {[1, 2]}
5345     {1 2}
5346     . json::decode -schema {[1, 2]}
5347     {1 2} {list num}
5348     . json::decode -schema {{"a":1, "b":2}}
5349     {a 1 b 2} {obj a num b num}
5350     . json::decode -schema {[1, 2, {a:"b", c:false}, "hello"]}
5351     {1 2 {a b c false} hello} {mixed num num {obj a str c bool} str}
5352     . json::decode -index {["foo", "bar"]}
5353     {0 foo 1 bar}
5354 ----
5356 [[BuiltinVariables]]
5357 BUILT-IN VARIABLES
5358 ------------------
5360 The following global variables are created automatically
5361 by the Tcl library.
5363 +*env*+::
5364     This variable is set by Jim as an array
5365     whose elements are the environment variables for the process.
5366     Reading an element will return the value of the corresponding
5367     environment variable.
5368     This array is initialised at startup from the `env` command.
5369     It may be modified and will affect the environment passed to
5370     commands invoked with `exec`.
5372 +*platform_tcl*+::
5373     This variable is set by Jim as an array containing information
5374     about the platform on which Jim was built. Currently this includes
5375     'os' and 'platform'.
5377 +*auto_path*+::
5378     This variable contains a list of paths to search for packages.
5379     It defaults to a location based on where jim is installed
5380     (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
5381     or the embedding application. Note that +jimsh+ will consider
5382     the environment variable +$JIMLIB+ to be a list of colon-separated
5383     list of paths to add to +*auto_path*+.
5385 +*errorCode*+::
5386     This variable holds the value of the -errorcode return
5387     option set by the most recent error that occurred in this
5388     interpreter. This list value represents additional information
5389     about the error in a form that is easy to process with
5390     programs. The first element of the list identifies a general
5391     class of errors, and determines the format of the rest of
5392     the list. The following formats for -errorcode return options
5393     are used by the Tcl core; individual applications may define
5394     additional formats. Currently only `exec` sets this variable.
5395     Otherwise it will be +NONE+.
5397 The following global variables are set by jimsh.
5399 +*tcl_interactive*+::
5400     This variable is set to 1 if jimsh is started in interactive mode
5401     or 0 otherwise.
5403 +*tcl_platform*+::
5404     This variable is set by Jim as an array containing information
5405     about the platform upon which Jim was built. The following is an
5406     example of the contents of this array.
5408 ----
5409     tcl_platform(byteOrder)     = littleEndian
5410     tcl_platform(engine)        = Jim
5411     tcl_platform(os)            = Darwin
5412     tcl_platform(platform)      = unix
5413     tcl_platform(pointerSize)   = 8
5414     tcl_platform(threaded)      = 0
5415     tcl_platform(wordSize)      = 8
5416     tcl_platform(pathSeparator) = :
5417 ----
5419 +*argv0*+::
5420     If jimsh is invoked to run a script, this variable contains the name
5421     of the script.
5423 +*argv*+::
5424     If jimsh is invoked to run a script, this variable contains a list
5425     of any arguments supplied to the script.
5427 +*argc*+::
5428     If jimsh is invoked to run a script, this variable contains the number
5429     of arguments supplied to the script.
5431 +*jim::argv0*+::
5432     The value of argv[0] when jimsh was invoked.
5434 The following variables have special meaning to Jim Tcl:
5436 +*jim::defer*+::
5437     If this variable is set, it is considered to be a list of scripts to evaluate
5438     when the current proc exits (local variables), or the interpreter exits (global variable).
5439     See `defer`.
5441 +*history::multiline*+::
5442     If this variable is set to "1", interactive line editing operates in multiline mode.
5443     That is, long lines will wrap across multiple lines rather than scrolling within a
5444     single line.
5446 CHANGES IN PREVIOUS RELEASES
5447 ----------------------------
5449 === In v0.74 ===
5451 1. Numbers with leading zeros are treated as decimal, not octal
5452 2. Add `aio isatty`
5453 3. Add LFS (64 bit) support for `aio seek`, `aio tell`, `aio copyto`, `file copy`
5454 4. `string compare` and `string equal` now support '-length'
5455 5. `glob` now supports '-directory'
5457 === In v0.73 ===
5459 1. Built-in regexp now support non-capturing parentheses: (?:...)
5460 2. Add `string replace`
5461 3. Add `string totitle`
5462 4. Add `info statics`
5463 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions)
5464 6. `local` now works with any command, not just procs
5465 7. Add `info alias` to access the target of an alias
5466 8. UTF-8 encoding past the basic multilingual plane (BMP) is supported
5467 9. Add `tcl::prefix`
5468 10. Add `history`
5469 11. Most extensions are now enabled by default
5470 12. Add support for namespaces and the `namespace` command
5471 13. Add `apply`
5473 === In v0.72 ===
5475 1. procs now allow 'args' and optional parameters in any position
5476 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
5477 3. Add support for the '-force' option to `file delete`
5478 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
5479 5. New +tcl_platform(pathSeparator)+
5480 6. Add support settings the modification time with `file mtime`
5481 7. `exec` is now fully supported on win32 (mingw32)
5482 8. `file join`, `pwd`, `glob` etc. now work for mingw32
5483 9. Line editing is now supported for the win32 console (mingw32)
5484 10. Add `aio listen` command
5486 === In v0.71 ===
5488 1. Allow 'args' to be renamed in procs
5489 2. Add +$(...)+ shorthand syntax for expressions
5490 3. Add automatic reference variables in procs with +&var+ syntax
5491 4. Support +jimsh --version+
5492 5. Additional variables in +tcl_platform()+
5493 6. `local` procs now push existing commands and `upcall` can call them
5494 7. Add `loop` command (TclX compatible)
5495 8. Add `aio buffering` command
5496 9. `info complete` can now return the missing character
5497 10. `binary format` and `binary scan` are now (optionally) supported
5498 11. Add `string byterange`
5499 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
5502 === In v0.70 ===
5504 1. +platform_tcl()+ settings are now automatically determined
5505 2. Add aio `$handle filename`
5506 3. Add `info channels`
5507 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
5508 5. Add `exists` command
5509 6. Add the pure-Tcl 'oo' extension
5510 7. The `exec` command now only uses vfork(), not fork()
5511 8. Unit test framework is less verbose and more Tcl-compatible
5512 9. Optional UTF-8 support
5513 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
5514 11. Command line editing in interactive mode, e.g. 'jimsh'
5516 === In v0.63 ===
5518 1. `source` now checks that a script is complete (.i.e. not missing a brace)
5519 2. 'info complete' now uses the real parser and so is 100% accurate
5520 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
5521 4. `tailcall` no longer loses stack trace information
5522 5. Add `alias` and `curry`
5523 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
5524 7. `local` allows procedures to be deleted automatically at the end of the current procedure
5525 8. udp sockets are now supported for both clients and servers.
5526 9. vfork-based exec is now working correctly
5527 10. Add 'file tempfile'
5528 11. Add 'socket pipe'
5529 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
5530 13. It is now possible to `return` from within `try`
5531 14. IPv6 support is now included
5532 15. Add 'string is'
5533 16. Event handlers works better if an error occurs. eof handler has been removed.
5534 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
5535 18. Command pipelines via open "|..." are now supported
5536 19. `pid` can now return pids of a command pipeline
5537 20. Add 'info references'
5538 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
5539 22. `exec` now sets environment based on $::env
5540 23. Add 'dict keys'
5541 24. Add support for 'lsort -index'
5543 === In v0.62 ===
5545 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
5546 2. Fix `exec` error messages when special token (e.g. '>') is the last token
5547 3. Fix `subst` handling of backslash escapes.
5548 4. Allow abbreviated options for `subst`
5549 5. Add support for `return`, `break`, `continue` in subst
5550 6. Many `expr` bug fixes
5551 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
5552 8. The variable name argument to `regsub` is now optional
5553 9. Add support for 'unset -nocomplain'
5554 10. Add support for list commands: `lassign`, `lrepeat`
5555 11. Fully-functional `lsearch` is now implemented
5556 12. Add 'info nameofexecutable' and 'info returncodes'
5557 13. Allow `catch` to determine what return codes are caught
5558 14. Allow `incr` to increment an unset variable by first setting to 0
5559 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
5560 16. Add 'file copy'
5561 17. Add 'try ... finally' command
5564 LICENCE
5565 -------
5567  Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5568  Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
5569  Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
5570  Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
5571  Copyright 2008 Andrew Lunn <andrew@lunn.ch>
5572  Copyright 2008 Duane Ellis <openocd@duaneellis.com>
5573  Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
5574  Copyright 2009 Steve Bennett <steveb@workware.net.au>
5576 [literal]
5577  Redistribution and use in source and binary forms, with or without
5578  modification, are permitted provided that the following conditions
5579  are met:
5580  1. Redistributions of source code must retain the above copyright
5581     notice, this list of conditions and the following disclaimer.
5582  2. Redistributions in binary form must reproduce the above
5583     copyright notice, this list of conditions and the following
5584     disclaimer in the documentation and/or other materials
5585     provided with the distribution.
5587  THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
5588  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
5589  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5590  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5591  JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
5592  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5593  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5594  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5595  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5596  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5597  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5598  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5600  The views and conclusions contained in the software and documentation
5601  are those of the authors and should not be interpreted as representing
5602  official policies, either expressed or implied, of the Jim Tcl Project.