aio: Don't use FD_CLOEXEC with JIM_ANSIC
[jimtcl.git] / jim_tcl.txt
blob64642a94630f0f9d94712914a318f60b317264b3
1 Jim Tcl(n)
2 ==========
4 NAME
5 ----
6 Jim Tcl v0.78+ - 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 since 0.78
56 ~~~~~~~~~~~~~~~~~~
57 1. Add `file mtimeus` for high resolution file timestamps
59 Changes between 0.77 and 0.78
60 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 1. Add serial/tty support with `aio tty`
62 2. Add support for 'jimsh -'
63 3. Add hidden '-commands' option to many commands
64 4. Add scriptable autocompletion support in interactive mode with `tcl::autocomplete`
65 5. Add `aio sockopt`
66 6. Add scriptable autocompletion support with `history completion`
67 7. Add support for `tree delete`
68 8. Add support for `defer` and '$jim::defer'
69 9. Renamed `os.wait` to `wait`, now more Tcl-compatible and compatible with `exec ... &`
70 10. `pipe` is now a synonym for `socket pipe`
71 11. Closing a pipe open with `open |...` now returns Tcl-like status
72 12. It is now possible to used `exec` redirection with a pipe opened with `open |...`
73 13. Interactive line editing now supports multiline mode if $::history::multiline is set
75 Changes between 0.76 and 0.77
76 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77 1. Add support for `aio sync`
78 2. Add SSL and TLS support in aio
79 3. Added `zlib`
80 4. Added support for boolean constants in `expr`
81 5. `string is` now supports 'boolean' class
82 6. Add support for `aio lock` and `aio unlock`
83 7. Add new `interp` command
85 Changes between 0.75 and 0.76
86 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 1. `glob` now supports the +-tails+ option
88 2. Add support for `string cat`
89 3. Allow `info source` to add source info
91 Changes between 0.74 and 0.75
92 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93 1. `binary`, `pack` and `unpack` now support floating point
94 2. `file copy` +-force+ handles source and target as the same file
95 3. `format` now supports +%b+ for binary conversion
96 4. `lsort` now supports +-unique+ and +-real+
97 5. Add support for half-close with `aio close` +?r|w?+
98 6. Add `socket pair` for a bidirectional pipe
99 7. Add '--random-hash' to randomise hash tables for greater security
100 8. `dict` now supports 'for', 'values', 'incr', 'append', 'lappend', 'update', 'info' and 'replace'
101 9. `file stat` no longer requires the variable name
102 10. Add support for `file link`
104 Changes between 0.73 and 0.74
105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106 1. Numbers with leading zeros are treated as decimal, not octal
107 2. Add `aio isatty`
108 3. Add LFS (64 bit) support for `aio seek`, `aio tell`, `aio copyto`, `file copy`
109 4. `string compare` and `string equal` now support '-length'
110 5. `glob` now supports '-directory'
112 Changes between 0.72 and 0.73
113 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114 1. Built-in regexp now support non-capturing parentheses: (?:...)
115 2. Add `string replace`
116 3. Add `string totitle`
117 4. Add `info statics`
118 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions)
119 6. `local` now works with any command, not just procs
120 7. Add `info alias` to access the target of an alias
121 8. UTF-8 encoding past the basic multilingual plane (BMP) is supported
122 9. Add `tcl::prefix`
123 10. Add `history`
124 11. Most extensions are now enabled by default
125 12. Add support for namespaces and the `namespace` command
126 13. Add `apply`
128 Changes between 0.71 and 0.72
129 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130 1. procs now allow 'args' and optional parameters in any position
131 2. Add Tcl-compatible expr functions, `rand()`, `srand()` and `pow()`
132 3. Add support for the '-force' option to `file delete`
133 4. Better diagnostics when `source` fails to load a script with a missing quote or bracket
134 5. New +tcl_platform(pathSeparator)+
135 6. Add support settings the modification time with `file mtime`
136 7. `exec` is now fully supported on win32 (mingw32)
137 8. `file join`, `pwd`, `glob` etc. now work for mingw32
138 9. Line editing is now supported for the win32 console (mingw32)
139 10. Add `aio listen` command
141 Changes between 0.70 and 0.71
142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143 1. Allow 'args' to be renamed in procs
144 2. Add +$(...)+ shorthand syntax for expressions
145 3. Add automatic reference variables in procs with +&var+ syntax
146 4. Support +jimsh --version+
147 5. Additional variables in +tcl_platform()+
148 6. `local` procs now push existing commands and `upcall` can call them
149 7. Add `loop` command (TclX compatible)
150 8. Add `aio buffering` command
151 9. `info complete` can now return the missing character
152 10. `binary format` and `binary scan` are now (optionally) supported
153 11. Add `string byterange`
154 12. Built-in regexp now support non-greedy repetition (*?, +?, ??)
156 TCL INTRODUCTION
157 -----------------
158 Tcl stands for 'tool command language' and is pronounced
159 'http://www.oxforddictionaries.com/definition/american_english/tickle[tickle]'.
160 It is actually two things: a language and a library.
162 First, Tcl is a simple textual language, intended primarily for
163 issuing commands to interactive programs such as text editors,
164 debuggers, illustrators, and shells.  It has a simple syntax and is also
165 programmable, so Tcl users can write command procedures to provide more
166 powerful commands than those in the built-in set.
168 Second, Tcl is a library package that can be embedded in application
169 programs.  The Tcl library consists of a parser for the Tcl language,
170 routines to implement the Tcl built-in commands, and procedures that
171 allow each application to extend Tcl with additional commands specific
172 to that application.  The application program generates Tcl commands and
173 passes them to the Tcl parser for execution.  Commands may be generated
174 by reading characters from an input source, or by associating command
175 strings with elements of the application's user interface, such as menu
176 entries, buttons, or keystrokes.
178 When the Tcl library receives commands it parses them into component
179 fields and executes built-in commands directly.  For commands implemented
180 by the application, Tcl calls back to the application to execute the
181 commands.  In many cases commands will invoke recursive invocations of the
182 Tcl interpreter by passing in additional strings to execute (procedures,
183 looping commands, and conditional commands all work in this way).
185 An application program gains three advantages by using Tcl for its command
186 language.  First, Tcl provides a standard syntax:  once users know Tcl,
187 they will be able to issue commands easily to any Tcl-based application.
188 Second, Tcl provides programmability.  All a Tcl application needs
189 to do is to implement a few application-specific low-level commands.
190 Tcl provides many utility commands plus a general programming interface
191 for building up complex command procedures.  By using Tcl, applications
192 need not re-implement these features.
194 Third, Tcl can be used as a common language for communicating between
195 applications.  Inter-application communication is not built into the
196 Tcl core described here, but various add-on libraries, such as the Tk
197 toolkit, allow applications to issue commands to each other.  This makes
198 it possible for applications to work together in much more powerful ways
199 than was previously possible.
201 Fourth, Jim Tcl includes a command processor, +jimsh+, which can be
202 used to run standalone Tcl scripts, or to run Tcl commands interactively.
204 This manual page focuses primarily on the Tcl language.  It describes
205 the language syntax and the built-in commands that will be available
206 in any application based on Tcl.  The individual library procedures are
207 described in more detail in separate manual pages, one per procedure.
209 JIMSH COMMAND INTERPRETER
210 -------------------------
211 A simple, but powerful command processor, +jimsh+, is part of Jim Tcl.
212 It may be invoked in interactive mode as:
214   jimsh
216 or to process the Tcl script in a file with:
218   jimsh filename
220 or to process the Tcl script from standard input:
222   jimsh -
224 It may also be invoked to execute an immediate script with:
226   jimsh -e "script"
228 Interactive Mode
229 ~~~~~~~~~~~~~~~~
230 Interactive mode reads Tcl commands from standard input, evaluates
231 those commands and prints the results.
233   $ jimsh
234   Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
235   . info version
236   0.73
237   . lsort [info commands p*]
238   package parray pid popen proc puts pwd
239   . foreach i {a b c} {
240   {> puts $i
241   {> }
242   a
243   b
244   c
245   . bad
246   invalid command name "bad"
247   [error] . exit
248   $
250 If +jimsh+ is configured with line editing (it is by default) and a VT-100-compatible
251 terminal is detected, Emacs-style line editing commands are available, including:
252 arrow keys, +\^W+ to erase a word, +\^U+ to erase the line, +^R+ for reverse incremental search
253 in history. Additionally, the +h+ command may be used to display the command history.
255 Command line history is automatically saved and loaded from +~/.jim_history+
257 In interactive mode, +jimsh+ automatically runs the script +~/.jimrc+ at startup
258 if it exists.
260 INTERPRETERS
261 ------------
262 The central data structure in Tcl is an interpreter (C type 'Jim_Interp').
263 An interpreter consists of a set of command bindings, a set of variable
264 values, and a few other miscellaneous pieces of state.  Each Tcl command
265 is interpreted in the context of a particular interpreter.
267 Some Tcl-based applications will maintain multiple interpreters
268 simultaneously, each associated with a different widget or portion of
269 the application.  Interpreters are relatively lightweight structures.
270 They can be created and deleted quickly, so application programmers should
271 feel free to use multiple interpreters if that simplifies the application.
273 DATA TYPES
274 ----------
275 Tcl supports only one type of data:  strings.  All commands, all arguments
276 to commands, all command results, and all variable values are strings.
278 Where commands require numeric arguments or return numeric results,
279 the arguments and results are passed as strings.  Many commands expect
280 their string arguments to have certain formats, but this interpretation
281 is up to the individual commands.  For example, arguments often contain
282 Tcl command strings, which may get executed as part of the commands.
283 The easiest way to understand the Tcl interpreter is to remember that
284 everything is just an operation on a string.  In many cases Tcl constructs
285 will look similar to more structured constructs from other languages.
286 However, the Tcl constructs are not structured at all; they are just
287 strings of characters, and this gives them a different behaviour than
288 the structures they may look like.
290 Although the exact interpretation of a Tcl string depends on who is doing
291 the interpretation, there are three common forms that strings take:
292 commands, expressions, and lists.  The major sections below discuss
293 these three forms in more detail.
295 BASIC COMMAND SYNTAX
296 --------------------
297 The Tcl language has syntactic similarities to both the Unix shells
298 and Lisp.  However, the interpretation of commands is different
299 in Tcl than in either of those other two systems.
300 A Tcl command string consists of one or more commands separated
301 by newline characters or semi-colons.
302 Each command consists of a collection of fields separated by
303 white space (spaces or tabs).
304 The first field must be the name of a command, and the
305 additional fields, if any, are arguments that will be passed to
306 that command.  For example, the command:
308     set a 22
310 has three fields:  the first, `set`, is the name of a Tcl command, and
311 the last two, 'a' and '22', will be passed as arguments to
312 the `set` command.  The command name may refer either to a built-in
313 Tcl command, an application-specific command bound in with the library
314 procedure 'Jim_CreateCommand', or a command procedure defined with the
315 `proc` built-in command.
317 Arguments are passed literally as text strings.  Individual commands may
318 interpret those strings in any fashion they wish.  The `set` command,
319 for example, will treat its first argument as the name of a variable
320 and its second argument as a string value to assign to that variable.
321 For other commands arguments may be interpreted as integers, lists,
322 file names, or Tcl commands.
324 Command names should normally be typed completely (e.g. no abbreviations).
325 However, if the Tcl interpreter cannot locate a command it invokes a
326 special command named `unknown` which attempts to find or create the
327 command.
329 For example, at many sites `unknown` will search through library
330 directories for the desired command and create it as a Tcl procedure if
331 it is found.  The `unknown` command often provides automatic completion
332 of abbreviated commands, but usually only for commands that were typed
333 interactively.
335 It's probably a bad idea to use abbreviations in command scripts and
336 other forms that will be re-used over time:  changes to the command set
337 may cause abbreviations to become ambiguous, resulting in scripts that
338 no longer work.
340 COMMENTS
341 --------
342 If the first non-blank character in a command is +\#+, then everything
343 from the +#+ up through the next newline character is treated as
344 a comment and ignored.  When comments are embedded inside nested
345 commands (e.g. fields enclosed in braces) they must have properly-matched
346 braces (this is necessary because when Tcl parses the top-level command
347 it doesn't yet know that the nested field will be used as a command so
348 it cannot process the nested comment character as a comment).
350 GROUPING ARGUMENTS WITH DOUBLE-QUOTES
351 -------------------------------------
352 Normally each argument field ends at the next white space, but
353 double-quotes may be used to create arguments with embedded space.
355 If an argument field begins with a double-quote, then the argument isn't
356 terminated by white space (including newlines) or a semi-colon (see below
357 for information on semi-colons); instead it ends at the next double-quote
358 character.  The double-quotes are not included in the resulting argument.
359 For example, the command
361     set a "This is a single argument"
363 will pass two arguments to `set`:  'a' and 'This is a single argument'.
365 Within double-quotes, command substitutions, variable substitutions,
366 and backslash substitutions still occur, as described below.  If the
367 first character of a command field is not a quote, then quotes receive
368 no special interpretation in the parsing of that field.
370 GROUPING ARGUMENTS WITH BRACES
371 ------------------------------
372 Curly braces may also be used for grouping arguments.  They are similar
373 to quotes except for two differences.  First, they nest; this makes them
374 easier to use for complicated arguments like nested Tcl command strings.
375 Second, the substitutions described below for commands, variables, and
376 backslashes do *not* occur in arguments enclosed in braces, so braces
377 can be used to prevent substitutions where they are undesirable.
379 If an argument field begins with a left brace, then the argument ends
380 at the matching right brace.  Tcl will strip off the outermost layer
381 of braces and pass the information between the braces to the command
382 without any further modification.  For example, in the command
384     set a {xyz a {b c d}}
386 the `set` command will receive two arguments: 'a'
387 and 'xyz a {b c d}'.
389 When braces or quotes are in effect, the matching brace or quote need
390 not be on the same line as the starting quote or brace; in this case
391 the newline will be included in the argument field along with any other
392 characters up to the matching brace or quote.  For example, the `eval`
393 command takes one argument, which is a command string; `eval` invokes
394 the Tcl interpreter to execute the command string.  The command
396     eval {
397       set a 22
398       set b 33
399     }
401 will assign the value '22' to 'a' and '33' to 'b'.
403 If the first character of a command field is not a left
404 brace, then neither left nor right
405 braces in the field will be treated specially (except as part of
406 variable substitution; see below).
408 COMMAND SUBSTITUTION WITH BRACKETS
409 ----------------------------------
410 If an open bracket occurs in a field of a command, then command
411 substitution occurs (except for fields enclosed in braces).  All of the
412 text up to the matching close bracket is treated as a Tcl command and
413 executed immediately.  Then the result of that command is substituted
414 for the bracketed text.  For example, consider the command
416     set a [set b]
418 When the `set` command has only a single argument, it is the name of a
419 variable and `set` returns the contents of that variable.  In this case,
420 if variable 'b' has the value 'foo', then the command above is equivalent
421 to the command
423     set a foo
425 Brackets can be used in more complex ways.  For example, if the variable
426 'b' has the value 'foo' and the variable 'c' has the value 'gorp',
427 then the command
429     set a xyz[set b].[set c]
431 is equivalent to the command
433     set a xyzfoo.gorp
436 A bracketed command may contain multiple commands separated by newlines
437 or semi-colons in the usual fashion.  In this case the value of the last
438 command is used for substitution.  For example, the command
440     set a x[set b 22
441     expr $b+2]x
443 is equivalent to the command
445     set a x24x
448 If a field is enclosed in braces then the brackets and the characters
449 between them are not interpreted specially; they are passed through to
450 the argument verbatim.
452 VARIABLE SUBSTITUTION WITH $
453 ----------------------------
454 The dollar sign (+$+) may be used as a special shorthand form for
455 substituting variable values.  If +$+ appears in an argument that isn't
456 enclosed in braces then variable substitution will occur.  The characters
457 after the +$+, up to the first character that isn't a number, letter,
458 or underscore, are taken as a variable name and the string value of that
459 variable is substituted for the name.
461 For example, if variable 'foo' has the value 'test', then the command
463     set a $foo.c
465 is equivalent to the command
467     set a test.c
469 There are two special forms for variable substitution.  If the next
470 character after the name of the variable is an open parenthesis, then
471 the variable is assumed to be an array name, and all of the characters
472 between the open parenthesis and the next close parenthesis are taken as
473 an index into the array.  Command substitutions and variable substitutions
474 are performed on the information between the parentheses before it is
475 used as an index.
477 For example, if the variable 'x' is an array with one element named
478 'first' and value '87' and another element named '14' and value 'more',
479 then the command
481     set a xyz$x(first)zyx
483 is equivalent to the command
485     set a xyz87zyx
487 If the variable 'index' has the value '14', then the command
489     set a xyz$x($index)zyx
491 is equivalent to the command
493     set a xyzmorezyx
495 For more information on arrays, see VARIABLES AND ARRAYS below.
497 The second special form for variables occurs when the dollar sign is
498 followed by an open curly brace.  In this case the variable name consists
499 of all the characters up to the next curly brace.
501 Array references are not possible in this form:  the name between braces
502 is assumed to refer to a scalar variable.  For example, if variable
503 'foo' has the value 'test', then the command
505     set a abc${foo}bar
507 is equivalent to the command
509     set a abctestbar
512 Variable substitution does not occur in arguments that are enclosed in
513 braces:  the dollar sign and variable name are passed through to the
514 argument verbatim.
516 The dollar sign abbreviation is simply a shorthand form.  +$a+ is
517 completely equivalent to +[set a]+; it is provided as a convenience
518 to reduce typing.
520 SEPARATING COMMANDS WITH SEMI-COLONS
521 ------------------------------------
522 Normally, each command occupies one line (the command is terminated by a
523 newline character).  However, semi-colon (+;+) is treated as a command
524 separator character; multiple commands may be placed on one line by
525 separating them with a semi-colon.  Semi-colons are not treated as
526 command separators if they appear within curly braces or double-quotes.
528 BACKSLASH SUBSTITUTION
529 ----------------------
530 Backslashes may be used to insert non-printing characters into command
531 fields and also to insert special characters like braces and brackets
532 into fields without them being interpreted specially as described above.
534 The backslash sequences understood by the Tcl interpreter are
535 listed below.  In each case, the backslash
536 sequence is replaced by the given character:
537 [[BackslashSequences]]
538 +{backslash}b+::
539     Backspace (0x8)
541 +{backslash}f+::
542     Form feed (0xc)
544 +{backslash}n+::
545     Newline (0xa)
547 +{backslash}r+::
548     Carriage-return (0xd).
550 +{backslash}t+::
551     Tab (0x9).
553 +{backslash}v+::
554     Vertical tab (0xb).
556 +{backslash}{+::
557     Left brace ({).
559 +{backslash}}+::
560     Right brace (}).
562 +{backslash}[+::
563     Open bracket ([).
565 +{backslash}]+::
566     Close bracket (]).
568 +{backslash}$+::
569     Dollar sign ($).
571 +{backslash}<space>+::
572     Space ( ): doesn't terminate argument.
574 +{backslash};+::
575     Semi-colon: doesn't terminate command.
577 +{backslash}"+::
578     Double-quote.
580 +{backslash}<newline>+::
581     Nothing:  this joins two lines together
582     into a single line.  This backslash feature is unique in that
583     it will be applied even when the sequence occurs within braces.
585 +{backslash}{backslash}+::
586     Backslash ('{backslash}').
588 +{backslash}ddd+::
589     The digits +'ddd'+ (one, two, or three of them) give the octal value of
590     the character.  Note that Jim supports null characters in strings.
592 +{backslash}unnnn+::
593 +{backslash}u\{nnn\}+::
594 +{backslash}Unnnnnnnn+::
595     The UTF-8 encoding of the unicode codepoint represented by the hex digits, +'nnnn'+, is inserted.
596     The 'u' form allows for one to four hex digits.
597     The 'U' form allows for one to eight hex digits.
598     The 'u\{nnn\}' form allows for one to eight hex digits, but makes it easier to insert
599     characters UTF-8 characters which are followed by a hex digit.
601 For example, in the command
603     set a \{x\[\ yz\141
605 the second argument to `set` will be +{x[ yza+.
607 If a backslash is followed by something other than one of the options
608 described above, then the backslash is transmitted to the argument
609 field without any special processing, and the Tcl scanner continues
610 normal processing with the next character.  For example, in the
611 command
613     set \*a \\\{foo
615 The first argument to `set` will be +{backslash}*a+ and the second
616 argument will be +{backslash}{foo+.
618 If an argument is enclosed in braces, then backslash sequences inside
619 the argument are parsed but no substitution occurs (except for
620 backslash-newline):  the backslash
621 sequence is passed through to the argument as is, without making
622 any special interpretation of the characters in the backslash sequence.
623 In particular, backslashed braces are not counted in locating the
624 matching right brace that terminates the argument.
625 For example, in the
626 command
628     set a {\{abc}
630 the second argument to `set` will be +{backslash}{abc+.
632 This backslash mechanism is not sufficient to generate absolutely
633 any argument structure; it only covers the
634 most common cases.  To produce particularly complicated arguments
635 it is probably easiest to use the `format` command along with
636 command substitution.
638 STRING AND LIST INDEX SPECIFICATIONS
639 ------------------------------------
641 Many string and list commands take one or more 'index' parameters which
642 specify a position in the string relative to the start or end of the string/list.
644 The index may be one of the following forms:
646 +integer+::
647     A simple integer, where '0' refers to the first element of the string
648     or list.
650 +integer+integer+ or::
651 +integer-integer+::
652     The sum or difference of the two integers. e.g. +2+3+ refers to the 5th element.
653     This is useful when used with (e.g.) +$i+1+ rather than the more verbose
654     +[expr {$i+1\}]+
656 +end+::
657     The last element of the string or list.
659 +end-integer+::
660     The 'nth-from-last' element of the string or list.
662 COMMAND SUMMARY
663 ---------------
664 1. A command is just a string.
665 2. Within a string commands are separated by newlines or semi-colons
666    (unless the newline or semi-colon is within braces or brackets
667    or is backslashed).
668 3. A command consists of fields.  The first field is the name of the command.
669    The other fields are strings that are passed to that command as arguments.
670 4. Fields are normally separated by white space.
671 5. Double-quotes allow white space and semi-colons to appear within
672    a single argument.
673    Command substitution, variable substitution, and backslash substitution
674    still occur inside quotes.
675 6. Braces defer interpretation of special characters.
676    If a field begins with a left brace, then it consists of everything
677    between the left brace and the matching right brace. The
678    braces themselves are not included in the argument.
679    No further processing is done on the information between the braces
680    except that backslash-newline sequences are eliminated.
681 7. If a field doesn't begin with a brace then backslash,
682    variable, and command substitution are done on the field.  Only a
683    single level of processing is done:  the results of one substitution
684    are not scanned again for further substitutions or any other
685    special treatment.  Substitution can
686    occur on any field of a command, including the command name
687    as well as the arguments.
688 8. If the first non-blank character of a command is a +\#+, everything
689    from the +#+ up through the next newline is treated as a comment
690    and ignored.
692 EXPRESSIONS
693 -----------
694 The second major interpretation applied to strings in Tcl is
695 as expressions.  Several commands, such as `expr`, `for`,
696 and `if`, treat one or more of their arguments as expressions
697 and call the Tcl expression processors ('Jim_ExprLong',
698 'Jim_ExprBoolean', etc.) to evaluate them.
700 The operators permitted in Tcl expressions are a subset of
701 the operators permitted in C expressions, and they have the
702 same meaning and precedence as the corresponding C operators.
703 Expressions almost always yield numeric results
704 (integer or floating-point values).
705 For example, the expression
707     8.2 + 6
709 evaluates to 14.2.
711 Tcl expressions differ from C expressions in the way that
712 operands are specified, and in that Tcl expressions support
713 non-numeric operands and string comparisons.
715 A Tcl expression consists of a combination of operands, operators,
716 and parentheses.
718 White space may be used between the operands and operators and
719 parentheses; it is ignored by the expression processor.
720 Where possible, operands are interpreted as integer values.
722 Integer values may be specified in decimal (the normal case) or in
723 hexadecimal (if the first two characters of the operand are '0x').
724 Note that Jim Tcl does *not* treat numbers with leading zeros as octal.
726 If an operand does not have one of the integer formats given
727 above, then it is treated as a floating-point number if that is
728 possible.  Floating-point numbers may be specified in any of the
729 ways accepted by an ANSI-compliant C compiler (except that the
730 'f', 'F', 'l', and 'L' suffixes will not be permitted in
731 most installations).  For example, all of the
732 following are valid floating-point numbers:  2.1, 3., 6e4, 7.91e+16.
734 If no numeric interpretation is possible, then an operand is left
735 as a string (and only a limited set of operators may be applied to
736 it).
738 String constants representing boolean constants
739 (+'0'+, +'1'+, +'false'+, +'off'+, +'no'+, +'true'+, +'on'+, +'yes'+)
740 are also recognized and can be used in logical operations.
742 1. Operands may be specified in any of the following ways:
744 2. As a numeric value, either integer or floating-point.
746 3. As one of valid boolean constants
748 4. As a Tcl variable, using standard '$' notation.
749 The variable's value will be used as the operand.
751 5. As a string enclosed in double-quotes.
752 The expression parser will perform backslash, variable, and
753 command substitutions on the information between the quotes,
754 and use the resulting value as the operand
756 6. As a string enclosed in braces.
757 The characters between the open brace and matching close brace
758 will be used as the operand without any substitutions.
760 7. As a Tcl command enclosed in brackets.
761 The command will be executed and its result will be used as
762 the operand.
764 Where substitutions occur above (e.g. inside quoted strings), they
765 are performed by the expression processor.
766 However, an additional layer of substitution may already have
767 been performed by the command parser before the expression
768 processor was called.
770 As discussed below, it is usually best to enclose expressions
771 in braces to prevent the command parser from performing substitutions
772 on the contents.
774 For some examples of simple expressions, suppose the variable 'a' has
775 the value 3 and the variable 'b' has the value 6.  Then the expression
776 on the left side of each of the lines below will evaluate to the value
777 on the right side of the line:
779     $a + 3.1                6.1
780     2 + "$a.$b"             5.6
781     4*[llength "6 2"]       8
782     {word one} < "word $a"  0
784 The valid operators are listed below, grouped in decreasing order
785 of precedence:
786 [[OperatorPrecedence]]
787 +int() double() round() abs(), rand(), srand()+::
788     Unary functions (except rand() which takes no arguments)
789     * +'int()'+ converts the numeric argument to an integer by truncating down.
790     * +'double()'+ converts the numeric argument to floating point.
791     * +'round()'+ converts the numeric argument to the closest integer value.
792     * +'abs()'+ takes the absolute value of the numeric argument.
793     * +'rand()'+ returns a pseudo-random floating-point value in the range (0,1).
794     * +'srand()'+ takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
796 +sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()+::
797     Unary math functions.
798     If Jim is compiled with math support, these functions are available.
800 +- + ~ !+::
801     Unary minus, unary plus, bit-wise NOT, logical NOT.  None of these operands
802     may be applied to string operands, and bit-wise NOT may be
803     applied only to integers.
805 +** pow(x,y)+::
806     Power. e.g. 'x^y^'. If Jim is compiled with math support, supports doubles and
807     integers. Otherwise supports integers only. (Note that the math-function form
808     has the same highest precedence)
810 +* / %+::
811     Multiply, divide, remainder.  None of these operands may be
812     applied to string operands, and remainder may be applied only
813     to integers.
815 ++ -+::
816     Add and subtract.  Valid for any numeric operands.
818 +<<  >> <<< >>>+::
819     Left and right shift, left and right rotate.  Valid for integer operands only.
821 +<  >  \<=  >=+::
822     Boolean less, greater, less than or equal, and greater than or equal.
823     Each operator produces 1 if the condition is true, 0 otherwise.
824     These operators may be applied to strings as well as numeric operands,
825     in which case string comparison is used.
827 +==  !=+::
828     Boolean equal and not equal.  Each operator produces a zero/one result.
829     Valid for all operand types. *Note* that values will be converted to integers
830     if possible, then floating point types, and finally strings will be compared.
831     It is recommended that 'eq' and 'ne' should be used for string comparison.
833 +eq ne+::
834     String equal and not equal.  Uses the string value directly without
835     attempting to convert to a number first.
837 +in ni+::
838     String in list and not in list. For 'in', result is 1 if the left operand (as a string)
839     is contained in the right operand (as a list), or 0 otherwise. The result for
840     +{$a ni $list}+ is equivalent to +{!($a in $list)}+.
842 +&+::
843     Bit-wise AND.  Valid for integer operands only.
845 +|+::
846     Bit-wise OR.  Valid for integer operands only.
848 +^+::
849     Bit-wise exclusive OR.  Valid for integer operands only.
851 +&&+::
852     Logical AND.  Produces a 1 result if both operands are non-zero, 0 otherwise.
853     Valid for numeric operands only (integers or floating-point).
855 +||+::
856     Logical OR.  Produces a 0 result if both operands are zero, 1 otherwise.
857     Valid for numeric operands only (integers or floating-point).
859 +x ? y : z+::
860     If-then-else, as in C.  If +'x'+
861     evaluates to non-zero, then the result is the value of +'y'+.
862     Otherwise the result is the value of +'z'+.
863     The +'x'+ operand must have a numeric value, while +'y'+ and +'z'+ can
864     be of any type.
866 See the C manual for more details on the results
867 produced by each operator.
868 All of the binary operators group left-to-right within the same
869 precedence level.  For example, the expression
871     4*2 < 7
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     $v ? [a] : [b]
881 only one of +[a]+ or +[b]+ will actually be evaluated,
882 depending on the value of +$v+.
884 All internal computations involving integers are done with the C
885 type 'long long' if available, or 'long' otherwise, and all internal
886 computations involving floating-point are done with the C type
887 'double'.
889 When converting a string to floating-point, exponent overflow is
890 detected and results in a Tcl error.
891 For conversion to integer from string, detection of overflow depends
892 on the behaviour of some routines in the local C library, so it should
893 be regarded as unreliable.
894 In any case, overflow and underflow are generally not detected
895 reliably for intermediate results.
897 Conversion among internal representations for integer, floating-point,
898 string operands is done automatically as needed.
899 For arithmetic computations, integers are used until some
900 floating-point number is introduced, after which floating-point is used.
901 For example,
903     5 / 4
905 yields the result 1, while
907     5 / 4.0
908     5 / ( [string length "abcd"] + 0.0 )
910 both yield the result 1.25.
912 String values may be used as operands of the comparison operators,
913 although the expression evaluator tries to do comparisons as integer
914 or floating-point when it can.
915 If one of the operands of a comparison is a string and the other
916 has a numeric value, the numeric operand is converted back to
917 a string using the C 'sprintf' format specifier
918 '%d' for integers and '%g' for floating-point values.
919 For example, the expressions
921     "0x03" > "2"
922     "0y" < "0x12"
924 both evaluate to 1.  The first comparison is done using integer
925 comparison, and the second is done using string comparison after
926 the second operand is converted to the string '18'.
928 In general it is safest to enclose an expression in braces when
929 entering it in a command:  otherwise, if the expression contains
930 any white space then the Tcl interpreter will split it
931 among several arguments.  For example, the command
933     expr $a + $b
935 results in three arguments being passed to `expr`:  +$a+,
936 \+, and +$b+.  In addition, if the expression isn't in braces
937 then the Tcl interpreter will perform variable and command substitution
938 immediately (it will happen in the command parser rather than in
939 the expression parser).  In many cases the expression is being
940 passed to a command that will evaluate the expression later (or
941 even many times if, for example, the expression is to be used to
942 decide when to exit a loop).  Usually the desired goal is to re-do
943 the variable or command substitutions each time the expression is
944 evaluated, rather than once and for all at the beginning.  For example,
945 the command
947     for {set i 1} $i<=10 {incr i} {...}        ** WRONG **
949 is probably intended to iterate over all values of +i+ from 1 to 10.
950 After each iteration of the body of the loop, `for` will pass
951 its second argument to the expression evaluator to see whether or not
952 to continue processing.  Unfortunately, in this case the value of +i+
953 in the second argument will be substituted once and for all when the
954 `for` command is parsed.  If +i+ was 0 before the `for`
955 command was invoked then the second argument of `for` will be +0\<=10+
956 which will always evaluate to 1, even though +i+ eventually
957 becomes greater than 10.  In the above case the loop will never
958 terminate.  Instead, the expression should be placed in braces:
960     for {set i 1} {$i<=10} {incr i} {...}      ** RIGHT **
962 This causes the substitution of 'i'
963 to be delayed; it will be re-done each time the expression is
964 evaluated, which is the desired result.
966 LISTS
967 -----
968 The third major way that strings are interpreted in Tcl is as lists.
969 A list is just a string with a list-like structure
970 consisting of fields separated by white space.  For example, the
971 string
973     Al Sue Anne John
975 is a list with four elements or fields.
976 Lists have the same basic structure as command strings, except
977 that a newline character in a list is treated as a field separator
978 just like space or tab.  Conventions for braces and quotes
979 and backslashes are the same for lists as for commands.  For example,
980 the string
982     a b\ c {d e {f g h}}
984 is a list with three elements:  +a+, +b c+, and +d e {f g h}+.
986 Whenever an element is extracted from a list, the same rules about
987 braces and quotes and backslashes are applied as for commands.  Thus in
988 the example above when the third element is extracted from the list,
989 the result is
991     d e {f g h}
993 (when the field was extracted, all that happened was to strip off
994 the outermost layer of braces).  Command substitution and
995 variable substitution are never
996 made on a list (at least, not by the list-processing commands; the
997 list can always be passed to the Tcl interpreter for evaluation).
999 The Tcl commands `concat`, `foreach`, `lappend`, `lindex`, `linsert`,
1000 `list`, `llength`, `lrange`, `lreplace`, `lsearch`, and `lsort` allow
1001 you to build lists, extract elements from them, search them, and perform
1002 other list-related functions.
1004 Advanced list commands include `lrepeat`, `lreverse`, `lmap`, `lassign`, `lset`.
1006 LIST EXPANSION
1007 --------------
1009 A new addition to Tcl 8.5 is the ability to expand a list into separate
1010 arguments. Support for this feature is also available in Jim.
1012 Consider the following attempt to exec a list:
1014     set cmd {ls -l}
1015     exec $cmd
1017 This will attempt to exec a command named "ls -l", which will clearly not
1018 work. Typically eval and concat are required to solve this problem, however
1019 it can be solved much more easily with +\{*\}+.
1021     exec {*}$cmd
1023 This will expand the following argument into individual elements and then evaluate
1024 the resulting command.
1026 Note that the official Tcl syntax is +\{*\}+, however +\{expand\}+ is retained
1027 for backward compatibility with experimental versions of this feature.
1029 REGULAR EXPRESSIONS
1030 -------------------
1031 Tcl provides two commands that support string matching using regular
1032 expressions, `regexp` and `regsub`, as well as `switch -regexp` and
1033 `lsearch -regexp`.
1035 Regular expressions may be implemented one of two ways. Either using the system's C library
1036 POSIX regular expression support, or using the built-in regular expression engine.
1037 The differences between these are described below.
1039 *NOTE* Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (+ARE+).
1041 POSIX Regular Expressions
1042 ~~~~~~~~~~~~~~~~~~~~~~~~~
1043 If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1044 this support will be used by default. The type of regular expressions supported are
1045 Extended Regular Expressions (+ERE+) rather than Basic Regular Expressions (+BRE+).
1046 See REG_EXTENDED in the documentation.
1048 Using the system-supported POSIX regular expressions will typically
1049 make for the smallest code size, but some features such as UTF-8
1050 and +{backslash}w+, +{backslash}d+, +{backslash}s+ are not supported, and null characters
1051 in strings are not supported.
1053 See regex(3) and regex(7) for full details.
1055 Jim built-in Regular Expressions
1056 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1057 The Jim built-in regular expression engine may be selected with +./configure --with-jim-regexp+
1058 or it will be selected automatically if UTF-8 support is enabled.
1060 This engine supports UTF-8 as well as some +ARE+ features. The differences with both Tcl 7.x/8.x
1061 and POSIX are highlighted below.
1063 1. UTF-8 strings and patterns are both supported
1064 2. All Tcl character classes are supported (e.g. +[:alnum:]+, +[:digit:]+, +[:space:]+), but...
1065 3. Character classes apply to ASCII characters only
1066 4. Supported shorthand character classes: +{backslash}w+ = +[:alnum:]+, +{backslash}W+ = +^[:alnum:]+, +{backslash}d+ = +[:digit:],+ +{backslash}D+ = +^[:digit:],+ +{backslash}s+ = +[:space:]+, + +{backslash}S+ = +^[:space:]+
1067 5. Supported constraint escapes: +{backslash}m+ = +{backslash}<+ = start of word, +{backslash}M+ = +{backslash}>+ = end of word
1068 6. Backslash escapes may be used within regular expressions, such as +{backslash}n+ = newline, +{backslash}uNNNN+ = unicode
1069 7. Partially supported constraint escapes: +{backslash}A+ = start of string, +{backslash}Z+ = end of string
1070 8. Support for the +?+ non-greedy quantifier. e.g. +*?+
1071 9. Support for non-capturing parentheses +(?:...)+
1072 10. Jim Tcl considers that both patterns and strings end at a null character (+\x00+)
1074 COMMAND RESULTS
1075 ---------------
1076 Each command produces two results:  a code and a string.  The
1077 code indicates whether the command completed successfully or not,
1078 and the string gives additional information.  The valid codes are
1079 defined in jim.h, and are:
1081 +JIM_OK(0)+::
1082     This is the normal return code, and indicates that the command completed
1083     successfully.  The string gives the command's return value.
1085 +JIM_ERR(1)+::
1086     Indicates that an error occurred; the string gives a message describing
1087     the error.
1089 +JIM_RETURN(2)+::
1090     Indicates that the `return` command has been invoked, and that the
1091     current procedure (or top-level command or `source` command)
1092     should return immediately.  The
1093     string gives the return value for the procedure or command.
1095 +JIM_BREAK(3)+::
1096     Indicates that the `break` command has been invoked, so the
1097     innermost loop should abort immediately.  The string should always
1098     be empty.
1100 +JIM_CONTINUE(4)+::
1101     Indicates that the `continue` command has been invoked, so the
1102     innermost loop should go on to the next iteration.  The string
1103     should always be empty.
1105 +JIM_SIGNAL(5)+::
1106     Indicates that a signal was caught while executing a commands.
1107     The string contains the name of the signal caught.
1108     See the `signal` and `catch` commands.
1110 +JIM_EXIT(6)+::
1111     Indicates that the command called the `exit` command.
1112     The string contains the exit code.
1114 Tcl programmers do not normally need to think about return codes,
1115 since +JIM_OK+ is almost always returned.  If anything else is returned
1116 by a command, then the Tcl interpreter immediately stops processing
1117 commands and returns to its caller.  If there are several nested
1118 invocations of the Tcl interpreter in progress, then each nested
1119 command will usually return the error to its caller, until eventually
1120 the error is reported to the top-level application code.  The
1121 application will then display the error message for the user.
1123 In a few cases, some commands will handle certain `error` conditions
1124 themselves and not return them upwards.  For example, the `for`
1125 command checks for the +JIM_BREAK+ code; if it occurs, then `for`
1126 stops executing the body of the loop and returns +JIM_OK+ to its
1127 caller.  The `for` command also handles +JIM_CONTINUE+ codes and the
1128 procedure interpreter handles +JIM_RETURN+ codes.  The `catch`
1129 command allows Tcl programs to catch errors and handle them without
1130 aborting command interpretation any further.
1132 The `info returncodes` command may be used to programmatically map between
1133 return codes and names.
1135 PROCEDURES
1136 ----------
1137 Tcl allows you to extend the command interface by defining
1138 procedures.  A Tcl procedure can be invoked just like any other Tcl
1139 command (it has a name and it receives one or more arguments).
1140 The only difference is that its body isn't a piece of C code linked
1141 into the program; it is a string containing one or more other
1142 Tcl commands.
1144 The `proc` command is used to create a new Tcl command procedure:
1146 +*proc* 'name arglist ?statics? body'+
1148 The new command is named +'name'+, and it replaces any existing command
1149 there may have been by that name. Whenever the new command is
1150 invoked, the contents of +'body'+ will be executed by the Tcl
1151 interpreter.
1153 +'arglist'+ specifies the formal arguments to the procedure.
1154 It consists of a list, possibly empty, of the following
1155 argument specifiers:
1157 +name+::
1158     Required Argument - A simple argument name.
1160 +{name default}+::
1161     Optional Argument - A two-element list consisting of the
1162     argument name, followed by the default value, which will
1163     be used if the corresponding argument is not supplied.
1165 +&name+::
1166     Reference Argument - The caller is expected to pass the name of
1167     an existing variable. An implicit +`upvar` 1 origname name+ is done
1168     to make the variable available in the proc scope.
1170 +*args*+::
1171     Variable Argument - The special name +'args'+, which is
1172     assigned all remaining arguments (including none) as a list. The
1173     variable argument may only be specified once. Note that
1174     the syntax +{args newname}+ may be used to retain the special
1175     behaviour of +'args'+ with a different local name. In this case,
1176     the variable is named +'newname'+ rather than +'args'+.
1178 When the command is invoked, a local variable will be created for each of
1179 the formal arguments to the procedure; its value will be the value
1180 of corresponding argument in the invoking command or the argument's
1181 default value.
1183 Arguments with default values need not be specified in a procedure
1184 invocation.  However, there must be enough actual arguments for all
1185 required arguments, and there must not be any extra actual arguments
1186 (unless the Variable Argument is specified).
1188 Actual arguments are assigned to formal arguments as in left-to-right
1189 order with the following precedence.
1191 1. Required Arguments (including Reference Arguments)
1192 2. Optional Arguments
1193 3. Variable Argument
1195 The following example illustrates precedence. Assume a procedure declaration:
1197     proc p {{a A} args b {c C} d} {...}
1199 This procedure requires at least two arguments, but can accept an unlimited number.
1200 The following table shows how various numbers of arguments are assigned.
1201 Values marked as +-+ are assigned the default value.
1203 [width="40%",frame="topbot",options="header"]
1204 |==============
1205 |Number of arguments|a|args|b|c|d
1206 |2|-|-|1|-|2
1207 |3|1|-|2|-|3
1208 |4|1|-|2|3|4
1209 |5|1|2|3|4|5
1210 |6|1|2,3|4|5|6
1211 |==============
1213 When +'body'+ is being executed, variable names normally refer to local
1214 variables, which are created automatically when referenced and deleted
1215 when the procedure returns.  One local variable is automatically created
1216 for each of the procedure's arguments.  Global variables can be
1217 accessed by invoking the `global` command or via the +::+ prefix.
1219 New in Jim
1220 ~~~~~~~~~~
1221 In addition to procedure arguments, Jim procedures may declare static variables.
1222 These variables scoped to the procedure and initialised at procedure definition.
1223 Either from the static variable definition, or from the enclosing scope.
1225 Consider the following example:
1227     jim> set a 1
1228     jim> proc a {} {a {b 2}} {
1229         set c 1
1230         puts "$a $b $c"
1231         incr a
1232         incr b
1233         incr c
1234     }
1235     jim> a
1236     1 2 1
1237     jim> a
1238     2 3 1
1240 The static variable +'a'+ has no initialiser, so it is initialised from
1241 the enclosing scope with the value 1. (Note that it is an error if there
1242 is no variable with the same name in the enclosing scope). However +'b'+
1243 has an initialiser, so it is initialised to 2.
1245 Unlike a local variable, the value of a static variable is retained across
1246 invocations of the procedure.
1248 See the `proc` command for information on how to define procedures
1249 and what happens when they are invoked. See also NAMESPACES.
1251 VARIABLES - SCALARS AND ARRAYS
1252 ------------------------------
1253 Tcl allows the definition of variables and the use of their values
1254 either through '$'-style variable substitution, the `set`
1255 command, or a few other mechanisms.
1257 Variables need not be declared:  a new variable will automatically
1258 be created each time a new variable name is used.
1260 Tcl supports two types of variables:  scalars and arrays.
1261 A scalar variable has a single value, whereas an array variable
1262 can have any number of elements, each with a name (called
1263 its 'index') and a value.
1265 Array indexes may be arbitrary strings; they need not be numeric.
1266 Parentheses are used refer to array elements in Tcl commands.
1267 For example, the command
1269     set x(first) 44
1271 will modify the element of 'x' whose index is 'first'
1272 so that its new value is '44'.
1274 Two-dimensional arrays can be simulated in Tcl by using indexes
1275 that contain multiple concatenated values.
1276 For example, the commands
1278     set a(2,3) 1
1279     set a(3,6) 2
1281 set the elements of 'a' whose indexes are '2,3' and '3,6'.
1283 In general, array elements may be used anywhere in Tcl that scalar
1284 variables may be used.
1286 If an array is defined with a particular name, then there may
1287 not be a scalar variable with the same name.
1289 Similarly, if there is a scalar variable with a particular
1290 name then it is not possible to make array references to the
1291 variable.
1293 To convert a scalar variable to an array or vice versa, remove
1294 the existing variable with the `unset` command.
1296 The `array` command provides several features for dealing
1297 with arrays, such as querying the names of all the elements of
1298 the array and converting between an array and a list.
1300 Variables may be either global or local.  If a variable
1301 name is used when a procedure isn't being executed, then it
1302 automatically refers to a global variable.  Variable names used
1303 within a procedure normally refer to local variables associated with that
1304 invocation of the procedure.  Local variables are deleted whenever
1305 a procedure exits.  Either `global` command may be used to request
1306 that a name refer to a global variable for the duration of the current
1307 procedure (this is somewhat analogous to 'extern' in C), or the variable
1308 may be explicitly scoped with the +::+ prefix. For example
1310     set a 1
1311     set b 2
1312     proc p {} {
1313         set c 3
1314         global a
1316         puts "$a $::b $c"
1317     }
1318     p
1320 will output:
1322     1 2 3
1324 ARRAYS AS LISTS IN JIM
1325 ----------------------
1326 Unlike Tcl, Jim can automatically convert between a list (with an even
1327 number of elements) and an array value. This is similar to the way Tcl
1328 can convert between a string and a list.
1330 For example:
1332   set a {1 one 2 two}
1333   puts $a(2)
1335 will output:
1337   two
1339 Thus `array set` is equivalent to `set` when the variable does not
1340 exist or is empty.
1342 The reverse is also true where an array will be converted into
1343 a list.
1345   set a(1) one; set a(2) two
1346   puts $a
1348 will output:
1350   1 one 2 two
1352 DICTIONARY VALUES
1353 -----------------
1354 Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
1355 of this command. Dictionaries provide efficient access to key-value
1356 pairs, just like arrays, but dictionaries are pure values. This
1357 means that you can pass them to a procedure just as a list or a
1358 string. Tcl dictionaries are therefore much more like Tcl lists,
1359 except that they represent a mapping from keys to values, rather
1360 than an ordered sequence.
1362 You can nest dictionaries, so that the value for a particular key
1363 consists of another dictionary. That way you can elegantly build
1364 complicated data structures, such as hierarchical databases. You
1365 can also combine dictionaries with other Tcl data structures. For
1366 instance, you can build a list of dictionaries that themselves
1367 contain lists.
1369 Dictionaries are values that contain an efficient, order-preserving
1370 mapping from arbitrary keys to arbitrary values. Each key in the
1371 dictionary maps to a single value. They have a textual format that
1372 is exactly that of any list with an even number of elements, with
1373 each mapping in the dictionary being represented as two items in
1374 the list. When a command takes a dictionary and produces a new
1375 dictionary based on it (either returning it or writing it back into
1376 the variable that the starting dictionary was read from) the new
1377 dictionary will have the same order of keys, modulo any deleted
1378 keys and with new keys added on to the end. When a string is
1379 interpreted as a dictionary and it would otherwise have duplicate
1380 keys, only the last value for a particular key is used; the others
1381 are ignored, meaning that, "apple banana" and "apple carrot apple
1382 banana" are equivalent dictionaries (with different string
1383 representations).
1385 Note that in Jim, arrays are implemented as dictionaries.
1386 Thus automatic conversion between lists and dictionaries applies
1387 as it does for arrays.
1389   jim> dict set a 1 one
1390   1 one
1391   jim> dict set a 2 two
1392   1 one 2 two
1393   jim> puts $a
1394   1 one 2 two
1395   jim> puts $a(2)
1396   two
1397   jim> dict set a 3 T three
1398   1 one 2 two 3 {T three}
1400 See the `dict` command for more details.
1402 NAMESPACES
1403 ----------
1404 Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
1405 including a number of 3rd party components. While there is less need for namespaces
1406 in Jim Tcl (which does not strive to support large applications), it is convenient to
1407 provide a subset of the support for namespaces to easy porting code from Tcl.
1409 Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
1410 purposes. This feature is currently experimental. See README.namespaces for more information
1411 and the documentation of the `namespace` command.
1413 GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION
1414 -----------------------------------------------
1415 Unlike Tcl, Jim has some sophisticated support for functional programming.
1416 These are described briefly below.
1418 More information may be found at http://wiki.tcl.tk/13847
1420 References
1421 ~~~~~~~~~~
1422 A reference can be thought of as holding a value with one level of indirection,
1423 where the value may be garbage collected when unreferenced.
1424 Consider the following example:
1426     jim> set r [ref "One String" test]
1427     <reference.<test___>.00000000000000000000>
1428     jim> getref $r
1429     One String
1431 The operation `ref` creates a references to the value specified by the
1432 first argument. (The second argument is a "type" used for documentation purposes).
1434 The operation `getref` is the dereferencing operation which retrieves the value
1435 stored in the reference.
1437     jim> setref $r "New String"
1438     New String
1439     jim> getref $r
1440     New String
1442 The operation `setref` replaces the value stored by the reference. If the old value
1443 is no longer accessible by any reference, it will eventually be automatically be garbage
1444 collected.
1446 Garbage Collection
1447 ~~~~~~~~~~~~~~~~~~
1448 Normally, all values in Tcl are passed by value. As such values are copied and released
1449 automatically as necessary.
1451 With the introduction of references, it is possible to create values whose lifetime
1452 transcend their scope. To support this, case, the Jim system will periodically identify
1453 and discard objects which are no longer accessible by any reference.
1455 The `collect` command may be used to force garbage collection.  Consider a reference created
1456 with a finalizer:
1458     jim> proc f {ref value} { puts "Finaliser called for $ref,$value" }
1459     jim> set r [ref "One String" test f]
1460     <reference.<test___>.00000000000
1461     jim> collect
1462     0
1463     jim> set r ""
1464     jim> collect
1465     Finaliser called for <reference.<test___>.00000000000,One String
1466     1
1468 Note that once the reference, 'r', was modified so that it no longer
1469 contained a reference to the value, the garbage collector discarded
1470 the value (after calling the finalizer).
1472 The finalizer for a reference may be examined or changed with the `finalize` command
1474     jim> finalize $r
1475     f
1476     jim> finalize $r newf
1477     newf
1479 Lambda Function
1480 ~~~~~~~~~~~~~~~
1481 Jim provides a garbage collected `lambda` function. This is a procedure
1482 which is able to create an anonymous procedure.  Consider:
1484     jim> set f [lambda {a} {{x 0}} { incr x $a }]
1485     jim> $f 1
1486     1
1487     jim> $f 2
1488     3
1489     jim> set f ""
1491 This create an anonymous procedure (with the name stored in 'f'), with a static variable
1492 which is incremented by the supplied value and the result returned.
1494 Once the procedure name is no longer accessible, it will automatically be deleted
1495 when the garbage collector runs.
1497 The procedure may also be delete immediately by renaming it "". e.g.
1499     jim> rename $f ""
1501 UTF-8 AND UNICODE
1502 -----------------
1503 If Jim is built with UTF-8 support enabled (configure --enable-utf),
1504 then most string-related commands become UTF-8 aware.  These include,
1505 but are not limited to, `string match`, `split`, `glob`, `scan` and
1506 `format`.
1508 UTF-8 encoding has many advantages, but one of the complications is that
1509 characters can take a variable number of bytes. Thus the addition of
1510 `string bytelength` which returns the number of bytes in a string,
1511 while `string length` returns the number of characters.
1513 If UTF-8 support is not enabled, all commands treat bytes as characters
1514 and `string bytelength` returns the same value as `string length`.
1516 Note that even if UTF-8 support is not enabled, the +{backslash}uNNNN+ and related syntax
1517 is still available to embed UTF-8 sequences.
1519 Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +'U+1FFFFF'.
1521 String Matching
1522 ~~~~~~~~~~~~~~~
1523 Commands such as `string match`, `lsearch -glob`, `array names` and others use string
1524 pattern matching rules. These commands support UTF-8. For example:
1526   string match a\[\ua0-\ubf\]b "a\u00a3b"
1528 format and scan
1529 ~~~~~~~~~~~~~~~
1530 +format %c+ allows a unicode codepoint to be be encoded. For example, the following will return
1531 a string with two bytes and one character. The same as +{backslash}ub5+
1533   format %c 0xb5
1535 `format` respects widths as character widths, not byte widths. For example, the following will
1536 return a string with three characters, not three bytes.
1538   format %.3s \ub5\ub6\ub7\ub8
1540 Similarly, +scan ... %c+ allows a UTF-8 to be decoded to a unicode codepoint. The following will set
1541 +'a'+ to 181 (0xb5) and +'b'+ to 65 (0x41).
1543   scan \u00b5A %c%c a b
1545 `scan %s` will also accept a character class, including unicode ranges.
1547 String Classes
1548 ~~~~~~~~~~~~~~
1549 `string is` has *not* been extended to classify UTF-8 characters. Therefore, the following
1550 will return 0, even though the string may be considered to be alphabetic.
1552   string is alpha \ub5Test
1554 This does not affect the string classes 'ascii', 'control', 'digit', 'double', 'integer' or 'xdigit'.
1556 Case Mapping and Conversion
1557 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1558 Jim provides a simplified unicode case mapping. This means that case conversion
1559 and comparison will not increase or decrease the number of characters in a string.
1560 (Although it may change the number of bytes).
1562 `string toupper` will convert any lowercase letters to their uppercase equivalent.
1563 Any character which is not a letter or has no uppercase equivalent is left unchanged.
1564 Similarly for `string tolower` and `string totitle`.
1566 Commands which perform case insensitive matches, such as `string compare -nocase`
1567 and `lsearch -nocase` fold both strings to uppercase before comparison.
1569 Invalid UTF-8 Sequences
1570 ~~~~~~~~~~~~~~~~~~~~~~~
1571 Some UTF-8 character sequences are invalid, such as those beginning with '0xff',
1572 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
1573 and those which end prematurely, such as a lone '0xc2'.
1575 In these situations, the offending bytes are treated as single characters. For example,
1576 the following returns 2.
1578   string bytelength \xff\xff
1580 Regular Expressions
1581 ~~~~~~~~~~~~~~~~~~~
1582 If UTF-8 support is enabled, the built-in regular expression engine will be
1583 selected which supports UTF-8 strings and patterns.
1585 See REGULAR EXPRESSIONS
1587 BUILT-IN COMMANDS
1588 -----------------
1589 The Tcl library provides the following built-in commands, which will
1590 be available in any application using Tcl.  In addition to these
1591 built-in commands, there may be additional commands defined by each
1592 application, plus commands defined as Tcl procedures.
1594 In the command syntax descriptions below, words in +*boldface*+ are
1595 literals that you type verbatim to Tcl.
1597 Words in +'italics'+ are meta-symbols; they serve as names for any of
1598 a range of values that you can type.
1600 Optional arguments or groups of arguments are indicated by enclosing them
1601 in +?question-marks?+.
1603 Ellipses (+\...+) indicate that any number of additional
1604 arguments or groups of arguments may appear, in the same format
1605 as the preceding argument(s).
1607 [[CommandIndex]]
1608 Command Index
1609 ~~~~~~~~~~~~~
1610 @INSERTINDEX@
1612 alarm
1613 ~~~~~
1614 +*alarm* 'seconds'+
1616 Delivers the +SIGALRM+ signal to the process after the given
1617 number of seconds. If the platform supports 'ualarm(3)' then
1618 the argument may be a floating point value. Otherwise it must
1619 be an integer.
1621 Note that unless a signal handler for +SIGALRM+ has been installed
1622 (see `signal`), the process will exit on this signal.
1624 alias
1625 ~~~~~
1626 +*alias* 'name args\...'+
1628 Creates a single word alias (command) for one or more words. For example,
1629 the following creates an alias for the command `info exists`.
1631     alias e info exists
1632     if {[e var]} {
1633       ...
1634     }
1636 `alias` returns +'name'+, allowing it to be used with `local`.
1638 See also `proc`, `curry`, `lambda`, `local`, `info alias`, `exists -alias`
1640 append
1641 ~~~~~~
1642 +*append* 'varName value ?value value ...?'+
1644 Append all of the +'value'+ arguments to the current value
1645 of variable +'varName'+.  If +'varName'+ doesn't exist,
1646 it is given a value equal to the concatenation of all the
1647 +'value'+ arguments.
1649 This command provides an efficient way to build up long
1650 variables incrementally.
1651 For example, "`append a $b`" is much more efficient than
1652 "`set a $a$b`" if +$a+ is long.
1654 apply
1655 ~~~~~~
1656 +*apply* 'lambdaExpr ?arg1 arg2 \...?'+
1658 The command `apply` provides for anonymous procedure calls,
1659 similar to `lambda`, but without command name being created, even temporarily.
1661 The function  +'lambdaExpr'+ is a two element list +{args body}+
1662 or a three element list +{args body namespace}+. The first element
1663 args specifies the formal arguments, in the same form as the `proc` and `lambda` commands.
1665 array
1666 ~~~~~
1667 +*array* 'option arrayName ?arg\...?'+
1669 This command performs one of several operations on the
1670 variable given by +'arrayName'+.
1672 Note that in general, if the named array does not exist, the +'array'+ command behaves
1673 as though the array exists but is empty.
1675 The +'option'+ argument determines what action is carried out by the
1676 command.  The legal +'options'+ (which may be abbreviated) are:
1678 +*array exists* 'arrayName'+::
1679     Returns 1 if arrayName is an array variable, 0 if there is
1680     no variable by that name.
1682 +*array get* 'arrayName ?pattern?'+::
1683     Returns a list containing pairs of elements. The first
1684     element in each pair is the name of an element in arrayName
1685     and the second element of each pair is the value of the
1686     array element. The order of the pairs is undefined. If
1687     pattern is not specified, then all of the elements of the
1688     array are included in the result. If pattern is specified,
1689     then only those elements whose names match pattern (using
1690     the matching rules of string match) are included. If arrayName
1691     isn't the name of an array variable, or if the array contains
1692     no elements, then an empty list is returned.
1694 +*array names* 'arrayName ?pattern?'+::
1695     Returns a list containing the names of all of the elements
1696     in the array that match pattern. If pattern is omitted then
1697     the command returns all of the element names in the array.
1698     If pattern is specified, then only those elements whose
1699     names match pattern (using the matching rules of string
1700     match) are included. If there are no (matching) elements
1701     in the array, or if arrayName isn't the name of an array
1702     variable, then an empty string is returned.
1704 +*array set* 'arrayName list'+::
1705     Sets the values of one or more elements in arrayName. list
1706     must have a form like that returned by array get, consisting
1707     of an even number of elements. Each odd-numbered element
1708     in list is treated as an element name within arrayName, and
1709     the following element in list is used as a new value for
1710     that array element. If the variable arrayName does not
1711     already exist and list is empty, arrayName is created with
1712     an empty array value.
1714 +*array size* 'arrayName'+::
1715     Returns the number of elements in the array. If arrayName
1716     isn't the name of an array then 0 is returned.
1718 +*array unset* 'arrayName ?pattern?'+::
1719     Unsets all of the elements in the array that match pattern
1720     (using the matching rules of string match). If arrayName
1721     isn't the name of an array variable or there are no matching
1722     elements in the array, no error will be raised. If pattern
1723     is omitted and arrayName is an array variable, then the
1724     command unsets the entire array. The command always returns
1725     an empty string.
1727 break
1728 ~~~~~
1729 +*break*+
1731 This command may be invoked only inside the body of a loop command
1732 such as `for` or `foreach` or `while`.  It returns a +JIM_BREAK+ code
1733 to signal the innermost containing loop command to return immediately.
1735 case
1736 ~~~~
1737 +*case* 'string' ?in? 'patList body ?patList body ...?'+
1739 +*case* 'string' ?in? {'patList body ?patList body ...?'}+
1741 *Note* that the `switch` command should generally be preferred unless compatibility
1742 with Tcl 6.x is desired.
1744 Match +'string'+ against each of the +'patList'+ arguments
1745 in order.  If one matches, then evaluate the following +'body'+ argument
1746 by passing it recursively to the Tcl interpreter, and return the result
1747 of that evaluation.  Each +'patList'+ argument consists of a single
1748 pattern or list of patterns.  Each pattern may contain any of the wild-cards
1749 described under `string match`.
1751 If a +'patList'+ argument is +default+, the corresponding body will be
1752 evaluated if no +'patList'+ matches +'string'+.  If no +'patList'+ argument
1753 matches +'string'+ and no default is given, then the `case` command returns
1754 an empty string.
1756 Two syntaxes are provided.
1758 The first uses a separate argument for each of the patterns and commands;
1759 this form is convenient if substitutions are desired on some of the
1760 patterns or commands.
1762 The second form places all of the patterns and commands together into
1763 a single argument; the argument must have proper list structure, with
1764 the elements of the list being the patterns and commands.
1766 The second form makes it easy to construct multi-line case commands,
1767 since the braces around the whole list make it unnecessary to include a
1768 backslash at the end of each line.
1770 Since the +'patList'+ arguments are in braces in the second form,
1771 no command or variable substitutions are performed on them;  this makes
1772 the behaviour of the second form different than the first form in some
1773 cases.
1775 Below are some examples of `case` commands:
1777     case abc in {a b} {format 1} default {format 2} a* {format 3}
1779 will return '3',
1781     case a in {
1782         {a b} {format 1}
1783         default {format 2}
1784         a* {format 3}
1785     }
1787 will return '1', and
1789     case xyz {
1790         {a b}
1791             {format 1}
1792         default
1793             {format 2}
1794         a*
1795             {format 3}
1796     }
1798 will return '2'.
1800 catch
1801 ~~~~~
1802 +*catch* ?-?no?'code \...'? ?--? 'command ?resultVarName? ?optionsVarName?'+
1804 The `catch` command may be used to prevent errors from aborting
1805 command interpretation.  `catch` evaluates +'command'+, and returns a
1806 +JIM_OK+ code, regardless of any errors that might occur while
1807 executing +'command'+ (with the possible exception of +JIM_SIGNAL+ -
1808 see below).
1810 The return value from `catch` is a decimal string giving the code
1811 returned by the Tcl interpreter after executing +'command'+.  This
1812 will be '0' (+JIM_OK+) if there were no errors in +'command'+; otherwise
1813 it will have a non-zero value corresponding to one of the exceptional
1814 return codes (see jim.h for the definitions of code values, or the
1815 `info returncodes` command).
1817 If the +'resultVarName'+ argument is given, then it gives the name
1818 of a variable; `catch` will set the value of the variable to the
1819 string returned from +'command'+ (either a result or an error message).
1821 If the +'optionsVarName'+ argument is given, then it gives the name
1822 of a variable; `catch` will set the value of the variable to a
1823 dictionary. For any return code other than +JIM_RETURN+, the value
1824 for the key +-code+ will be set to the return code. For +JIM_RETURN+
1825 it will be set to the code given in `return -code`. Additionally,
1826 for the return code +JIM_ERR+, the value of the key +-errorinfo+
1827 will contain the current stack trace (the same result as `info stacktrace`),
1828 the value of the key +-errorcode+ will contain the
1829 same value as the global variable $::errorCode, and the value of
1830 the key +-level+ will be the current return level (see `return -level`).
1831 This can be useful to rethrow an error:
1833     if {[catch {...} msg opts]} {
1834         ...maybe do something with the error...
1835         incr opts(-level)
1836         return {*}$opts $msg
1837     }
1839 Normally `catch` will +'not'+ catch any of the codes +JIM_EXIT+, +JIM_EVAL+ or +JIM_SIGNAL+.
1840 The set of codes which will be caught may be modified by specifying the one more codes before
1841 +'command'+.
1843 e.g. To catch +JIM_EXIT+ but not +JIM_BREAK+ or +JIM_CONTINUE+
1845     catch -exit -nobreak -nocontinue -- { ... }
1847 The use of +--+ is optional. It signifies that no more return code options follow.
1849 Note that if a signal marked as `signal handle` is caught with `catch -signal`, the return value
1850 (stored in +'resultVarName'+) is name of the signal caught.
1854 +*cd* 'dirName'+
1856 Change the current working directory to +'dirName'+.
1858 Returns an empty string.
1860 This command can potentially be disruptive to an application, so it may
1861 be removed in some applications.
1863 clock
1864 ~~~~~
1865 +*clock seconds*+::
1866     Returns the current time as seconds since the epoch.
1868 +*clock clicks*+::
1869     Returns the current time in `clicks'.
1871 +*clock microseconds*+::
1872     Returns the current time in microseconds.
1874 +*clock milliseconds*+::
1875     Returns the current time in milliseconds.
1877 +*clock format* 'seconds' ?*-format* 'format?'+::
1878     Format the given time (seconds since the epoch) according to the given
1879     format. See strftime(3) for supported formats.
1880     If no format is supplied, "%c" is used.
1882 +*clock scan* 'str' *-format* 'format'+::
1883     Scan the given time string using the given format string.
1884     See strptime(3) for supported formats.
1886 close
1887 ~~~~~
1888 +*close* 'fileId'+
1890 +'fileId' *close*+
1892 Closes the file given by +'fileId'+.
1893 +'fileId'+ must be the return value from a previous invocation
1894 of the `open` command; after this command, it should not be
1895 used anymore.
1897 collect
1898 ~~~~~~~
1899 +*collect*+
1901 Normally reference garbage collection is automatically performed periodically.
1902 However it may be run immediately with the `collect` command.
1904 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
1906 concat
1907 ~~~~~~
1908 +*concat* 'arg ?arg \...?'+
1910 This command treats each argument as a list and concatenates them
1911 into a single list.  It permits any number of arguments.  For example,
1912 the command
1914     concat a b {c d e} {f {g h}}
1916 will return
1918     a b c d e f {g h}
1920 as its result.
1922 continue
1923 ~~~~~~~~
1924 +*continue*+
1926 This command may be invoked only inside the body of a loop command such
1927 as `for` or `foreach` or `while`.  It returns a  +JIM_CONTINUE+ code to
1928 signal the innermost containing loop command to skip the remainder of
1929 the loop's body but continue with the next iteration of the loop.
1931 curry
1932 ~~~~~
1933 +*alias* 'args\...'+
1935 Similar to `alias` except it creates an anonymous procedure (lambda) instead of
1936 a named procedure.
1938 the following creates a local, unnamed alias for the command `info exists`.
1940     set e [local curry info exists]
1941     if {[$e var]} {
1942       ...
1943     }
1945 `curry` returns the name of the procedure.
1947 See also `proc`, `alias`, `lambda`, `local`.
1949 dict
1950 ~~~~
1951 +*dict* 'option ?arg\...?'+
1953 Performs one of several operations on dictionary values.
1955 The +'option'+ argument determines what action is carried out by the
1956 command.  The legal +'options'+ are:
1958 +*dict create* '?key value \...?'+::
1959     Create and return a new dictionary value that contains each of
1960     the key/value mappings listed as  arguments (keys and values
1961     alternating, with each key being followed by its associated
1962     value.)
1964 +*dict exists* 'dictionary key ?key \...?'+::
1965     Returns a boolean value indicating whether the given key (or path
1966     of keys through a set of nested dictionaries) exists in the given
1967     dictionary value.  This returns a true value exactly when `dict get`
1968     on that path will succeed.
1970 +*dict get* 'dictionary ?key \...?'+::
1971     Given a dictionary value (first argument) and a key (second argument),
1972     this will retrieve the value for that key. Where several keys are
1973     supplied, the behaviour of the command shall be as if the result
1974     of "`dict get $dictVal $key`" was passed as the first argument to
1975     dict get with the remaining arguments as second (and possibly
1976     subsequent) arguments. This facilitates lookups in nested dictionaries.
1977     If no keys are provided, dict would return a list containing pairs
1978     of elements in a manner similar to array get. That is, the first
1979     element of each pair would be the key and the second element would
1980     be the value for that key.  It is an error to attempt to retrieve
1981     a value for a key that is not present in the dictionary.
1983 +*dict keys* 'dictionary ?pattern?'+::
1984     Returns a list of the keys in the dictionary.
1985     If pattern is specified, then only those keys whose
1986     names match +'pattern'+ (using the matching rules of string
1987     match) are included.
1989 +*dict merge* ?'dictionary \...'?+::
1990     Return a dictionary that contains the contents of each of the
1991     +'dictionary'+ arguments. Where two (or more) dictionaries
1992     contain a mapping for the same key, the resulting dictionary
1993     maps that key to the value according to the last dictionary on
1994     the command line containing a mapping for that key.
1996 +*dict set* 'dictionaryName key ?key \...? value'+::
1997     This operation takes the +'name'+ of a variable containing a dictionary
1998     value and places an updated dictionary value in that variable
1999     containing a mapping from the given key to the given value. When
2000     multiple keys are present, this operation creates or updates a chain
2001     of nested dictionaries.
2003 +*dict size* 'dictionary'+::
2004     Return the number of key/value mappings in the given dictionary value.
2006 +*dict unset* 'dictionaryName key ?key \...? value'+::
2007     This operation (the companion to `dict set`) takes the name of a
2008     variable containing a dictionary value and places an updated
2009     dictionary value in that variable that does not contain a mapping
2010     for the given key. Where multiple keys are present, this describes
2011     a path through nested dictionaries to the mapping to remove. At
2012     least one key must be specified, but the last key on the key-path
2013     need not exist. All other components on the path must exist.
2015 +*dict with* 'dictionaryName key ?key \...? script'+::
2016     Execute the Tcl script in +'script'+ with the value for each
2017     key in +'dictionaryName'+ mapped to a variable with the same
2018     name. Where one or more keys are given, these indicate a chain
2019     of nested dictionaries, with the innermost dictionary being the
2020     one opened out for the execution of body. Making +'dictionaryName'+
2021     unreadable will make the updates to the dictionary be discarded,
2022     and this also happens if the contents of +'dictionaryName'+ are
2023     adjusted so that the chain of dictionaries no longer exists.
2024     The result of `dict with` is (unless some kind of error occurs)
2025     the result of the evaluation of body.
2026  ::
2027     The variables are mapped in the scope enclosing the `dict with`;
2028     it is recommended that this command only be used in a local
2029     scope (procedure). Because of this, the variables set by
2030     `dict with` will continue to exist after the command finishes (unless
2031     explicitly unset). Note that changes to the contents of +'dictionaryName'+
2032     only happen when +'script'+ terminates.
2034 +*dict for, values, incr, append, lappend, update, info, replace*+ to be documented...
2038 +*env* '?name? ?default?'+
2040 If +'name'+ is supplied, returns the value of +'name'+ from the initial
2041 environment (see getenv(3)). An error is returned if +'name'+ does not
2042 exist in the environment, unless +'default'+ is supplied - in which case
2043 that value is returned instead.
2045 If no arguments are supplied, returns a list of all environment variables
2046 and their values as +{name value \...}+
2048 See also the global variable +::env+
2052 +*eof* 'fileId'+
2054 +'fileId' *eof*+
2056 Returns 1 if an end-of-file condition has occurred on +'fileId'+,
2057 0 otherwise.
2059 +'fileId'+ must have been the return value from a previous call to `open`,
2060 or it may be +stdin+, +stdout+, or +stderr+ to refer to one of the
2061 standard I/O channels.
2063 error
2064 ~~~~~
2065 +*error* 'message ?stacktrace?'+
2067 Returns a +JIM_ERR+ code, which causes command interpretation to be
2068 unwound.  +'message'+ is a string that is returned to the application
2069 to indicate what went wrong.
2071 If the +'stacktrace'+ argument is provided and is non-empty,
2072 it is used to initialize the stacktrace.
2074 This feature is most useful in conjunction with the `catch` command:
2075 if a caught error cannot be handled successfully, +'stacktrace'+ can be used
2076 to return a stack trace reflecting the original point of occurrence
2077 of the error:
2079     catch {...} errMsg
2080     ...
2081     error $errMsg [info stacktrace]
2083 See also `errorInfo`, `info stacktrace`, `catch` and `return`
2085 errorInfo
2086 ~~~~~~~~~
2087 +*errorInfo* 'error ?stacktrace?'+
2089 Returns a human-readable representation of the given error message and stack trace.
2090 Typical usage is:
2092     if {[catch {...} error]} {
2093         puts stderr [errorInfo $error [info stacktrace]]
2094         exit 1
2095     }
2097 See also `error`.
2099 eval
2100 ~~~~
2101 +*eval* 'arg ?arg\...?'+
2103 `eval` takes one or more arguments, which together comprise a Tcl
2104 command (or collection of Tcl commands separated by newlines in the
2105 usual way).  `eval` concatenates all its arguments in the same
2106 fashion as the `concat` command, passes the concatenated string to the
2107 Tcl interpreter recursively, and returns the result of that
2108 evaluation (or any error generated by it).
2110 exec
2111 ~~~~
2112 +*exec* 'arg ?arg\...?'+
2114 This command treats its arguments as the specification
2115 of one or more UNIX commands to execute as subprocesses.
2116 The commands take the form of a standard shell pipeline;
2117 +|+ arguments separate commands in the
2118 pipeline and cause standard output of the preceding command
2119 to be piped into standard input of the next command (or +|&+ for
2120 both standard output and standard error).
2122 Under normal conditions the result of the `exec` command
2123 consists of the standard output produced by the last command
2124 in the pipeline followed by the standard error output.
2126 If any of the commands writes to its standard error file,
2127 then this will be included in the result after the standard output
2128 of the last command.
2130 Note that unlike Tcl, data written to standard error does not cause
2131 `exec` to return an error.
2133 If any of the commands in the pipeline exit abnormally or
2134 are killed or suspended, then `exec` will return an error.
2135 If no standard error output was produced, or is redirected,
2136 the error message will include the normal result, as above,
2137 followed by error messages describing the abnormal terminations.
2139 If any standard error output was produced, these abnormal termination
2140 messages are suppressed.
2142 If the last character of the result or error message
2143 is a newline then that character is deleted from the result
2144 or error message for consistency with normal
2145 Tcl return values.
2147 An +'arg'+ may have one of the following special forms:
2149 +>filename+::
2150     The standard output of the last command in the pipeline
2151     is redirected to the file.  In this situation `exec`
2152     will normally return an empty string.
2154 +>>filename+::
2155     As above, but append to the file.
2157 +>@fileId+::
2158     The standard output of the last command in the pipeline is
2159     redirected to the given (writable) file descriptor (e.g. stdout,
2160     stderr, or the result of `open`). In this situation `exec`
2161     will normally return an empty string.
2163 +2>filename+::
2164     The standard error of the last command in the pipeline
2165     is redirected to the file.
2167 +2>>filename+::
2168     As above, but append to the file.
2170 +2>@fileId+::
2171     The standard error of the last command in the pipeline is
2172     redirected to the given (writable) file descriptor.
2174 +2>@1+::
2175     The standard error of the last command in the pipeline is
2176     redirected to the same file descriptor as the standard output.
2178 +>&filename+::
2179     Both the standard output and standard error of the last command
2180     in the pipeline is redirected to the file.
2182 +>>&filename+::
2183     As above, but append to the file.
2185 +<filename+::
2186     The standard input of the first command in the pipeline
2187     is taken from the file.
2189 +<<string+::
2190     The standard input of the first command is taken as the
2191     given immediate value.
2193 +<@fileId+::
2194     The standard input of the first command in the pipeline
2195     is taken from the given (readable) file descriptor.
2197 If there is no redirection of standard input, standard error
2198 or standard output, these are connected to the corresponding
2199 input or output of the application.
2201 If the last +'arg'+ is +&+ then the command will be
2202 executed in background.
2203 In this case the standard output from the last command
2204 in the pipeline will
2205 go to the application's standard output unless
2206 redirected in the command, and error output from all
2207 the commands in the pipeline will go to the application's
2208 standard error file. The return value of exec in this case
2209 is a list of process ids (pids) in the pipeline.
2211 Each +'arg'+ becomes one word for a command, except for
2212 +|+, +<+, +<<+, +>+, and +&+ arguments, and the
2213 arguments that follow +<+, +<<+, and +>+.
2215 The first word in each command is taken as the command name;
2216 the directories in the PATH environment variable are searched for
2217 an executable by the given name.
2219 No `glob` expansion or other shell-like substitutions
2220 are performed on the arguments to commands.
2222 If the command fails, the global $::errorCode (and the -errorcode
2223 option in `catch`) will be set to a list, as follows:
2225 +*CHILDKILLED* 'pid sigName msg'+::
2226         This format is used when a child process has been killed
2227         because of a signal. The pid element will be the process's
2228         identifier (in decimal). The sigName element will be the
2229         symbolic name of the signal that caused the process to
2230         terminate; it will be one of the names from the include
2231         file signal.h, such as SIGPIPE. The msg element will be a
2232         short human-readable message describing the signal, such
2233         as "write on pipe with no readers" for SIGPIPE.
2235 +*CHILDSUSP* 'pid sigName msg'+::
2236         This format is used when a child process has been suspended
2237         because of a signal. The pid element will be the process's
2238         identifier, in decimal. The sigName element will be the
2239         symbolic name of the signal that caused the process to
2240         suspend; this will be one of the names from the include
2241         file signal.h, such as SIGTTIN. The msg element will be a
2242         short human-readable message describing the signal, such
2243         as "background tty read" for SIGTTIN.
2245 +*CHILDSTATUS* 'pid code'+::
2246         This format is used when a child process has exited with a
2247         non-zero exit status. The pid element will be the process's
2248         identifier (in decimal) and the code element will be the
2249         exit code returned by the process (also in decimal).
2251 The environment for the executed command is set from $::env (unless
2252 this variable is unset, in which case the original environment is used).
2254 exists
2255 ~~~~~~
2256 +*exists ?-var|-proc|-command|-alias?* 'name'+
2258 Checks the existence of the given variable, procedure, command
2259 or alias respectively and returns 1 if it exists or 0 if not.  This command
2260 provides a more simplified/convenient version of `info exists`,
2261 `info procs` and `info commands`.
2263 If the type is omitted, a type of '-var' is used. The type may be abbreviated.
2265 exit
2266 ~~~~
2267 +*exit* '?returnCode?'+
2269 Terminate the process, returning +'returnCode'+ to the
2270 parent as the exit status.
2272 If +'returnCode'+ isn't specified then it defaults
2273 to 0.
2275 Note that exit can be caught with `catch`.
2277 expr
2278 ~~~~
2279 +*expr* 'arg'+
2281 Calls the expression processor to evaluate +'arg'+, and returns
2282 the result as a string.  See the section EXPRESSIONS above.
2284 Note that Jim supports a shorthand syntax for `expr` as +$(\...)+
2285 The following two are identical.
2287   set x [expr {3 * 2 + 1}]
2288   set x $(3 * 2 + 1)
2290 file
2291 ~~~~
2292 +*file* 'option name ?arg\...?'+
2294 Operate on a file or a file name.  +'name'+ is the name of a file.
2296 +'option'+ indicates what to do with the file name.  Any unique
2297 abbreviation for +'option'+ is acceptable.  The valid options are:
2299 +*file atime* 'name'+::
2300     Return a decimal string giving the time at which file +'name'+
2301     was last accessed.  The time is measured in the standard UNIX
2302     fashion as seconds from a fixed starting time (often January 1, 1970).
2303     If the file doesn't exist or its access time cannot be queried then an
2304     error is generated.
2306 +*file copy ?-force?* 'source target'+::
2307     Copies file +'source'+ to file +'target'+. The source file must exist.
2308     The target file must not exist, unless +-force+ is specified.
2310 +*file delete ?-force? ?--?* 'name\...'+::
2311     Deletes file or directory +'name'+. If the file or directory doesn't exist, nothing happens.
2312     If it can't be deleted, an error is generated. Non-empty directories will not be deleted
2313     unless the +-force+ options is given. In this case no errors will be generated, even
2314     if the file/directory can't be deleted. Use +'--'+ if there is any possibility of
2315     the first name being +'-force'+.
2317 +*file dirname* 'name'+::
2318     Return all of the characters in +'name'+ up to but not including
2319     the last slash character.  If there are no slashes in +'name'+
2320     then return +.+ (a single dot).  If the last slash in +'name'+ is its first
2321     character, then return +/+.
2323 +*file executable* 'name'+::
2324     Return '1' if file +'name'+ is executable by
2325     the current user, '0' otherwise.
2327 +*file exists* 'name'+::
2328     Return '1' if file +'name'+ exists and the current user has
2329     search privileges for the directories leading to it, '0' otherwise.
2331 +*file extension* 'name'+::
2332     Return all of the characters in +'name'+ after and including the
2333     last dot in +'name'+.  If there is no dot in +'name'+ then return
2334     the empty string.
2336 +*file isdirectory* 'name'+::
2337     Return '1' if file +'name'+ is a directory,
2338     '0' otherwise.
2340 +*file isfile* 'name'+::
2341     Return '1' if file +'name'+ is a regular file,
2342     '0' otherwise.
2344 +*file join* 'arg\...'+::
2345     Joins multiple path components. Note that if any components is
2346     an absolute path, the preceding components are ignored.
2347     Thus +"`file` join /tmp /root"+ returns +"/root"+.
2349 +*file link* ?*-hard|-symbolic*? 'newname target'+::
2350     Creates a hard link (default) or symbolic link from +'newname'+ to +'target'+.
2351     Note that the sense of this command is the opposite of `file rename` and `file copy`
2352     and also of `ln`, but this is compatible with Tcl.
2353     An error is returned if +'target'+ doesn't exist or +'newname'+ already exists.
2355 +*file lstat* 'name varName'+::
2356     Same as 'stat' option (see below) except uses the +'lstat'+
2357     kernel call instead of +'stat'+.  This means that if +'name'+
2358     refers to a symbolic link the information returned in +'varName'+
2359     is for the link rather than the file it refers to.  On systems that
2360     don't support symbolic links this option behaves exactly the same
2361     as the 'stat' option.
2363 +*file mkdir* 'dir1 ?dir2\...?'+::
2364     Creates each directory specified. For each pathname +'dir'+ specified,
2365     this command will create all non-existing parent directories
2366     as well as +'dir'+ itself. If an existing directory is specified,
2367     then no action is taken and no error is returned. Trying to
2368     overwrite an existing file with a directory will result in an
2369     error.  Arguments are processed in the order specified, halting
2370     at the first error, if any.
2372 +*file mtime* 'name ?time?'+::
2373     Return a decimal string giving the time at which file +'name'+
2374     was last modified.  The time is measured in the standard UNIX
2375     fashion as seconds from a fixed starting time (often January 1, 1970).
2376     If the file doesn't exist or its modified time cannot be queried then an
2377     error is generated. If +'time'+ is given, sets the modification time
2378     of the file to the given value.
2380 +*file mtimeus* 'name ?time_us?'+::
2381     As for `file mtime` except the time value is in microseconds
2382         since the epoch (see also `clock microseconds`).
2383         Note that some platforms and some filesystems don't support high
2384         resolution timestamps for files.
2386 +*file normalize* 'name'+::
2387     Return the normalized path of +'name'+. See 'realpath(3)'.
2389 +*file owned* 'name'+::
2390     Return '1' if file +'name'+ is owned by the current user,
2391     '0' otherwise.
2393 +*file readable* 'name'+::
2394     Return '1' if file +'name'+ is readable by
2395     the current user, '0' otherwise.
2397 +*file readlink* 'name'+::
2398     Returns the value of the symbolic link given by +'name'+ (i.e. the
2399     name of the file it points to).  If
2400     +'name'+ isn't a symbolic link or its value cannot be read, then
2401     an error is returned.  On systems that don't support symbolic links
2402     this option is undefined.
2404 +*file rename* ?*-force*? 'oldname' 'newname'+::
2405     Renames the file from the old name to the new name.
2406     If +'newname'+ already exists, an error is returned unless +'-force'+ is
2407     specified.
2409 +*file rootname* 'name'+::
2410     Return all of the characters in +'name'+ up to but not including
2411     the last '.' character in the name.  If +'name'+ doesn't contain
2412     a dot, then return +'name'+.
2414 +*file size* 'name'+::
2415     Return a decimal string giving the size of file +'name'+ in bytes.
2416     If the file doesn't exist or its size cannot be queried then an
2417     error is generated.
2419 +*file stat* 'name ?varName?'+::
2420     Invoke the 'stat' kernel call on +'name'+, and return the result
2421     as a dictionary with the following keys: 'atime',
2422     'ctime', 'dev', 'gid', 'ino', 'mode', 'mtime',
2423     'nlink', 'size', 'type', 'uid', 'mtimeus' (if supported - see `file mtimeus`)
2424     Each element except 'type' is a decimal string with the value of
2425     the corresponding field from the 'stat' return structure; see the
2426     manual entry for 'stat' for details on the meanings of the values.
2427     The 'type' element gives the type of the file in the same form
2428     returned by the command `file type`.
2429     If +'varName'+ is specified, it is taken to be the name of an array
2430     variable and the values are also stored into the array.
2432 +*file tail* 'name'+::
2433     Return all of the characters in +'name'+ after the last slash.
2434     If +'name'+ contains no slashes then return +'name'+.
2436 +*file tempfile* '?template?'+::
2437     Creates and returns the name of a unique temporary file. If +'template'+ is omitted, a
2438     default template will be used to place the file in /tmp. See 'mkstemp(3)' for
2439     the format of the template and security concerns.
2441 +*file type* 'name'+::
2442     Returns a string giving the type of file +'name'+, which will be
2443     one of +file+, +directory+, +characterSpecial+,
2444     +blockSpecial+, +fifo+, +link+, or +socket+.
2446 +*file writable* 'name'+::
2447     Return '1' if file +'name'+ is writable by
2448     the current user, '0' otherwise.
2450 The `file` commands that return 0/1 results are often used in
2451 conditional or looping commands, for example:
2453     if {![file exists foo]} {
2454         error {bad file name}
2455     } else {
2456         ...
2457     }
2459 finalize
2460 ~~~~~~~~
2461 +*finalize* 'reference ?command?'+
2463 If +'command'+ is omitted, returns the finalizer command for the given reference.
2465 Otherwise, sets a new finalizer command for the given reference. +'command'+ may be
2466 the empty string to remove the current finalizer.
2468 The reference must be a valid reference create with the `ref`
2469 command.
2471 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2473 flush
2474 ~~~~~
2475 +*flush* 'fileId'+
2477 +'fileId' *flush*+
2479 Flushes any output that has been buffered for +'fileId'+.  +'fileId'+ must
2480 have been the return value from a previous call to `open`, or it may be
2481 +stdout+ or +stderr+ to access one of the standard I/O streams; it must
2482 refer to a file that was opened for writing.  This command returns an
2483 empty string.
2487 +*for* 'start test next body'+
2489 `for` is a looping command, similar in structure to the C `for` statement.
2490 The +'start'+, +'next'+, and +'body'+ arguments must be Tcl command strings,
2491 and +'test'+ is an expression string.
2493 The `for` command first invokes the Tcl interpreter to execute +'start'+.
2494 Then it repeatedly evaluates +'test'+ as an expression; if the result is
2495 non-zero it invokes the Tcl interpreter on +'body'+, then invokes the Tcl
2496 interpreter on +'next'+, then repeats the loop.  The command terminates
2497 when +'test'+ evaluates to 0.
2499 If a `continue` command is invoked within +'body'+ then any remaining
2500 commands in the current execution of +'body'+ are skipped; processing
2501 continues by invoking the Tcl interpreter on +'next'+, then evaluating
2502 +'test'+, and so on.
2504 If a `break` command is invoked within +'body'+ or +'next'+, then the `for`
2505 command will return immediately.
2507 The operation of `break` and `continue` are similar to the corresponding
2508 statements in C.
2510 `for` returns an empty string.
2512 foreach
2513 ~~~~~~~
2514 +*foreach* 'varName list body'+
2516 +*foreach* 'varList list ?varList2 list2 \...? body'+
2518 In this command, +'varName'+ is the name of a variable, +'list'+
2519 is a list of values to assign to +'varName'+, and +'body'+ is a
2520 collection of Tcl commands.
2522 For each field in +'list'+ (in order from left to right), `foreach` assigns
2523 the contents of the field to +'varName'+ (as if the `lindex` command
2524 had been used to extract the field), then calls the Tcl interpreter to
2525 execute +'body'+.
2527 If instead of being a simple name, +'varList'+ is used, multiple assignments
2528 are made each time through the loop, one for each element of +'varList'+.
2530 For example, if there are two elements in +'varList'+ and six elements in
2531 the list, the loop will be executed three times.
2533 If the length of the list doesn't evenly divide by the number of elements
2534 in +'varList'+, the value of the remaining variables in the last iteration
2535 of the loop are undefined.
2537 The `break` and `continue` statements may be invoked inside +'body'+,
2538 with the same effect as in the `for` command.
2540 `foreach` returns an empty string.
2542 format
2543 ~~~~~~
2544 +*format* 'formatString ?arg \...?'+
2546 This command generates a formatted string in the same way as the
2547 C 'sprintf' procedure (it uses 'sprintf' in its
2548 implementation).  +'formatString'+ indicates how to format
2549 the result, using +%+ fields as in 'sprintf', and the additional
2550 arguments, if any, provide values to be substituted into the result.
2552 All of the 'sprintf' options are valid; see the 'sprintf'
2553 man page for details.  Each +'arg'+ must match the expected type
2554 from the +%+ field in +'formatString'+; the `format` command
2555 converts each argument to the correct type (floating, integer, etc.)
2556 before passing it to 'sprintf' for formatting.
2558 The only unusual conversion is for +%c+; in this case the argument
2559 must be a decimal string, which will then be converted to the corresponding
2560 ASCII (or UTF-8) character value.
2562 In addition, Jim Tcl provides basic support for conversion to binary with +%b+.
2564 `format` does backslash substitution on its +'formatString'+
2565 argument, so backslash sequences in +'formatString'+ will be handled
2566 correctly even if the argument is in braces.
2568 The return value from `format` is the formatted string.
2570 getref
2571 ~~~~~~
2572 +*getref* 'reference'+
2574 Returns the string associated with +'reference'+. The reference must
2575 be a valid reference create with the `ref` command.
2577 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2579 gets
2580 ~~~~
2581 +*gets* 'fileId ?varName?'+
2583 +'fileId' *gets* '?varName?'+
2585 Reads the next line from the file given by +'fileId'+ and discards
2586 the terminating newline character.
2588 If +'varName'+ is specified, then the line is placed in the variable
2589 by that name and the return value is a count of the number of characters
2590 read (not including the newline).
2592 If the end of the file is reached before reading
2593 any characters then -1 is returned and +'varName'+ is set to an
2594 empty string.
2596 If +'varName'+ is not specified then the return value will be
2597 the line (minus the newline character) or an empty string if
2598 the end of the file is reached before reading any characters.
2600 An empty string will also be returned if a line contains no characters
2601 except the newline, so `eof` may have to be used to determine
2602 what really happened.
2604 If the last character in the file is not a newline character, then
2605 `gets` behaves as if there were an additional newline character
2606 at the end of the file.
2608 +'fileId'+ must be +stdin+ or the return value from a previous
2609 call to `open`; it must refer to a file that was opened
2610 for reading.
2612 glob
2613 ~~~~
2614 +*glob* ?*-nocomplain*? ?*-directory* 'dir'? ?*-tails*? ?*--*? 'pattern ?pattern \...?'+
2616 This command performs filename globbing, using csh rules.  The returned
2617 value from `glob` is the list of expanded filenames.
2619 If +-nocomplain+ is specified as the first argument then an empty
2620 list may be returned;  otherwise an error is returned if the expanded
2621 list is empty.  The +-nocomplain+ argument must be provided
2622 exactly: an abbreviation will not be accepted.
2624 If +-directory+ is given, the +'dir'+ is understood to contain a
2625 directory name to search in. This allows globbing inside directories
2626 whose names may contain glob-sensitive characters. The returned names
2627 include the directory name unless +'-tails'+ is specified.
2629 If +'-tails'+ is specified, along with +-directory+, the returned names
2630 are relative to the given directory.
2632 global
2633 ~~~~~~
2635 +*global* 'varName ?varName \...?'+
2637 This command is ignored unless a Tcl procedure is being interpreted.
2638 If so, then it declares each given +'varName'+ to be a global variable
2639 rather than a local one.  For the duration of the current procedure
2640 (and only while executing in the current procedure), any reference to
2641 +'varName'+ will be bound to a global variable instead
2642 of a local one.
2644 An alternative to using `global` is to use the +::+ prefix
2645 to explicitly name a variable in the global scope.
2649 +*if* 'expr1' ?*then*? 'body1' *elseif* 'expr2' ?*then*? 'body2' *elseif* \... ?*else*? ?'bodyN'?+
2651 The `if` command evaluates +'expr1'+ as an expression (in the same way
2652 that `expr` evaluates its argument).  The value of the expression must
2653 be numeric; if it is non-zero then +'body1'+ is executed by passing it to
2654 the Tcl interpreter.
2656 Otherwise +'expr2'+ is evaluated as an expression and if it is non-zero
2657 then +'body2'+ is executed, and so on.
2659 If none of the expressions evaluates to non-zero then +'bodyN'+ is executed.
2661 The +then+ and +else+ arguments are optional "noise words" to make the
2662 command easier to read.
2664 There may be any number of +elseif+ clauses, including zero.  +'bodyN'+
2665 may also be omitted as long as +else+ is omitted too.
2667 The return value from the command is the result of the body script that
2668 was executed, or an empty string if none of the expressions was non-zero
2669 and there was no +'bodyN'+.
2671 incr
2672 ~~~~
2673 +*incr* 'varName ?increment?'+
2675 Increment the value stored in the variable whose name is +'varName'+.
2676 The value of the variable must be integral.
2678 If +'increment'+ is supplied then its value (which must be an
2679 integer) is added to the value of variable +'varName'+;  otherwise
2680 1 is added to +'varName'+.
2682 The new value is stored as a decimal string in variable +'varName'+
2683 and also returned as result.
2685 If the variable does not exist, the variable is implicitly created
2686 and set to +0+ first.
2688 info
2689 ~~~~
2691 +*info* 'option ?arg\...?'+::
2693 Provide information about various internals to the Tcl interpreter.
2694 The legal +'option'+'s (which may be abbreviated) are:
2696 +*info args* 'procname'+::
2697     Returns a list containing the names of the arguments to procedure
2698     +'procname'+, in order.  +'procname'+ must be the name of a
2699     Tcl command procedure.
2701 +*info alias* 'command'+::
2702     +'command'+ must be an alias created with `alias`. In which case the target
2703     command and arguments, as passed to `alias` are returned. See `exists -alias`
2705 +*info body* 'procname'+::
2706     Returns the body of procedure +'procname'+.  +'procname'+ must be
2707     the name of a Tcl command procedure.
2709 +*info channels*+::
2710     Returns a list of all open file handles from `open` or `socket`
2712 +*info commands* ?'pattern'?+::
2713     If +'pattern'+ isn't specified, returns a list of names of all the
2714     Tcl commands, including both the built-in commands written in C and
2715     the command procedures defined using the `proc` command.
2716     If +'pattern'+ is specified, only those names matching +'pattern'+
2717     are returned.  Matching is determined using the same rules as for
2718     `string match`.
2720 +*info complete* 'command' ?'missing'?+::
2721     Returns 1 if +'command'+ is a complete Tcl command in the sense of
2722     having no unclosed quotes, braces, brackets or array element names,
2723     If the command doesn't appear to be complete then 0 is returned.
2724     This command is typically used in line-oriented input environments
2725     to allow users to type in commands that span multiple lines;  if the
2726     command isn't complete, the script can delay evaluating it until additional
2727     lines have been typed to complete the command. If +'varName'+ is specified, the
2728     missing character is stored in the variable with that name.
2730 +*info exists* 'varName'+::
2731     Returns '1' if the variable named +'varName'+ exists in the
2732     current context (either as a global or local variable), returns '0'
2733     otherwise.
2735 +*info frame* ?'number'?+::
2736     If +'number'+ is not specified, this command returns a number
2737     which is the same result as `info level` - the current stack frame level.
2738     If +'number'+ is specified, then the result is a list consisting of the procedure,
2739     filename and line number for the procedure call at level +'number'+ on the stack.
2740     If +'number'+ is positive then it selects a particular stack level (1 refers
2741     to the top-most active procedure, 2 to the procedure it called, and
2742     so on); otherwise it gives a level relative to the current level
2743     (0 refers to the current procedure, -1 to its caller, and so on).
2744     The level has an identical meaning to `info level`.
2746 +*info globals* ?'pattern'?+::
2747     If +'pattern'+ isn't specified, returns a list of all the names
2748     of currently-defined global variables.
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 hostname*+::
2754     An alias for `os.gethostname` for compatibility with Tcl 6.x
2756 +*info level* ?'number'?+::
2757     If +'number'+ is not specified, this command returns a number
2758     giving the stack level of the invoking procedure, or 0 if the
2759     command is invoked at top-level.  If +'number'+ is specified,
2760     then the result is a list consisting of the name and arguments for the
2761     procedure call at level +'number'+ on the stack.  If +'number'+
2762     is positive then it selects a particular stack level (1 refers
2763     to the top-most active procedure, 2 to the procedure it called, and
2764     so on); otherwise it gives a level relative to the current level
2765     (0 refers to the current procedure, -1 to its caller, and so on).
2766     See the `uplevel` command for more information on what stack
2767     levels mean.
2769 +*info locals* ?'pattern'?+::
2770     If +'pattern'+ isn't specified, returns a list of all the names
2771     of currently-defined local variables, including arguments to the
2772     current procedure, if any.  Variables defined with the `global`
2773     and `upvar` commands will not be returned.  If +'pattern'+ is
2774     specified, only those names matching +'pattern'+ are returned.
2775     Matching is determined using the same rules as for `string match`.
2777 +*info nameofexecutable*+::
2778     Returns the name of the binary file from which the application
2779     was invoked. A full path will be returned, unless the path
2780     can't be determined, in which case the empty string will be returned.
2782 +*info procs* ?'pattern'?+::
2783     If +'pattern'+ isn't specified, returns a list of all the
2784     names of Tcl command procedures.
2785     If +'pattern'+ is specified, only those names matching +'pattern'+
2786     are returned.  Matching is determined using the same rules as for
2787     `string match`.
2789 +*info references*+::
2790     Returns a list of all references which have not yet been garbage
2791     collected.
2793 +*info returncodes* ?'code'?+::
2794     Returns a list representing the mapping of standard return codes
2795     to names. e.g. +{0 ok 1 error 2 return \...}+. If a code is given,
2796     instead returns the name for the given code.
2798 +*info script*+::
2799     If a Tcl script file is currently being evaluated (i.e. there is a
2800     call to 'Jim_EvalFile' active or there is an active invocation
2801     of the `source` command), then this command returns the name
2802     of the innermost file being processed.  Otherwise the command returns an
2803     empty string.
2805 +*info source* 'script ?filename line?'+::
2806     With a single argument, returns the original source location of the given script as a list of
2807     +{filename linenumber}+. If the source location can't be determined, the
2808     list +{{} 0}+ is returned. If +'filename'+ and +'line'+ are given, returns a copy
2809     of +'script'+ with the associate source information. This can be useful to produce
2810     useful messages from `eval`, etc. if the original source information may be lost.
2812 +*info stacktrace*+::
2813     After an error is caught with `catch`, returns the stack trace as a list
2814     of +{procedure filename line \...}+.
2816 +*info statics* 'procname'+::
2817     Returns a dictionary of the static variables of procedure
2818     +'procname'+.  +'procname'+ must be the name of a Tcl command
2819     procedure. An empty dictionary is returned if the procedure has
2820     no static variables.
2822 +*info version*+::
2823     Returns the version number for this version of Jim in the form +*x.yy*+.
2825 +*info vars* ?'pattern'?+::
2826     If +'pattern'+ isn't specified,
2827     returns a list of all the names of currently-visible variables, including
2828     both locals and currently-visible globals.
2829     If +'pattern'+ is specified, only those names matching +'pattern'+
2830     are returned.  Matching is determined using the same rules as for
2831     `string match`.
2833 join
2834 ~~~~
2835 +*join* 'list ?joinString?'+
2837 The +'list'+ argument must be a valid Tcl list.  This command returns the
2838 string formed by joining all of the elements of +'list'+ together with
2839 +'joinString'+ separating each adjacent pair of elements.
2841 The +'joinString'+ argument defaults to a space character.
2843 kill
2844 ~~~~
2845 +*kill* ?'SIG'|*-0*? 'pid'+
2847 Sends the given signal to the process identified by +'pid'+.
2849 The signal may be specified by name or number in one of the following forms:
2851 * +TERM+
2852 * +SIGTERM+
2853 * +-TERM+
2854 * +15+
2855 * +-15+
2857 The signal name may be in either upper or lower case.
2859 The special signal name +-0+ simply checks that a signal +'could'+ be sent.
2861 If no signal is specified, SIGTERM is used.
2863 An error is raised if the signal could not be delivered.
2865 lambda
2866 ~~~~~~
2867 +*lambda* 'args ?statics? body'+
2869 The `lambda` command is identical to `proc`, except rather than
2870 creating a named procedure, it creates an anonymous procedure and returns
2871 the name of the procedure.
2873 See `proc` and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
2875 lappend
2876 ~~~~~~~
2877 +*lappend* 'varName value ?value value \...?'+
2879 Treat the variable given by +'varName'+ as a list and append each of
2880 the +'value'+ arguments to that list as a separate element, with spaces
2881 between elements.
2883 If +'varName'+ doesn't exist, it is created as a list with elements given
2884 by the +'value'+ arguments. `lappend` is similar to `append` except that
2885 each +'value'+ is appended as a list element rather than raw text.
2887 This command provides a relatively efficient way to build up large lists.
2888 For example,
2890     lappend a $b
2892 is much more efficient than
2894     set a [concat $a [list $b]]
2896 when +$a+ is long.
2898 lassign
2899 ~~~~~~~
2900 +*lassign* 'list varName ?varName \...?'+
2902 This command treats the value +'list'+ as a list and assigns successive elements from that list to
2903 the variables given by the +'varName'+ arguments in order. If there are more variable names than
2904 list elements, the remaining variables are set to the empty string. If there are more list elements
2905 than variables, a list of unassigned elements is returned.
2907     jim> lassign {1 2 3} a b; puts a=$a,b=$b
2908     3
2909     a=1,b=2
2911 local
2912 ~~~~~
2913 +*local* 'cmd ?arg\...?'+
2915 First, `local` evaluates +'cmd'+ with the given arguments. The return value must
2916 be the name of an existing command, which is marked as having local scope.
2917 This means that when the current procedure exits, the specified
2918 command is deleted. This can be useful with `lambda`, local procedures or
2919 to automatically close a filehandle.
2921 In addition, if a command already exists with the same name,
2922 the existing command will be kept rather than deleted, and may be called
2923 via `upcall`. The previous command will be restored when the current
2924 procedure exits. See `upcall` for more details.
2926 In this example, a local procedure is created. Note that the procedure
2927 continues to have global scope while it is active.
2929     proc outer {} {
2930       # proc ... returns "inner" which is marked local
2931       local proc inner {} {
2932         # will be deleted when 'outer' exits
2933       }
2935       inner
2936       ...
2937     }
2939 In this example, the lambda is deleted at the end of the procedure rather
2940 than waiting until garbage collection.
2942     proc outer {} {
2943       set x [lambda inner {args} {
2944         # will be deleted when 'outer' exits
2945       }]
2946       # Use 'function' here which simply returns $x
2947       local function $x
2949       $x ...
2950       ...
2951     }
2953 loop
2954 ~~~~
2955 +*loop* 'var first limit ?incr? body'+
2957 Similar to `for` except simpler and possibly more efficient.
2958 With a positive increment, equivalent to:
2960   for {set var $first} {$var < $limit} {incr var $incr} $body
2962 If +'incr'+ is not specified, 1 is used.
2963 Note that setting the loop variable inside the loop does not
2964 affect the loop count.
2966 lindex
2967 ~~~~~~
2968 +*lindex* 'list ?index ...?'+
2970 Treats +'list'+ as a Tcl list and returns element +'index'+ from it
2971 (0 refers to the first element of the list).
2972 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
2974 In extracting the element, +'lindex'+ observes the same rules concerning
2975 braces and quotes and backslashes as the Tcl command interpreter; however,
2976 variable substitution and command substitution do not occur.
2978 If no index values are given, simply returns +'list'+
2980 If +'index'+ is negative or greater than or equal to the number of elements
2981 in +'list'+, then an empty string is returned.
2983 If additional index arguments are supplied, then each argument is
2984 used in turn to select an element from the previous indexing
2985 operation, allowing the script to select elements from sublists.
2987 linsert
2988 ~~~~~~~
2989 +*linsert* 'list index element ?element element \...?'+
2991 This command produces a new list from +'list'+ by inserting all
2992 of the +'element'+ arguments just before the element +'index'+
2993 of +'list'+. Each +'element'+ argument will become
2994 a separate element of the new list. If +'index'+ is less than
2995 or equal to zero, then the new elements are inserted at the
2996 beginning of the list. If +'index'+ is greater than or equal
2997 to the number of elements in the list, then the new elements are
2998 appended to the list.
3000 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3002 list
3003 ~~~~
3005 +*list* 'arg ?arg \...?'+
3007 This command returns a list comprised of all the arguments, +'arg'+. Braces
3008 and backslashes get added as necessary, so that the `lindex` command
3009 may be used on the result to re-extract the original arguments, and also
3010 so that `eval` may be used to execute the resulting list, with
3011 +'arg1'+ comprising the command's name and the other args comprising
3012 its arguments. `list` produces slightly different results than
3013 `concat`:  `concat` removes one level of grouping before forming
3014 the list, while `list` works directly from the original arguments.
3015 For example, the command
3017     list a b {c d e} {f {g h}}
3019 will return
3021     a b {c d e} {f {g h}}
3023 while `concat` with the same arguments will return
3025     a b c d e f {g h}
3027 llength
3028 ~~~~~~~
3029 +*llength* 'list'+
3031 Treats +'list'+ as a list and returns a decimal string giving
3032 the number of elements in it.
3034 lset
3035 ~~~~
3036 +*lset* 'varName ?index ..? newValue'+
3038 Sets an element in a list.
3040 The `lset` command accepts a parameter, +'varName'+, which it interprets
3041 as the name of a variable containing a Tcl list. It also accepts
3042 zero or more indices into the list. Finally, it accepts a new value
3043 for an element of varName. If no indices are presented, the command
3044 takes the form:
3046     lset varName newValue
3048 In this case, newValue replaces the old value of the variable
3049 varName.
3051 When presented with a single index, the `lset` command
3052 treats the content of the varName variable as a Tcl list. It addresses
3053 the index'th element in it (0 refers to the first element of the
3054 list). When interpreting the list, `lset` observes the same rules
3055 concerning braces and quotes and backslashes as the Tcl command
3056 interpreter; however, variable substitution and command substitution
3057 do not occur. The command constructs a new list in which the
3058 designated element is replaced with newValue. This new list is
3059 stored in the variable varName, and is also the return value from
3060 the `lset` command.
3062 If index is negative or greater than or equal to the number of
3063 elements in $varName, then an error occurs.
3065 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'index'+.
3067 If additional index arguments are supplied, then each argument is
3068 used in turn to address an element within a sublist designated by
3069 the previous indexing operation, allowing the script to alter
3070 elements in sublists. The command,
3072     lset a 1 2 newValue
3074 replaces element 2 of sublist 1 with +'newValue'+.
3076 The integer appearing in each index argument must be greater than
3077 or equal to zero. The integer appearing in each index argument must
3078 be strictly less than the length of the corresponding list. In other
3079 words, the `lset` command cannot change the size of a list. If an
3080 index is outside the permitted range, an error is reported.
3082 lmap
3083 ~~~~
3085 +*lmap* 'varName list body'+
3087 +*lmap* 'varList list ?varList2 list2 \...? body'+
3089 `lmap` is a "collecting" `foreach` which returns a list of its results.
3091 For example:
3093     jim> lmap i {1 2 3 4 5} {expr $i*$i}
3094     1 4 9 16 25
3095     jim> lmap a {1 2 3} b {A B C} {list $a $b}
3096     {1 A} {2 B} {3 C}
3098 If the body invokes `continue`, no value is added for this iteration.
3099 If the body invokes `break`, the loop ends and no more values are added.
3101 load
3102 ~~~~
3103 +*load* 'filename'+
3105 Loads the dynamic extension, +'filename'+. Generally the filename should have
3106 the extension +.so+. The initialisation function for the module must be based
3107 on the name of the file. For example loading +hwaccess.so+ will invoke
3108 the initialisation function, +Jim_hwaccessInit+. Normally the `load` command
3109 should not be used directly. Instead it is invoked automatically by `package require`.
3111 lrange
3112 ~~~~~~
3113 +*lrange* 'list first last'+
3115 +'list'+ must be a valid Tcl list. This command will return a new
3116 list consisting of elements +'first'+ through +'last'+, inclusive.
3118 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3120 If +'last'+ is greater than or equal to the number of elements
3121 in the list, then it is treated as if it were +end+.
3123 If +'first'+ is greater than +'last'+ then an empty string
3124 is returned.
3126 Note: +"`lrange` 'list first first'"+ does not always produce the
3127 same result as +"`lindex` 'list first'"+ (although it often does
3128 for simple fields that aren't enclosed in braces); it does, however,
3129 produce exactly the same results as +"`list` [`lindex` 'list first']"+
3131 lreplace
3132 ~~~~~~~~
3134 +*lreplace* 'list first last ?element element \...?'+
3136 Returns a new list formed by replacing one or more elements of
3137 +'list'+ with the +'element'+ arguments.
3139 +'first'+ gives the index in +'list'+ of the first element
3140 to be replaced.
3142 If +'first'+ is less than zero then it refers to the first
3143 element of +'list'+;  the element indicated by +'first'+
3144 must exist in the list.
3146 +'last'+ gives the index in +'list'+ of the last element
3147 to be replaced;  it must be greater than or equal to +'first'+.
3149 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
3151 The +'element'+ arguments specify zero or more new arguments to
3152 be added to the list in place of those that were deleted.
3154 Each +'element'+ argument will become a separate element of
3155 the list.
3157 If no +'element'+ arguments are specified, then the elements
3158 between +'first'+ and +'last'+ are simply deleted.
3160 lrepeat
3161 ~~~~~~~~
3162 +*lrepeat* 'number element1 ?element2 \...?'+
3164 Build a list by repeating elements +'number'+ times (which must be
3165 a positive integer).
3167     jim> lrepeat 3 a b
3168     a b a b a b
3170 lreverse
3171 ~~~~~~~~
3172 +*lreverse* 'list'+
3174 Returns the list in reverse order.
3176     jim> lreverse {1 2 3}
3177     3 2 1
3179 lsearch
3180 ~~~~~~~
3181 +*lsearch* '?options? list pattern'+
3183 This command searches the elements +'list'+ to see if one of them matches +'pattern'+. If so, the
3184 command returns the index of the first matching element (unless the options +-all+, +-inline+ or +-bool+ are
3185 specified.) If not, the command returns -1. The option arguments indicates how the elements of
3186 the list are to be matched against pattern and must have one of the values below:
3188 *Note* that this command is different from Tcl in that default match type is +-exact+ rather than +-glob+.
3190 +*-exact*+::
3191     +'pattern'+ is a literal string that is compared for exact equality against each list element.
3192     This is the default.
3194 +*-glob*+::
3195     +'pattern'+ is a glob-style pattern which is matched against each list element using the same
3196     rules as the string match command.
3198 +*-regexp*+::
3199     +'pattern'+ is treated as a regular expression and matched against each list element using
3200     the rules described by `regexp`.
3202 +*-command* 'cmdname'+::
3203     +'cmdname'+ is a command which is used to match the pattern against each element of the
3204     list. It is invoked as +'cmdname' ?*-nocase*? 'pattern listvalue'+ and should return 1
3205     for a match, or 0 for no match.
3207 +*-all*+::
3208     Changes the result to be the list of all matching indices (or all matching values if
3209     +-inline+ is specified as well). If indices are returned, the indices will be in numeric
3210     order. If values are returned, the order of the values will be the order of those values
3211     within the input list.
3213 +*-inline*+::
3214     The matching value is returned instead of its index (or an empty string if no value
3215     matches). If +-all+ is also specified, then the result of the command is the list of all
3216     values that matched. The +-inline+ and +-bool+ options are mutually exclusive.
3218 +*-bool*+::
3219     Changes the result to '1' if a match was found, or '0' otherwise. If +-all+ is also specified,
3220     the result will be a list of '0' and '1' for each element of the list depending upon whether
3221     the corresponding element matches. The +-inline+ and +-bool+ options are mutually exclusive.
3223 +*-not*+::
3224     This negates the sense of the match, returning the index (or value
3225     if +-inline+ is specified) of the first non-matching value in the
3226     list. If +-bool+ is also specified, the '0' will be returned if a
3227     match is found, or '1' otherwise. If +-all+ is also specified,
3228     non-matches will be returned rather than matches.
3230 +*-nocase*+::
3231     Causes comparisons to be handled in a case-insensitive manner.
3233 lsort
3234 ~~~~~
3235 +*lsort* ?*-index* 'listindex'? ?*-nocase|-integer|-real|-command* 'cmdname'? ?*-unique*? ?*-decreasing*|*-increasing*? 'list'+
3237 Sort the elements of +'list'+, returning a new list in sorted order.
3238 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.
3240 If +-nocase+ is specified, comparisons are case-insensitive.
3242 If +-integer+ is specified, numeric sorting is used.
3244 If +-real+ is specified, floating point number sorting is used.
3246 If +-command 'cmdname'+ is specified, +'cmdname'+ is treated as a command
3247 name. For each comparison, +'cmdname $value1 $value2+' is called which
3248 should compare the values and return an integer less than, equal
3249 to, or greater than zero if the +'$value1'+ is to be considered less
3250 than, equal to, or greater than +'$value2'+, respectively.
3252 If +-decreasing+ is specified, the resulting list is in the opposite
3253 order to what it would be otherwise. +-increasing+ is the default.
3255 If +-unique+ is specified, then only the last set of duplicate elements found in the list will be retained.
3256 Note that duplicates are determined relative to the comparison used in the sort. Thus if +-index 0+ is used,
3257 +{1 a}+ and +{1 b}+ would be considered duplicates and only the second element, +{1 b}+, would be retained.
3259 If +-index 'listindex'+ is specified, each element of the list is treated as a list and
3260 the given index is extracted from the list for comparison. The list index may
3261 be any valid list index, such as +1+, +end+ or +end-2+.
3263 defer
3264 ~~~~~
3265 +*defer* 'script'+
3267 This command is a simple helper command to add a script to the '+$jim::defer+' variable
3268 that will run when the current proc or interpreter exits. For example:
3270     jim> proc a {} { defer {puts "Leaving a"}; puts "Exit" }
3271     jim> a
3272     Exit
3273     Leaving a
3275 If the '+$jim::defer+' variable exists, it is treated as a list of scripts to run
3276 when the proc or interpreter exits.
3278 open
3279 ~~~~
3280 +*open* 'fileName ?access?'+
3282 +*open* '|command-pipeline ?access?'+
3284 Opens a file and returns an identifier
3285 that may be used in future invocations
3286 of commands like `read`, `puts`, and `close`.
3287 +'fileName'+ gives the name of the file to open.
3289 The +'access'+ argument indicates the way in which the file is to be accessed.
3290 It may have any of the following values:
3292 +r+::
3293     Open the file for reading only; the file must already exist.
3295 +r++::
3296     Open the file for both reading and writing; the file must
3297     already exist.
3299 +w+::
3300     Open the file for writing only. Truncate it if it exists. If it doesn't
3301     exist, create a new file.
3303 +w++::
3304     Open the file for reading and writing. Truncate it if it exists.
3305     If it doesn't exist, create a new file.
3307 +a+::
3308     Open the file for writing only. The file must already exist, and the file
3309     is positioned so that new data is appended to the file.
3311 +a++::
3312     Open the file for reading and writing. If the file doesn't
3313     exist, create a new empty file. Set the initial access position
3314     to the end of the file.
3316 +'access'+ defaults to 'r'.
3318 If a file is opened for both reading and writing, then `seek`
3319 must be invoked between a read and a write, or vice versa.
3321 If the first character of +'fileName'+ is "|" then the remaining
3322 characters of +'fileName'+ are treated as a list of arguments that
3323 describe a command pipeline to invoke, in the same style as the
3324 arguments for exec. In this case, the channel identifier returned
3325 by open may be used to write to the command's input pipe or read
3326 from its output pipe, depending on the value of +'access'+. If write-only
3327 access is used (e.g. +'access'+ is 'w'), then standard output for the
3328 pipeline is directed to the current standard output unless overridden
3329 by the command. If read-only access is used (e.g. +'access'+ is r),
3330 standard input for the pipeline is taken from the current standard
3331 input unless overridden by the command.
3333 The `pid` command may be used to return the process ids of the commands
3334 forming the command pipeline.
3336 See also `socket`, `pid`, `exec`
3338 package
3339 ~~~~~~~
3340 +*package provide* 'name ?version?'+
3342 Indicates that the current script provides the package named +'name'+.
3343 If no version is specified, '1.0' is used.
3345 Any script which provides a package may include this statement
3346 as the first statement, although it is not required.
3348 +*package require* 'name ?version?'*+
3350 Searches for the package with the given +'name'+ by examining each path
3351 in '$::auto_path' and trying to load '$path/$name.so' as a dynamic extension,
3352 or '$path/$name.tcl' as a script package.
3354 The first such file which is found is considered to provide the package.
3355 (The version number is ignored).
3357 If '$name.so' exists, it is loaded with the `load` command,
3358 otherwise if '$name.tcl' exists it is loaded with the `source` command.
3360 If `load` or `source` fails, `package require` will fail immediately.
3361 No further attempt will be made to locate the file.
3365 +*pid*+
3367 +*pid* 'fileId'+
3369 The first form returns the process identifier of the current process.
3371 The second form accepts a handle returned by `open` and returns a list
3372 of the process ids forming the pipeline in the same form as `exec ... &`.
3373 If 'fileId' represents a regular file handle rather than a command pipeline,
3374 the empty string is returned instead.
3376 See also `open`, `exec`
3378 proc
3379 ~~~~
3380 +*proc* 'name args ?statics? body'+
3382 The `proc` command creates a new Tcl command procedure, +'name'+.
3383 When the new command is invoked, the contents of +'body'+ will be executed.
3384 Tcl interpreter. +'args'+ specifies the formal arguments to the procedure.
3385 If specified, +'statics'+, declares static variables which are bound to the
3386 procedure.
3388 See PROCEDURES for detailed information about Tcl procedures.
3390 The `proc` command returns +'name'+ (which is useful with `local`).
3392 When a procedure is invoked, the procedure's return value is the
3393 value specified in a `return` command.  If the procedure doesn't
3394 execute an explicit `return`, then its return value is the value
3395 of the last command executed in the procedure's body.
3397 If an error occurs while executing the procedure body, then the
3398 procedure-as-a-whole will return that same error.
3400 puts
3401 ~~~~
3402 +*puts* ?*-nonewline*? '?fileId? string'+
3404 +'fileId' *puts* ?*-nonewline*? 'string'+
3406 Writes the characters given by +'string'+ to the file given
3407 by +'fileId'+. +'fileId'+ must have been the return
3408 value from a previous call to `open`, or it may be
3409 +stdout+ or +stderr+ to refer to one of the standard I/O
3410 channels; it must refer to a file that was opened for
3411 writing.
3413 In the first form, if no +'fileId'+ is specified then it defaults to +stdout+.
3414 `puts` normally outputs a newline character after +'string'+,
3415 but this feature may be suppressed by specifying the +-nonewline+
3416 switch.
3418 Output to files is buffered internally by Tcl; the `flush`
3419 command may be used to force buffered characters to be output.
3421 pipe
3422 ~~~~
3423 Creates a pair of `aio` channels and returns the handles as a list: +{read write}+
3427 +*pwd*+
3429 Returns the path name of the current working directory.
3431 rand
3432 ~~~~
3433 +*rand* '?min? ?max?'+
3435 Returns a random integer between +'min'+ (defaults to 0) and +'max'+
3436 (defaults to the maximum integer).
3438 If only one argument is given, it is interpreted as +'max'+.
3440 range
3441 ~~~~
3442 +*range* '?start? end ?step?'+
3444 Returns a list of integers starting at +'start'+ (defaults to 0)
3445 and ranging up to but not including +'end'+ in steps of +'step'+ defaults to 1).
3447     jim> range 5
3448     0 1 2 3 4
3449     jim> range 2 5
3450     2 3 4
3451     jim> range 2 10 4
3452     2 6
3453     jim> range 7 4 -2
3454     7 5
3456 read
3457 ~~~~
3458 +*read* ?*-nonewline*? 'fileId'+
3460 +'fileId' *read* ?*-nonewline*?+
3462 +*read* 'fileId numBytes'+
3464 +'fileId' *read* 'numBytes'+
3467 In the first form, all of the remaining bytes are read from the file
3468 given by +'fileId'+; they are returned as the result of the command.
3469 If the +-nonewline+ switch is specified then the last
3470 character of the file is discarded if it is a newline.
3472 In the second form, the extra argument specifies how many bytes to read;
3473 exactly this many bytes will be read and returned, unless there are fewer than
3474 +'numBytes'+ bytes left in the file; in this case, all the remaining
3475 bytes are returned.
3477 +'fileId'+ must be +stdin+ or the return value from a previous call
3478 to `open`; it must refer to a file that was opened for reading.
3480 regexp
3481 ~~~~~~
3482 +*regexp ?-nocase? ?-line? ?-indices? ?-start* 'offset'? *?-all? ?-inline? ?--?* 'exp string ?matchVar? ?subMatchVar subMatchVar \...?'+
3484 Determines whether the regular expression +'exp'+ matches part or
3485 all of +'string'+ and returns 1 if it does, 0 if it doesn't.
3487 See REGULAR EXPRESSIONS above for complete information on the
3488 syntax of +'exp'+ and how it is matched against +'string'+.
3490 If additional arguments are specified after +'string'+ then they
3491 are treated as the names of variables to use to return
3492 information about which part(s) of +'string'+ matched +'exp'+.
3493 +'matchVar'+ will be set to the range of +'string'+ that
3494 matched all of +'exp'+. The first +'subMatchVar'+ will contain
3495 the characters in +'string'+ that matched the leftmost parenthesized
3496 subexpression within +'exp'+, the next +'subMatchVar'+ will
3497 contain the characters that matched the next parenthesized
3498 subexpression to the right in +'exp'+, and so on.
3500 Normally, +'matchVar'+ and the each +'subMatchVar'+ are set to hold the
3501 matching characters from `string`, however see +-indices+ and
3502 +-inline+ below.
3504 If there are more values for +'subMatchVar'+ than parenthesized subexpressions
3505 within +'exp'+, or if a particular subexpression in +'exp'+ doesn't
3506 match the string (e.g. because it was in a portion of the expression
3507 that wasn't matched), then the corresponding +'subMatchVar'+ will be
3508 set to +"-1 -1"+ if +-indices+ has been specified or to an empty
3509 string otherwise.
3511 The following switches modify the behaviour of +'regexp'+
3513 +*-nocase*+::
3514     Causes upper-case and lower-case characters to be treated as
3515     identical during the matching process.
3517 +*-line*+::
3518     Use newline-sensitive matching. By default, newline
3519     is a completely ordinary character with no special meaning in
3520     either REs or strings. With this flag, +[^+ bracket expressions
3521     and +.+ never match newline, an +^+ anchor matches the null
3522     string after any newline in the string in addition to its normal
3523     function, and the +$+ anchor matches the null string before any
3524     newline in the string in addition to its normal function.
3526 +*-indices*+::
3527     Changes what is stored in the subMatchVars. Instead of
3528     storing the matching characters from string, each variable
3529     will contain a list of two decimal strings giving the indices
3530     in string of the first and last characters in the matching
3531     range of characters.
3533 +*-start* 'offset'+::
3534     Specifies a character index offset into the string at which to start
3535     matching the regular expression. If +-indices+ is
3536     specified, the indices will be indexed starting from the
3537     absolute beginning of the input string. +'offset'+ will be
3538     constrained to the bounds of the input string.
3540 +*-all*+::
3541     Causes the regular expression to be matched as many times as possible
3542     in the string, returning the total number of matches found. If this
3543     is specified with match variables, they will contain information
3544     for the last match only.
3546 +*-inline*+::
3547     Causes the command to return, as a list, the data that would otherwise
3548     be placed in match variables. When using +-inline+, match variables
3549     may not be specified. If used with +-all+, the list will be concatenated
3550     at each iteration, such that a flat list is always returned. For
3551     each match iteration, the command will append the overall match
3552     data, plus one element for each subexpression in the regular
3553     expression.
3555 +*--*+::
3556     Marks the end of switches. The argument following this one will be
3557     treated as +'exp'+ even if it starts with a +-+.
3559 regsub
3560 ~~~~~~
3561 +*regsub ?-nocase? ?-all? ?-line? ?-start* 'offset'? ?*--*? 'exp string subSpec ?varName?'+
3563 This command matches the regular expression +'exp'+ against
3564 +'string'+ using the rules described in REGULAR EXPRESSIONS
3565 above.
3567 If +'varName'+ is specified, the commands stores +'string'+ to +'varName'+
3568 with the substitutions detailed below, and returns the number of
3569 substitutions made (normally 1 unless +-all+ is specified).
3570 This is 0 if there were no matches.
3572 If +'varName'+ is not specified, the substituted string will be returned
3573 instead.
3575 When copying +'string'+, the portion of +'string'+ that
3576 matched +'exp'+ is replaced with +'subSpec'+.
3577 If +'subSpec'+ contains a +&+ or +{backslash}0+, then it is replaced
3578 in the substitution with the portion of +'string'+ that
3579 matched +'exp'+.
3581 If +'subSpec'+ contains a +{backslash}n+, where +'n'+ is a digit
3582 between 1 and 9, then it is replaced in the substitution with
3583 the portion of +'string'+ that matched the +'n'+\'-th
3584 parenthesized subexpression of +'exp'+.
3585 Additional backslashes may be used in +'subSpec'+ to prevent special
3586 interpretation of +&+ or +{backslash}0+ or +{backslash}n+ or
3587 backslash.
3589 The use of backslashes in +'subSpec'+ tends to interact badly
3590 with the Tcl parser's use of backslashes, so it's generally
3591 safest to enclose +'subSpec'+ in braces if it includes
3592 backslashes.
3594 The following switches modify the behaviour of +'regsub'+
3596 +*-nocase*+::
3597     Upper-case characters in +'string'+ are converted to lower-case
3598     before matching against +'exp'+;  however, substitutions
3599     specified by +'subSpec'+ use the original unconverted form
3600     of +'string'+.
3602 +*-all*+::
3603     All ranges in +'string'+ that match +'exp'+ are found and substitution
3604     is performed for each of these ranges, rather than only the
3605     first. The +&+ and +{backslash}n+ sequences are handled for
3606     each substitution using the information from the corresponding
3607     match.
3609 +*-line*+::
3610     Use newline-sensitive matching. By default, newline
3611     is a completely ordinary character with no special meaning in
3612     either REs or strings.  With this flag, +[^+ bracket expressions
3613     and +.+ never match newline, an +^+ anchor matches the null
3614     string after any newline in the string in addition to its normal
3615     function, and the +$+ anchor matches the null string before any
3616     newline in the string in addition to its normal function.
3618 +*-start* 'offset'+::
3619     Specifies a character index offset into the string at which to
3620     start matching the regular expression. +'offset'+ will be
3621     constrained to the bounds of the input string.
3623 +*--*+::
3624     Marks the end of switches. The argument following this one will be
3625     treated as +'exp'+ even if it starts with a +-+.
3629 +*ref* 'string tag ?finalizer?'+
3631 Create a new reference containing +'string'+ of type +'tag'+.
3632 If +'finalizer'+ is specified, it is a command which will be invoked
3633 when the a garbage collection cycle runs and this reference is
3634 no longer accessible.
3636 The finalizer is invoked as:
3638   finalizer reference string
3640 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3642 rename
3643 ~~~~~~
3644 +*rename* 'oldName newName'+
3646 Rename the command that used to be called +'oldName'+ so that it
3647 is now called +'newName'+.  If +'newName'+ is an empty string
3648 (e.g. {}) then +'oldName'+ is deleted.  The `rename` command
3649 returns an empty string as result.
3651 return
3652 ~~~~~~
3653 +*return* ?*-code* 'code'? ?*-errorinfo* 'stacktrace'? ?*-errorcode* 'errorcode'? ?*-level* 'n'? ?'value'?+
3655 Return immediately from the current procedure (or top-level command
3656 or `source` command), with +'value'+ as the return value.  If +'value'+
3657 is not specified, an empty string will be returned as result.
3659 If +-code+ is specified (as either a number or ok, error, break,
3660 continue, signal, return or exit), this code will be used instead
3661 of +JIM_OK+. This is generally useful when implementing flow of control
3662 commands.
3664 If +-level+ is specified and greater than 1, it has the effect of delaying
3665 the new return code from +-code+. This is useful when rethrowing an error
3666 from `catch`. See the implementation of try/catch in tclcompat.tcl for
3667 an example of how this is done.
3669 Note: The following options are only used when +-code+ is JIM_ERR.
3671 If +-errorinfo+ is specified (as returned from `info stacktrace`)
3672 it is used to initialize the stacktrace.
3674 If +-errorcode+ is specified, it is used to set the global variable $::errorCode.
3676 scan
3677 ~~~~
3678 +*scan* 'string format varName1 ?varName2 \...?'+
3680 This command parses fields from an input string in the same fashion
3681 as the C 'sscanf' procedure.  +'string'+ gives the input to be parsed
3682 and +'format'+ indicates how to parse it, using '%' fields as in
3683 'sscanf'.  All of the 'sscanf' options are valid; see the 'sscanf'
3684 man page for details.  Each +'varName'+ gives the name of a variable;
3685 when a field is scanned from +'string'+, the result is converted back
3686 into a string and assigned to the corresponding +'varName'+.  The
3687 only unusual conversion is for '%c'.  For '%c' conversions a single
3688 character value is converted to a decimal string, which is then
3689 assigned to the corresponding +'varName'+; no field width may be
3690 specified for this conversion.
3692 seek
3693 ~~~~
3694 +*seek* 'fileId offset ?origin?'+
3696 +'fileId' *seek* 'offset ?origin?'+
3698 Change the current access position for +'fileId'+.
3699 The +'offset'+ and +'origin'+ arguments specify the position at
3700 which the next read or write will occur for +'fileId'+.
3701 +'offset'+ must be a number (which may be negative) and +'origin'+
3702 must be one of the following:
3704 +*start*+::
3705     The new access position will be +'offset'+ bytes from the start
3706     of the file.
3708 +*current*+::
3709     The new access position will be +'offset'+ bytes from the current
3710     access position; a negative +'offset'+ moves the access position
3711     backwards in the file.
3713 +*end*+::
3714     The new access position will be +'offset'+ bytes from the end of
3715     the file.  A negative +'offset'+ places the access position before
3716     the end-of-file, and a positive +'offset'+ places the access position
3717     after the end-of-file.
3719 The +'origin'+ argument defaults to +start+.
3721 +'fileId'+ must have been the return value from a previous call to
3722 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
3723 of the standard I/O channels.
3725 This command returns an empty string.
3729 +*set* 'varName ?value?'+
3731 Returns the value of variable +'varName'+.
3733 If +'value'+ is specified, then set the value of +'varName'+ to +'value'+,
3734 creating a new variable if one doesn't already exist, and return
3735 its value.
3737 If +'varName'+ contains an open parenthesis and ends with a
3738 close parenthesis, then it refers to an array element:  the characters
3739 before the open parenthesis are the name of the array, and the characters
3740 between the parentheses are the index within the array.
3741 Otherwise +'varName'+ refers to a scalar variable.
3743 If no procedure is active, then +'varName'+ refers to a global
3744 variable.
3746 If a procedure is active, then +'varName'+ refers to a parameter
3747 or local variable of the procedure, unless the +'global'+ command
3748 has been invoked to declare +'varName'+ to be global.
3750 The +::+ prefix may also be used to explicitly reference a variable
3751 in the global scope.
3753 setref
3754 ~~~~~~
3755 +*setref* 'reference string'+
3757 Store a new string in +'reference'+, replacing the existing string.
3758 The reference must be a valid reference create with the `ref`
3759 command.
3761 See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.
3763 signal
3764 ~~~~~~
3765 Command for signal handling.
3767 See `kill` for the different forms which may be used to specify signals.
3769 Commands which return a list of signal names do so using the canonical form:
3770 "+SIGINT SIGTERM+".
3772 +*signal handle* ?'signals \...'?+::
3773     If no signals are given, returns a list of all signals which are currently
3774     being handled.
3775     If signals are specified, these are added to the list of signals currently
3776     being handled.
3778 +*signal ignore* ?'signals \...'?+::
3779     If no signals are given, returns a lists all signals which are currently
3780     being ignored.
3781     If signals are specified, these are added to the list of signals
3782     currently being ignored. These signals are still delivered, but
3783     are not considered by `catch -signal` or `try -signal`. Use
3784     `signal check` to determine which signals have occurred but
3785     been ignored.
3787 +*signal default* ?'signals \...'?+::
3788     If no signals are given, returns a lists all signals which are currently have
3789     the default behaviour.
3790     If signals are specified, these are added to the list of signals which have
3791     the default behaviour.
3793 +*signal check ?-clear?* ?'signals \...'?+::
3794     Returns a list of signals which have been delivered to the process
3795     but are 'ignored'. If signals are specified, only that set of signals will
3796     be checked, otherwise all signals will be checked.
3797     If +-clear+ is specified, any signals returned are removed and will not be
3798     returned by subsequent calls to `signal check` unless delivered again.
3800 +*signal throw* ?'signal'?+::
3801     Raises the given signal, which defaults to +SIGINT+ if not specified.
3802     The behaviour is identical to:
3804         kill signal [pid]
3806 Note that `signal handle` and `signal ignore` represent two forms of signal
3807 handling. `signal handle` is used in conjunction with `catch -signal` or `try -signal`
3808 to immediately abort execution when the signal is delivered. Alternatively, `signal ignore`
3809 is used in conjunction with `signal check` to handle signal synchronously. Consider the
3810 two examples below.
3812 Prevent a processing from taking too long
3814     signal handle SIGALRM
3815     alarm 20
3816     try -signal {
3817         .. possibly long running process ..
3818         alarm 0
3819     } on signal {sig} {
3820         puts stderr "Process took too long"
3821     }
3823 Handle SIGHUP to reconfigure:
3825     signal ignore SIGHUP
3826     while {1} {
3827         ... handle configuration/reconfiguration ...
3828         while {[signal check -clear SIGHUP] eq ""} {
3829             ... do processing ..
3830         }
3831         # Received SIGHUP, so reconfigure
3832     }
3834 Note: signal handling is currently not supported in child interpreters.
3835 In these interpreters, the signal command does not exist.
3837 sleep
3838 ~~~~~
3839 +*sleep* 'seconds'+
3841 Pauses for the given number of seconds, which may be a floating
3842 point value less than one to sleep for less than a second, or an
3843 integer to sleep for one or more seconds.
3845 source
3846 ~~~~~~
3847 +*source* 'fileName'+
3849 Read file +'fileName'+ and pass the contents to the Tcl interpreter
3850 as a sequence of commands to execute in the normal fashion.  The return
3851 value of `source` is the return value of the last command executed
3852 from the file.  If an error occurs in executing the contents of the
3853 file, then the `source` command will return that error.
3855 If a `return` command is invoked from within the file, the remainder of
3856 the file will be skipped and the `source` command will return
3857 normally with the result from the `return` command.
3859 split
3860 ~~~~~
3861 +*split* 'string ?splitChars?'+
3863 Returns a list created by splitting +'string'+ at each character
3864 that is in the +'splitChars'+ argument.
3866 Each element of the result list will consist of the
3867 characters from +'string'+ between instances of the
3868 characters in +'splitChars'+.
3870 Empty list elements will be generated if +'string'+ contains
3871 adjacent characters in +'splitChars'+, or if the first or last
3872 character of +'string'+ is in +'splitChars'+.
3874 If +'splitChars'+ is an empty string then each character of
3875 +'string'+ becomes a separate element of the result list.
3877 +'splitChars'+ defaults to the standard white-space characters.
3878 For example,
3880     split "comp.unix.misc" .
3882 returns +'"comp unix misc"'+ and
3884     split "Hello world" {}
3886 returns +'"H e l l o { } w o r l d"'+.
3888 stackdump
3889 ~~~~~~~~~
3891 +*stackdump* 'stacktrace'+
3893 Creates a human readable representation of a stack trace.
3895 stacktrace
3896 ~~~~~~~~~~
3898 +*stacktrace*+
3900 Returns a live stack trace as a list of +proc file line proc file line \...+.
3901 Iteratively uses `info frame` to create the stack trace. This stack trace is in the
3902 same form as produced by `catch` and `info stacktrace`
3904 See also `stackdump`.
3906 string
3907 ~~~~~~
3909 +*string* 'option arg ?arg \...?'+
3911 Perform one of several string operations, depending on +'option'+.
3912 The legal options (which may be abbreviated) are:
3914 +*string bytelength* 'string'+::
3915     Returns the length of the string in bytes. This will return
3916     the same value as `string length` if UTF-8 support is not enabled,
3917     or if the string is composed entirely of ASCII characters.
3918     See UTF-8 AND UNICODE.
3920 +*string byterange* 'string first last'+::
3921     Like `string range` except works on bytes rather than characters.
3922     These commands are identical if UTF-8 support is not enabled.
3924 +*string cat* '?string1 string2 \...?'+::
3925     Concatenates the given strings into a single string.
3927 +*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
3928     Perform a character-by-character comparison of strings +'string1'+ and
3929     +'string2'+ in the same way as the C 'strcmp' procedure.  Return
3930     -1, 0, or 1, depending on whether +'string1'+ is lexicographically
3931     less than, equal to, or greater than +'string2'+. If +-length+
3932     is specified, then only the first +'len'+ characters are used
3933     in the comparison.  If +'len'+ is negative, it is ignored.
3934     Performs a case-insensitive comparison if +-nocase+ is specified.
3936 +*string equal ?-nocase?* '?*-length* len?' 'string1 string2'+::
3937     Returns 1 if the strings are equal, or 0 otherwise. If +-length+
3938     is specified, then only the first +'len'+ characters are used
3939     in the comparison.  If +'len'+ is negative, it is ignored.
3940     Performs a case-insensitive comparison if +-nocase+ is specified.
3942 +*string first* 'string1 string2 ?firstIndex?'+::
3943     Search +'string2'+ for a sequence of characters that exactly match
3944     the characters in +'string1'+.  If found, return the index of the
3945     first character in the first such match within +'string2'+.  If not
3946     found, return -1. If +'firstIndex'+ is specified, matching will start
3947     from +'firstIndex'+ of +'string1'+.
3948  ::
3949     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'firstIndex'+.
3951 +*string index* 'string charIndex'+::
3952     Returns the +'charIndex'+'th character of the +'string'+
3953     argument.  A +'charIndex'+ of 0 corresponds to the first
3954     character of the string.
3955     If +'charIndex'+ is less than 0 or greater than
3956     or equal to the length of the string then an empty string is
3957     returned.
3958  ::
3959     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'charIndex'+.
3961 +*string is* 'class' ?*-strict*? 'string'+::
3962     Returns 1 if +'string'+ is a valid member of the specified character
3963     class, otherwise returns 0. If +-strict+ is specified, then an
3964     empty string returns 0, otherwise an empty string will return 1
3965     on any class. The following character classes are recognized
3966     (the class name can be abbreviated):
3967   ::
3968   +alnum+;;  Any alphabet or digit character.
3969   +alpha+;;  Any alphabet character.
3970   +ascii+;;  Any character with a value less than 128 (those that are in the 7-bit ascii range).
3971   +boolean+;;  Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
3972   +control+;; Any control character.
3973   +digit+;;  Any digit character.
3974   +double+;; Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
3975              In case of under/overflow in the value, 0 is returned.
3976   +graph+;;  Any printing character, except space.
3977   +integer+;; Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
3978   +lower+;;  Any lower case alphabet character.
3979   +print+;;  Any printing character, including space.
3980   +punct+;;  Any punctuation character.
3981   +space+;;  Any space character.
3982   +upper+;;  Any upper case alphabet character.
3983   +xdigit+;; Any hexadecimal digit character ([0-9A-Fa-f]).
3984  ::
3985     Note that string classification does +'not'+ respect UTF-8. See UTF-8 AND UNICODE
3986  ::
3987     Note that only +'lowercase'+ boolean values are recognized (Tcl accepts any case).
3989 +*string last* 'string1 string2 ?lastIndex?'+::
3990     Search +'string2'+ for a sequence of characters that exactly match
3991     the characters in +'string1'+.  If found, return the index of the
3992     first character in the last such match within +'string2'+.  If there
3993     is no match, then return -1. If +'lastIndex'+ is specified, only characters
3994     up to +'lastIndex'+ of +'string2'+ will be considered in the match.
3995  ::
3996     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'lastIndex'+.
3998 +*string length* 'string'+::
3999     Returns a decimal string giving the number of characters in +'string'+.
4000     If UTF-8 support is enabled, this may be different than the number of bytes.
4001     See UTF-8 AND UNICODE
4003 +*string map ?-nocase?* 'mapping string'+::
4004     Replaces substrings in +'string'+ based on the key-value pairs in
4005     +'mapping'+, which is a list of +key value key value \...+ as in the form
4006     returned by `array get`. Each instance of a key in the string will be
4007     replaced with its corresponding value.  If +-nocase+ is specified, then
4008     matching is done without regard to case differences. Both key and value may
4009     be multiple characters.  Replacement is done in an ordered manner, so the
4010     key appearing first in the list will be checked first, and so on. +'string'+ is
4011     only iterated over once, so earlier key replacements will have no affect for
4012     later key matches. For example,
4014       string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc
4016  ::
4017     will return the string +01321221+.
4018  ::
4019     Note that if an earlier key is a prefix of a later one, it will completely mask the later
4020     one.  So if the previous example is reordered like this,
4022       string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc
4024  ::
4025     it will return the string +02c322c222c+.
4027 +*string match ?-nocase?* 'pattern string'+::
4028     See if +'pattern'+ matches +'string'+; return 1 if it does, 0
4029     if it doesn't.  Matching is done in a fashion similar to that
4030     used by the C-shell.  For the two strings to match, their contents
4031     must be identical except that the following special sequences
4032     may appear in +'pattern'+:
4034     +*+;;
4035         Matches any sequence of characters in +'string'+,
4036         including a null string.
4038     +?+;;
4039         Matches any single character in +'string'+.
4041     +['chars']+;;
4042         Matches any character in the set given by +'chars'+.
4043         If a sequence of the form +'x-y'+ appears in +'chars'+,
4044         then any character between +'x'+ and +'y'+, inclusive,
4045         will match.
4047     +{backslash}x+;;
4048         Matches the single character +'x'+.  This provides a way of
4049         avoiding the special interpretation of the characters +{backslash}*?[]+
4050         in +'pattern'+.
4051  ::
4052     Performs a case-insensitive comparison if +-nocase+ is specified.
4054 +*string range* 'string first last'+::
4055     Returns a range of consecutive characters from +'string'+, starting
4056     with the character whose index is +'first'+ and ending with the
4057     character whose index is +'last'+.  An index of 0 refers to the
4058     first character of the string.
4059  ::
4060     See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for +'first'+ and +'last'+.
4061  ::
4062     If +'first'+ is less than zero then it is treated as if it were zero, and
4063     if +'last'+ is greater than or equal to the length of the string then
4064     it is treated as if it were +end+.  If +'first'+ is greater than
4065     +'last'+ then an empty string is returned.
4067 +*string repeat* 'string count'+::
4068     Returns a new string consisting of +'string'+ repeated +'count'+ times.
4070 +*string replace* 'string first last ?newstring?'+::
4071     Removes a range of consecutive characters from +'string'+, starting
4072     with the character whose index is +'first'+ and ending with the
4073     character whose index is +'last'+.  If +'newstring'+ is specified,
4074     then it is placed in the removed character range. If +'first'+ is
4075     less than zero then it is treated as if it were zero, and if +'last'+
4076     is greater than or equal to the length of the string then it is
4077     treated as if it were +end+. If +'first'+ is greater than +'last'+
4078     or the length of the initial string, or +'last'+ is less than 0,
4079     then the initial string is returned untouched.
4081 +*string reverse* 'string'+::
4082     Returns a string that is the same length as +'string'+ but
4083     with its characters in the reverse order.
4085 +*string tolower* 'string'+::
4086     Returns a value equal to +'string'+ except that all upper case
4087     letters have been converted to lower case.
4089 +*string totitle* 'string'+::
4090     Returns a value equal to +'string'+ except that the first character
4091     is converted to title case (or upper case if there is no UTF-8 titlecase variant)
4092     and all remaining characters have been converted to lower case.
4094 +*string toupper* 'string'+::
4095     Returns a value equal to +'string'+ except that all lower case
4096     letters have been converted to upper case.
4098 +*string trim* 'string ?chars?'+::
4099     Returns a value equal to +'string'+ except that any leading
4100     or trailing characters from the set given by +'chars'+ are
4101     removed.
4102     If +'chars'+ is not specified then white space is removed
4103     (spaces, tabs, newlines, and carriage returns).
4105 +*string trimleft* 'string ?chars?'+::
4106     Returns a value equal to +'string'+ except that any
4107     leading characters from the set given by +'chars'+ are
4108     removed.
4109     If +'chars'+ is not specified then white space is removed
4110     (spaces, tabs, newlines, and carriage returns).
4112 +*string trimright* 'string ?chars?'+::
4113     Returns a value equal to +'string'+ except that any
4114     trailing characters from the set given by +'chars'+ are
4115     removed.
4116     If +'chars'+ is not specified then white space is removed
4117     (spaces, tabs, newlines, and carriage returns).
4118     Null characters are always removed.
4120 subst
4121 ~~~~~
4122 +*subst ?-nobackslashes? ?-nocommands? ?-novariables?* 'string'+
4124 This command performs variable substitutions, command substitutions,
4125 and backslash substitutions on its string argument and returns the
4126 fully-substituted result. The substitutions are performed in exactly
4127 the same way as for Tcl commands. As a result, the string argument
4128 is actually substituted twice, once by the Tcl parser in the usual
4129 fashion for Tcl commands, and again by the subst command.
4131 If any of the +-nobackslashes+, +-nocommands+, or +-novariables+ are
4132 specified, then the corresponding substitutions are not performed.
4133 For example, if +-nocommands+ is specified, no command substitution
4134 is performed: open and close brackets are treated as ordinary
4135 characters with no special interpretation.
4137 *Note*: when it performs its substitutions, subst does not give any
4138 special treatment to double quotes or curly braces. For example,
4139 the following script returns +xyz \{44\}+, not +xyz \{$a\}+.
4141     set a 44
4142     subst {xyz {$a}}
4145 switch
4146 ~~~~~~
4147 +*switch* '?options? string pattern body ?pattern body \...?'+
4149 +*switch* '?options? string {pattern body ?pattern body \...?}'+
4151 The `switch` command matches its string argument against each of
4152 the pattern arguments in order. As soon as it finds a pattern that
4153 matches string it evaluates the following body and returns the
4154 result of that evaluation. If the last pattern argument is default
4155 then it matches anything. If no pattern argument matches string and
4156 no default is given, then the `switch` command returns an empty string.
4157 If the initial arguments to switch start with - then they are treated
4158 as options. The following options are currently supported:
4160     +-exact+::
4161         Use exact matching when comparing string to a
4162         pattern. This is the default.
4164     +-glob+::
4165         When matching string to the patterns, use glob-style
4166         matching (i.e. the same as implemented by the string
4167         match command).
4169     +-regexp+::
4170         When matching string to the patterns, use regular
4171         expression matching (i.e. the same as implemented
4172         by the regexp command).
4174     +-command 'commandname'+::
4175         When matching string to the patterns, use the given command, which
4176         must be a single word. The command is invoked as
4177         'commandname pattern string', or 'commandname -nocase pattern string'
4178         and must return 1 if matched, or 0 if not.
4180     +--+::
4181         Marks the end of options. The argument following
4182         this one will be treated as string even if it starts
4183         with a +-+.
4185 Two syntaxes are provided for the pattern and body arguments. The
4186 first uses a separate argument for each of the patterns and commands;
4187 this form is convenient if substitutions are desired on some of the
4188 patterns or commands. The second form places all of the patterns
4189 and commands together into a single argument; the argument must
4190 have proper list structure, with the elements of the list being the
4191 patterns and commands. The second form makes it easy to construct
4192 multi-line `switch` commands, since the braces around the whole list
4193 make it unnecessary to include a backslash at the end of each line.
4194 Since the pattern arguments are in braces in the second form, no
4195 command or variable substitutions are performed on them; this makes
4196 the behaviour of the second form different than the first form in
4197 some cases.
4199 If a body is specified as +-+ it means that the body for the next
4200 pattern should also be used as the body for this pattern (if the
4201 next pattern also has a body of +-+ then the body after that is
4202 used, and so on). This feature makes it possible to share a single
4203 body among several patterns.
4205 Below are some examples of `switch` commands:
4207     switch abc a - b {format 1} abc {format 2} default {format 3}
4209 will return 2,
4211     switch -regexp aaab {
4212            ^a.*b$ -
4213            b {format 1}
4214            a* {format 2}
4215            default {format 3}
4216     }
4218 will return 1, and
4220     switch xyz {
4221            a -
4222            b {format 1}
4223            a* {format 2}
4224            default {format 3}
4225     }
4227 will return 3.
4229 tailcall
4230 ~~~~~~~~
4231 +*tailcall* 'cmd ?arg\...?'+
4233 The `tailcall` command provides an optimised way of invoking a command whilst replacing
4234 the current call frame. This is similar to 'exec' in Bourne Shell.
4236 The following are identical except the first immediately replaces the current call frame.
4238   tailcall a b c
4240   return [uplevel 1 [list a b c]]
4242 `tailcall` is useful as a dispatch mechanism:
4244   proc a {cmd args} {
4245     tailcall sub_$cmd {*}$args
4246   }
4247   proc sub_cmd1 ...
4248   proc sub_cmd2 ...
4250 tell
4251 ~~~~
4252 +*tell* 'fileId'+
4254 +'fileId' *tell*+
4256 Returns a decimal string giving the current access position in
4257 +'fileId'+.
4259 +'fileId'+ must have been the return value from a previous call to
4260 `open`, or it may be +stdin+, +stdout+, or +stderr+ to refer to one
4261 of the standard I/O channels.
4263 throw
4264 ~~~~~
4265 +*throw* 'code ?msg?'+
4267 This command throws an exception (return) code along with an optional message.
4268 This command is mostly for convenient usage with `try`.
4270 The command +throw break+ is equivalent to +break+.
4271 The command +throw 20 message+ can be caught with an +on 20 \...+ clause to `try`.
4273 time
4274 ~~~~
4275 +*time* 'command ?count?'+
4277 This command will call the Tcl interpreter +'count'+
4278 times to execute +'command'+ (or once if +'count'+ isn't
4279 specified).  It will then return a string of the form
4281     503 microseconds per iteration
4283 which indicates the average amount of time required per iteration,
4284 in microseconds.
4286 Time is measured in elapsed time, not CPU time.
4290 +*try* '?catchopts? tryscript' ?*on* 'returncodes {?resultvar? ?optsvar?} handlerscript \...'? ?*finally* 'finalscript'?+
4292 The `try` command is provided as a convenience for exception handling.
4294 This interpeter first evaluates +'tryscript'+ under the effect of the catch
4295 options +'catchopts'+ (e.g. +-signal -noexit --+, see `catch`).
4297 It then evaluates the script for the first matching 'on' handler
4298 (there many be zero or more) based on the return code from the `try`
4299 section. For example a normal +JIM_ERR+ error will be matched by
4300 an 'on error' handler.
4302 Finally, any +'finalscript'+ is evaluated.
4304 The result of this command is the result of +'tryscript'+, except in the
4305 case where an exception occurs in a matching 'on' handler script or the 'finally' script,
4306 in which case the result is this new exception.
4308 The specified +'returncodes'+ is a list of return codes either as names ('ok', 'error', 'break', etc.)
4309 or as integers.
4311 If +'resultvar'+ and +'optsvar'+ are specified, they are set as for `catch` before evaluating
4312 the matching handler.
4314 For example:
4316     set f [open input]
4317     try -signal {
4318         process $f
4319     } on {continue break} {} {
4320         error "Unexpected break/continue"
4321     } on error {msg opts} {
4322         puts "Dealing with error"
4323         return {*}$opts $msg
4324     } on signal sig {
4325         puts "Got signal: $sig"
4326     } finally {
4327         $f close
4328     }
4330 If break, continue or error are raised, they are dealt with by the matching
4331 handler.
4333 In any case, the file will be closed via the 'finally' clause.
4335 See also `throw`, `catch`, `return`, `error`.
4337 unknown
4338 ~~~~~~~
4339 +*unknown* 'cmdName ?arg arg ...?'+
4341 This command doesn't actually exist as part of Tcl, but Tcl will
4342 invoke it if it does exist.
4344 If the Tcl interpreter encounters a command name for which there
4345 is not a defined command, then Tcl checks for the existence of
4346 a command named `unknown`.
4348 If there is no such command, then the interpreter returns an
4349 error.
4351 If the `unknown` command exists, then it is invoked with
4352 arguments consisting of the fully-substituted name and arguments
4353 for the original non-existent command.
4355 The `unknown` command typically does things like searching
4356 through library directories for a command procedure with the name
4357 +'cmdName'+, or expanding abbreviated command names to full-length,
4358 or automatically executing unknown commands as UNIX sub-processes.
4360 In some cases (such as expanding abbreviations) `unknown` will
4361 change the original command slightly and then (re-)execute it.
4362 The result of the `unknown` command is used as the result for
4363 the original non-existent command.
4365 unset
4366 ~~~~~
4367 +*unset ?-nocomplain? ?--?* '?name name ...?'+
4369 Remove variables.
4370 Each +'name'+ is a variable name, specified in any of the
4371 ways acceptable to the `set` command.
4373 If a +'name'+ refers to an element of an array, then that
4374 element is removed without affecting the rest of the array.
4376 If a +'name'+ consists of an array name with no parenthesized
4377 index, then the entire array is deleted.
4379 The `unset` command returns an empty string as result.
4381 An error occurs if any of the variables doesn't exist, unless '-nocomplain'
4382 is specified. The '--' argument may be specified to stop option processing
4383 in case the variable name may be '-nocomplain'.
4385 upcall
4386 ~~~~~~~
4387 +*upcall* 'command ?args ...?'+
4389 May be used from within a proc defined as `local` `proc` in order to call
4390 the previous, hidden version of the same command.
4392 If there is no previous definition of the command, an error is returned.
4394 uplevel
4395 ~~~~~~~
4396 +*uplevel* '?level? command ?command ...?'+
4398 All of the +'command'+ arguments are concatenated as if they had
4399 been passed to `concat`; the result is then evaluated in the
4400 variable context indicated by +'level'+.  `uplevel` returns
4401 the result of that evaluation.  If +'level'+ is an integer, then
4402 it gives a distance (up the procedure calling stack) to move before
4403 executing the command.  If +'level'+ consists of +\#+ followed by
4404 a number then the number gives an absolute level number.  If +'level'+
4405 is omitted then it defaults to +1+.  +'level'+ cannot be
4406 defaulted if the first +'command'+ argument starts with a digit or +#+.
4408 For example, suppose that procedure 'a' was invoked
4409 from top-level, and that it called 'b', and that 'b' called 'c'.
4410 Suppose that 'c' invokes the `uplevel` command.  If +'level'+
4411 is +1+ or +#2+  or omitted, then the command will be executed
4412 in the variable context of 'b'.  If +'level'+ is +2+ or +#1+
4413 then the command will be executed in the variable context of 'a'.
4415 If +'level'+ is '3' or +#0+ then the command will be executed
4416 at top-level (only global variables will be visible).
4417 The `uplevel` command causes the invoking procedure to disappear
4418 from the procedure calling stack while the command is being executed.
4419 In the above example, suppose 'c' invokes the command
4421     uplevel 1 {set x 43; d}
4423 where 'd' is another Tcl procedure.  The `set` command will
4424 modify the variable 'x' in 'b's context, and 'd' will execute
4425 at level 3, as if called from 'b'.  If it in turn executes
4426 the command
4428     uplevel {set x 42}
4430 then the `set` command will modify the same variable 'x' in 'b's
4431 context:  the procedure 'c' does not appear to be on the call stack
4432 when 'd' is executing.  The command `info level` may
4433 be used to obtain the level of the current procedure.
4435 `uplevel` makes it possible to implement new control
4436 constructs as Tcl procedures (for example, `uplevel` could
4437 be used to implement the `while` construct as a Tcl procedure).
4439 upvar
4440 ~~~~~
4441 +*upvar* '?level? otherVar myVar ?otherVar myVar ...?'+
4443 This command arranges for one or more local variables in the current
4444 procedure to refer to variables in an enclosing procedure call or
4445 to global variables.
4447 +'level'+ may have any of the forms permitted for the `uplevel`
4448 command, and may be omitted if the first letter of the first +'otherVar'+
4449 isn't +#+ or a digit (it defaults to '1').
4451 For each +'otherVar'+ argument, `upvar` makes the variable
4452 by that name in the procedure frame given by +'level'+ (or at
4453 global level, if +'level'+ is +#0+) accessible
4454 in the current procedure by the name given in the corresponding
4455 +'myVar'+ argument.
4457 The variable named by +'otherVar'+ need not exist at the time of the
4458 call;  it will be created the first time +'myVar'+ is referenced, just like
4459 an ordinary variable.
4461 `upvar` may only be invoked from within procedures.
4463 `upvar` returns an empty string.
4465 The `upvar` command simplifies the implementation of call-by-name
4466 procedure calling and also makes it easier to build new control constructs
4467 as Tcl procedures.
4468 For example, consider the following procedure:
4470     proc add2 name {
4471         upvar $name x
4472         set x [expr $x+2]
4473     }
4475 'add2' is invoked with an argument giving the name of a variable,
4476 and it adds two to the value of that variable.
4477 Although 'add2' could have been implemented using `uplevel`
4478 instead of `upvar`, `upvar` makes it simpler for 'add2'
4479 to access the variable in the caller's procedure frame.
4481 wait
4482 ~~~~
4483 +*wait*+
4485 +*wait -nohang* 'pid'+
4487 With no arguments, cleans up any processes started by `exec ... &` that have completed
4488 (reaps zombie processes).
4490 With one or two arguments, waits for a process by id, either returned by `exec ... &`
4491 or by `os.fork` (if supported).
4493 Waits for the process to complete, unless +-nohang+ is specified, in which case returns
4494 immediately if the process is still running.
4496 Returns a list of 3 elements.
4498 +{NONE x x}+ if the process does not exist or has already been waited for, or
4499 if -nohang is specified, and the process is still alive.
4501 +{CHILDSTATUS <pid> <exit-status>}+ if the process exited normally.
4503 +{CHILDKILLED <pid> <signal>}+ if the process terminated on a signal.
4505 +{CHILDSUSP <pid> none}+ if the process terminated for some other reason.
4507 Note that on platforms supporting waitpid(2), +pid+ can also be given special values such
4508 as 0 or -1. See waitpid(2) for more detail.
4510 while
4511 ~~~~~
4512 +*while* 'test body'+
4514 The +'while'+ command evaluates +'test'+ as an expression
4515 (in the same way that `expr` evaluates its argument).
4516 The value of the expression must be numeric; if it is non-zero
4517 then +'body'+ is executed by passing it to the Tcl interpreter.
4519 Once +'body'+ has been executed then +'test'+ is evaluated
4520 again, and the process repeats until eventually +'test'+
4521 evaluates to a zero numeric value.  `continue`
4522 commands may be executed inside +'body'+ to terminate the current
4523 iteration of the loop, and `break`
4524 commands may be executed inside +'body'+ to cause immediate
4525 termination of the `while` command.
4527 The `while` command always returns an empty string.
4529 OPTIONAL-EXTENSIONS
4530 -------------------
4532 The following extensions may or may not be available depending upon
4533 what options were selected when Jim Tcl was built.
4536 [[cmd_1]]
4537 posix: os.fork, os.gethostname, os.getids, os.uptime
4538 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4539 +*os.fork*+::
4540     Invokes 'fork(2)' and returns the result.
4542 +*os.gethostname*+::
4543     Invokes 'gethostname(3)' and returns the result.
4545 +*os.getids*+::
4546     Returns the various user/group ids for the current process.
4548     jim> os.getids
4549     uid 1000 euid 1000 gid 100 egid 100
4551 +*os.uptime*+::
4552     Returns the number of seconds since system boot. See description of 'uptime' in 'sysinfo(2)'.
4554 ANSI I/O (aio) and EVENTLOOP API
4555 --------------------------------
4556 Jim provides an alternative object-based API for I/O.
4558 See `open` and `socket` for commands which return an I/O handle.
4562 +$handle *accept* ?addrvar?+::
4563     Server socket only: Accept a connection and return stream.
4564     If +'addrvar'+ is specified, the address of the connected client is stored
4565     in the named variable in the form 'addr:port'. See `socket` for details.
4567 +$handle *buffering none|line|full*+::
4568     Sets the buffering mode of the stream.
4570 +$handle *close* ?r(ead)|w(rite)?+::
4571     Closes the stream.
4572     The  two-argument form is a "half-close" on a socket. See the +shutdown(2)+ man page.
4574 +$handle *copyto* 'tofd ?size?'+::
4575     Copy bytes to the file descriptor +'tofd'+. If +'size'+ is specified, at most
4576     that many bytes will be copied. Otherwise copying continues until the end
4577     of the input file. Returns the number of bytes actually copied.
4579 +$handle *eof*+::
4580     Returns 1 if stream is at eof
4582 +$handle *filename*+::
4583     Returns the original filename associated with the handle.
4584     Handles returned by `socket` give the socket type instead of a filename.
4586 +$handle *flush*+::
4587     Flush the stream
4589 +$handle *gets* '?var?'+::
4590     Read one line and return it or store it in the var
4592 +$handle *isatty*+::
4593     Returns 1 if the stream is a tty device.
4595 +$handle *lock*+::
4596     Apply a POSIX lock to the open file associated with the handle using
4597     fcntl(2).
4598     The handle must be open for write access.
4599     Returns 1 if the lock was successfully obtained, 0 otherwise.
4600     An error occurs if the handle is not suitable for locking (e.g.
4601     if it is not open for write)
4603 +$handle *ndelay ?0|1?*+::
4604     Set O_NDELAY (if arg). Returns current/new setting.
4605     Note that in general ANSI I/O interacts badly with non-blocking I/O.
4606     Use with care.
4608 +$handle *puts ?-nonewline?* 'str'+::
4609     Write the string, with newline unless -nonewline
4611 +$handle *read ?-nonewline?* '?len?'+::
4612     Read and return bytes from the stream. To eof if no len.
4614 +$handle *recvfrom* 'maxlen ?addrvar?'+::
4615     Receives a message from the handle via recvfrom(2) and returns it.
4616     At most +'maxlen'+ bytes are read.
4617     If +'addrvar'+ is specified, the sending address of the message is stored in
4618     the named variable in the form 'addr:port'. See `socket` for details.
4620 +$handle *seek* 'offset' *?start|current|end?*+::
4621     Seeks in the stream (default 'current')
4623 +$handle *sendto* 'str ?addr:?port'+::
4624     Sends the string, +'str'+, to the given address via the socket using sendto(2).
4625     This is intended for udp/dgram sockets and may give an error or behave in unintended
4626     ways for other handle types.
4627     Returns the number of bytes written.
4629 +$handle *sockopt* '?name value?'+::
4630     With no arguments, returns a dictionary of socket options currently set for the handle
4631         (will be empty for a non-socket). With +'name'+ and +'value'+, sets the socket option
4632         to the given value. Currently supports the following boolean socket options:
4633         +broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay+, and the following
4634         integer socket options: +sndbuf, rcvbuf+
4636 +$handle *sync*+::
4637     Flush the stream, then fsync(2) to commit any changes to storage.
4638     Only available on platforms that support fsync(2).
4640 +$handle *tell*+::
4641     Returns the current seek position
4643 +$handle *tty* ?settings?+::
4644         If no arguments are given, returns a dictionary containing the tty settings for the stream.
4645         If arguments are given, they must either be a dictionary, or +setting value \...+
4646         Abbrevations are supported for both settings and values, so the following is acceptable:
4647         +$f tty parity e input c out raw+.
4648     Only available on platforms that support termios(3). Supported settings are:
4650     +*baud* 'rate'+;;
4651         Baud rate. e.g. 115200
4653     +*data 5|6|7|8*+;;
4654         Number of data bits
4656     +*stop 1|2*+;;
4657         Number of stop bits
4659     +*parity even|odd|none*+;;
4660         Parity setting
4662     +*handshake xonxoff|rtscts|none*+;;
4663                 Handshaking type
4665     +*input raw|cooked*+;;
4666                 Input character processing. In raw mode, the usual key sequences such as ^C do
4667                 not generate signals.
4669     +*output raw|cooked*+;;
4670                 Output character processing. Typically CR -> CRNL is disabled in raw mode.
4672     +*vmin* 'numchars'+;;
4673                 Minimum number of characters to read.
4675     +*vtime* 'time'+;;
4676                 Timeout for noncanonical read (units of 0.1 seconds)
4678 +$handle *ssl* *?-server cert priv?*+::
4679     Upgrades the stream to a SSL/TLS session and returns the handle.
4681 +$handle *unlock*+::
4682     Release a POSIX lock previously acquired by `aio lock`.
4684 +$handle *verify*+::
4685     Verifies the certificate of a SSL/TLS stream peer
4687 +*load_ssl_certs* 'dir'+::
4688     Loads SSL/TLS CA certificates for use during verification
4690 fconfigure
4691 ~~~~~~~~~~
4692 +*fconfigure* 'handle' *?-blocking 0|1? ?-buffering noneline|full? ?-translation* 'mode'?+::
4693     For compatibility with Tcl, a limited form of the `fconfigure`
4694     command is supported.
4695     * `fconfigure ... -blocking` maps to `aio ndelay`
4696     * `fconfigure ... -buffering` maps to `aio buffering`
4697     * `fconfigure ... -translation` is accepted but ignored
4699 [[cmd_2]]
4700 eventloop: after, vwait, update
4701 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4703 The following commands allow a script to be invoked when the given condition occurs.
4704 If no script is given, returns the current script. If the given script is the empty, the
4705 handler is removed.
4707 +$handle *readable* '?readable-script?'+::
4708     Sets or returns the script for when the socket is readable.
4710 +$handle *writable* '?writable-script?'+::
4711     Sets or returns the script for when the socket is writable.
4713 +$handle *onexception* '?exception-script?'+::
4714     Sets or returns the script for when oob data received.
4716 For compatibility with 'Tcl', these may be prefixed with `fileevent`.  e.g.
4718  ::
4719     +fileevent $handle *readable* '\...'+
4721 Time-based execution is also available via the eventloop API.
4723 +*after* 'ms'+::
4724     Sleeps for the given number of milliseconds. No events are
4725     processed during this time.
4727 +*after* 'ms'|*idle* 'script ?script \...?'+::
4728     The scripts are concatenated and executed after the given
4729     number of milliseconds have elapsed.  If 'idle' is specified,
4730     the script will run the next time the event loop is processed
4731     with `vwait` or `update`. The script is only run once and
4732     then removed.  Returns an event id.
4734 +*after cancel* 'id|command'+::
4735     Cancels an `after` event with the given event id or matching
4736     command (script).  Returns the number of milliseconds
4737     remaining until the event would have fired.  Returns the
4738     empty string if no matching event is found.
4740 +*after info* '?id?'+::
4741     If +'id'+ is not given, returns a list of current `after`
4742     events.  If +'id'+ is given, returns a list containing the
4743     associated script and either 'timer' or 'idle' to indicated
4744     the type of the event. An error occurs if +'id'+ does not
4745     match an event.
4747 +*vwait* 'variable'+::
4748     A call to `vwait` enters the eventloop. `vwait` processes
4749     events until the named (global) variable changes or all
4750     event handlers are removed. The variable need not exist
4751     beforehand.  If there are no event handlers defined, `vwait`
4752     returns immediately.
4754 +*update ?idletasks?*+::
4755     A call to `update` enters the eventloop to process expired events, but
4756     no new events. If 'idletasks' is specified, only expired time events are handled,
4757     not file events.
4758     Returns once handlers have been run for all expired events.
4760 Scripts are executed at the global scope. If an error occurs during a handler script,
4761 an attempt is made to call (the user-defined command) `bgerror` with the details of the error.
4762 If the `bgerror` command does not exist, the error message details are printed to stderr instead.
4764 If a file event handler script generates an error, the handler is automatically removed
4765 to prevent infinite errors. (A time event handler is always removed after execution).
4767 +*bgerror* 'msg'+::
4768     Called when an event handler script generates an error. Note that the normal command resolution
4769     rules are used for bgerror. First the name is resolved in the current namespace, then in the
4770     global scope.
4772 socket
4773 ~~~~~~
4774 Various socket types may be created.
4776 +*socket unix* 'path'+::
4777     A unix domain socket client.
4779 +*socket unix.server* 'path'+::
4780     A unix domain socket server.
4782 +*socket ?-ipv6? stream* 'addr:port'+::
4783     A TCP socket client. (See the forms for +'addr'+ below)
4785 +*socket ?-ipv6? stream.server* '?addr:?port'+::
4786     A TCP socket server (+'addr'+ defaults to +0.0.0.0+ for IPv4 or +[::]+ for IPv6).
4788 +*socket ?-ipv6? dgram* ?'addr:port'?+::
4789     A UDP socket client. If the address is not specified,
4790     the client socket will be unbound and 'sendto' must be used
4791     to indicated the destination.
4793 +*socket ?-ipv6? dgram.server* 'addr:port'+::
4794     A UDP socket server.
4796 +*socket pipe*+::
4797         A synonym for `pipe`
4799 +*socket pair*+::
4800     A socketpair (see socketpair(2)). Like `pipe`, this command returns
4801     a list of two channels: {s1 s2}. These channels are both readable and writable.
4803 This command creates a socket connected (client) or bound (server) to the given
4804 address.
4806 The returned value is channel and may generally be used with the various file I/O
4807 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.
4809     . set f [socket stream www.google.com:80]
4810     aio.sockstream1
4811     . $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
4812     . $f gets
4813     HTTP/1.0 302 Found
4814     . $f close
4816 Server sockets, however support only 'accept', which is most useful in conjunction with
4817 the EVENTLOOP API.
4819     set f [socket stream.server 80]
4820     $f readable {
4821         set client [$f accept]
4822         $client gets $buf
4823         ...
4824         $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
4825         $client close
4826     }
4827     vwait done
4829 The address, +'addr'+, can be given in one of the following forms:
4831 1. For IPv4 socket types, an IPv4 address such as 192.168.1.1
4832 2. For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
4833 3. A hostname
4835 Note that on many systems, listening on an IPv6 address such as [::] will
4836 also accept requests via IPv4.
4838 Where a hostname is specified, the +'first'+ returned address is used
4839 which matches the socket type is used.
4841 The special type 'pipe' isn't really a socket.
4843     lassign [socket pipe] r w
4845     # Must close $w after exec
4846     exec ps >@$w &
4847     $w close
4849     $r readable ...
4851 syslog
4852 ~~~~~~
4853 +*syslog* '?options? ?priority? message'+
4855 This  command sends message to system syslog facility with given
4856 priority. Valid priorities are:
4858     emerg, alert, crit, err, error, warning, notice, info, debug
4860 If a message is specified, but no priority is specified, then a
4861 priority of info is used.
4863 By default, facility user is used and the value of global tcl variable
4864 argv0 is used as ident string. However, any of the following options
4865 may be specified before priority to control these parameters:
4867 +*-facility* 'value'+::
4868     Use specified facility instead of user. The following
4869     values for facility are recognized:
4871     authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
4872     uucp, local0-local7
4874 +*-ident* 'string'+::
4875     Use given string instead of argv0 variable for ident string.
4877 +*-options* 'integer'+::
4878     Set syslog options such as +LOG_CONS+, +LOG_NDELAY+. You should
4879     use numeric values of those from your system syslog.h file,
4880     because I haven't got time to implement yet another hash
4881     table.
4883 pack: pack, unpack
4884 ~~~~~~~~~~~~~~~~~~
4885 The optional 'pack' extension provides commands to encode and decode binary strings.
4887 +*pack* 'varName value' *-intle|-intbe|-floatle|-floatbe|-str* 'bitwidth ?bitoffset?'+::
4888     Packs the binary representation of +'value'+ into the variable
4889     +'varName'+. The value is packed according to the given type
4890     (integer/floating point/string, big-endian/little-endian), width and bit offset.
4891     The variable is created if necessary (like `append`).
4892     The variable is expanded if necessary.
4894 +*unpack* 'binvalue' *-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str* 'bitpos bitwidth'+::
4895     Unpacks bits from +'binvalue'+ at bit position +'bitpos'+ and with +'bitwidth'+.
4896     Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
4897     and signed/unsigned) and returns it. For integer types, +'bitwidth'+
4898     may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
4899     +'bitwidth'+ may be 32 bits (for single precision numbers) or 64 bits (for double precision).
4900     For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
4901     access outside the length of the value will return 0 for integer types, 0.0 for floating point types
4902     or the empty string for the string type.
4904 zlib
4905 ~~~~
4906 The optional 'zlib' extension provides a Tcl-compatible subset of the `zlib` command.
4908 +*crc32* 'data' '?startValue?'+::
4909     Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
4910     for calculating the checksum of chunked data read from a stream (for instance, a pipe).
4912 +*deflate* 'string' '?level?'+::
4913     Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
4914     be specified to choose the desired speed vs. compression rate ratio.
4916 +*inflate* 'data' '?bufferSize?'+::
4917     Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
4918     allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
4920 +*gzip* 'string' '?-level level?'+::
4921     Compresses a buffer and adds a gzip header.
4923 +*gunzip* 'data' '?-buffersize size?'+::
4924     Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
4925     which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
4926     systems without a severe memory constraint.
4928 binary
4929 ~~~~~~
4930 The optional, pure-Tcl 'binary' extension provides the Tcl-compatible `binary scan` and `binary format`
4931 commands based on the low-level `pack` and `unpack` commands.
4933 See the Tcl documentation at: http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
4935 Note that 'binary format' with f/r/R specifiers (single-precision float) uses the value of Infinity
4936  in case of overflow.
4938 oo: class, super
4939 ~~~~~~~~~~~~~~~~
4940 The optional, pure-Tcl 'oo' extension provides object-oriented (OO) support for Jim Tcl.
4942 See the online documentation (http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/) for more details.
4944 +*class* 'classname ?baseclasses? classvars'+::
4945     Create a new class, +'classname'+, with the given dictionary
4946     (+'classvars'+) as class variables. These are the initial variables
4947     which all newly created objects of this class are initialised with.
4948     If a list of baseclasses is given, methods and instance variables
4949     are inherited.
4951 +*super* 'method ?args \...?'+::
4952     From within a method, invokes the given method on the base class.
4953     Note that this will only call the last baseclass given.
4955 tree
4956 ~~~~
4957 The optional, pure-Tcl 'tree' extension implements an OO, general purpose tree structure
4958 similar to that provided by tcllib ::struct::tree (http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html)
4960 A tree is a collection of nodes, where each node (except the root node) has a single parent
4961 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.
4963 +*tree*+::
4964     Creates and returns a new tree object with a single node named "root".
4965     All operations on the tree are invoked through this object.
4967 +$tree *destroy*+::
4968     Destroy the tree and all it's nodes. (Note that the tree will also
4969     be automatically garbage collected once it goes out of scope).
4971 +$tree *set* 'nodename key value'+::
4972     Set the value for the given attribute key.
4974 +$tree *lappend* 'nodename key value \...'+::
4975     Append to the (list) value(s) for the given attribute key, or set if not yet set.
4977 +$tree *keyexists* 'nodename key'+::
4978     Returns 1 if the given attribute key exists.
4980 +$tree *get* 'nodename key'+::
4981     Returns the value associated with the given attribute key.
4983 +$tree *getall* 'nodename'+::
4984     Returns the entire attribute dictionary associated with the given key.
4986 +$tree *depth* 'nodename'+::
4987     Returns the depth of the given node. The depth of "root" is 0.
4989 +$tree *parent* 'nodename'+::
4990     Returns the node name of the parent node, or "" for the root node.
4992 +$tree *numchildren* 'nodename'+::
4993     Returns the number of child nodes.
4995 +$tree *children* 'nodename'+::
4996     Returns a list of the child nodes.
4998 +$tree *next* 'nodename'+::
4999     Returns the next sibling node, or "" if none.
5001 +$tree *insert* 'nodename ?index?'+::
5002     Add a new child node to the given node. The index is a list index
5003     such as +3+ or +end-2+. The default index is +end+.
5004     Returns the name of the newly added node.
5006 +$tree *walk* 'nodename' *dfs|bfs* {'actionvar nodevar'} 'script'+::
5007     Walks the tree starting from the given node, either breadth first (+bfs+)
5008     depth first (+dfs+).
5009     The value +"enter"+ or +"exit"+ is stored in variable +'actionvar'+.
5010     The name of each node is stored in +'nodevar'+.
5011     The script is evaluated twice for each node, on entry and exit.
5013 +$tree *dump*+::
5014     Dumps the tree contents to stdout
5016 tcl::prefix
5017 ~~~~~~~~~~~
5018 The optional tclprefix extension provides the Tcl8.6-compatible `tcl::prefix` command
5019 (http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm) for matching strings against a table
5020 of possible values (typically commands or options).
5022 +*tcl::prefix all* 'table string'+::
5023     Returns a list of all elements in +'table'+ that begin with the prefix +'string'+.
5025 +*tcl::prefix longest* 'table string'+::
5026     Returns the longest common prefix of all elements in +'table'+ that begin with the prefix +'string'+.
5028 +*tcl::prefix match* '?options? table string'+::
5029     If +'string'+ equals one element in +'table'+ or is a prefix to
5030     exactly one element, the matched element is returned. If not, the
5031     result depends on the +-error+ option.
5033     * +*-exact*+ Accept only exact matches.
5034     * +*-message* 'string'+ Use +'string'+ in the error message at a mismatch. Default is "option".
5035     * +*-error* 'options'+ The options are used when no match is found. If +'options'+ is
5036       empty, no error is generated and an empty string is returned.
5037       Otherwise the options are used as return options when
5038       generating the error message. The default corresponds to
5039       setting +-level 0+.
5041 tcl::autocomplete
5042 ~~~~~~~~~~~~~~~~~
5043 Scriptable command line completion is supported in the interactive shell, 'jimsh', through
5044 the `tcl::autocomplete` callback. A simple implementation is provided, however this may
5045 be replaced with a custom command instead if desired.
5047 In the interactive shell, press <TAB> to activate command line completion.
5049 +*tcl::autocomplete* 'commandline'+::
5050         This command is called with the current command line when the user presses <TAB>.
5051         The command should return a list of all possible command lines that match the current command line.
5052         For example if +*pr*+ is the current command line, the list +*{prefix proc}*+ may be returned.
5054 history
5055 ~~~~~~~
5056 The optional history extension provides script access to the command line editing
5057 and history support available in 'jimsh'. See 'examples/jtclsh.tcl' for an example.
5058 Note: if line editing support is not available, `history getline` acts like `gets` and
5059 the remaining subcommands do nothing.
5061 +*history load* 'filename'+::
5062     Load history from a (text) file. If the file does not exist or is not readable,
5063     it is ignored.
5065 +*history getline* 'prompt ?varname?'+::
5066     Displays the given prompt and allows a line to be entered. Similarly to `gets`,
5067     if +'varname'+ is given, it receives the line and the length of the line is returned,
5068     or -1 on EOF. If +'varname'+ is not given, the line is returned directly.
5070 +*history completion* 'command'+::
5071     Sets an autocompletion command (see `tcl::autocomplete`) that is active during `history getline`.
5072         If the command is empty, autocompletion is disabled.
5074 +*history add* 'line'+::
5075     Adds the given line to the history buffer.
5077 +*history save* 'filename'+::
5078     Saves the current history buffer to the given file.
5080 +*history show*+::
5081     Displays the current history buffer to standard output.
5083 namespace
5084 ~~~~~~~~~
5085 Provides namespace-related functions. See also: http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
5087 +*namespace code* 'script'+::
5088     Captures the current namespace context for later execution of
5089     the script +'script'+. It returns a new script in which script has
5090     been wrapped in a +*namespace inscope*+ command.
5092 +*namespace current*+::
5093     Returns the fully-qualified name for the current namespace.
5095 +*namespace delete* '?namespace ...?'+::
5096     Deletes all commands and variables with the given namespace prefixes.
5098 +*namespace eval* 'namespace arg ?arg...?'+::
5099     Activates a namespace called +'namespace'+ and evaluates some code in that context.
5101 +*namespace origin* 'command'+::
5102     Returns the fully-qualified name of the original command to which the imported command +'command'+ refers.
5104 +*namespace parent* ?namespace?+::
5105     Returns the fully-qualified name of the parent namespace for namespace +'namespace'+, if given, otherwise
5106     for the current namespace.
5108 +*namespace qualifiers* 'string'+::
5109     Returns any leading namespace qualifiers for +'string'+
5111 +*namespace tail* 'string'+::
5112     Returns the simple name at the end of a qualified string.
5114 +*namespace upvar* 'namespace ?arg...?'+::
5115     This command arranges for zero or more local variables in the current procedure to refer to variables in +'namespace'+
5117 +*namespace which* '?-command|-variable? name'+::
5118     Looks up +'name'+ as either a command (the default) or variable and returns its fully-qualified name.
5120 interp
5121 ~~~~~~
5122 The optional 'interp' command allows sub-interpreters to be created where commands may be run
5123 independently (but synchronously) of the main interpreter.
5125 +*interp*+::
5126     Creates and returns a new interpreter object (command).
5127         The created interpeter contains any built-in commands along with static extensions,
5128         but does not include any dynamically loaded commands (package require, load).
5129         These must be reloaded in the child interpreter if required.
5131 +*$interp delete*+::
5132     Deletes the interpeter object.
5134 +*$interp eval* 'script' ...+::
5135         Evaluates a script in the context for the child interpreter, in the same way as 'eval'.
5137 +*$interp alias* 'alias childcmd parentcmd ?arg ...?'+::
5138         Similar to 'alias', but creates a command, +'childcmd'+, in the child interpreter that is an
5139         alias for +'parentcmd'+ in the parent interpreter, with the given, fixed arguments.
5140         The alias may be deleted in the child with 'rename'.
5142 [[BuiltinVariables]]
5143 BUILT-IN VARIABLES
5144 ------------------
5146 The following global variables are created automatically
5147 by the Tcl library.
5149 +*env*+::
5150     This variable is set by Jim as an array
5151     whose elements are the environment variables for the process.
5152     Reading an element will return the value of the corresponding
5153     environment variable.
5154     This array is initialised at startup from the `env` command.
5155     It may be modified and will affect the environment passed to
5156     commands invoked with `exec`.
5158 +*platform_tcl*+::
5159     This variable is set by Jim as an array containing information
5160     about the platform on which Jim was built. Currently this includes
5161     'os' and 'platform'.
5163 +*auto_path*+::
5164     This variable contains a list of paths to search for packages.
5165     It defaults to a location based on where jim is installed
5166     (e.g. +/usr/local/lib/jim+), but may be changed by +jimsh+
5167     or the embedding application. Note that +jimsh+ will consider
5168     the environment variable +$JIMLIB+ to be a list of colon-separated
5169     list of paths to add to +*auto_path*+.
5171 +*errorCode*+::
5172     This variable holds the value of the -errorcode return
5173     option set by the most recent error that occurred in this
5174     interpreter. This list value represents additional information
5175     about the error in a form that is easy to process with
5176     programs. The first element of the list identifies a general
5177     class of errors, and determines the format of the rest of
5178     the list. The following formats for -errorcode return options
5179     are used by the Tcl core; individual applications may define
5180     additional formats. Currently only `exec` sets this variable.
5181     Otherwise it will be +NONE+.
5183 The following global variables are set by jimsh.
5185 +*tcl_interactive*+::
5186     This variable is set to 1 if jimsh is started in interactive mode
5187     or 0 otherwise.
5189 +*tcl_platform*+::
5190     This variable is set by Jim as an array containing information
5191     about the platform upon which Jim was built. The following is an
5192     example of the contents of this array.
5194     tcl_platform(byteOrder)     = littleEndian
5195     tcl_platform(engine)        = Jim
5196     tcl_platform(os)            = Darwin
5197     tcl_platform(platform)      = unix
5198     tcl_platform(pointerSize)   = 8
5199     tcl_platform(threaded)      = 0
5200     tcl_platform(wordSize)      = 8
5201     tcl_platform(pathSeparator) = :
5203 +*argv0*+::
5204     If jimsh is invoked to run a script, this variable contains the name
5205     of the script.
5207 +*argv*+::
5208     If jimsh is invoked to run a script, this variable contains a list
5209     of any arguments supplied to the script.
5211 +*argc*+::
5212     If jimsh is invoked to run a script, this variable contains the number
5213     of arguments supplied to the script.
5215 +*jim::argv0*+::
5216     The value of argv[0] when jimsh was invoked.
5218 The following variables have special meaning to Jim Tcl:
5220 +*jim::defer*+::
5221     If this variable is set, it is considered to be a list of scripts to evaluate
5222         when the current proc exits (local variables), or the interpreter exits (global variable).
5223         See `defer`.
5225 +*history::multiline*+::
5226     If this variable is set to "1", interactive line editing operates in multiline mode.
5227         That is, long lines will wrap across multiple lines rather than scrolling within a
5228         single line.
5230 CHANGES IN PREVIOUS RELEASES
5231 ----------------------------
5233 === In v0.70 ===
5235 1. +platform_tcl()+ settings are now automatically determined
5236 2. Add aio `$handle filename`
5237 3. Add `info channels`
5238 4. The 'bio' extension is gone. Now `aio` supports 'copyto'.
5239 5. Add `exists` command
5240 6. Add the pure-Tcl 'oo' extension
5241 7. The `exec` command now only uses vfork(), not fork()
5242 8. Unit test framework is less verbose and more Tcl-compatible
5243 9. Optional UTF-8 support
5244 10. Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
5245 11. Command line editing in interactive mode, e.g. 'jimsh'
5247 === In v0.63 ===
5249 1. `source` now checks that a script is complete (.i.e. not missing a brace)
5250 2. 'info complete' now uses the real parser and so is 100% accurate
5251 3. Better access to live stack frames with 'info frame', `stacktrace` and `stackdump`
5252 4. `tailcall` no longer loses stack trace information
5253 5. Add `alias` and `curry`
5254 6. `lambda`, `alias` and `curry` are implemented via `tailcall` for efficiency
5255 7. `local` allows procedures to be deleted automatically at the end of the current procedure
5256 8. udp sockets are now supported for both clients and servers.
5257 9. vfork-based exec is now working correctly
5258 10. Add 'file tempfile'
5259 11. Add 'socket pipe'
5260 12. Enhance 'try ... on ... finally' to be more Tcl 8.6 compatible
5261 13. It is now possible to `return` from within `try`
5262 14. IPv6 support is now included
5263 15. Add 'string is'
5264 16. Event handlers works better if an error occurs. eof handler has been removed.
5265 17. `exec` now sets $::errorCode, and catch sets opts(-errorcode) for exit status
5266 18. Command pipelines via open "|..." are now supported
5267 19. `pid` can now return pids of a command pipeline
5268 20. Add 'info references'
5269 21. Add support for 'after +'ms'+', 'after idle', 'after info', `update`
5270 22. `exec` now sets environment based on $::env
5271 23. Add 'dict keys'
5272 24. Add support for 'lsort -index'
5274 === In v0.62 ===
5276 1. Add support to `exec` for '>&', '>>&', '|&', '2>@1'
5277 2. Fix `exec` error messages when special token (e.g. '>') is the last token
5278 3. Fix `subst` handling of backslash escapes.
5279 4. Allow abbreviated options for `subst`
5280 5. Add support for `return`, `break`, `continue` in subst
5281 6. Many `expr` bug fixes
5282 7. Add support for functions in `expr` (e.g. int(), abs()), and also 'in', 'ni' list operations
5283 8. The variable name argument to `regsub` is now optional
5284 9. Add support for 'unset -nocomplain'
5285 10. Add support for list commands: `lassign`, `lrepeat`
5286 11. Fully-functional `lsearch` is now implemented
5287 12. Add 'info nameofexecutable' and 'info returncodes'
5288 13. Allow `catch` to determine what return codes are caught
5289 14. Allow `incr` to increment an unset variable by first setting to 0
5290 15. Allow 'args' and optional arguments to the left or required arguments in `proc`
5291 16. Add 'file copy'
5292 17. Add 'try ... finally' command
5295 LICENCE
5296 -------
5298  Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
5299  Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
5300  Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
5301  Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
5302  Copyright 2008 Andrew Lunn <andrew@lunn.ch>
5303  Copyright 2008 Duane Ellis <openocd@duaneellis.com>
5304  Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
5305  Copyright 2009 Steve Bennett <steveb@workware.net.au>
5307 [literal]
5308  Redistribution and use in source and binary forms, with or without
5309  modification, are permitted provided that the following conditions
5310  are met:
5311  1. Redistributions of source code must retain the above copyright
5312     notice, this list of conditions and the following disclaimer.
5313  2. Redistributions in binary form must reproduce the above
5314     copyright notice, this list of conditions and the following
5315     disclaimer in the documentation and/or other materials
5316     provided with the distribution.
5318  THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
5319  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
5320  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
5321  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
5322  JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
5323  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
5324  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5325  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5326  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
5327  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5328  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
5329  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5331  The views and conclusions contained in the software and documentation
5332  are those of the authors and should not be interpreted as representing
5333  official policies, either expressed or implied, of the Jim Tcl Project.