1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"application/xhtml+xml; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.6.6" />
7 <title>Jim Tcl(n)
</title>
8 <style type=
"text/css">
9 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
13 font-family: Georgia
,serif
;
17 h1
, h2
, h3
, h4
, h5
, h6
,
18 div
.title
, caption
.title
,
19 thead
, p
.table
.header
,
21 #author, #revnumber
, #revdate
, #revremark
,
23 font-family: Arial
,Helvetica
,sans-serif
;
27 margin: 1em 5% 1em 5%;
32 text-decoration: underline
;
48 h1
, h2
, h3
, h4
, h5
, h6
{
56 border-bottom: 2px solid silver
;
76 border: 1px solid silver
;
87 ul
> li
{ color: #aaa; }
88 ul
> li
> * { color: black
; }
102 #revnumber, #revdate
, #revremark
{
107 border-top: 2px solid silver
;
113 padding-bottom: 0.5em;
117 padding-bottom: 0.5em;
122 margin-bottom: 1.5em;
124 div
.imageblock
, div
.exampleblock
, div
.verseblock
,
125 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
126 div
.admonitionblock
{
128 margin-bottom: 1.5em;
130 div
.admonitionblock
{
132 margin-bottom: 2.0em;
137 div
.content
{ /* Block element content. */
141 /* Block element titles. */
142 div
.title
, caption
.title
{
147 margin-bottom: 0.5em;
153 td div
.title:first-child
{
156 div
.content div
.title:first-child
{
159 div
.content
+ div
.title
{
163 div
.sidebarblock
> div
.content
{
165 border: 1px solid
#dddddd;
166 border-left: 4px solid
#f0f0f0;
170 div
.listingblock
> div
.content
{
171 border: 1px solid
#dddddd;
172 border-left: 5px solid
#f0f0f0;
177 div
.quoteblock
, div
.verseblock
{
181 border-left: 5px solid
#f0f0f0;
185 div
.quoteblock
> div
.attribution
{
190 div
.verseblock
> pre
.content
{
191 font-family: inherit
;
194 div
.verseblock
> div
.attribution
{
198 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
199 div
.verseblock
+ div
.attribution
{
203 div
.admonitionblock
.icon
{
207 text-decoration: underline
;
209 padding-right: 0.5em;
211 div
.admonitionblock td
.content
{
213 border-left: 3px solid
#dddddd;
216 div
.exampleblock
> div
.content
{
217 border-left: 3px solid
#dddddd;
221 div
.imageblock div
.content
{ padding-left: 0; }
222 span
.image img
{ border-style: none
; }
223 a
.image:visited
{ color: white
; }
227 margin-bottom: 0.8em;
240 list-style-position: outside
;
243 list-style-type: decimal
;
246 list-style-type: lower-alpha
;
249 list-style-type: upper-alpha
;
252 list-style-type: lower-roman
;
255 list-style-type: upper-roman
;
258 div
.compact ul
, div
.compact ol
,
259 div
.compact p
, div
.compact p
,
260 div
.compact div
, div
.compact div
{
262 margin-bottom: 0.1em;
274 margin-bottom: 0.8em;
277 padding-bottom: 15px;
279 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
285 padding-right: 0.8em;
291 div
.hdlist
.compact tr
{
300 .footnote, .footnoteref {
304 span
.footnote
, span
.footnoteref
{
305 vertical-align: super
;
309 margin: 20px 0 20px 0;
313 #footnotes div
.footnote
{
319 border-top: 1px solid silver
;
328 padding-right: 0.5em;
329 padding-bottom: 0.3em;
337 #footer-badges { display: none
; }
341 margin-bottom: 2.5em;
349 margin-bottom: 0.1em;
352 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
369 span
.aqua
{ color: aqua
; }
370 span
.black
{ color: black
; }
371 span
.blue
{ color: blue
; }
372 span
.fuchsia
{ color: fuchsia
; }
373 span
.gray
{ color: gray
; }
374 span
.green
{ color: green
; }
375 span
.lime
{ color: lime
; }
376 span
.maroon
{ color: maroon
; }
377 span
.navy
{ color: navy
; }
378 span
.olive
{ color: olive
; }
379 span
.purple
{ color: purple
; }
380 span
.red
{ color: red
; }
381 span
.silver
{ color: silver
; }
382 span
.teal
{ color: teal
; }
383 span
.white
{ color: white
; }
384 span
.yellow
{ color: yellow
; }
386 span
.aqua-background
{ background: aqua
; }
387 span
.black-background
{ background: black
; }
388 span
.blue-background
{ background: blue
; }
389 span
.fuchsia-background
{ background: fuchsia
; }
390 span
.gray-background
{ background: gray
; }
391 span
.green-background
{ background: green
; }
392 span
.lime-background
{ background: lime
; }
393 span
.maroon-background
{ background: maroon
; }
394 span
.navy-background
{ background: navy
; }
395 span
.olive-background
{ background: olive
; }
396 span
.purple-background
{ background: purple
; }
397 span
.red-background
{ background: red
; }
398 span
.silver-background
{ background: silver
; }
399 span
.teal-background
{ background: teal
; }
400 span
.white-background
{ background: white
; }
401 span
.yellow-background
{ background: yellow
; }
403 span
.big
{ font-size: 2em; }
404 span
.small
{ font-size: 0.6em; }
406 span
.underline
{ text-decoration: underline
; }
407 span
.overline
{ text-decoration: overline
; }
408 span
.line-through
{ text-decoration: line-through
; }
417 font-family: monospace
;
424 margin-bottom: 1.5em;
426 div
.tableblock
> table
{
427 border: 3px solid
#527bbd;
429 thead
, p
.table
.header
{
436 /* Because the table frame attribute is overriden by CSS in most browsers. */
437 div
.tableblock
> table
[frame
="void"] {
440 div
.tableblock
> table
[frame
="hsides"] {
441 border-left-style: none
;
442 border-right-style: none
;
444 div
.tableblock
> table
[frame
="vsides"] {
445 border-top-style: none
;
446 border-bottom-style: none
;
456 font-family: monospace
;
463 margin-bottom: 1.5em;
465 thead
, p
.tableblock
.header
{
476 border-color: #527bbd;
477 border-collapse: collapse
;
479 th
.tableblock
, td
.tableblock
{
483 border-color: #527bbd;
486 table
.tableblock
.frame-topbot
{
487 border-left-style: hidden
;
488 border-right-style: hidden
;
490 table
.tableblock
.frame-sides
{
491 border-top-style: hidden
;
492 border-bottom-style: hidden
;
494 table
.tableblock
.frame-none
{
495 border-style: hidden
;
498 th
.tableblock
.halign-left
, td
.tableblock
.halign-left
{
501 th
.tableblock
.halign-center
, td
.tableblock
.halign-center
{
504 th
.tableblock
.halign-right
, td
.tableblock
.halign-right
{
508 th
.tableblock
.valign-top
, td
.tableblock
.valign-top
{
511 th
.tableblock
.valign-middle
, td
.tableblock
.valign-middle
{
512 vertical-align: middle
;
514 th
.tableblock
.valign-bottom
, td
.tableblock
.valign-bottom
{
515 vertical-align: bottom
;
526 padding-bottom: 0.5em;
527 border-top: 2px solid silver
;
528 border-bottom: 2px solid silver
;
533 body
.manpage div
.sectionbody
{
538 body
.manpage div#toc
{ display: none
; }
541 <script type=
"text/javascript">
543 var asciidoc
= { // Namespace.
545 /////////////////////////////////////////////////////////////////////
546 // Table Of Contents generator
547 /////////////////////////////////////////////////////////////////////
549 /* Author: Mihai Bazon, September 2002
550 * http://students.infoiasi.ro/~mishoo
552 * Table Of Content generator
555 * Feel free to use this script under the terms of the GNU General Public
556 * License, as long as you do not remove or alter this notice.
559 /* modified by Troy D. Hanson, September 2006. License: GPL */
560 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
563 toc: function (toclevels
) {
565 function getText(el
) {
567 for (var i
= el
.firstChild
; i
!= null; i
= i
.nextSibling
) {
568 if (i
.nodeType
== 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
570 else if (i
.firstChild
!= null)
576 function TocEntry(el
, text
, toclevel
) {
579 this.toclevel
= toclevel
;
582 function tocEntries(el
, toclevels
) {
583 var result
= new Array
;
584 var re
= new RegExp('[hH]([2-'+(toclevels
+1)+'])');
585 // Function that scans the DOM tree for header elements (the DOM2
586 // nodeIterator API would be a better technique but not supported by all
588 var iterate = function (el
) {
589 for (var i
= el
.firstChild
; i
!= null; i
= i
.nextSibling
) {
590 if (i
.nodeType
== 1 /* Node.ELEMENT_NODE */) {
591 var mo
= re
.exec(i
.tagName
);
592 if (mo
&& (i
.getAttribute("class") || i
.getAttribute("className")) != "float") {
593 result
[result
.length
] = new TocEntry(i
, getText(i
), mo
[1]-1);
603 var toc
= document
.getElementById("toc");
608 // Delete existing TOC entries in case we're reloading the TOC.
609 var tocEntriesToRemove
= [];
611 for (i
= 0; i
< toc
.childNodes
.length
; i
++) {
612 var entry
= toc
.childNodes
[i
];
613 if (entry
.nodeName
== 'div'
614 && entry
.getAttribute("class")
615 && entry
.getAttribute("class").match(/^toclevel/))
616 tocEntriesToRemove
.push(entry
);
618 for (i
= 0; i
< tocEntriesToRemove
.length
; i
++) {
619 toc
.removeChild(tocEntriesToRemove
[i
]);
622 // Rebuild TOC entries.
623 var entries
= tocEntries(document
.getElementById("content"), toclevels
);
624 for (var i
= 0; i
< entries
.length
; ++i
) {
625 var entry
= entries
[i
];
626 if (entry
.element
.id
== "")
627 entry
.element
.id
= "_toc_" + i
;
628 var a
= document
.createElement("a");
629 a
.href
= "#" + entry
.element
.id
;
630 a
.appendChild(document
.createTextNode(entry
.text
));
631 var div
= document
.createElement("div");
633 div
.className
= "toclevel" + entry
.toclevel
;
634 toc
.appendChild(div
);
636 if (entries
.length
== 0)
637 toc
.parentNode
.removeChild(toc
);
641 /////////////////////////////////////////////////////////////////////
642 // Footnotes generator
643 /////////////////////////////////////////////////////////////////////
645 /* Based on footnote generation code from:
646 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
649 footnotes: function () {
650 // Delete existing footnote entries in case we're reloading the footnodes.
652 var noteholder
= document
.getElementById("footnotes");
656 var entriesToRemove
= [];
657 for (i
= 0; i
< noteholder
.childNodes
.length
; i
++) {
658 var entry
= noteholder
.childNodes
[i
];
659 if (entry
.nodeName
== 'div' && entry
.getAttribute("class") == "footnote")
660 entriesToRemove
.push(entry
);
662 for (i
= 0; i
< entriesToRemove
.length
; i
++) {
663 noteholder
.removeChild(entriesToRemove
[i
]);
666 // Rebuild footnote entries.
667 var cont
= document
.getElementById("content");
668 var spans
= cont
.getElementsByTagName("span");
671 for (i
=0; i
<spans
.length
; i
++) {
672 if (spans
[i
].className
== "footnote") {
674 var note
= spans
[i
].getAttribute("data-note");
676 // Use [\s\S] in place of . so multi-line matches work.
677 // Because JavaScript has no s (dotall) regex flag.
678 note
= spans
[i
].innerHTML
.match(/\s*\[([\s\S]*)]\s*/)[1];
680 "[<a id='_footnoteref_" + n
+ "' href='#_footnote_" + n
+
681 "' title='View footnote' class='footnote'>" + n
+ "</a>]";
682 spans
[i
].setAttribute("data-note", note
);
684 noteholder
.innerHTML
+=
685 "<div class='footnote' id='_footnote_" + n
+ "'>" +
686 "<a href='#_footnoteref_" + n
+ "' title='Return to text'>" +
687 n
+ "</a>. " + note
+ "</div>";
688 var id
=spans
[i
].getAttribute("id");
689 if (id
!= null) refs
["#"+id
] = n
;
693 noteholder
.parentNode
.removeChild(noteholder
);
695 // Process footnoterefs.
696 for (i
=0; i
<spans
.length
; i
++) {
697 if (spans
[i
].className
== "footnoteref") {
698 var href
= spans
[i
].getElementsByTagName("a")[0].getAttribute("href");
699 href
= href
.match(/#.*/)[0]; // Because IE return full URL.
702 "[<a href='#_footnote_" + n
+
703 "' title='View footnote' class='footnote'>" + n
+ "</a>]";
709 install: function(toclevels
) {
712 function reinstall() {
713 asciidoc
.footnotes();
715 asciidoc
.toc(toclevels
);
719 function reinstallAndRemoveTimer() {
720 clearInterval(timerId
);
724 timerId
= setInterval(reinstall
, 500);
725 if (document
.addEventListener
)
726 document
.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer
, false);
728 window
.onload
= reinstallAndRemoveTimer
;
736 <body class=
"manpage">
739 Jim Tcl(n) Manual Page
742 <div class=
"sectionbody">
744 reference manual for the Jim Tcl scripting language
750 <h2 id=
"_synopsis">SYNOPSIS
</h2>
751 <div class=
"sectionbody">
752 <div class=
"literalblock">
753 <div class=
"content">
754 <pre><tt>cc
<source
> -ljim
</tt></pre>
756 <div class=
"paragraph"><p>or
</p></div>
757 <div class=
"literalblock">
758 <div class=
"content">
759 <pre><tt>jimsh [
<scriptfile
>]
760 jimsh -e '
<immediate-script
>'
761 jimsh --version
</tt></pre>
763 <div class=
"ulist"><div class=
"title">Quick Index
</div><ul>
766 <a href=
"#CommandIndex">Command Reference
</a>
771 <a href=
"#OperatorPrecedence">Operator Precedence
</a>
776 <a href=
"#BuiltinVariables">Builtin Variables
</a>
781 <a href=
"#BackslashSequences">Backslash Sequences
</a>
788 <h2 id=
"_introduction">INTRODUCTION
</h2>
789 <div class=
"sectionbody">
790 <div class=
"paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
791 The core language engine is compatible with Tcl
8.5+, while implementing
792 a significant subset of the Tcl
8.6 command set, plus additional features
793 available only in Jim Tcl.
</p></div>
794 <div class=
"paragraph"><p>Some notable differences with Tcl
8.5/
8.6 are:
</p></div>
795 <div class=
"olist arabic"><ol class=
"arabic">
798 Object-based I/O (aio), but with a Tcl-compatibility layer
803 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
813 Support for references (
<a href=
"#_ref"><strong><tt>ref
</tt></strong></a>/
<a href=
"#_getref"><strong><tt>getref
</tt></strong></a>/
<a href=
"#_setref"><strong><tt>setref
</tt></strong></a>) and garbage collection
818 Builtin dictionary type (
<a href=
"#_dict"><strong><tt>dict
</tt></strong></a>) with some limitations compared to Tcl
8.6
823 <a href=
"#_env"><strong><tt>env
</tt></strong></a> command to access environment variables
828 Operating system features:
<a href=
"#cmd_1"><strong><tt>os.fork
</tt></strong></a>,
<a href=
"#cmd_1"><strong><tt>os.wait
</tt></strong></a>,
<a href=
"#cmd_1"><strong><tt>os.uptime
</tt></strong></a>,
<a href=
"#_signal"><strong><tt>signal
</tt></strong></a>,
<a href=
"#_alarm"><strong><tt>alarm
</tt></strong></a>,
<a href=
"#_sleep"><strong><tt>sleep
</tt></strong></a>
833 Much better error reporting.
<a href=
"#_info"><strong><tt>info
</tt></strong></a> <tt>stacktrace
</tt> as a replacement for
<em>$errorInfo
</em>,
<em>$errorCode
</em>
838 Support for
"static" variables in procedures
843 Threads and coroutines are not supported
848 Command and variable traces are not supported
853 Built-in command line editing
858 Expression shorthand syntax:
<tt>$(
…)
</tt>
863 Modular build allows many features to be omitted or built as dynamic, loadable modules
868 Highly suitable for use in an embedded environment
873 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
880 <h2 id=
"_recent_changes">RECENT CHANGES
</h2>
881 <div class=
"sectionbody">
883 <h3 id=
"_changes_between_0_74_and_0_75">Changes between
0.74 and
0.75</h3>
884 <div class=
"olist arabic"><ol class=
"arabic">
887 <a href=
"#_binary"><strong><tt>binary
</tt></strong></a>,
<a href=
"#cmd_3"><strong><tt>pack
</tt></strong></a> and
<a href=
"#cmd_3"><strong><tt>unpack
</tt></strong></a> now support floating point
892 <a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>copy
</tt> <em>-force
</em> handles source and target as the same file
897 <a href=
"#_format"><strong><tt>format
</tt></strong></a> now supports
<tt>%b
</tt> for binary conversion
902 <a href=
"#_lsort"><strong><tt>lsort
</tt></strong></a> now supports
<em>-unique
</em> and
<em>-real
</em>
907 Add support for half-close with
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>close
</tt> ?r|w?
912 Add
<a href=
"#_socket"><strong><tt>socket
</tt></strong></a> <tt>pair
</tt> for a bidirectional pipe
917 Add --random-hash to randomise hash tables for greater security
922 <a href=
"#_dict"><strong><tt>dict
</tt></strong></a> now supports
<em>for
</em>,
<em>values
</em>,
<em>incr
</em>,
<em>append
</em>,
<em>lappend
</em>,
<em>update
</em>,
<em>info
</em> and
<em>replace
</em>
927 <a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>stat
</tt> no longer requires the variable name
933 <h3 id=
"_changes_between_0_73_and_0_74">Changes between
0.73 and
0.74</h3>
934 <div class=
"olist arabic"><ol class=
"arabic">
937 Numbers with leading zeros are treated as decimal, not octal
942 Add
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>isatty
</tt>
947 Add LFS (
64 bit) support for
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>seek
</tt>,
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>tell
</tt>,
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>copyto
</tt>,
<a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>copy
</tt>
952 <a href=
"#_string"><strong><tt>string
</tt></strong></a> <tt>compare
</tt> and
<a href=
"#_string"><strong><tt>string
</tt></strong></a> <tt>equal
</tt> now support
<em>-length
</em>
957 <a href=
"#_glob"><strong><tt>glob
</tt></strong></a> now supports
<em>-directory
</em>
963 <h3 id=
"_changes_between_0_72_and_0_73">Changes between
0.72 and
0.73</h3>
964 <div class=
"olist arabic"><ol class=
"arabic">
967 Built-in regexp now support non-capturing parentheses: (?:
…)
972 Add
<a href=
"#_string"><strong><tt>string
</tt></strong></a> <tt>replace
</tt>
977 Add
<a href=
"#_string"><strong><tt>string
</tt></strong></a> <tt>totitle
</tt>
982 Add
<a href=
"#_info"><strong><tt>info
</tt></strong></a> <tt>statics
</tt>
987 Add
<tt>build-jim-ext
</tt> for easy separate building of loadable modules (extensions)
992 <a href=
"#_local"><strong><tt>local
</tt></strong></a> now works with any command, not just procs
997 Add
<a href=
"#_info"><strong><tt>info
</tt></strong></a> <tt>alias
</tt> to access the target of an alias
1002 UTF-
8 encoding past the basic multilingual plane (BMP) is supported
1007 Add
<a href=
"#_tcl_prefix"><strong><tt>tcl::prefix
</tt></strong></a>
1012 Add
<a href=
"#_history"><strong><tt>history
</tt></strong></a>
1017 Most extensions are now enabled by default
1022 Add support for namespaces and the
<a href=
"#_namespace"><strong><tt>namespace
</tt></strong></a> command
1027 Add
<a href=
"#_apply"><strong><tt>apply
</tt></strong></a>
1033 <h3 id=
"_changes_between_0_71_and_0_72">Changes between
0.71 and
0.72</h3>
1034 <div class=
"olist arabic"><ol class=
"arabic">
1037 procs now allow
<em>args
</em> and optional parameters in any position
1042 Add Tcl-compatible expr functions,
<tt>rand()
</tt>,
<tt>srand()
</tt> and
<tt>pow()
</tt>
1047 Add support for the
<em>-force
</em> option to
<a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>delete
</tt>
1052 Better diagnostics when
<a href=
"#_source"><strong><tt>source
</tt></strong></a> fails to load a script with a missing quote or bracket
1057 New
<tt>tcl_platform(pathSeparator)
</tt>
1062 Add support settings the modification time with
<a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>mtime
</tt>
1067 <a href=
"#_exec"><strong><tt>exec
</tt></strong></a> is now fully supported on win32 (mingw32)
1072 <a href=
"#_file"><strong><tt>file
</tt></strong></a> <tt>join
</tt>,
<a href=
"#_pwd"><strong><tt>pwd
</tt></strong></a>,
<a href=
"#_glob"><strong><tt>glob
</tt></strong></a> etc. now work for mingw32
1077 Line editing is now supported for the win32 console (mingw32)
1082 Add
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>listen
</tt> command
1088 <h3 id=
"_changes_between_0_70_and_0_71">Changes between
0.70 and
0.71</h3>
1089 <div class=
"olist arabic"><ol class=
"arabic">
1092 Allow
<em>args
</em> to be renamed in procs
1097 Add
<tt>$(
…)
</tt> shorthand syntax for expressions
1102 Add automatic reference variables in procs with
<tt>&var
</tt> syntax
1107 Support
<tt>jimsh --version
</tt>
1112 Additional variables in
<tt>tcl_platform()
</tt>
1117 <a href=
"#_local"><strong><tt>local
</tt></strong></a> procs now push existing commands and
<a href=
"#_upcall"><strong><tt>upcall
</tt></strong></a> can call them
1122 Add
<a href=
"#_loop"><strong><tt>loop
</tt></strong></a> command (TclX compatible)
1127 Add
<a href=
"#_aio"><strong><tt>aio
</tt></strong></a> <tt>buffering
</tt> command
1132 <a href=
"#_info"><strong><tt>info
</tt></strong></a> <tt>complete
</tt> can now return the missing character
1137 <a href=
"#_binary"><strong><tt>binary
</tt></strong></a> <tt>format
</tt> and
<a href=
"#_binary"><strong><tt>binary
</tt></strong></a> <tt>scan
</tt> are now (optionally) supported
1142 Add
<a href=
"#_string"><strong><tt>string
</tt></strong></a> <tt>byterange
</tt>
1147 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1155 <h2 id=
"_tcl_introduction">TCL INTRODUCTION
</h2>
1156 <div class=
"sectionbody">
1157 <div class=
"paragraph"><p>Tcl stands for
<em>tool command language
</em> and is pronounced
<em>tickle.
</em>
1158 It is actually two things: a language and a library.
</p></div>
1159 <div class=
"paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1160 issuing commands to interactive programs such as text editors,
1161 debuggers, illustrators, and shells. It has a simple syntax and is also
1162 programmable, so Tcl users can write command procedures to provide more
1163 powerful commands than those in the built-in set.
</p></div>
1164 <div class=
"paragraph"><p>Second, Tcl is a library package that can be embedded in application
1165 programs. The Tcl library consists of a parser for the Tcl language,
1166 routines to implement the Tcl built-in commands, and procedures that
1167 allow each application to extend Tcl with additional commands specific
1168 to that application. The application program generates Tcl commands and
1169 passes them to the Tcl parser for execution. Commands may be generated
1170 by reading characters from an input source, or by associating command
1171 strings with elements of the application
’s user interface, such as menu
1172 entries, buttons, or keystrokes.
</p></div>
1173 <div class=
"paragraph"><p>When the Tcl library receives commands it parses them into component
1174 fields and executes built-in commands directly. For commands implemented
1175 by the application, Tcl calls back to the application to execute the
1176 commands. In many cases commands will invoke recursive invocations of the
1177 Tcl interpreter by passing in additional strings to execute (procedures,
1178 looping commands, and conditional commands all work in this way).
</p></div>
1179 <div class=
"paragraph"><p>An application program gains three advantages by using Tcl for its command
1180 language. First, Tcl provides a standard syntax: once users know Tcl,
1181 they will be able to issue commands easily to any Tcl-based application.
1182 Second, Tcl provides programmability. All a Tcl application needs
1183 to do is to implement a few application-specific low-level commands.
1184 Tcl provides many utility commands plus a general programming interface
1185 for building up complex command procedures. By using Tcl, applications
1186 need not re-implement these features.
</p></div>
1187 <div class=
"paragraph"><p>Third, Tcl can be used as a common language for communicating between
1188 applications. Inter-application communication is not built into the
1189 Tcl core described here, but various add-on libraries, such as the Tk
1190 toolkit, allow applications to issue commands to each other. This makes
1191 it possible for applications to work together in much more powerful ways
1192 than was previously possible.
</p></div>
1193 <div class=
"paragraph"><p>Fourth, Jim Tcl includes a command processor,
<tt>jimsh
</tt>, which can be
1194 used to run standalone Tcl scripts, or to run Tcl commands interactively.
</p></div>
1195 <div class=
"paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1196 the language syntax and the built-in commands that will be available
1197 in any application based on Tcl. The individual library procedures are
1198 described in more detail in separate manual pages, one per procedure.
</p></div>
1202 <h2 id=
"_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER
</h2>
1203 <div class=
"sectionbody">
1204 <div class=
"paragraph"><p>A simple, but powerful command processor,
<tt>jimsh
</tt>, is part of Jim Tcl.
1205 It may be invoked in interactive mode as:
</p></div>
1206 <div class=
"literalblock">
1207 <div class=
"content">
1208 <pre><tt>jimsh
</tt></pre>
1210 <div class=
"paragraph"><p>or to process the Tcl script in a file with:
</p></div>
1211 <div class=
"literalblock">
1212 <div class=
"content">
1213 <pre><tt>jimsh filename
</tt></pre>
1215 <div class=
"paragraph"><p>It may also be invoked to execute an immediate script with:
</p></div>
1216 <div class=
"literalblock">
1217 <div class=
"content">
1218 <pre><tt>jimsh -e
"script"</tt></pre>
1221 <h3 id=
"_interactive_mode">Interactive Mode
</h3>
1222 <div class=
"paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1223 those commands and prints the results.
</p></div>
1224 <div class=
"literalblock">
1225 <div class=
"content">
1227 Welcome to Jim version
0.73, Copyright (c)
2005-
8 Salvatore Sanfilippo
1230 . lsort [info commands p*]
1231 package parray pid popen proc puts pwd
1232 . foreach i {a b c} {
1239 invalid command name
"bad"
1243 <div class=
"paragraph"><p>If
<tt>jimsh
</tt> is configured with line editing (it is by default) and a VT-
100-compatible
1244 terminal is detected, Emacs-style line editing commands are available, including:
1245 arrow keys,
<tt>^W
</tt> to erase a word,
<tt>^U
</tt> to erase the line,
<tt>^R
</tt> for reverse incremental search
1246 in history. Additionally, the
<tt>h
</tt> command may be used to display the command history.
</p></div>
1247 <div class=
"paragraph"><p>Command line history is automatically saved and loaded from
<tt>~/.jim_history
</tt></p></div>
1248 <div class=
"paragraph"><p>In interactive mode,
<tt>jimsh
</tt> automatically runs the script
<tt>~/.jimrc
</tt> at startup
1249 if it exists.
</p></div>
1254 <h2 id=
"_interpreters">INTERPRETERS
</h2>
1255 <div class=
"sectionbody">
1256 <div class=
"paragraph"><p>The central data structure in Tcl is an interpreter (C type
<em>Jim_Interp
</em>).
1257 An interpreter consists of a set of command bindings, a set of variable
1258 values, and a few other miscellaneous pieces of state. Each Tcl command
1259 is interpreted in the context of a particular interpreter.
</p></div>
1260 <div class=
"paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1261 simultaneously, each associated with a different widget or portion of
1262 the application. Interpreters are relatively lightweight structures.
1263 They can be created and deleted quickly, so application programmers should
1264 feel free to use multiple interpreters if that simplifies the application.
</p></div>
1268 <h2 id=
"_data_types">DATA TYPES
</h2>
1269 <div class=
"sectionbody">
1270 <div class=
"paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1271 to commands, all command results, and all variable values are strings.
</p></div>
1272 <div class=
"paragraph"><p>Where commands require numeric arguments or return numeric results,
1273 the arguments and results are passed as strings. Many commands expect
1274 their string arguments to have certain formats, but this interpretation
1275 is up to the individual commands. For example, arguments often contain
1276 Tcl command strings, which may get executed as part of the commands.
1277 The easiest way to understand the Tcl interpreter is to remember that
1278 everything is just an operation on a string. In many cases Tcl constructs
1279 will look similar to more structured constructs from other languages.
1280 However, the Tcl constructs are not structured at all; they are just
1281 strings of characters, and this gives them a different behaviour than
1282 the structures they may look like.
</p></div>
1283 <div class=
"paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1284 the interpretation, there are three common forms that strings take:
1285 commands, expressions, and lists. The major sections below discuss
1286 these three forms in more detail.
</p></div>
1290 <h2 id=
"_basic_command_syntax">BASIC COMMAND SYNTAX
</h2>
1291 <div class=
"sectionbody">
1292 <div class=
"paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1293 and Lisp. However, the interpretation of commands is different
1294 in Tcl than in either of those other two systems.
1295 A Tcl command string consists of one or more commands separated
1296 by newline characters or semi-colons.
1297 Each command consists of a collection of fields separated by
1298 white space (spaces or tabs).
1299 The first field must be the name of a command, and the
1300 additional fields, if any, are arguments that will be passed to
1301 that command. For example, the command:
</p></div>
1302 <div class=
"literalblock">
1303 <div class=
"content">
1304 <pre><tt>set a
22</tt></pre>
1306 <div class=
"paragraph"><p>has three fields: the first,
<a href=
"#_set"><strong><tt>set
</tt></strong></a>, is the name of a Tcl command, and
1307 the last two,
<em>a
</em> and
<em>22</em>, will be passed as arguments to
1308 the
<a href=
"#_set"><strong><tt>set
</tt></strong></a> command. The command name may refer either to a built-in
1309 Tcl command, an application-specific command bound in with the library
1310 procedure
<em>Jim_CreateCommand
</em>, or a command procedure defined with the
1311 <a href=
"#_proc"><strong><tt>proc
</tt></strong></a> built-in command.
</p></div>
1312 <div class=
"paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1313 interpret those strings in any fashion they wish. The
<a href=
"#_set"><strong><tt>set
</tt></strong></a> command,
1314 for example, will treat its first argument as the name of a variable
1315 and its second argument as a string value to assign to that variable.
1316 For other commands arguments may be interpreted as integers, lists,
1317 file names, or Tcl commands.
</p></div>
1318 <div class=
"paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1319 However, if the Tcl interpreter cannot locate a command it invokes a
1320 special command named
<a href=
"#_unknown"><strong><tt>unknown
</tt></strong></a> which attempts to find or create the
1322 <div class=
"paragraph"><p>For example, at many sites
<a href=
"#_unknown"><strong><tt>unknown
</tt></strong></a> will search through library
1323 directories for the desired command and create it as a Tcl procedure if
1324 it is found. The
<a href=
"#_unknown"><strong><tt>unknown
</tt></strong></a> command often provides automatic completion
1325 of abbreviated commands, but usually only for commands that were typed
1326 interactively.
</p></div>
1327 <div class=
"paragraph"><p>It
’s probably a bad idea to use abbreviations in command scripts and
1328 other forms that will be re-used over time: changes to the command set
1329 may cause abbreviations to become ambiguous, resulting in scripts that
1330 no longer work.
</p></div>
1334 <h2 id=
"_comments">COMMENTS
</h2>
1335 <div class=
"sectionbody">
1336 <div class=
"paragraph"><p>If the first non-blank character in a command is
<tt>#
</tt>, then everything
1337 from the
<tt>#
</tt> up through the next newline character is treated as
1338 a comment and ignored. When comments are embedded inside nested
1339 commands (e.g. fields enclosed in braces) they must have properly-matched
1340 braces (this is necessary because when Tcl parses the top-level command
1341 it doesn
’t yet know that the nested field will be used as a command so
1342 it cannot process the nested comment character as a comment).
</p></div>
1346 <h2 id=
"_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES
</h2>
1347 <div class=
"sectionbody">
1348 <div class=
"paragraph"><p>Normally each argument field ends at the next white space, but
1349 double-quotes may be used to create arguments with embedded space.
</p></div>
1350 <div class=
"paragraph"><p>If an argument field begins with a double-quote, then the argument isn
’t
1351 terminated by white space (including newlines) or a semi-colon (see below
1352 for information on semi-colons); instead it ends at the next double-quote
1353 character. The double-quotes are not included in the resulting argument.
1354 For example, the command
</p></div>
1355 <div class=
"literalblock">
1356 <div class=
"content">
1357 <pre><tt>set a
"This is a single argument"</tt></pre>
1359 <div class=
"paragraph"><p>will pass two arguments to
<a href=
"#_set"><strong><tt>set
</tt></strong></a>:
<em>a
</em> and
<em>This is a single argument
</em>.
</p></div>
1360 <div class=
"paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1361 and backslash substitutions still occur, as described below. If the
1362 first character of a command field is not a quote, then quotes receive
1363 no special interpretation in the parsing of that field.
</p></div>
1367 <h2 id=
"_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES
</h2>
1368 <div class=
"sectionbody">
1369 <div class=
"paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1370 to quotes except for two differences. First, they nest; this makes them
1371 easier to use for complicated arguments like nested Tcl command strings.
1372 Second, the substitutions described below for commands, variables, and
1373 backslashes do
<strong>not
</strong> occur in arguments enclosed in braces, so braces
1374 can be used to prevent substitutions where they are undesirable.
</p></div>
1375 <div class=
"paragraph"><p>If an argument field begins with a left brace, then the argument ends
1376 at the matching right brace. Tcl will strip off the outermost layer
1377 of braces and pass the information between the braces to the command
1378 without any further modification. For example, in the command
</p></div>
1379 <div class=
"literalblock">
1380 <div class=
"content">
1381 <pre><tt>set a {xyz a {b c d}}
</tt></pre>
1383 <div class=
"paragraph"><p>the
<a href=
"#_set"><strong><tt>set
</tt></strong></a> command will receive two arguments:
<em>a
</em>
1384 and
<em>xyz a {b c d}
</em>.
</p></div>
1385 <div class=
"paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1386 not be on the same line as the starting quote or brace; in this case
1387 the newline will be included in the argument field along with any other
1388 characters up to the matching brace or quote. For example, the
<a href=
"#_eval"><strong><tt>eval
</tt></strong></a>
1389 command takes one argument, which is a command string;
<a href=
"#_eval"><strong><tt>eval
</tt></strong></a> invokes
1390 the Tcl interpreter to execute the command string. The command
</p></div>
1391 <div class=
"literalblock">
1392 <div class=
"content">
1398 <div class=
"paragraph"><p>will assign the value
<em>22</em> to
<em>a
</em> and
<em>33</em> to
<em>b
</em>.
</p></div>
1399 <div class=
"paragraph"><p>If the first character of a command field is not a left
1400 brace, then neither left nor right
1401 braces in the field will be treated specially (except as part of
1402 variable substitution; see below).
</p></div>
1406 <h2 id=
"_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS
</h2>
1407 <div class=
"sectionbody">
1408 <div class=
"paragraph"><p>If an open bracket occurs in a field of a command, then command
1409 substitution occurs (except for fields enclosed in braces). All of the
1410 text up to the matching close bracket is treated as a Tcl command and
1411 executed immediately. Then the result of that command is substituted
1412 for the bracketed text. For example, consider the command
</p></div>
1413 <div class=
"literalblock">
1414 <div class=
"content">
1415 <pre><tt>set a [set b]
</tt></pre>
1417 <div class=
"paragraph"><p>When the
<a href=
"#_set"><strong><tt>set
</tt></strong></a> command has only a single argument, it is the name of a
1418 variable and
<a href=
"#_set"><strong><tt>set
</tt></strong></a> returns the contents of that variable. In this case,
1419 if variable
<em>b
</em> has the value
<em>foo
</em>, then the command above is equivalent
1420 to the command
</p></div>
1421 <div class=
"literalblock">
1422 <div class=
"content">
1423 <pre><tt>set a foo
</tt></pre>
1425 <div class=
"paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1426 <em>b
</em> has the value
<em>foo
</em> and the variable
<em>c
</em> has the value
<em>gorp
</em>,
1427 then the command
</p></div>
1428 <div class=
"literalblock">
1429 <div class=
"content">
1430 <pre><tt>set a xyz[set b].[set c]
</tt></pre>
1432 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1433 <div class=
"literalblock">
1434 <div class=
"content">
1435 <pre><tt>set a xyzfoo.gorp
</tt></pre>
1437 <div class=
"paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1438 or semi-colons in the usual fashion. In this case the value of the last
1439 command is used for substitution. For example, the command
</p></div>
1440 <div class=
"literalblock">
1441 <div class=
"content">
1442 <pre><tt>set a x[set b
22
1443 expr $b+
2]x
</tt></pre>
1445 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1446 <div class=
"literalblock">
1447 <div class=
"content">
1448 <pre><tt>set a x24x
</tt></pre>
1450 <div class=
"paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1451 between them are not interpreted specially; they are passed through to
1452 the argument verbatim.
</p></div>
1456 <h2 id=
"_variable_substitution_with">VARIABLE SUBSTITUTION WITH $
</h2>
1457 <div class=
"sectionbody">
1458 <div class=
"paragraph"><p>The dollar sign (
<tt>$
</tt>) may be used as a special shorthand form for
1459 substituting variable values. If
<tt>$
</tt> appears in an argument that isn
’t
1460 enclosed in braces then variable substitution will occur. The characters
1461 after the
<tt>$
</tt>, up to the first character that isn
’t a number, letter,
1462 or underscore, are taken as a variable name and the string value of that
1463 variable is substituted for the name.
</p></div>
1464 <div class=
"paragraph"><p>For example, if variable
<em>foo
</em> has the value
<em>test
</em>, then the command
</p></div>
1465 <div class=
"literalblock">
1466 <div class=
"content">
1467 <pre><tt>set a $foo.c
</tt></pre>
1469 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1470 <div class=
"literalblock">
1471 <div class=
"content">
1472 <pre><tt>set a test.c
</tt></pre>
1474 <div class=
"paragraph"><p>There are two special forms for variable substitution. If the next
1475 character after the name of the variable is an open parenthesis, then
1476 the variable is assumed to be an array name, and all of the characters
1477 between the open parenthesis and the next close parenthesis are taken as
1478 an index into the array. Command substitutions and variable substitutions
1479 are performed on the information between the parentheses before it is
1480 used as an index.
</p></div>
1481 <div class=
"paragraph"><p>For example, if the variable
<em>x
</em> is an array with one element named
1482 <em>first
</em> and value
<em>87</em> and another element named
<em>14</em> and value
<em>more
</em>,
1483 then the command
</p></div>
1484 <div class=
"literalblock">
1485 <div class=
"content">
1486 <pre><tt>set a xyz$x(first)zyx
</tt></pre>
1488 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1489 <div class=
"literalblock">
1490 <div class=
"content">
1491 <pre><tt>set a xyz87zyx
</tt></pre>
1493 <div class=
"paragraph"><p>If the variable
<em>index
</em> has the value
<em>14</em>, then the command
</p></div>
1494 <div class=
"literalblock">
1495 <div class=
"content">
1496 <pre><tt>set a xyz$x($index)zyx
</tt></pre>
1498 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1499 <div class=
"literalblock">
1500 <div class=
"content">
1501 <pre><tt>set a xyzmorezyx
</tt></pre>
1503 <div class=
"paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.
</p></div>
1504 <div class=
"paragraph"><p>The second special form for variables occurs when the dollar sign is
1505 followed by an open curly brace. In this case the variable name consists
1506 of all the characters up to the next curly brace.
</p></div>
1507 <div class=
"paragraph"><p>Array references are not possible in this form: the name between braces
1508 is assumed to refer to a scalar variable. For example, if variable
1509 <em>foo
</em> has the value
<em>test
</em>, then the command
</p></div>
1510 <div class=
"literalblock">
1511 <div class=
"content">
1512 <pre><tt>set a abc${foo}bar
</tt></pre>
1514 <div class=
"paragraph"><p>is equivalent to the command
</p></div>
1515 <div class=
"literalblock">
1516 <div class=
"content">
1517 <pre><tt>set a abctestbar
</tt></pre>
1519 <div class=
"paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1520 braces: the dollar sign and variable name are passed through to the
1521 argument verbatim.
</p></div>
1522 <div class=
"paragraph"><p>The dollar sign abbreviation is simply a shorthand form.
<tt>$a
</tt> is
1523 completely equivalent to
<tt>[set a]
</tt>; it is provided as a convenience
1524 to reduce typing.
</p></div>
1528 <h2 id=
"_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS
</h2>
1529 <div class=
"sectionbody">
1530 <div class=
"paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1531 newline character). However, semi-colon (
<tt>;
</tt>) is treated as a command
1532 separator character; multiple commands may be placed on one line by
1533 separating them with a semi-colon. Semi-colons are not treated as
1534 command separators if they appear within curly braces or double-quotes.
</p></div>
1538 <h2 id=
"_backslash_substitution">BACKSLASH SUBSTITUTION
</h2>
1539 <div class=
"sectionbody">
1540 <div class=
"paragraph"><p>Backslashes may be used to insert non-printing characters into command
1541 fields and also to insert special characters like braces and brackets
1542 into fields without them being interpreted specially as described above.
</p></div>
1543 <div class=
"paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1544 listed below. In each case, the backslash
1545 sequence is replaced by the given character:
</p></div>
1546 <div class=
"dlist" id=
"BackslashSequences"><dl>
1547 <dt class=
"hdlist1">
1555 <dt class=
"hdlist1">
1563 <dt class=
"hdlist1">
1571 <dt class=
"hdlist1">
1576 Carriage-return (
0xd).
1579 <dt class=
"hdlist1">
1587 <dt class=
"hdlist1">
1595 <dt class=
"hdlist1">
1603 <dt class=
"hdlist1">
1611 <dt class=
"hdlist1">
1619 <dt class=
"hdlist1">
1627 <dt class=
"hdlist1">
1635 <dt class=
"hdlist1">
1636 <tt>\
<space
></tt>
1640 Space ( ): doesn
’t terminate argument.
1643 <dt class=
"hdlist1">
1648 Semi-colon: doesn
’t terminate command.
1651 <dt class=
"hdlist1">
1659 <dt class="hdlist1
">
1660 <tt>\<newline></tt>
1664 Nothing: this joins two lines together
1665 into a single line. This backslash feature is unique in that
1666 it will be applied even when the sequence occurs within braces.
1669 <dt class="hdlist1
">
1674 Backslash (<em>\</em>).
1677 <dt class="hdlist1
">
1682 The digits <tt><em>ddd</em></tt> (one, two, or three of them) give the octal value of
1683 the character. Note that Jim supports null characters in strings.
1686 <dt class="hdlist1
">
1689 <dt class="hdlist1
">
1692 <dt class="hdlist1
">
1697 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <tt><em>nnnn</em></tt>, is inserted.
1698 The <em>u</em> form allows for one to four hex digits.
1699 The <em>U</em> form allows for one to eight hex digits.
1700 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1701 characters UTF-8 characters which are followed by a hex digit.
1705 <div class="paragraph
"><p>For example, in the command</p></div>
1706 <div class="literalblock
">
1707 <div class="content
">
1708 <pre><tt>set a \{x\[\ yz\141</tt></pre>
1710 <div class="paragraph
"><p>the second argument to <a href="#_set
"><strong><tt>set</tt></strong></a> will be <tt>{x[ yza</tt>.</p></div>
1711 <div class="paragraph
"><p>If a backslash is followed by something other than one of the options
1712 described above, then the backslash is transmitted to the argument
1713 field without any special processing, and the Tcl scanner continues
1714 normal processing with the next character. For example, in the
1716 <div class="literalblock
">
1717 <div class="content
">
1718 <pre><tt>set \*a \\\{foo</tt></pre>
1720 <div class="paragraph
"><p>The first argument to <a href="#_set
"><strong><tt>set</tt></strong></a> will be <tt>\*a</tt> and the second
1721 argument will be <tt>\{foo</tt>.</p></div>
1722 <div class="paragraph
"><p>If an argument is enclosed in braces, then backslash sequences inside
1723 the argument are parsed but no substitution occurs (except for
1724 backslash-newline): the backslash
1725 sequence is passed through to the argument as is, without making
1726 any special interpretation of the characters in the backslash sequence.
1727 In particular, backslashed braces are not counted in locating the
1728 matching right brace that terminates the argument.
1731 <div class="literalblock
">
1732 <div class="content
">
1733 <pre><tt>set a {\{abc}</tt></pre>
1735 <div class="paragraph
"><p>the second argument to <a href="#_set
"><strong><tt>set</tt></strong></a> will be <tt>\{abc</tt>.</p></div>
1736 <div class="paragraph
"><p>This backslash mechanism is not sufficient to generate absolutely
1737 any argument structure; it only covers the
1738 most common cases. To produce particularly complicated arguments
1739 it is probably easiest to use the <a href="#_format
"><strong><tt>format</tt></strong></a> command along with
1740 command substitution.</p></div>
1744 <h2 id="_string_and_list_index_specifications
">STRING AND LIST INDEX SPECIFICATIONS</h2>
1745 <div class="sectionbody
">
1746 <div class="paragraph
"><p>Many string and list commands take one or more <em>index</em> parameters which
1747 specify a position in the string relative to the start or end of the string/list.</p></div>
1748 <div class="paragraph
"><p>The index may be one of the following forms:</p></div>
1749 <div class="dlist
"><dl>
1750 <dt class="hdlist1
">
1755 A simple integer, where <em>0</em> refers to the first element of the string
1759 <dt class="hdlist1
">
1760 <tt>integer+integer</tt> or
1762 <dt class="hdlist1
">
1763 <tt>integer-integer</tt>
1767 The sum or difference of the two integers. e.g. <tt>2+3</tt> refers to the 5th element.
1768 This is useful when used with (e.g.) <tt>$i+1</tt> rather than the more verbose
1769 <tt>[expr {$i+1}]</tt>
1772 <dt class="hdlist1
">
1777 The last element of the string or list.
1780 <dt class="hdlist1
">
1781 <tt>end-integer</tt>
1785 The <em>nth-from-last</em> element of the string or list.
1792 <h2 id="_command_summary
">COMMAND SUMMARY</h2>
1793 <div class="sectionbody
">
1794 <div class="olist arabic
"><ol class="arabic
">
1797 A command is just a string.
1802 Within a string commands are separated by newlines or semi-colons
1803 (unless the newline or semi-colon is within braces or brackets
1809 A command consists of fields. The first field is the name of the command.
1810 The other fields are strings that are passed to that command as arguments.
1815 Fields are normally separated by white space.
1820 Double-quotes allow white space and semi-colons to appear within
1822 Command substitution, variable substitution, and backslash substitution
1823 still occur inside quotes.
1828 Braces defer interpretation of special characters.
1829 If a field begins with a left brace, then it consists of everything
1830 between the left brace and the matching right brace. The
1831 braces themselves are not included in the argument.
1832 No further processing is done on the information between the braces
1833 except that backslash-newline sequences are eliminated.
1838 If a field doesn’t begin with a brace then backslash,
1839 variable, and command substitution are done on the field. Only a
1840 single level of processing is done: the results of one substitution
1841 are not scanned again for further substitutions or any other
1842 special treatment. Substitution can
1843 occur on any field of a command, including the command name
1844 as well as the arguments.
1849 If the first non-blank character of a command is a <tt>#</tt>, everything
1850 from the <tt>#</tt> up through the next newline is treated as a comment
1858 <h2 id="_expressions
">EXPRESSIONS</h2>
1859 <div class="sectionbody
">
1860 <div class="paragraph
"><p>The second major interpretation applied to strings in Tcl is
1861 as expressions. Several commands, such as <a href="#_expr
"><strong><tt>expr</tt></strong></a>, <a href="#_for
"><strong><tt>for</tt></strong></a>,
1862 and <a href="#_if
"><strong><tt>if</tt></strong></a>, treat one or more of their arguments as expressions
1863 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1864 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1865 <div class="paragraph
"><p>The operators permitted in Tcl expressions are a subset of
1866 the operators permitted in C expressions, and they have the
1867 same meaning and precedence as the corresponding C operators.
1868 Expressions almost always yield numeric results
1869 (integer or floating-point values).
1870 For example, the expression</p></div>
1871 <div class="literalblock
">
1872 <div class="content
">
1873 <pre><tt>8.2 + 6</tt></pre>
1875 <div class="paragraph
"><p>evaluates to 14.2.</p></div>
1876 <div class="paragraph
"><p>Tcl expressions differ from C expressions in the way that
1877 operands are specified, and in that Tcl expressions support
1878 non-numeric operands and string comparisons.</p></div>
1879 <div class="paragraph
"><p>A Tcl expression consists of a combination of operands, operators,
1880 and parentheses.</p></div>
1881 <div class="paragraph
"><p>White space may be used between the operands and operators and
1882 parentheses; it is ignored by the expression processor.
1883 Where possible, operands are interpreted as integer values.</p></div>
1884 <div class="paragraph
"><p>Integer values may be specified in decimal (the normal case) or in
1885 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1886 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1887 <div class="paragraph
"><p>If an operand does not have one of the integer formats given
1888 above, then it is treated as a floating-point number if that is
1889 possible. Floating-point numbers may be specified in any of the
1890 ways accepted by an ANSI-compliant C compiler (except that the
1891 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1892 most installations). For example, all of the
1893 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1894 <div class="paragraph
"><p>If no numeric interpretation is possible, then an operand is left
1895 as a string (and only a limited set of operators may be applied to
1897 <div class="olist arabic
"><ol class="arabic
">
1900 Operands may be specified in any of the following ways:
1905 As a numeric value, either integer or floating-point.
1910 As a Tcl variable, using standard <em>$</em> notation.
1911 The variable’s value will be used as the operand.
1916 As a string enclosed in double-quotes.
1917 The expression parser will perform backslash, variable, and
1918 command substitutions on the information between the quotes,
1919 and use the resulting value as the operand
1924 As a string enclosed in braces.
1925 The characters between the open brace and matching close brace
1926 will be used as the operand without any substitutions.
1931 As a Tcl command enclosed in brackets.
1932 The command will be executed and its result will be used as
1937 <div class="paragraph
"><p>Where substitutions occur above (e.g. inside quoted strings), they
1938 are performed by the expression processor.
1939 However, an additional layer of substitution may already have
1940 been performed by the command parser before the expression
1941 processor was called.</p></div>
1942 <div class="paragraph
"><p>As discussed below, it is usually best to enclose expressions
1943 in braces to prevent the command parser from performing substitutions
1944 on the contents.</p></div>
1945 <div class="paragraph
"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1946 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1947 on the left side of each of the lines below will evaluate to the value
1948 on the right side of the line:</p></div>
1949 <div class="literalblock
">
1950 <div class="content
">
1951 <pre><tt>$a + 3.1 6.1
1954 {word one} < "word $a
" 0</tt></pre>
1956 <div class="paragraph
"><p>The valid operators are listed below, grouped in decreasing order
1957 of precedence:</p></div>
1958 <div class="dlist
" id="OperatorPrecedence
"><dl>
1959 <dt class="hdlist1
">
1960 <tt>int() double() round() abs(), rand(), srand()</tt>
1964 Unary functions (except rand() which takes no arguments)
1966 <div class="ulist
"><ul>
1969 <tt><em>int()</em></tt> converts the numeric argument to an integer by truncating down.
1974 <tt><em>double()</em></tt> converts the numeric argument to floating point.
1979 <tt><em>round()</em></tt> converts the numeric argument to the closest integer value.
1984 <tt><em>abs()</em></tt> takes the absolute value of the numeric argument.
1989 <tt><em>rand()</em></tt> takes the absolute value of the numeric argument.
1994 <tt><em>rand()</em></tt> returns a pseudo-random floating-point value in the range (0,1).
1999 <tt><em>srand()</em></tt> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2004 <dt class="hdlist1
">
2005 <tt>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</tt>
2009 Unary math functions.
2010 If Jim is compiled with math support, these functions are available.
2013 <dt class="hdlist1
">
2018 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2019 may be applied to string operands, and bit-wise NOT may be
2020 applied only to integers.
2023 <dt class="hdlist1
">
2024 <tt>** pow(x,y)</tt>
2028 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2029 integers. Otherwise supports integers only. (Note that the math-function form
2030 has the same highest precedence)
2033 <dt class="hdlist1
">
2038 Multiply, divide, remainder. None of these operands may be
2039 applied to string operands, and remainder may be applied only
2043 <dt class="hdlist1
">
2048 Add and subtract. Valid for any numeric operands.
2051 <dt class="hdlist1
">
2052 <tt><< >> <<< >>></tt>
2056 Left and right shift, left and right rotate. Valid for integer operands only.
2059 <dt class="hdlist1
">
2060 <tt>< > <= >=</tt>
2064 Boolean less, greater, less than or equal, and greater than or equal.
2065 Each operator produces 1 if the condition is true, 0 otherwise.
2066 These operators may be applied to strings as well as numeric operands,
2067 in which case string comparison is used.
2070 <dt class="hdlist1
">
2075 Boolean equal and not equal. Each operator produces a zero/one result.
2076 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2077 if possible, then floating point types, and finally strings will be compared.
2078 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2081 <dt class="hdlist1
">
2086 String equal and not equal. Uses the string value directly without
2087 attempting to convert to a number first.
2090 <dt class="hdlist1
">
2095 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2096 is contained in the right operand (as a list), or 0 otherwise. The result for
2097 <tt>{$a ni $list}</tt> is equivalent to <tt>{!($a in $list)}</tt>.
2100 <dt class="hdlist1
">
2105 Bit-wise AND. Valid for integer operands only.
2108 <dt class="hdlist1
">
2113 Bit-wise OR. Valid for integer operands only.
2116 <dt class="hdlist1
">
2121 Bit-wise exclusive OR. Valid for integer operands only.
2124 <dt class="hdlist1
">
2129 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2130 Valid for numeric operands only (integers or floating-point).
2133 <dt class="hdlist1
">
2138 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2139 Valid for numeric operands only (integers or floating-point).
2142 <dt class="hdlist1
">
2147 If-then-else, as in C. If <tt><em>x</em></tt>
2148 evaluates to non-zero, then the result is the value of <tt><em>y</em></tt>.
2149 Otherwise the result is the value of <tt><em>z</em></tt>.
2150 The <tt><em>x</em></tt> operand must have a numeric value, while <tt><em>y</em></tt> and <tt><em>z</em></tt> can
2155 <div class="paragraph
"><p>See the C manual for more details on the results
2156 produced by each operator.
2157 All of the binary operators group left-to-right within the same
2158 precedence level. For example, the expression</p></div>
2159 <div class="literalblock
">
2160 <div class="content
">
2161 <pre><tt>4*2 < 7</tt></pre>
2163 <div class="paragraph
"><p>evaluates to 0.</p></div>
2164 <div class="paragraph
"><p>The <tt>&&</tt>, <tt>||</tt>, and <tt>?:</tt> operators have <em>lazy evaluation</em>, just as
2165 in C, which means that operands are not evaluated if they are not
2166 needed to determine the outcome. For example, in</p></div>
2167 <div class="literalblock
">
2168 <div class="content
">
2169 <pre><tt>$v ? [a] : [b]</tt></pre>
2171 <div class="paragraph
"><p>only one of <tt>[a]</tt> or <tt>[b]</tt> will actually be evaluated,
2172 depending on the value of <tt>$v</tt>.</p></div>
2173 <div class="paragraph
"><p>All internal computations involving integers are done with the C
2174 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2175 computations involving floating-point are done with the C type
2176 <em>double</em>.</p></div>
2177 <div class="paragraph
"><p>When converting a string to floating-point, exponent overflow is
2178 detected and results in a Tcl error.
2179 For conversion to integer from string, detection of overflow depends
2180 on the behaviour of some routines in the local C library, so it should
2181 be regarded as unreliable.
2182 In any case, overflow and underflow are generally not detected
2183 reliably for intermediate results.</p></div>
2184 <div class="paragraph
"><p>Conversion among internal representations for integer, floating-point,
2185 and string operands is done automatically as needed.
2186 For arithmetic computations, integers are used until some
2187 floating-point number is introduced, after which floating-point is used.
2188 For example,</p></div>
2189 <div class="literalblock
">
2190 <div class="content
">
2191 <pre><tt>5 / 4</tt></pre>
2193 <div class="paragraph
"><p>yields the result 1, while</p></div>
2194 <div class="literalblock
">
2195 <div class="content
">
2197 5 / ( [string length "abcd
"] + 0.0 )</tt></pre>
2199 <div class="paragraph
"><p>both yield the result 1.25.</p></div>
2200 <div class="paragraph
"><p>String values may be used as operands of the comparison operators,
2201 although the expression evaluator tries to do comparisons as integer
2202 or floating-point when it can.
2203 If one of the operands of a comparison is a string and the other
2204 has a numeric value, the numeric operand is converted back to
2205 a string using the C <em>sprintf</em> format specifier
2206 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2207 For example, the expressions</p></div>
2208 <div class="literalblock
">
2209 <div class="content
">
2210 <pre><tt>"0x03" > "2"
2211 "0y
" < "0x12"</tt></pre>
2213 <div class="paragraph
"><p>both evaluate to 1. The first comparison is done using integer
2214 comparison, and the second is done using string comparison after
2215 the second operand is converted to the string <em>18</em>.</p></div>
2216 <div class="paragraph
"><p>In general it is safest to enclose an expression in braces when
2217 entering it in a command: otherwise, if the expression contains
2218 any white space then the Tcl interpreter will split it
2219 among several arguments. For example, the command</p></div>
2220 <div class="literalblock
">
2221 <div class="content
">
2222 <pre><tt>expr $a + $b</tt></pre>
2224 <div class="paragraph
"><p>results in three arguments being passed to <a href="#_expr
"><strong><tt>expr</tt></strong></a>: <tt>$a</tt>,
2225 +, and <tt>$b</tt>. In addition, if the expression isn’t in braces
2226 then the Tcl interpreter will perform variable and command substitution
2227 immediately (it will happen in the command parser rather than in
2228 the expression parser). In many cases the expression is being
2229 passed to a command that will evaluate the expression later (or
2230 even many times if, for example, the expression is to be used to
2231 decide when to exit a loop). Usually the desired goal is to re-do
2232 the variable or command substitutions each time the expression is
2233 evaluated, rather than once and for all at the beginning. For example,
2234 the command</p></div>
2235 <div class="literalblock
">
2236 <div class="content
">
2237 <pre><tt>for {set i 1} $i<=10 {incr i} {...} ** WRONG **</tt></pre>
2239 <div class="paragraph
"><p>is probably intended to iterate over all values of <tt>i</tt> from 1 to 10.
2240 After each iteration of the body of the loop, <a href="#_for
"><strong><tt>for</tt></strong></a> will pass
2241 its second argument to the expression evaluator to see whether or not
2242 to continue processing. Unfortunately, in this case the value of <tt>i</tt>
2243 in the second argument will be substituted once and for all when the
2244 <a href="#_for
"><strong><tt>for</tt></strong></a> command is parsed. If <tt>i</tt> was 0 before the <a href="#_for
"><strong><tt>for</tt></strong></a>
2245 command was invoked then the second argument of <a href="#_for
"><strong><tt>for</tt></strong></a> will be <tt>0<=10</tt>
2246 which will always evaluate to 1, even though <tt>i</tt> eventually
2247 becomes greater than 10. In the above case the loop will never
2248 terminate. Instead, the expression should be placed in braces:</p></div>
2249 <div class="literalblock
">
2250 <div class="content
">
2251 <pre><tt>for {set i 1} {$i<=10} {incr i} {...} ** RIGHT **</tt></pre>
2253 <div class="paragraph
"><p>This causes the substitution of <em>i</em>
2254 to be delayed; it will be re-done each time the expression is
2255 evaluated, which is the desired result.</p></div>
2259 <h2 id="_lists
">LISTS</h2>
2260 <div class="sectionbody
">
2261 <div class="paragraph
"><p>The third major way that strings are interpreted in Tcl is as lists.
2262 A list is just a string with a list-like structure
2263 consisting of fields separated by white space. For example, the
2265 <div class="literalblock
">
2266 <div class="content
">
2267 <pre><tt>Al Sue Anne John</tt></pre>
2269 <div class="paragraph
"><p>is a list with four elements or fields.
2270 Lists have the same basic structure as command strings, except
2271 that a newline character in a list is treated as a field separator
2272 just like space or tab. Conventions for braces and quotes
2273 and backslashes are the same for lists as for commands. For example,
2274 the string</p></div>
2275 <div class="literalblock
">
2276 <div class="content
">
2277 <pre><tt>a b\ c {d e {f g h}}</tt></pre>
2279 <div class="paragraph
"><p>is a list with three elements: <tt>a</tt>, <tt>b c</tt>, and <tt>d e {f g h}</tt>.</p></div>
2280 <div class="paragraph
"><p>Whenever an element is extracted from a list, the same rules about
2281 braces and quotes and backslashes are applied as for commands. Thus in
2282 the example above when the third element is extracted from the list,
2283 the result is</p></div>
2284 <div class="literalblock
">
2285 <div class="content
">
2286 <pre><tt>d e {f g h}</tt></pre>
2288 <div class="paragraph
"><p>(when the field was extracted, all that happened was to strip off
2289 the outermost layer of braces). Command substitution and
2290 variable substitution are never
2291 made on a list (at least, not by the list-processing commands; the
2292 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2293 <div class="paragraph
"><p>The Tcl commands <a href="#_concat
"><strong><tt>concat</tt></strong></a>, <a href="#_foreach
"><strong><tt>foreach</tt></strong></a>, <a href="#_lappend
"><strong><tt>lappend</tt></strong></a>, <a href="#_lindex
"><strong><tt>lindex</tt></strong></a>, <a href="#_linsert
"><strong><tt>linsert</tt></strong></a>,
2294 <a href="#_list
"><strong><tt>list</tt></strong></a>, <a href="#_llength
"><strong><tt>llength</tt></strong></a>, <a href="#_lrange
"><strong><tt>lrange</tt></strong></a>, <a href="#_lreplace
"><strong><tt>lreplace</tt></strong></a>, <a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a>, and <a href="#_lsort
"><strong><tt>lsort</tt></strong></a> allow
2295 you to build lists, extract elements from them, search them, and perform
2296 other list-related functions.</p></div>
2297 <div class="paragraph
"><p>Advanced list commands include <a href="#_lrepeat
"><strong><tt>lrepeat</tt></strong></a>, <a href="#_lreverse
"><strong><tt>lreverse</tt></strong></a>, <a href="#_lmap
"><strong><tt>lmap</tt></strong></a>, <a href="#_lassign
"><strong><tt>lassign</tt></strong></a>, <a href="#_lset
"><strong><tt>lset</tt></strong></a>.</p></div>
2301 <h2 id="_list_expansion
">LIST EXPANSION</h2>
2302 <div class="sectionbody
">
2303 <div class="paragraph
"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2304 arguments. Support for this feature is also available in Jim.</p></div>
2305 <div class="paragraph
"><p>Consider the following attempt to exec a list:</p></div>
2306 <div class="literalblock
">
2307 <div class="content
">
2308 <pre><tt>set cmd {ls -l}
2309 exec $cmd</tt></pre>
2311 <div class="paragraph
"><p>This will attempt to exec the a command named "ls -l
", which will clearly not
2312 work. Typically eval and concat are required to solve this problem, however
2313 it can be solved much more easily with <tt>{*}</tt>.</p></div>
2314 <div class="literalblock
">
2315 <div class="content
">
2316 <pre><tt>exec {*}$cmd</tt></pre>
2318 <div class="paragraph
"><p>This will expand the following argument into individual elements and then evaluate
2319 the resulting command.</p></div>
2320 <div class="paragraph
"><p>Note that the official Tcl syntax is <tt>{*}</tt>, however <tt>{expand}</tt> is retained
2321 for backward compatibility with experimental versions of this feature.</p></div>
2325 <h2 id="_regular_expressions
">REGULAR EXPRESSIONS</h2>
2326 <div class="sectionbody
">
2327 <div class="paragraph
"><p>Tcl provides two commands that support string matching using regular
2328 expressions, <a href="#_regexp
"><strong><tt>regexp</tt></strong></a> and <a href="#_regsub
"><strong><tt>regsub</tt></strong></a>, as well as <a href="#_switch
"><strong><tt>switch</tt></strong></a> <tt>-regexp</tt> and
2329 <a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a> <tt>-regexp</tt>.</p></div>
2330 <div class="paragraph
"><p>Regular expressions may be implemented one of two ways. Either using the system’s C library
2331 POSIX regular expression support, or using the built-in regular expression engine.
2332 The differences between these are described below.</p></div>
2333 <div class="paragraph
"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<tt>ARE</tt>).</p></div>
2335 <h3 id="_posix_regular_expressions
">POSIX Regular Expressions</h3>
2336 <div class="paragraph
"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2337 this support will be used by default. The type of regular expressions supported are
2338 Extended Regular Expressions (<tt>ERE</tt>) rather than Basic Regular Expressions (<tt>BRE</tt>).
2339 See REG_EXTENDED in the documentation.</p></div>
2340 <div class="paragraph
"><p>Using the system-supported POSIX regular expressions will typically
2341 make for the smallest code size, but some features such as UTF-8
2342 and <tt>\w</tt>, <tt>\d</tt>, <tt>\s</tt> are not supported.</p></div>
2343 <div class="paragraph
"><p>See regex(3) and regex(7) for full details.</p></div>
2346 <h3 id="_jim_built_in_regular_expressions
">Jim built-in Regular Expressions</h3>
2347 <div class="paragraph
"><p>The Jim built-in regulare expression engine may be selected with <tt>./configure --with-jim-regexp</tt>
2348 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2349 <div class="paragraph
"><p>This engine supports UTF-8 as well as some <tt>ARE</tt> features. The differences with both Tcl 7.x/8.x
2350 and POSIX are highlighted below.</p></div>
2351 <div class="olist arabic
"><ol class="arabic
">
2354 UTF-8 strings and patterns are both supported
2359 Supported character classes: <tt>[:alnum:]</tt>, <tt>[:digit:]</tt> and <tt>[:space:]</tt>
2364 Supported shorthand character classes: <tt>\w</tt> = <tt>[:alnum:]</tt>, <tt>\d</tt> = <tt>[:digit:],</tt> <tt>\s</tt> = <tt>[:space:]</tt>
2369 Character classes apply to ASCII characters only
2374 Supported constraint escapes: <tt>\m</tt> = <tt>\<</tt> = start of word, <tt>\M</tt> = <tt>\></tt> = end of word
2379 Backslash escapes may be used within regular expressions, such as <tt>\n</tt> = newline, <tt>\uNNNN</tt> = unicode
2384 Support for the <tt>?</tt> non-greedy quantifier. e.g. <tt>*?</tt>
2389 Support for non-capuring parentheses <tt>(?:…)</tt>
2397 <h2 id="_command_results
">COMMAND RESULTS</h2>
2398 <div class="sectionbody
">
2399 <div class="paragraph
"><p>Each command produces two results: a code and a string. The
2400 code indicates whether the command completed successfully or not,
2401 and the string gives additional information. The valid codes are
2402 defined in jim.h, and are:</p></div>
2403 <div class="dlist
"><dl>
2404 <dt class="hdlist1
">
2409 This is the normal return code, and indicates that the command completed
2410 successfully. The string gives the command’s return value.
2413 <dt class="hdlist1
">
2418 Indicates that an error occurred; the string gives a message describing
2422 <dt class="hdlist1
">
2423 <tt>JIM_RETURN(2)</tt>
2427 Indicates that the <a href="#_return
"><strong><tt>return</tt></strong></a> command has been invoked, and that the
2428 current procedure (or top-level command or <a href="#_source
"><strong><tt>source</tt></strong></a> command)
2429 should return immediately. The
2430 string gives the return value for the procedure or command.
2433 <dt class="hdlist1
">
2434 <tt>JIM_BREAK(3)</tt>
2438 Indicates that the <a href="#_break
"><strong><tt>break</tt></strong></a> command has been invoked, so the
2439 innermost loop should abort immediately. The string should always
2443 <dt class="hdlist1
">
2444 <tt>JIM_CONTINUE(4)</tt>
2448 Indicates that the <a href="#_continue
"><strong><tt>continue</tt></strong></a> command has been invoked, so the
2449 innermost loop should go on to the next iteration. The string
2450 should always be empty.
2453 <dt class="hdlist1
">
2454 <tt>JIM_SIGNAL(5)</tt>
2458 Indicates that a signal was caught while executing a commands.
2459 The string contains the name of the signal caught.
2460 See the <a href="#_signal
"><strong><tt>signal</tt></strong></a> and <a href="#_catch
"><strong><tt>catch</tt></strong></a> commands.
2463 <dt class="hdlist1
">
2464 <tt>JIM_EXIT(6)</tt>
2468 Indicates that the command called the <a href="#_exit
"><strong><tt>exit</tt></strong></a> command.
2469 The string contains the exit code.
2473 <div class="paragraph
"><p>Tcl programmers do not normally need to think about return codes,
2474 since <tt>JIM_OK</tt> is almost always returned. If anything else is returned
2475 by a command, then the Tcl interpreter immediately stops processing
2476 commands and returns to its caller. If there are several nested
2477 invocations of the Tcl interpreter in progress, then each nested
2478 command will usually return the error to its caller, until eventually
2479 the error is reported to the top-level application code. The
2480 application will then display the error message for the user.</p></div>
2481 <div class="paragraph
"><p>In a few cases, some commands will handle certain <a href="#_error
"><strong><tt>error</tt></strong></a> conditions
2482 themselves and not return them upwards. For example, the <a href="#_for
"><strong><tt>for</tt></strong></a>
2483 command checks for the <tt>JIM_BREAK</tt> code; if it occurs, then <a href="#_for
"><strong><tt>for</tt></strong></a>
2484 stops executing the body of the loop and returns <tt>JIM_OK</tt> to its
2485 caller. The <a href="#_for
"><strong><tt>for</tt></strong></a> command also handles <tt>JIM_CONTINUE</tt> codes and the
2486 procedure interpreter handles <tt>JIM_RETURN</tt> codes. The <a href="#_catch
"><strong><tt>catch</tt></strong></a>
2487 command allows Tcl programs to catch errors and handle them without
2488 aborting command interpretation any further.</p></div>
2489 <div class="paragraph
"><p>The <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>returncodes</tt> command may be used to programmatically map between
2490 return codes and names.</p></div>
2494 <h2 id="_procedures
">PROCEDURES</h2>
2495 <div class="sectionbody
">
2496 <div class="paragraph
"><p>Tcl allows you to extend the command interface by defining
2497 procedures. A Tcl procedure can be invoked just like any other Tcl
2498 command (it has a name and it receives one or more arguments).
2499 The only difference is that its body isn’t a piece of C code linked
2500 into the program; it is a string containing one or more other
2501 Tcl commands.</p></div>
2502 <div class="paragraph
"><p>The <a href="#_proc
"><strong><tt>proc</tt></strong></a> command is used to create a new Tcl command procedure:</p></div>
2503 <div class="paragraph
"><p><tt><strong>proc</strong> <em>name arglist ?statics? body</em></tt></p></div>
2504 <div class="paragraph
"><p>The new command is named <tt><em>name</em></tt>, and it replaces any existing command
2505 there may have been by that name. Whenever the new command is
2506 invoked, the contents of <tt><em>body</em></tt> will be executed by the Tcl
2507 interpreter.</p></div>
2508 <div class="paragraph
"><p><tt><em>arglist</em></tt> specifies the formal arguments to the procedure.
2509 It consists of a list, possibly empty, of the following
2510 argument specifiers:</p></div>
2511 <div class="dlist
"><dl>
2512 <dt class="hdlist1
">
2517 Required Argument - A simple argument name.
2520 <dt class="hdlist1
">
2521 <tt>name default</tt>
2525 Optional Argument - A two-element list consisting of the
2526 argument name, followed by the default value, which will
2527 be used if the corresponding argument is not supplied.
2530 <dt class="hdlist1
">
2535 Reference Argument - The caller is expected to pass the name of
2536 an existing variable. An implicit <a href="#_upvar
"><strong><tt>upvar</tt></strong></a> <tt>1 'origname' 'name'</tt> is done
2537 to make the variable available in the proc scope.
2540 <dt class="hdlist1
">
2541 <tt><strong>args</strong></tt>
2545 Variable Argument - The special name <tt><em>args</em></tt>, which is
2546 assigned all remaining arguments (including none) as a list. The
2547 variable argument may only be specified once. Note that
2548 the syntax <tt>args newname</tt> may be used to retain the special
2549 behaviour of <tt><em>args</em></tt> with a different local name. In this case,
2550 the variable is named <tt><em>newname</em></tt> rather than <tt><em>args</em></tt>.
2554 <div class="paragraph
"><p>When the command is invoked, a local variable will be created for each of
2555 the formal arguments to the procedure; its value will be the value
2556 of corresponding argument in the invoking command or the argument’s
2557 default value.</p></div>
2558 <div class="paragraph
"><p>Arguments with default values need not be specified in a procedure
2559 invocation. However, there must be enough actual arguments for all
2560 required arguments, and there must not be any extra actual arguments
2561 (unless the Variable Argument is specified).</p></div>
2562 <div class="paragraph
"><p>Actual arguments are assigned to formal arguments as in left-to-right
2563 order with the following precedence.</p></div>
2564 <div class="olist arabic
"><ol class="arabic
">
2567 Required Arguments (including Reference Arguments)
2581 <div class="paragraph
"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2582 <div class="literalblock
">
2583 <div class="content
">
2584 <pre><tt>proc p {{a A} args b {c C} d} {...}</tt></pre>
2586 <div class="paragraph
"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2587 The following table shows how various numbers of arguments are assigned.
2588 Values marked as <tt>-</tt> are assigned the default value.</p></div>
2589 <div class="tableblock
">
2593 cellspacing="0" cellpadding="4">
2602 <th align="left
" valign="top
">Number of arguments</th>
2603 <th align="left
" valign="top
">a</th>
2604 <th align="left
" valign="top
">args</th>
2605 <th align="left
" valign="top
">b</th>
2606 <th align="left
" valign="top
">c</th>
2607 <th align="left
" valign="top
">d</th>
2612 <td align="left
" valign="top
"><p class="table
">2</p></td>
2613 <td align="left
" valign="top
"><p class="table
">-</p></td>
2614 <td align="left
" valign="top
"><p class="table
">-</p></td>
2615 <td align="left
" valign="top
"><p class="table
">1</p></td>
2616 <td align="left
" valign="top
"><p class="table
">-</p></td>
2617 <td align="left
" valign="top
"><p class="table
">2</p></td>
2620 <td align="left
" valign="top
"><p class="table
">3</p></td>
2621 <td align="left
" valign="top
"><p class="table
">1</p></td>
2622 <td align="left
" valign="top
"><p class="table
">-</p></td>
2623 <td align="left
" valign="top
"><p class="table
">2</p></td>
2624 <td align="left
" valign="top
"><p class="table
">-</p></td>
2625 <td align="left
" valign="top
"><p class="table
">3</p></td>
2628 <td align="left
" valign="top
"><p class="table
">4</p></td>
2629 <td align="left
" valign="top
"><p class="table
">1</p></td>
2630 <td align="left
" valign="top
"><p class="table
">-</p></td>
2631 <td align="left
" valign="top
"><p class="table
">2</p></td>
2632 <td align="left
" valign="top
"><p class="table
">3</p></td>
2633 <td align="left
" valign="top
"><p class="table
">4</p></td>
2636 <td align="left
" valign="top
"><p class="table
">5</p></td>
2637 <td align="left
" valign="top
"><p class="table
">1</p></td>
2638 <td align="left
" valign="top
"><p class="table
">2</p></td>
2639 <td align="left
" valign="top
"><p class="table
">3</p></td>
2640 <td align="left
" valign="top
"><p class="table
">4</p></td>
2641 <td align="left
" valign="top
"><p class="table
">5</p></td>
2644 <td align="left
" valign="top
"><p class="table
">6</p></td>
2645 <td align="left
" valign="top
"><p class="table
">1</p></td>
2646 <td align="left
" valign="top
"><p class="table
">2,3</p></td>
2647 <td align="left
" valign="top
"><p class="table
">4</p></td>
2648 <td align="left
" valign="top
"><p class="table
">5</p></td>
2649 <td align="left
" valign="top
"><p class="table
">6</p></td>
2654 <div class="paragraph
"><p>When <tt><em>body</em></tt> is being executed, variable names normally refer to local
2655 variables, which are created automatically when referenced and deleted
2656 when the procedure returns. One local variable is automatically created
2657 for each of the procedure’s arguments. Global variables can be
2658 accessed by invoking the <a href="#_global
"><strong><tt>global</tt></strong></a> command or via the <tt>::</tt> prefix.</p></div>
2660 <h3 id="_new_in_jim
">New in Jim</h3>
2661 <div class="paragraph
"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2662 These variables scoped to the procedure and initialised at procedure definition.
2663 Either from the static variable definition, or from the enclosing scope.</p></div>
2664 <div class="paragraph
"><p>Consider the following example:</p></div>
2665 <div class="literalblock
">
2666 <div class="content
">
2667 <pre><tt>jim> set a 1
2668 jim> proc a {} {a {b 2}} {
2680 <div class="paragraph
"><p>The static variable <tt><em>a</em></tt> has no initialiser, so it is initialised from
2681 the enclosing scope with the value 1. (Note that it is an error if there
2682 is no variable with the same name in the enclosing scope). However <tt><em>b</em></tt>
2683 has an initialiser, so it is initialised to 2.</p></div>
2684 <div class="paragraph
"><p>Unlike a local variable, the value of a static variable is retained across
2685 invocations of the procedure.</p></div>
2686 <div class="paragraph
"><p>See the <a href="#_proc
"><strong><tt>proc</tt></strong></a> command for information on how to define procedures
2687 and what happens when they are invoked. See also NAMESPACES.</p></div>
2692 <h2 id="_variables_scalars_and_arrays
">VARIABLES - SCALARS AND ARRAYS</h2>
2693 <div class="sectionbody
">
2694 <div class="paragraph
"><p>Tcl allows the definition of variables and the use of their values
2695 either through <em>$</em>-style variable substitution, the <a href="#_set
"><strong><tt>set</tt></strong></a>
2696 command, or a few other mechanisms.</p></div>
2697 <div class="paragraph
"><p>Variables need not be declared: a new variable will automatically
2698 be created each time a new variable name is used.</p></div>
2699 <div class="paragraph
"><p>Tcl supports two types of variables: scalars and arrays.
2700 A scalar variable has a single value, whereas an array variable
2701 can have any number of elements, each with a name (called
2702 its <em>index</em>) and a value.</p></div>
2703 <div class="paragraph
"><p>Array indexes may be arbitrary strings; they need not be numeric.
2704 Parentheses are used refer to array elements in Tcl commands.
2705 For example, the command</p></div>
2706 <div class="literalblock
">
2707 <div class="content
">
2708 <pre><tt>set x(first) 44</tt></pre>
2710 <div class="paragraph
"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2711 so that its new value is <em>44</em>.</p></div>
2712 <div class="paragraph
"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2713 that contain multiple concatenated values.
2714 For example, the commands</p></div>
2715 <div class="literalblock
">
2716 <div class="content
">
2717 <pre><tt>set a(2,3) 1
2718 set a(3,6) 2</tt></pre>
2720 <div class="paragraph
"><p>set the elements of <em>a</em> whose indexes are <em>2,3</em> and <em>3,6</em>.</p></div>
2721 <div class="paragraph
"><p>In general, array elements may be used anywhere in Tcl that scalar
2722 variables may be used.</p></div>
2723 <div class="paragraph
"><p>If an array is defined with a particular name, then there may
2724 not be a scalar variable with the same name.</p></div>
2725 <div class="paragraph
"><p>Similarly, if there is a scalar variable with a particular
2726 name then it is not possible to make array references to the
2728 <div class="paragraph
"><p>To convert a scalar variable to an array or vice versa, remove
2729 the existing variable with the <a href="#_unset
"><strong><tt>unset</tt></strong></a> command.</p></div>
2730 <div class="paragraph
"><p>The <a href="#_array
"><strong><tt>array</tt></strong></a> command provides several features for dealing
2731 with arrays, such as querying the names of all the elements of
2732 the array and converting between an array and a list.</p></div>
2733 <div class="paragraph
"><p>Variables may be either global or local. If a variable
2734 name is used when a procedure isn’t being executed, then it
2735 automatically refers to a global variable. Variable names used
2736 within a procedure normally refer to local variables associated with that
2737 invocation of the procedure. Local variables are deleted whenever
2738 a procedure exits. Either <a href="#_global
"><strong><tt>global</tt></strong></a> command may be used to request
2739 that a name refer to a global variable for the duration of the current
2740 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2741 may be explicitly scoped with the <tt>::</tt> prefix. For example</p></div>
2742 <div class="literalblock
">
2743 <div class="content
">
2750 <div class="literalblock
">
2751 <div class="content
">
2752 <pre><tt> puts "$a $::b $c
"
2756 <div class="paragraph
"><p>will output:</p></div>
2757 <div class="literalblock
">
2758 <div class="content
">
2759 <pre><tt>1 2 3</tt></pre>
2764 <h2 id="_arrays_as_lists_in_jim
">ARRAYS AS LISTS IN JIM</h2>
2765 <div class="sectionbody
">
2766 <div class="paragraph
"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2767 number of elements) and an array value. This is similar to the way Tcl
2768 can convert between a string and a list.</p></div>
2769 <div class="paragraph
"><p>For example:</p></div>
2770 <div class="literalblock
">
2771 <div class="content
">
2772 <pre><tt>set a {1 one 2 two}
2773 puts $a(2)</tt></pre>
2775 <div class="paragraph
"><p>will output:</p></div>
2776 <div class="literalblock
">
2777 <div class="content
">
2778 <pre><tt>two</tt></pre>
2780 <div class="paragraph
"><p>Thus <a href="#_array
"><strong><tt>array</tt></strong></a> <tt>set</tt> is equivalent to <a href="#_set
"><strong><tt>set</tt></strong></a> when the variable does not
2781 exist or is empty.</p></div>
2782 <div class="paragraph
"><p>The reverse is also true where an array will be converted into
2784 <div class="literalblock
">
2785 <div class="content
">
2786 <pre><tt>set a(1) one; set a(2) two
2789 <div class="paragraph
"><p>will output:</p></div>
2790 <div class="literalblock
">
2791 <div class="content
">
2792 <pre><tt>1 one 2 two</tt></pre>
2797 <h2 id="_dictionary_values
">DICTIONARY VALUES</h2>
2798 <div class="sectionbody
">
2799 <div class="paragraph
"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2800 of this command. Dictionaries provide efficient access to key-value
2801 pairs, just like arrays, but dictionaries are pure values. This
2802 means that you can pass them to a procedure just as a list or a
2803 string. Tcl dictionaries are therefore much more like Tcl lists,
2804 except that they represent a mapping from keys to values, rather
2805 than an ordered sequence.</p></div>
2806 <div class="paragraph
"><p>You can nest dictionaries, so that the value for a particular key
2807 consists of another dictionary. That way you can elegantly build
2808 complicated data structures, such as hierarchical databases. You
2809 can also combine dictionaries with other Tcl data structures. For
2810 instance, you can build a list of dictionaries that themselves
2811 contain lists.</p></div>
2812 <div class="paragraph
"><p>Dictionaries are values that contain an efficient, order-preserving
2813 mapping from arbitrary keys to arbitrary values. Each key in the
2814 dictionary maps to a single value. They have a textual format that
2815 is exactly that of any list with an even number of elements, with
2816 each mapping in the dictionary being represented as two items in
2817 the list. When a command takes a dictionary and produces a new
2818 dictionary based on it (either returning it or writing it back into
2819 the variable that the starting dictionary was read from) the new
2820 dictionary will have the same order of keys, modulo any deleted
2821 keys and with new keys added on to the end. When a string is
2822 interpreted as a dictionary and it would otherwise have duplicate
2823 keys, only the last value for a particular key is used; the others
2824 are ignored, meaning that, "apple banana
" and "apple carrot apple
2825 banana
" are equivalent dictionaries (with different string
2826 representations).</p></div>
2827 <div class="paragraph
"><p>Note that in Jim, arrays are implemented as dictionaries.
2828 Thus automatic conversion between lists and dictionaries applies
2829 as it does for arrays.</p></div>
2830 <div class="literalblock
">
2831 <div class="content
">
2832 <pre><tt>jim> dict set a 1 one
2834 jim> dict set a 2 two
2840 jim> dict set a 3 T three
2841 1 one 2 two 3 {T three}</tt></pre>
2843 <div class="paragraph
"><p>See the <a href="#_dict
"><strong><tt>dict</tt></strong></a> command for more details.</p></div>
2847 <h2 id="_namespaces
">NAMESPACES</h2>
2848 <div class="sectionbody
">
2849 <div class="paragraph
"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2850 including a number of 3rd party components. While there is less need for namespaces
2851 in Jim Tcl (which does not strive to support large applications), it is convenient to
2852 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2853 <div class="paragraph
"><p>Jim Tcl currently supports "light-weight
" namespaces which should be adequate for most
2854 purposes. This feature is currently experimental. See README.namespaces for more information
2855 and the documentation of the <a href="#_namespace
"><strong><tt>namespace</tt></strong></a> command.</p></div>
2859 <h2 id="_garbage_collection_references_lambda
">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2860 <div class="sectionbody
">
2861 <div class="paragraph
"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2862 These are described briefly below.</p></div>
2863 <div class="paragraph
"><p>More information may be found at <a href="http://wiki.tcl.tk/
13847">http://wiki.tcl.tk/13847</a></p></div>
2865 <h3 id="_references
">References</h3>
2866 <div class="paragraph
"><p>A reference can be thought of as holding a value with one level of indirection,
2867 where the value may be garbage collected when unreferenced.
2868 Consider the following example:</p></div>
2869 <div class="literalblock
">
2870 <div class="content
">
2871 <pre><tt>jim> set r [ref "One String
" test]
2872 <reference.<test___>.00000000000000000000>
2874 One String</tt></pre>
2876 <div class="paragraph
"><p>The operation <a href="#_ref
"><strong><tt>ref</tt></strong></a> creates a references to the value specified by the
2877 first argument. (The second argument is a "type
" used for documentation purposes).</p></div>
2878 <div class="paragraph
"><p>The operation <a href="#_getref
"><strong><tt>getref</tt></strong></a> is the dereferencing operation which retrieves the value
2879 stored in the reference.</p></div>
2880 <div class="literalblock
">
2881 <div class="content
">
2882 <pre><tt>jim> setref $r "New String
"
2885 New String</tt></pre>
2887 <div class="paragraph
"><p>The operation <a href="#_setref
"><strong><tt>setref</tt></strong></a> replaces the value stored by the reference. If the old value
2888 is no longer accessible by any reference, it will eventually be automatically be garbage
2889 collected.</p></div>
2892 <h3 id="_garbage_collection
">Garbage Collection</h3>
2893 <div class="paragraph
"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2894 automatically as necessary.</p></div>
2895 <div class="paragraph
"><p>With the introduction of references, it is possible to create values whose lifetime
2896 transcend their scope. To support this, case, the Jim system will periodically identify
2897 and discard objects which are no longer accessible by any reference.</p></div>
2898 <div class="paragraph
"><p>The <a href="#_collect
"><strong><tt>collect</tt></strong></a> command may be used to force garbage collection. Consider a reference created
2899 with a finalizer:</p></div>
2900 <div class="literalblock
">
2901 <div class="content
">
2902 <pre><tt>jim> proc f {ref value} { puts "Finaliser called for $ref,$value
" }
2903 jim> set r [ref "One String
" test f]
2904 <reference.<test___>.00000000000
2909 Finaliser called for <reference.<test___>.00000000000,One String
2912 <div class="paragraph
"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2913 contained a reference to the value, the garbage collector discarded
2914 the value (after calling the finalizer).</p></div>
2915 <div class="paragraph
"><p>The finalizer for a reference may be examined or changed with the <a href="#_finalize
"><strong><tt>finalize</tt></strong></a> command</p></div>
2916 <div class="literalblock
">
2917 <div class="content
">
2918 <pre><tt>jim> finalize $r
2920 jim> finalize $r newf
2925 <h3 id="_lambda
">Lambda</h3>
2926 <div class="paragraph
"><p>Jim provides a garbage collected lambda function. This is a procedure
2927 which is able to create an anonymous procedure. Consider:</p></div>
2928 <div class="literalblock
">
2929 <div class="content
">
2930 <pre><tt>jim> set f [lambda {a} {{x 0}} { incr x $a }]
2935 jim> set f ""</tt></pre>
2937 <div class="paragraph
"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2938 which is incremented by the supplied value and the result returned.</p></div>
2939 <div class="paragraph
"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2940 when the garbage collector runs.</p></div>
2941 <div class="paragraph
"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2942 <div class="literalblock
">
2943 <div class="content
">
2944 <pre><tt>jim> rename $f ""</tt></pre>
2950 <h2 id="_utf_8_and_unicode
">UTF-8 AND UNICODE</h2>
2951 <div class="sectionbody
">
2952 <div class="paragraph
"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2953 then most string-related commands become UTF-8 aware. These include,
2954 but are not limited to, <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>, <a href="#_split
"><strong><tt>split</tt></strong></a>, <a href="#_glob
"><strong><tt>glob</tt></strong></a>, <a href="#_scan
"><strong><tt>scan</tt></strong></a> and
2955 <a href="#_format
"><strong><tt>format</tt></strong></a>.</p></div>
2956 <div class="paragraph
"><p>UTF-8 encoding has many advantages, but one of the complications is that
2957 characters can take a variable number of bytes. Thus the addition of
2958 <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>bytelength</tt> which returns the number of bytes in a string,
2959 while <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>length</tt> returns the number of characters.</p></div>
2960 <div class="paragraph
"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2961 and <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>bytelength</tt> returns the same value as <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>length</tt>.</p></div>
2962 <div class="paragraph
"><p>Note that even if UTF-8 support is not enabled, the <tt>\uNNNN</tt> and related syntax
2963 is still available to embed UTF-8 sequences.</p></div>
2964 <div class="paragraph
"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
2966 <h3 id="_string_matching
">String Matching</h3>
2967 <div class="paragraph
"><p>Commands such as <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>, <a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a> <tt>-glob</tt>, <a href="#_array
"><strong><tt>array</tt></strong></a> <tt>names</tt> and others use string
2968 pattern matching rules. These commands support UTF-8. For example:</p></div>
2969 <div class="literalblock
">
2970 <div class="content
">
2971 <pre><tt>string match a\[\ua0-\ubf\]b "a\u00a3b
"</tt></pre>
2975 <h3 id="_format_and_scan
">format and scan</h3>
2976 <div class="paragraph
"><p><tt>format %c</tt> allows a unicode codepoint to be be encoded. For example, the following will return
2977 a string with two bytes and one character. The same as <tt>\ub5</tt></p></div>
2978 <div class="literalblock
">
2979 <div class="content
">
2980 <pre><tt>format %c 0xb5</tt></pre>
2982 <div class="paragraph
"><p><a href="#_format
"><strong><tt>format</tt></strong></a> respects widths as character widths, not byte widths. For example, the following will
2983 return a string with three characters, not three bytes.</p></div>
2984 <div class="literalblock
">
2985 <div class="content
">
2986 <pre><tt>format %.3s \ub5\ub6\ub7\ub8</tt></pre>
2988 <div class="paragraph
"><p>Similarly, <tt>scan … %c</tt> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
2989 <tt><em>a</em></tt> to 181 (0xb5) and <tt><em>b</em></tt> to 65 (0x41).</p></div>
2990 <div class="literalblock
">
2991 <div class="content
">
2992 <pre><tt>scan \u00b5A %c%c a b</tt></pre>
2994 <div class="paragraph
"><p><a href="#_scan
"><strong><tt>scan</tt></strong></a> <tt>%s</tt> will also accept a character class, including unicode ranges.</p></div>
2997 <h3 id="_string_classes
">String Classes</h3>
2998 <div class="paragraph
"><p><a href="#_string
"><strong><tt>string</tt></strong></a> <tt>is</tt> has <strong>not</strong> been extended to classify UTF-8 characters. Therefore, the following
2999 will return 0, even though the string may be considered to be alphabetic.</p></div>
3000 <div class="literalblock
">
3001 <div class="content
">
3002 <pre><tt>string is alpha \ub5Test</tt></pre>
3004 <div class="paragraph
"><p>This does not affect the string classes <em>ascii</em>, <em>control</em>, <em>digit</em>, <em>double</em>, <em>integer</em> or <em>xdigit</em>.</p></div>
3007 <h3 id="_case_mapping_and_conversion
">Case Mapping and Conversion</h3>
3008 <div class="paragraph
"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3009 and comparison will not increase or decrease the number of characters in a string.
3010 (Although it may change the number of bytes).</p></div>
3011 <div class="paragraph
"><p><a href="#_string
"><strong><tt>string</tt></strong></a> <tt>toupper</tt> will convert any lowercase letters to their uppercase equivalent.
3012 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3013 Similarly for <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>tolower</tt> and <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>totitle</tt>.</p></div>
3014 <div class="paragraph
"><p>Commands which perform case insensitive matches, such as <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>compare -nocase</tt>
3015 and <a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a> <tt>-nocase</tt> fold both strings to uppercase before comparison.</p></div>
3018 <h3 id="_invalid_utf_8_sequences
">Invalid UTF-8 Sequences</h3>
3019 <div class="paragraph
"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3020 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3021 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3022 <div class="paragraph
"><p>In these situations, the offending bytes are treated as single characters. For example,
3023 the following returns 2.</p></div>
3024 <div class="literalblock
">
3025 <div class="content
">
3026 <pre><tt>string bytelength \xff\xff</tt></pre>
3030 <h3 id="_regular_expressions_2
">Regular Expressions</h3>
3031 <div class="paragraph
"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3032 selected which supports UTF-8 strings and patterns.</p></div>
3033 <div class="paragraph
"><p>See REGULAR EXPRESSIONS</p></div>
3038 <h2 id="_built_in_commands
">BUILT-IN COMMANDS</h2>
3039 <div class="sectionbody
">
3040 <div class="paragraph
"><p>The Tcl library provides the following built-in commands, which will
3041 be available in any application using Tcl. In addition to these
3042 built-in commands, there may be additional commands defined by each
3043 application, plus commands defined as Tcl procedures.</p></div>
3044 <div class="paragraph
"><p>In the command syntax descriptions below, words in <tt><strong>boldface</strong></tt> are
3045 literals that you type verbatim to Tcl.</p></div>
3046 <div class="paragraph
"><p>Words in <tt><em>italics</em></tt> are meta-symbols; they serve as names for any of
3047 a range of values that you can type.</p></div>
3048 <div class="paragraph
"><p>Optional arguments or groups of arguments are indicated by enclosing them
3049 in <tt>?question-marks?</tt>.</p></div>
3050 <div class="paragraph
"><p>Ellipses (<tt>...</tt>) indicate that any number of additional
3051 arguments or groups of arguments may appear, in the same format
3052 as the preceding argument(s).</p></div>
3054 <h3 id="CommandIndex
">Command Index</h3>
3055 <div class="tableblock
">
3059 cellspacing="0" cellpadding="4">
3070 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><tt>after</tt></strong></a></p></td>
3071 <td align="left
" valign="top
"><p class="table
"><a href="#_aio
"><strong><tt>aio</tt></strong></a></p></td>
3072 <td align="left
" valign="top
"><p class="table
"><a href="#_alarm
"><strong><tt>alarm</tt></strong></a></p></td>
3073 <td align="left
" valign="top
"><p class="table
"><a href="#_alias
"><strong><tt>alias</tt></strong></a></p></td>
3074 <td align="left
" valign="top
"><p class="table
"><a href="#_append
"><strong><tt>append</tt></strong></a></p></td>
3075 <td align="left
" valign="top
"><p class="table
"><a href="#_apply
"><strong><tt>apply</tt></strong></a></p></td>
3076 <td align="left
" valign="top
"><p class="table
"><a href="#_array
"><strong><tt>array</tt></strong></a></p></td>
3077 <td align="left
" valign="top
"><p class="table
"><a href="#_binary
"><strong><tt>binary</tt></strong></a></p></td>
3080 <td align="left
" valign="top
"><p class="table
"><a href="#_break
"><strong><tt>break</tt></strong></a></p></td>
3081 <td align="left
" valign="top
"><p class="table
"><a href="#_case
"><strong><tt>case</tt></strong></a></p></td>
3082 <td align="left
" valign="top
"><p class="table
"><a href="#_catch
"><strong><tt>catch</tt></strong></a></p></td>
3083 <td align="left
" valign="top
"><p class="table
"><a href="#_cd
"><strong><tt>cd</tt></strong></a></p></td>
3084 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><tt>class</tt></strong></a></p></td>
3085 <td align="left
" valign="top
"><p class="table
"><a href="#_clock
"><strong><tt>clock</tt></strong></a></p></td>
3086 <td align="left
" valign="top
"><p class="table
"><a href="#_close
"><strong><tt>close</tt></strong></a></p></td>
3087 <td align="left
" valign="top
"><p class="table
"><a href="#_collect
"><strong><tt>collect</tt></strong></a></p></td>
3090 <td align="left
" valign="top
"><p class="table
"><a href="#_concat
"><strong><tt>concat</tt></strong></a></p></td>
3091 <td align="left
" valign="top
"><p class="table
"><a href="#_continue
"><strong><tt>continue</tt></strong></a></p></td>
3092 <td align="left
" valign="top
"><p class="table
"><a href="#_curry
"><strong><tt>curry</tt></strong></a></p></td>
3093 <td align="left
" valign="top
"><p class="table
"><a href="#_dict
"><strong><tt>dict</tt></strong></a></p></td>
3094 <td align="left
" valign="top
"><p class="table
"><a href="#_env
"><strong><tt>env</tt></strong></a></p></td>
3095 <td align="left
" valign="top
"><p class="table
"><a href="#_eof
"><strong><tt>eof</tt></strong></a></p></td>
3096 <td align="left
" valign="top
"><p class="table
"><a href="#_error
"><strong><tt>error</tt></strong></a></p></td>
3097 <td align="left
" valign="top
"><p class="table
"><a href="#_eval
"><strong><tt>eval</tt></strong></a></p></td>
3100 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><tt>eventloop</tt></strong></a></p></td>
3101 <td align="left
" valign="top
"><p class="table
"><a href="#_exec
"><strong><tt>exec</tt></strong></a></p></td>
3102 <td align="left
" valign="top
"><p class="table
"><a href="#_exists
"><strong><tt>exists</tt></strong></a></p></td>
3103 <td align="left
" valign="top
"><p class="table
"><a href="#_exit
"><strong><tt>exit</tt></strong></a></p></td>
3104 <td align="left
" valign="top
"><p class="table
"><a href="#_expr
"><strong><tt>expr</tt></strong></a></p></td>
3105 <td align="left
" valign="top
"><p class="table
"><a href="#_fconfigure
"><strong><tt>fconfigure</tt></strong></a></p></td>
3106 <td align="left
" valign="top
"><p class="table
"><a href="#_file
"><strong><tt>file</tt></strong></a></p></td>
3107 <td align="left
" valign="top
"><p class="table
"><a href="#_finalize
"><strong><tt>finalize</tt></strong></a></p></td>
3110 <td align="left
" valign="top
"><p class="table
"><a href="#_flush
"><strong><tt>flush</tt></strong></a></p></td>
3111 <td align="left
" valign="top
"><p class="table
"><a href="#_for
"><strong><tt>for</tt></strong></a></p></td>
3112 <td align="left
" valign="top
"><p class="table
"><a href="#_foreach
"><strong><tt>foreach</tt></strong></a></p></td>
3113 <td align="left
" valign="top
"><p class="table
"><a href="#_format
"><strong><tt>format</tt></strong></a></p></td>
3114 <td align="left
" valign="top
"><p class="table
"><a href="#_getref
"><strong><tt>getref</tt></strong></a></p></td>
3115 <td align="left
" valign="top
"><p class="table
"><a href="#_gets
"><strong><tt>gets</tt></strong></a></p></td>
3116 <td align="left
" valign="top
"><p class="table
"><a href="#_glob
"><strong><tt>glob</tt></strong></a></p></td>
3117 <td align="left
" valign="top
"><p class="table
"><a href="#_global
"><strong><tt>global</tt></strong></a></p></td>
3120 <td align="left
" valign="top
"><p class="table
"><a href="#_history
"><strong><tt>history</tt></strong></a></p></td>
3121 <td align="left
" valign="top
"><p class="table
"><a href="#_if
"><strong><tt>if</tt></strong></a></p></td>
3122 <td align="left
" valign="top
"><p class="table
"><a href="#_incr
"><strong><tt>incr</tt></strong></a></p></td>
3123 <td align="left
" valign="top
"><p class="table
"><a href="#_info
"><strong><tt>info</tt></strong></a></p></td>
3124 <td align="left
" valign="top
"><p class="table
"><a href="#_join
"><strong><tt>join</tt></strong></a></p></td>
3125 <td align="left
" valign="top
"><p class="table
"><a href="#_kill
"><strong><tt>kill</tt></strong></a></p></td>
3126 <td align="left
" valign="top
"><p class="table
"><a href="#_lambda
"><strong><tt>lambda</tt></strong></a></p></td>
3127 <td align="left
" valign="top
"><p class="table
"><a href="#_lappend
"><strong><tt>lappend</tt></strong></a></p></td>
3130 <td align="left
" valign="top
"><p class="table
"><a href="#_lassign
"><strong><tt>lassign</tt></strong></a></p></td>
3131 <td align="left
" valign="top
"><p class="table
"><a href="#_lindex
"><strong><tt>lindex</tt></strong></a></p></td>
3132 <td align="left
" valign="top
"><p class="table
"><a href="#_linsert
"><strong><tt>linsert</tt></strong></a></p></td>
3133 <td align="left
" valign="top
"><p class="table
"><a href="#_list
"><strong><tt>list</tt></strong></a></p></td>
3134 <td align="left
" valign="top
"><p class="table
"><a href="#_llength
"><strong><tt>llength</tt></strong></a></p></td>
3135 <td align="left
" valign="top
"><p class="table
"><a href="#_lmap
"><strong><tt>lmap</tt></strong></a></p></td>
3136 <td align="left
" valign="top
"><p class="table
"><a href="#_load
"><strong><tt>load</tt></strong></a></p></td>
3137 <td align="left
" valign="top
"><p class="table
"><a href="#_local
"><strong><tt>local</tt></strong></a></p></td>
3140 <td align="left
" valign="top
"><p class="table
"><a href="#_loop
"><strong><tt>loop</tt></strong></a></p></td>
3141 <td align="left
" valign="top
"><p class="table
"><a href="#_lrange
"><strong><tt>lrange</tt></strong></a></p></td>
3142 <td align="left
" valign="top
"><p class="table
"><a href="#_lrepeat
"><strong><tt>lrepeat</tt></strong></a></p></td>
3143 <td align="left
" valign="top
"><p class="table
"><a href="#_lreplace
"><strong><tt>lreplace</tt></strong></a></p></td>
3144 <td align="left
" valign="top
"><p class="table
"><a href="#_lreverse
"><strong><tt>lreverse</tt></strong></a></p></td>
3145 <td align="left
" valign="top
"><p class="table
"><a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a></p></td>
3146 <td align="left
" valign="top
"><p class="table
"><a href="#_lset
"><strong><tt>lset</tt></strong></a></p></td>
3147 <td align="left
" valign="top
"><p class="table
"><a href="#_lsort
"><strong><tt>lsort</tt></strong></a></p></td>
3150 <td align="left
" valign="top
"><p class="table
"><a href="#_namespace
"><strong><tt>namespace</tt></strong></a></p></td>
3151 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><tt>oo</tt></strong></a></p></td>
3152 <td align="left
" valign="top
"><p class="table
"><a href="#_open
"><strong><tt>open</tt></strong></a></p></td>
3153 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>os.fork</tt></strong></a></p></td>
3154 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>os.gethostname</tt></strong></a></p></td>
3155 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>os.getids</tt></strong></a></p></td>
3156 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>os.uptime</tt></strong></a></p></td>
3157 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>os.wait</tt></strong></a></p></td>
3160 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><tt>pack</tt></strong></a></p></td>
3161 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><tt>pack</tt></strong></a></p></td>
3162 <td align="left
" valign="top
"><p class="table
"><a href="#_package
"><strong><tt>package</tt></strong></a></p></td>
3163 <td align="left
" valign="top
"><p class="table
"><a href="#_pid
"><strong><tt>pid</tt></strong></a></p></td>
3164 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_1
"><strong><tt>posix</tt></strong></a></p></td>
3165 <td align="left
" valign="top
"><p class="table
"><a href="#_proc
"><strong><tt>proc</tt></strong></a></p></td>
3166 <td align="left
" valign="top
"><p class="table
"><a href="#_puts
"><strong><tt>puts</tt></strong></a></p></td>
3167 <td align="left
" valign="top
"><p class="table
"><a href="#_pwd
"><strong><tt>pwd</tt></strong></a></p></td>
3170 <td align="left
" valign="top
"><p class="table
"><a href="#_rand
"><strong><tt>rand</tt></strong></a></p></td>
3171 <td align="left
" valign="top
"><p class="table
"><a href="#_range
"><strong><tt>range</tt></strong></a></p></td>
3172 <td align="left
" valign="top
"><p class="table
"><a href="#_read
"><strong><tt>read</tt></strong></a></p></td>
3173 <td align="left
" valign="top
"><p class="table
"><a href="#_ref
"><strong><tt>ref</tt></strong></a></p></td>
3174 <td align="left
" valign="top
"><p class="table
"><a href="#_regexp
"><strong><tt>regexp</tt></strong></a></p></td>
3175 <td align="left
" valign="top
"><p class="table
"><a href="#_regsub
"><strong><tt>regsub</tt></strong></a></p></td>
3176 <td align="left
" valign="top
"><p class="table
"><a href="#_rename
"><strong><tt>rename</tt></strong></a></p></td>
3177 <td align="left
" valign="top
"><p class="table
"><a href="#_return
"><strong><tt>return</tt></strong></a></p></td>
3180 <td align="left
" valign="top
"><p class="table
"><a href="#_scan
"><strong><tt>scan</tt></strong></a></p></td>
3181 <td align="left
" valign="top
"><p class="table
"><a href="#_seek
"><strong><tt>seek</tt></strong></a></p></td>
3182 <td align="left
" valign="top
"><p class="table
"><a href="#_set
"><strong><tt>set</tt></strong></a></p></td>
3183 <td align="left
" valign="top
"><p class="table
"><a href="#_setref
"><strong><tt>setref</tt></strong></a></p></td>
3184 <td align="left
" valign="top
"><p class="table
"><a href="#_signal
"><strong><tt>signal</tt></strong></a></p></td>
3185 <td align="left
" valign="top
"><p class="table
"><a href="#_sleep
"><strong><tt>sleep</tt></strong></a></p></td>
3186 <td align="left
" valign="top
"><p class="table
"><a href="#_socket
"><strong><tt>socket</tt></strong></a></p></td>
3187 <td align="left
" valign="top
"><p class="table
"><a href="#_source
"><strong><tt>source</tt></strong></a></p></td>
3190 <td align="left
" valign="top
"><p class="table
"><a href="#_split
"><strong><tt>split</tt></strong></a></p></td>
3191 <td align="left
" valign="top
"><p class="table
"><a href="#_stackdump
"><strong><tt>stackdump</tt></strong></a></p></td>
3192 <td align="left
" valign="top
"><p class="table
"><a href="#_stacktrace
"><strong><tt>stacktrace</tt></strong></a></p></td>
3193 <td align="left
" valign="top
"><p class="table
"><a href="#_string
"><strong><tt>string</tt></strong></a></p></td>
3194 <td align="left
" valign="top
"><p class="table
"><a href="#_subst
"><strong><tt>subst</tt></strong></a></p></td>
3195 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_4
"><strong><tt>super</tt></strong></a></p></td>
3196 <td align="left
" valign="top
"><p class="table
"><a href="#_switch
"><strong><tt>switch</tt></strong></a></p></td>
3197 <td align="left
" valign="top
"><p class="table
"><a href="#_syslog
"><strong><tt>syslog</tt></strong></a></p></td>
3200 <td align="left
" valign="top
"><p class="table
"><a href="#_tailcall
"><strong><tt>tailcall</tt></strong></a></p></td>
3201 <td align="left
" valign="top
"><p class="table
"><a href="#_tcl_prefix
"><strong><tt>tcl::prefix</tt></strong></a></p></td>
3202 <td align="left
" valign="top
"><p class="table
"><a href="#_tell
"><strong><tt>tell</tt></strong></a></p></td>
3203 <td align="left
" valign="top
"><p class="table
"><a href="#_throw
"><strong><tt>throw</tt></strong></a></p></td>
3204 <td align="left
" valign="top
"><p class="table
"><a href="#_time
"><strong><tt>time</tt></strong></a></p></td>
3205 <td align="left
" valign="top
"><p class="table
"><a href="#_tree
"><strong><tt>tree</tt></strong></a></p></td>
3206 <td align="left
" valign="top
"><p class="table
"><a href="#_try
"><strong><tt>try</tt></strong></a></p></td>
3207 <td align="left
" valign="top
"><p class="table
"><a href="#_unknown
"><strong><tt>unknown</tt></strong></a></p></td>
3210 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_3
"><strong><tt>unpack</tt></strong></a></p></td>
3211 <td align="left
" valign="top
"><p class="table
"><a href="#_unset
"><strong><tt>unset</tt></strong></a></p></td>
3212 <td align="left
" valign="top
"><p class="table
"><a href="#_upcall
"><strong><tt>upcall</tt></strong></a></p></td>
3213 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><tt>update</tt></strong></a></p></td>
3214 <td align="left
" valign="top
"><p class="table
"><a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a></p></td>
3215 <td align="left
" valign="top
"><p class="table
"><a href="#_upvar
"><strong><tt>upvar</tt></strong></a></p></td>
3216 <td align="left
" valign="top
"><p class="table
"><a href="#cmd_2
"><strong><tt>vwait</tt></strong></a></p></td>
3217 <td align="left
" valign="top
"><p class="table
"><a href="#_while
"><strong><tt>while</tt></strong></a></p></td>
3224 <h3 id="_alarm
">alarm</h3>
3225 <div class="paragraph
"><p><tt><strong>alarm</strong> <em>seconds</em></tt></p></div>
3226 <div class="paragraph
"><p>Delivers the <tt>SIGALRM</tt> signal to the process after the given
3227 number of seconds. If the platform supports <em>ualarm(3)</em> then
3228 the argument may be a floating point value. Otherwise it must
3229 be an integer.</p></div>
3230 <div class="paragraph
"><p>Note that unless a signal handler for <tt>SIGALRM</tt> has been installed
3231 (see <a href="#_signal
"><strong><tt>signal</tt></strong></a>), the process will exit on this signal.</p></div>
3234 <h3 id="_alias
">alias</h3>
3235 <div class="paragraph
"><p><tt><strong>alias</strong> <em>name args...</em></tt></p></div>
3236 <div class="paragraph
"><p>Creates a single word alias (command) for one or more words. For example,
3237 the following creates an alias for the command <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>exists</tt>.</p></div>
3238 <div class="literalblock
">
3239 <div class="content
">
3240 <pre><tt>alias e info exists
3245 <div class="paragraph
"><p><a href="#_alias
"><strong><tt>alias</tt></strong></a> returns <tt><em>name</em></tt>, allowing it to be used with <a href="#_local
"><strong><tt>local</tt></strong></a>.</p></div>
3246 <div class="paragraph
"><p>See also <a href="#_proc
"><strong><tt>proc</tt></strong></a>, <a href="#_curry
"><strong><tt>curry</tt></strong></a>, <a href="#_lambda
"><strong><tt>lambda</tt></strong></a>, <a href="#_local
"><strong><tt>local</tt></strong></a>, <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>alias</tt>, <a href="#_exists
"><strong><tt>exists</tt></strong></a> <tt>-alias</tt></p></div>
3249 <h3 id="_append
">append</h3>
3250 <div class="paragraph
"><p><tt><strong>append</strong> <em>varName value ?value value …?</em></tt></p></div>
3251 <div class="paragraph
"><p>Append all of the <tt><em>value</em></tt> arguments to the current value
3252 of variable <tt><em>varName</em></tt>. If <tt><em>varName</em></tt> doesn’t exist,
3253 it is given a value equal to the concatenation of all the
3254 <tt><em>value</em></tt> arguments.</p></div>
3255 <div class="paragraph
"><p>This command provides an efficient way to build up long
3256 variables incrementally.
3257 For example, "<a href=
"#_append"><strong><tt>append
</tt></strong></a> <tt>a $b
</tt>" is much more efficient than
3258 "<a href=
"#_set"><strong><tt>set
</tt></strong></a> <tt>a $a$b
</tt>" if <tt>$a</tt> is long.</p></div>
3261 <h3 id="_apply
">apply</h3>
3262 <div class="paragraph
"><p><tt><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></tt></p></div>
3263 <div class="paragraph
"><p>The command <a href="#_apply
"><strong><tt>apply</tt></strong></a> provides for anonymous procedure calls,
3264 similar to <a href="#_lambda
"><strong><tt>lambda</tt></strong></a>, but without command name being created, even temporarily.</p></div>
3265 <div class="paragraph
"><p>The function <tt><em>lambdaExpr</em></tt> is a two element list <tt>{args body}</tt>
3266 or a three element list <tt>{args body namespace}</tt>. The first element
3267 args specifies the formal arguments, in the same form as the <a href="#_proc
"><strong><tt>proc</tt></strong></a> and <a href="#_lambda
"><strong><tt>lambda</tt></strong></a> commands.</p></div>
3270 <h3 id="_array
">array</h3>
3271 <div class="paragraph
"><p><tt><strong>array</strong> <em>option arrayName ?arg...?</em></tt></p></div>
3272 <div class="paragraph
"><p>This command performs one of several operations on the
3273 variable given by <tt><em>arrayName</em></tt>.</p></div>
3274 <div class="paragraph
"><p>Note that in general, if the named array does not exist, the <tt><em>array</em></tt> command behaves
3275 as though the array exists but is empty.</p></div>
3276 <div class="paragraph
"><p>The <tt><em>option</em></tt> argument determines what action is carried out by the
3277 command. The legal <tt><em>options</em></tt> (which may be abbreviated) are:</p></div>
3278 <div class="dlist
"><dl>
3279 <dt class="hdlist1
">
3280 <tt><strong>array exists</strong> <em>arrayName</em></tt>
3284 Returns 1 if arrayName is an array variable, 0 if there is
3285 no variable by that name. This command is essentially
3286 identical to <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>exists</tt>
3289 <dt class="hdlist1
">
3290 <tt><strong>array get</strong> <em>arrayName ?pattern?</em></tt>
3294 Returns a list containing pairs of elements. The first
3295 element in each pair is the name of an element in arrayName
3296 and the second element of each pair is the value of the
3297 array element. The order of the pairs is undefined. If
3298 pattern is not specified, then all of the elements of the
3299 array are included in the result. If pattern is specified,
3300 then only those elements whose names match pattern (using
3301 the matching rules of string match) are included. If arrayName
3302 isn’t the name of an array variable, or if the array contains
3303 no elements, then an empty list is returned.
3306 <dt class="hdlist1
">
3307 <tt><strong>array names</strong> <em>arrayName ?pattern?</em></tt>
3311 Returns a list containing the names of all of the elements
3312 in the array that match pattern. If pattern is omitted then
3313 the command returns all of the element names in the array.
3314 If pattern is specified, then only those elements whose
3315 names match pattern (using the matching rules of string
3316 match) are included. If there are no (matching) elements
3317 in the array, or if arrayName isn’t the name of an array
3318 variable, then an empty string is returned.
3321 <dt class="hdlist1
">
3322 <tt><strong>array set</strong> <em>arrayName list</em></tt>
3326 Sets the values of one or more elements in arrayName. list
3327 must have a form like that returned by array get, consisting
3328 of an even number of elements. Each odd-numbered element
3329 in list is treated as an element name within arrayName, and
3330 the following element in list is used as a new value for
3331 that array element. If the variable arrayName does not
3332 already exist and list is empty, arrayName is created with
3333 an empty array value.
3336 <dt class="hdlist1
">
3337 <tt><strong>array size</strong> <em>arrayName</em></tt>
3341 Returns the number of elements in the array. If arrayName
3342 isn’t the name of an array then 0 is returned.
3345 <dt class="hdlist1
">
3346 <tt><strong>array unset</strong> <em>arrayName ?pattern?</em></tt>
3350 Unsets all of the elements in the array that match pattern
3351 (using the matching rules of string match). If arrayName
3352 isn’t the name of an array variable or there are no matching
3353 elements in the array, no error will be raised. If pattern
3354 is omitted and arrayName is an array variable, then the
3355 command unsets the entire array. The command always returns
3362 <h3 id="_break
">break</h3>
3363 <div class="paragraph
"><p><tt><strong>break</strong></tt></p></div>
3364 <div class="paragraph
"><p>This command may be invoked only inside the body of a loop command
3365 such as <a href="#_for
"><strong><tt>for</tt></strong></a> or <a href="#_foreach
"><strong><tt>foreach</tt></strong></a> or <a href="#_while
"><strong><tt>while</tt></strong></a>. It returns a <tt>JIM_BREAK</tt> code
3366 to signal the innermost containing loop command to return immediately.</p></div>
3369 <h3 id="_case
">case</h3>
3370 <div class="paragraph
"><p><tt><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body …?</em></tt></p></div>
3371 <div class="paragraph
"><p><tt><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body …?</em>}</tt></p></div>
3372 <div class="paragraph
"><p><strong>Note</strong> that the <a href="#_switch
"><strong><tt>switch</tt></strong></a> command should generally be preferred unless compatibility
3373 with Tcl 6.x is desired.</p></div>
3374 <div class="paragraph
"><p>Match <tt><em>string</em></tt> against each of the <tt><em>patList</em></tt> arguments
3375 in order. If one matches, then evaluate the following <tt><em>body</em></tt> argument
3376 by passing it recursively to the Tcl interpreter, and return the result
3377 of that evaluation. Each <tt><em>patList</em></tt> argument consists of a single
3378 pattern or list of patterns. Each pattern may contain any of the wild-cards
3379 described under <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.</p></div>
3380 <div class="paragraph
"><p>If a <tt><em>patList</em></tt> argument is <tt>default</tt>, the corresponding body will be
3381 evaluated if no <tt><em>patList</em></tt> matches <tt><em>string</em></tt>. If no <tt><em>patList</em></tt> argument
3382 matches <tt><em>string</em></tt> and no default is given, then the <a href="#_case
"><strong><tt>case</tt></strong></a> command returns
3383 an empty string.</p></div>
3384 <div class="paragraph
"><p>Two syntaxes are provided.</p></div>
3385 <div class="paragraph
"><p>The first uses a separate argument for each of the patterns and commands;
3386 this form is convenient if substitutions are desired on some of the
3387 patterns or commands.</p></div>
3388 <div class="paragraph
"><p>The second form places all of the patterns and commands together into
3389 a single argument; the argument must have proper list structure, with
3390 the elements of the list being the patterns and commands.</p></div>
3391 <div class="paragraph
"><p>The second form makes it easy to construct multi-line case commands,
3392 since the braces around the whole list make it unnecessary to include a
3393 backslash at the end of each line.</p></div>
3394 <div class="paragraph
"><p>Since the <tt><em>patList</em></tt> arguments are in braces in the second form,
3395 no command or variable substitutions are performed on them; this makes
3396 the behaviour of the second form different than the first form in some
3398 <div class="paragraph
"><p>Below are some examples of <a href="#_case
"><strong><tt>case</tt></strong></a> commands:</p></div>
3399 <div class="literalblock
">
3400 <div class="content
">
3401 <pre><tt>case abc in {a b} {format 1} default {format 2} a* {format 3}</tt></pre>
3403 <div class="paragraph
"><p>will return <em>3</em>,</p></div>
3404 <div class="literalblock
">
3405 <div class="content
">
3406 <pre><tt>case a in {
3412 <div class="paragraph
"><p>will return <em>1</em>, and</p></div>
3413 <div class="literalblock
">
3414 <div class="content
">
3424 <div class="paragraph
"><p>will return <em>2</em>.</p></div>
3427 <h3 id="_catch
">catch</h3>
3428 <div class="paragraph
"><p><tt><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></tt></p></div>
3429 <div class="paragraph
"><p>The <a href="#_catch
"><strong><tt>catch</tt></strong></a> command may be used to prevent errors from aborting
3430 command interpretation. <a href="#_catch
"><strong><tt>catch</tt></strong></a> evaluates <tt><em>command</em></tt>, and returns a
3431 <tt>JIM_OK</tt> code, regardless of any errors that might occur while
3432 executing <tt><em>command</em></tt> (with the possible exception of <tt>JIM_SIGNAL</tt> -
3433 see below).</p></div>
3434 <div class="paragraph
"><p>The return value from <a href="#_catch
"><strong><tt>catch</tt></strong></a> is a decimal string giving the code
3435 returned by the Tcl interpreter after executing <tt><em>command</em></tt>. This
3436 will be <em>0</em> (<tt>JIM_OK</tt>) if there were no errors in <tt><em>command</em></tt>; otherwise
3437 it will have a non-zero value corresponding to one of the exceptional
3438 return codes (see jim.h for the definitions of code values, or the
3439 <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>returncodes</tt> command).</p></div>
3440 <div class="paragraph
"><p>If the <tt><em>resultVarName</em></tt> argument is given, then it gives the name
3441 of a variable; <a href="#_catch
"><strong><tt>catch</tt></strong></a> will set the value of the variable to the
3442 string returned from <tt><em>command</em></tt> (either a result or an error message).</p></div>
3443 <div class="paragraph
"><p>If the <tt><em>optionsVarName</em></tt> argument is given, then it gives the name
3444 of a variable; <a href="#_catch
"><strong><tt>catch</tt></strong></a> will set the value of the variable to a
3445 dictionary. For any return code other than <tt>JIM_RETURN</tt>, the value
3446 for the key <tt>-code</tt> will be set to the return code. For <tt>JIM_RETURN</tt>
3447 it will be set to the code given in <a href="#_return
"><strong><tt>return</tt></strong></a> <tt>-code</tt>. Additionally,
3448 for the return code <tt>JIM_ERR</tt>, the value of the key <tt>-errorinfo</tt>
3449 will contain the current stack trace (the same result as <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>),
3450 the value of the key <tt>-errorcode</tt> will contain the
3451 same value as the global variable $::errorCode, and the value of
3452 the key <tt>-level</tt> will be the current return level (see <a href="#_return
"><strong><tt>return</tt></strong></a> <tt>-level</tt>).
3453 This can be useful to rethrow an error:</p></div>
3454 <div class="literalblock
">
3455 <div class="content
">
3456 <pre><tt>if {[catch {...} msg opts]} {
3457 ...maybe do something with the error...
3459 return {*}$opts $msg
3462 <div class="paragraph
"><p>Normally <a href="#_catch
"><strong><tt>catch</tt></strong></a> will <tt><em>not</em></tt> catch any of the codes <tt>JIM_EXIT</tt>, <tt>JIM_EVAL</tt> or <tt>JIM_SIGNAL</tt>.
3463 The set of codes which will be caught may be modified by specifying the one more codes before
3464 <tt><em>command</em></tt>.</p></div>
3465 <div class="paragraph
"><p>e.g. To catch <tt>JIM_EXIT</tt> but not <tt>JIM_BREAK</tt> or <tt>JIM_CONTINUE</tt></p></div>
3466 <div class="literalblock
">
3467 <div class="content
">
3468 <pre><tt>catch -exit -nobreak -nocontinue -- { ... }</tt></pre>
3470 <div class="paragraph
"><p>The use of <tt>--</tt> is optional. It signifies that no more return code options follow.</p></div>
3471 <div class="paragraph
"><p>Note that if a signal marked as <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>handle</tt> is caught with <a href="#_catch
"><strong><tt>catch</tt></strong></a> <tt>-signal</tt>, the return value
3472 (stored in <tt><em>resultVarName</em></tt>) is name of the signal caught.</p></div>
3475 <h3 id="_cd
">cd</h3>
3476 <div class="paragraph
"><p><tt><strong>cd</strong> <em>dirName</em></tt></p></div>
3477 <div class="paragraph
"><p>Change the current working directory to <tt><em>dirName</em></tt>.</p></div>
3478 <div class="paragraph
"><p>Returns an empty string.</p></div>
3479 <div class="paragraph
"><p>This command can potentially be disruptive to an application, so it may
3480 be removed in some applications.</p></div>
3483 <h3 id="_clock
">clock</h3>
3484 <div class="dlist
"><dl>
3485 <dt class="hdlist1
">
3486 <tt><strong>clock seconds</strong></tt>
3490 Returns the current time as seconds since the epoch.
3493 <dt class="hdlist1
">
3494 <tt><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></tt>
3498 Format the given time (seconds since the epoch) according to the given
3499 format. See strftime(3) for supported formats.
3500 If no format is supplied, "%c
" is used.
3503 <dt class="hdlist1
">
3504 <tt><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></tt>
3508 Scan the given time string using the given format string.
3509 See strptime(3) for supported formats.
3515 <h3 id="_close
">close</h3>
3516 <div class="paragraph
"><p><tt><strong>close</strong> <em>fileId</em></tt></p></div>
3517 <div class="paragraph
"><p><tt><em>fileId</em> <strong>close</strong></tt></p></div>
3518 <div class="paragraph
"><p>Closes the file given by <tt><em>fileId</em></tt>.
3519 <tt><em>fileId</em></tt> must be the return value from a previous invocation
3520 of the <a href="#_open
"><strong><tt>open</tt></strong></a> command; after this command, it should not be
3521 used anymore.</p></div>
3524 <h3 id="_collect
">collect</h3>
3525 <div class="paragraph
"><p><tt><strong>collect</strong></tt></p></div>
3526 <div class="paragraph
"><p>Normally reference garbage collection is automatically performed periodically.
3527 However it may be run immediately with the <a href="#_collect
"><strong><tt>collect</tt></strong></a> command.</p></div>
3528 <div class="paragraph
"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3531 <h3 id="_concat
">concat</h3>
3532 <div class="paragraph
"><p><tt><strong>concat</strong> <em>arg ?arg ...?</em></tt></p></div>
3533 <div class="paragraph
"><p>This command treats each argument as a list and concatenates them
3534 into a single list. It permits any number of arguments. For example,
3535 the command</p></div>
3536 <div class="literalblock
">
3537 <div class="content
">
3538 <pre><tt>concat a b {c d e} {f {g h}}</tt></pre>
3540 <div class="paragraph
"><p>will return</p></div>
3541 <div class="literalblock
">
3542 <div class="content
">
3543 <pre><tt>a b c d e f {g h}</tt></pre>
3545 <div class="paragraph
"><p>as its result.</p></div>
3548 <h3 id="_continue
">continue</h3>
3549 <div class="paragraph
"><p><tt><strong>continue</strong></tt></p></div>
3550 <div class="paragraph
"><p>This command may be invoked only inside the body of a loop command such
3551 as <a href="#_for
"><strong><tt>for</tt></strong></a> or <a href="#_foreach
"><strong><tt>foreach</tt></strong></a> or <a href="#_while
"><strong><tt>while</tt></strong></a>. It returns a <tt>JIM_CONTINUE</tt> code to
3552 signal the innermost containing loop command to skip the remainder of
3553 the loop’s body but continue with the next iteration of the loop.</p></div>
3556 <h3 id="_curry
">curry</h3>
3557 <div class="paragraph
"><p><tt><strong>alias</strong> <em>args...</em></tt></p></div>
3558 <div class="paragraph
"><p>Similar to <a href="#_alias
"><strong><tt>alias</tt></strong></a> except it creates an anonymous procedure (lambda) instead of
3559 a named procedure.</p></div>
3560 <div class="paragraph
"><p>the following creates a local, unnamed alias for the command <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>exists</tt>.</p></div>
3561 <div class="literalblock
">
3562 <div class="content
">
3563 <pre><tt>set e [local curry info exists]
3568 <div class="paragraph
"><p><a href="#_curry
"><strong><tt>curry</tt></strong></a> returns the name of the procedure.</p></div>
3569 <div class="paragraph
"><p>See also <a href="#_proc
"><strong><tt>proc</tt></strong></a>, <a href="#_alias
"><strong><tt>alias</tt></strong></a>, <a href="#_lambda
"><strong><tt>lambda</tt></strong></a>, <a href="#_local
"><strong><tt>local</tt></strong></a>.</p></div>
3572 <h3 id="_dict
">dict</h3>
3573 <div class="paragraph
"><p><tt><strong>dict</strong> <em>option ?arg...?</em></tt></p></div>
3574 <div class="paragraph
"><p>Performs one of several operations on dictionary values.</p></div>
3575 <div class="paragraph
"><p>The <tt><em>option</em></tt> argument determines what action is carried out by the
3576 command. The legal <tt><em>options</em></tt> are:</p></div>
3577 <div class="dlist
"><dl>
3578 <dt class="hdlist1
">
3579 <tt><strong>dict create</strong> <em>?key value ...?</em></tt>
3583 Create and return a new dictionary value that contains each of
3584 the key/value mappings listed as arguments (keys and values
3585 alternating, with each key being followed by its associated
3589 <dt class="hdlist1
">
3590 <tt><strong>dict exists</strong> <em>dictionary key ?key ...?</em></tt>
3594 Returns a boolean value indicating whether the given key (or path
3595 of keys through a set of nested dictionaries) exists in the given
3596 dictionary value. This returns a true value exactly when <a href="#_dict
"><strong><tt>dict</tt></strong></a> <tt>get</tt>
3597 on that path will succeed.
3600 <dt class="hdlist1
">
3601 <tt><strong>dict get</strong> <em>dictionary ?key ...?</em></tt>
3605 Given a dictionary value (first argument) and a key (second argument),
3606 this will retrieve the value for that key. Where several keys are
3607 supplied, the behaviour of the command shall be as if the result
3608 of "<a href=
"#_dict"><strong><tt>dict
</tt></strong></a> <tt>get $dictVal $key
</tt>" was passed as the first argument to
3609 dict get with the remaining arguments as second (and possibly
3610 subsequent) arguments. This facilitates lookups in nested dictionaries.
3611 If no keys are provided, dict would return a list containing pairs
3612 of elements in a man- ner similar to array get. That is, the first
3613 element of each pair would be the key and the second element would
3614 be the value for that key. It is an error to attempt to retrieve
3615 a value for a key that is not present in the dictionary.
3618 <dt class="hdlist1
">
3619 <tt><strong>dict keys</strong> <em>dictionary ?pattern?</em></tt>
3623 Returns a list of the keys in the dictionary.
3624 If pattern is specified, then only those keys whose
3625 names match <tt><em>pattern</em></tt> (using the matching rules of string
3626 match) are included.
3629 <dt class="hdlist1
">
3630 <tt><strong>dict merge</strong> ?<em>dictionary ...</em>?</tt>
3634 Return a dictionary that contains the contents of each of the
3635 <tt><em>dictionary</em></tt> arguments. Where two (or more) dictionaries
3636 contain a mapping for the same key, the resulting dictionary
3637 maps that key to the value according to the last dictionary on
3638 the command line containing a mapping for that key.
3641 <dt class="hdlist1
">
3642 <tt><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></tt>
3646 This operation takes the <tt><em>name</em></tt> of a variable containing a dictionary
3647 value and places an updated dictionary value in that variable
3648 containing a mapping from the given key to the given value. When
3649 multiple keys are present, this operation creates or updates a chain
3650 of nested dictionaries.
3653 <dt class="hdlist1
">
3654 <tt><strong>dict size</strong> <em>dictionary</em></tt>
3658 Return the number of key/value mappings in the given dictionary value.
3661 <dt class="hdlist1
">
3662 <tt><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></tt>
3666 This operation (the companion to <a href="#_dict
"><strong><tt>dict</tt></strong></a> <tt>set</tt>) takes the name of a
3667 variable containing a dictionary value and places an updated
3668 dictionary value in that variable that does not contain a mapping
3669 for the given key. Where multiple keys are present, this describes
3670 a path through nested dictionaries to the mapping to remove. At
3671 least one key must be specified, but the last key on the key-path
3672 need not exist. All other components on the path must exist.
3675 <dt class="hdlist1
">
3676 <tt><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></tt>
3680 Execute the Tcl script in <tt><em>script</em></tt> with the value for each
3681 key in <tt><em>dictionaryName</em></tt> mapped to a variable with the same
3682 name. Where one or more keys are given, these indicate a chain
3683 of nested dictionaries, with the innermost dictionary being the
3684 one opened out for the execution of body. Making <tt><em>dictionaryName</em></tt>
3685 unreadable will make the updates to the dictionary be discarded,
3686 and this also happens if the contents of <tt><em>dictionaryName</em></tt> are
3687 adjusted so that the chain of dictionaries no longer exists.
3688 The result of <a href="#_dict
"><strong><tt>dict</tt></strong></a> <tt>with</tt> is (unless some kind of error occurs)
3689 the result of the evaluation of body.
3692 <dt class="hdlist1
">
3697 The variables are mapped in the scope enclosing the <a href="#_dict
"><strong><tt>dict</tt></strong></a> <tt>with</tt>;
3698 it is recommended that this command only be used in a local
3699 scope (procedure). Because of this, the variables set by
3700 <a href="#_dict
"><strong><tt>dict</tt></strong></a> <tt>with</tt> will continue to exist after the command finishes (unless
3701 explicitly unset). Note that changes to the contents of <tt><em>dictionaryName</em></tt>
3702 only happen when <tt><em>script</em></tt> terminates.
3706 <div class="paragraph
"><p><tt><strong>dict for, values, incr, append, lappend, update, info, replace</strong></tt> to be documented…</p></div>
3709 <h3 id="_env
">env</h3>
3710 <div class="paragraph
"><p><tt><strong>env</strong> <em>?name? ?default?</em></tt></p></div>
3711 <div class="paragraph
"><p>If <tt><em>name</em></tt> is supplied, returns the value of <tt><em>name</em></tt> from the initial
3712 environment (see getenv(3)). An error is returned if <tt><em>name</em></tt> does not
3713 exist in the environment, unless <tt><em>default</em></tt> is supplied - in which case
3714 that value is returned instead.</p></div>
3715 <div class="paragraph
"><p>If no arguments are supplied, returns a list of all environment variables
3716 and their values as <tt>{name value ...}</tt></p></div>
3717 <div class="paragraph
"><p>See also the global variable <tt>::env</tt></p></div>
3720 <h3 id="_eof
">eof</h3>
3721 <div class="paragraph
"><p><tt><strong>eof</strong> <em>fileId</em></tt></p></div>
3722 <div class="paragraph
"><p><tt><em>fileId</em> <strong>eof</strong></tt></p></div>
3723 <div class="paragraph
"><p>Returns 1 if an end-of-file condition has occurred on <tt><em>fileId</em></tt>,
3724 0 otherwise.</p></div>
3725 <div class="paragraph
"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to <a href="#_open
"><strong><tt>open</tt></strong></a>,
3726 or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one of the
3727 standard I/O channels.</p></div>
3730 <h3 id="_error
">error</h3>
3731 <div class="paragraph
"><p><tt><strong>error</strong> <em>message ?stacktrace?</em></tt></p></div>
3732 <div class="paragraph
"><p>Returns a <tt>JIM_ERR</tt> code, which causes command interpretation to be
3733 unwound. <tt><em>message</em></tt> is a string that is returned to the application
3734 to indicate what went wrong.</p></div>
3735 <div class="paragraph
"><p>If the <tt><em>stacktrace</em></tt> argument is provided and is non-empty,
3736 it is used to initialize the stacktrace.</p></div>
3737 <div class="paragraph
"><p>This feature is most useful in conjunction with the <a href="#_catch
"><strong><tt>catch</tt></strong></a> command:
3738 if a caught error cannot be handled successfully, <tt><em>stacktrace</em></tt> can be used
3739 to return a stack trace reflecting the original point of occurrence
3740 of the error:</p></div>
3741 <div class="literalblock
">
3742 <div class="content
">
3743 <pre><tt>catch {...} errMsg
3745 error $errMsg [info stacktrace]</tt></pre>
3747 <div class="paragraph
"><p>See also <tt>errorInfo</tt>, <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>, <a href="#_catch
"><strong><tt>catch</tt></strong></a> and <a href="#_return
"><strong><tt>return</tt></strong></a></p></div>
3750 <h3 id="_errorinfo
">errorInfo</h3>
3751 <div class="paragraph
"><p><tt><strong>errorInfo</strong> <em>error ?stacktrace?</em></tt></p></div>
3752 <div class="paragraph
"><p>Returns a human-readable representation of the given error message and stack trace.
3753 Typical usage is:</p></div>
3754 <div class="literalblock
">
3755 <div class="content
">
3756 <pre><tt>if {[catch {...} error]} {
3757 puts stderr [errorInfo $error [info stacktrace]]
3761 <div class="paragraph
"><p>See also <a href="#_error
"><strong><tt>error</tt></strong></a>.</p></div>
3764 <h3 id="_eval
">eval</h3>
3765 <div class="paragraph
"><p><tt><strong>eval</strong> <em>arg ?arg...?</em></tt></p></div>
3766 <div class="paragraph
"><p><a href="#_eval
"><strong><tt>eval</tt></strong></a> takes one or more arguments, which together comprise a Tcl
3767 command (or collection of Tcl commands separated by newlines in the
3768 usual way). <a href="#_eval
"><strong><tt>eval</tt></strong></a> concatenates all its arguments in the same
3769 fashion as the <a href="#_concat
"><strong><tt>concat</tt></strong></a> command, passes the concatenated string to the
3770 Tcl interpreter recursively, and returns the result of that
3771 evaluation (or any error generated by it).</p></div>
3774 <h3 id="_exec
">exec</h3>
3775 <div class="paragraph
"><p><tt><strong>exec</strong> <em>arg ?arg...?</em></tt></p></div>
3776 <div class="paragraph
"><p>This command treats its arguments as the specification
3777 of one or more UNIX commands to execute as subprocesses.
3778 The commands take the form of a standard shell pipeline;
3779 <tt>|</tt> arguments separate commands in the
3780 pipeline and cause standard output of the preceding command
3781 to be piped into standard input of the next command (or <tt>|&</tt> for
3782 both standard output and standard error).</p></div>
3783 <div class="paragraph
"><p>Under normal conditions the result of the <a href="#_exec
"><strong><tt>exec</tt></strong></a> command
3784 consists of the standard output produced by the last command
3785 in the pipeline.</p></div>
3786 <div class="paragraph
"><p>If any of the commands in the pipeline exit abnormally or
3787 are killed or suspended, then <a href="#_exec
"><strong><tt>exec</tt></strong></a> will return an error
3788 and the error message will include the pipeline’s output followed by
3789 error messages describing the abnormal terminations.</p></div>
3790 <div class="paragraph
"><p>If any of the commands writes to its standard error file,
3791 then <a href="#_exec
"><strong><tt>exec</tt></strong></a> will return an error, and the error message
3792 will include the pipeline’s output, followed by messages
3793 about abnormal terminations (if any), followed by the standard error
3795 <div class="paragraph
"><p>If the last character of the result or error message
3796 is a newline then that character is deleted from the result
3797 or error message for consistency with normal
3798 Tcl return values.</p></div>
3799 <div class="paragraph
"><p>An <tt><em>arg</em></tt> may have one of the following special forms:</p></div>
3800 <div class="dlist
"><dl>
3801 <dt class="hdlist1
">
3802 <tt>>filename</tt>
3806 The standard output of the last command in the pipeline
3807 is redirected to the file. In this situation <a href="#_exec
"><strong><tt>exec</tt></strong></a>
3808 will normally return an empty string.
3811 <dt class="hdlist1
">
3812 <tt>>>filename</tt>
3816 As above, but append to the file.
3819 <dt class="hdlist1
">
3820 <tt>>@fileId</tt>
3824 The standard output of the last command in the pipeline is
3825 redirected to the given (writable) file descriptor (e.g. stdout,
3826 stderr, or the result of <a href="#_open
"><strong><tt>open</tt></strong></a>). In this situation <a href="#_exec
"><strong><tt>exec</tt></strong></a>
3827 will normally return an empty string.
3830 <dt class="hdlist1
">
3831 <tt>2>filename</tt>
3835 The standard error of the last command in the pipeline
3836 is redirected to the file.
3839 <dt class="hdlist1
">
3840 <tt>2>>filename</tt>
3844 As above, but append to the file.
3847 <dt class="hdlist1
">
3848 <tt>2>@fileId</tt>
3852 The standard error of the last command in the pipeline is
3853 redirected to the given (writable) file descriptor.
3856 <dt class="hdlist1
">
3861 The standard error of the last command in the pipeline is
3862 redirected to the same file descriptor as the standard output.
3865 <dt class="hdlist1
">
3866 <tt>>&filename</tt>
3870 Both the standard output and standard error of the last command
3871 in the pipeline is redirected to the file.
3874 <dt class="hdlist1
">
3875 <tt>>>&filename</tt>
3879 As above, but append to the file.
3882 <dt class="hdlist1
">
3883 <tt><filename</tt>
3887 The standard input of the first command in the pipeline
3888 is taken from the file.
3891 <dt class="hdlist1
">
3892 <tt><<string</tt>
3896 The standard input of the first command is taken as the
3897 given immediate value.
3900 <dt class="hdlist1
">
3901 <tt><@fileId</tt>
3905 The standard input of the first command in the pipeline
3906 is taken from the given (readable) file descriptor.
3910 <div class="paragraph
"><p>If there is no redirection of standard input, standard error
3911 or standard output, these are connected to the corresponding
3912 input or output of the application.</p></div>
3913 <div class="paragraph
"><p>If the last <tt><em>arg</em></tt> is <tt>&</tt> then the command will be
3914 executed in background.
3915 In this case the standard output from the last command
3916 in the pipeline will
3917 go to the application’s standard output unless
3918 redirected in the command, and error output from all
3919 the commands in the pipeline will go to the application’s
3920 standard error file. The return value of exec in this case
3921 is a list of process ids (pids) in the pipeline.</p></div>
3922 <div class="paragraph
"><p>Each <tt><em>arg</em></tt> becomes one word for a command, except for
3923 <tt>|</tt>, <tt><</tt>, <tt><<</tt>, <tt>></tt>, and <tt>&</tt> arguments, and the
3924 arguments that follow <tt><</tt>, <tt><<</tt>, and <tt>></tt>.</p></div>
3925 <div class="paragraph
"><p>The first word in each command is taken as the command name;
3926 the directories in the PATH environment variable are searched for
3927 an executable by the given name.</p></div>
3928 <div class="paragraph
"><p>No <a href="#_glob
"><strong><tt>glob</tt></strong></a> expansion or other shell-like substitutions
3929 are performed on the arguments to commands.</p></div>
3930 <div class="paragraph
"><p>If the command fails, the global $::errorCode (and the -errorcode
3931 option in <a href="#_catch
"><strong><tt>catch</tt></strong></a>) will be set to a list, as follows:</p></div>
3932 <div class="dlist
"><dl>
3933 <dt class="hdlist1
">
3934 <tt><strong>CHILDKILLED</strong> <em>pid sigName msg</em></tt>
3938 This format is used when a child process has been killed
3939 because of a signal. The pid element will be the process’s
3940 identifier (in decimal). The sigName element will be the
3941 symbolic name of the signal that caused the process to
3942 terminate; it will be one of the names from the include
3943 file signal.h, such as SIGPIPE. The msg element will be a
3944 short human-readable message describing the signal, such
3945 as "write on pipe with no readers
" for SIGPIPE.
3948 <dt class="hdlist1
">
3949 <tt><strong>CHILDSUSP</strong> <em>pid sigName msg</em></tt>
3953 This format is used when a child process has been suspended
3954 because of a signal. The pid element will be the process’s
3955 identifier, in decimal. The sigName element will be the
3956 symbolic name of the signal that caused the process to
3957 suspend; this will be one of the names from the include
3958 file signal.h, such as SIGTTIN. The msg element will be a
3959 short human-readable message describing the signal, such
3960 as "background tty read
" for SIGTTIN.
3963 <dt class="hdlist1
">
3964 <tt><strong>CHILDSTATUS</strong> <em>pid code</em></tt>
3968 This format is used when a child process has exited with a
3969 non-zero exit status. The pid element will be the process’s
3970 identifier (in decimal) and the code element will be the
3971 exit code returned by the process (also in decimal).
3975 <div class="paragraph
"><p>The environment for the executed command is set from $::env (unless
3976 this variable is unset, in which case the original environment is used).</p></div>
3979 <h3 id="_exists
">exists</h3>
3980 <div class="paragraph
"><p><tt><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></tt></p></div>
3981 <div class="paragraph
"><p>Checks the existence of the given variable, procedure, command
3982 or alias respectively and returns 1 if it exists or 0 if not. This command
3983 provides a more simplified/convenient version of <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>exists</tt>,
3984 <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>procs</tt> and <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>commands</tt>.</p></div>
3985 <div class="paragraph
"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
3988 <h3 id="_exit
">exit</h3>
3989 <div class="paragraph
"><p><tt><strong>exit</strong> <em>?returnCode?</em></tt></p></div>
3990 <div class="paragraph
"><p>Terminate the process, returning <tt><em>returnCode</em></tt> to the
3991 parent as the exit status.</p></div>
3992 <div class="paragraph
"><p>If <tt><em>returnCode</em></tt> isn’t specified then it defaults
3994 <div class="paragraph
"><p>Note that exit can be caught with <a href="#_catch
"><strong><tt>catch</tt></strong></a>.</p></div>
3997 <h3 id="_expr
">expr</h3>
3998 <div class="paragraph
"><p><tt><strong>expr</strong> <em>arg</em></tt></p></div>
3999 <div class="paragraph
"><p>Calls the expression processor to evaluate <tt><em>arg</em></tt>, and returns
4000 the result as a string. See the section EXPRESSIONS above.</p></div>
4001 <div class="paragraph
"><p>Note that Jim supports a shorthand syntax for <a href="#_expr
"><strong><tt>expr</tt></strong></a> as <tt>$(...)</tt>
4002 The following two are identical.</p></div>
4003 <div class="literalblock
">
4004 <div class="content
">
4005 <pre><tt>set x [expr {3 * 2 + 1}]
4006 set x $(3 * 2 + 1)</tt></pre>
4010 <h3 id="_file
">file</h3>
4011 <div class="paragraph
"><p><tt><strong>file</strong> <em>option name ?arg...?</em></tt></p></div>
4012 <div class="paragraph
"><p>Operate on a file or a file name. <tt><em>name</em></tt> is the name of a file.</p></div>
4013 <div class="paragraph
"><p><tt><em>option</em></tt> indicates what to do with the file name. Any unique
4014 abbreviation for <tt><em>option</em></tt> is acceptable. The valid options are:</p></div>
4015 <div class="dlist
"><dl>
4016 <dt class="hdlist1
">
4017 <tt><strong>file atime</strong> <em>name</em></tt>
4021 Return a decimal string giving the time at which file <tt><em>name</em></tt>
4022 was last accessed. The time is measured in the standard UNIX
4023 fashion as seconds from a fixed starting time (often January 1, 1970).
4024 If the file doesn’t exist or its access time cannot be queried then an
4028 <dt class="hdlist1
">
4029 <tt><strong>file copy ?-force?</strong> <em>source target</em></tt>
4033 Copies file <tt><em>source</em></tt> to file <tt><em>target</em></tt>. The source file must exist.
4034 The target file must not exist, unless <tt>-force</tt> is specified.
4037 <dt class="hdlist1
">
4038 <tt><strong>file delete ?-force?</strong> <em>name...</em></tt>
4042 Deletes file or directory <tt><em>name</em></tt>. If the file or directory doesn’t exist, nothing happens.
4043 If it can’t be deleted, an error is generated. Non-empty directories will not be deleted
4044 unless the <tt>-force</tt> options is given. In this case no errors will be generated, even
4045 if the file/directory can’t be deleted.
4048 <dt class="hdlist1
">
4049 <tt><strong>file dirname</strong> <em>name</em></tt>
4053 Return all of the characters in <tt><em>name</em></tt> up to but not including
4054 the last slash character. If there are no slashes in <tt><em>name</em></tt>
4055 then return <tt>.</tt> (a single dot). If the last slash in <tt><em>name</em></tt> is its first
4056 character, then return <tt>/</tt>.
4059 <dt class="hdlist1
">
4060 <tt><strong>file executable</strong> <em>name</em></tt>
4064 Return <em>1</em> if file <tt><em>name</em></tt> is executable by
4065 the current user, <em>0</em> otherwise.
4068 <dt class="hdlist1
">
4069 <tt><strong>file exists</strong> <em>name</em></tt>
4073 Return <em>1</em> if file <tt><em>name</em></tt> exists and the current user has
4074 search privileges for the directories leading to it, <em>0</em> otherwise.
4077 <dt class="hdlist1
">
4078 <tt><strong>file extension</strong> <em>name</em></tt>
4082 Return all of the characters in <tt><em>name</em></tt> after and including the
4083 last dot in <tt><em>name</em></tt>. If there is no dot in <tt><em>name</em></tt> then return
4087 <dt class="hdlist1
">
4088 <tt><strong>file isdirectory</strong> <em>name</em></tt>
4092 Return <em>1</em> if file <tt><em>name</em></tt> is a directory,
4093 <em>0</em> otherwise.
4096 <dt class="hdlist1
">
4097 <tt><strong>file isfile</strong> <em>name</em></tt>
4101 Return <em>1</em> if file <tt><em>name</em></tt> is a regular file,
4102 <em>0</em> otherwise.
4105 <dt class="hdlist1
">
4106 <tt><strong>file join</strong> <em>arg...</em></tt>
4110 Joins multiple path components. Note that if any components is
4111 an absolute path, the preceding components are ignored.
4112 Thus <tt>"<a href=
"#_file"><strong><tt>file
</tt></strong></a> join /tmp /root
"</tt> returns <tt>"/root
"</tt>.
4115 <dt class="hdlist1
">
4116 <tt><strong>file lstat</strong> <em>name varName</em></tt>
4120 Same as <em>stat</em> option (see below) except uses the <tt><em>lstat</em></tt>
4121 kernel call instead of <tt><em>stat</em></tt>. This means that if <tt><em>name</em></tt>
4122 refers to a symbolic link the information returned in <tt><em>varName</em></tt>
4123 is for the link rather than the file it refers to. On systems that
4124 don’t support symbolic links this option behaves exactly the same
4125 as the <em>stat</em> option.
4128 <dt class="hdlist1
">
4129 <tt><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></tt>
4133 Creates each directory specified. For each pathname <tt><em>dir</em></tt> specified,
4134 this command will create all non-existing parent directories
4135 as well as <tt><em>dir</em></tt> itself. If an existing directory is specified,
4136 then no action is taken and no error is returned. Trying to
4137 overwrite an existing file with a directory will result in an
4138 error. Arguments are processed in the order specified, halting
4139 at the first error, if any.
4142 <dt class="hdlist1
">
4143 <tt><strong>file mtime</strong> <em>name ?time?</em></tt>
4147 Return a decimal string giving the time at which file <tt><em>name</em></tt>
4148 was last modified. The time is measured in the standard UNIX
4149 fashion as seconds from a fixed starting time (often January 1, 1970).
4150 If the file doesn’t exist or its modified time cannot be queried then an
4151 error is generated. If <tt><em>time</em></tt> is given, sets the modification time
4152 of the file to the given value.
4155 <dt class="hdlist1
">
4156 <tt><strong>file normalize</strong> <em>name</em></tt>
4160 Return the normalized path of <tt><em>name</em></tt>. See <em>realpath(3)</em>.
4163 <dt class="hdlist1
">
4164 <tt><strong>file owned</strong> <em>name</em></tt>
4168 Return <em>1</em> if file <tt><em>name</em></tt> is owned by the current user,
4169 <em>0</em> otherwise.
4172 <dt class="hdlist1
">
4173 <tt><strong>file readable</strong> <em>name</em></tt>
4177 Return <em>1</em> if file <tt><em>name</em></tt> is readable by
4178 the current user, <em>0</em> otherwise.
4181 <dt class="hdlist1
">
4182 <tt><strong>file readlink</strong> <em>name</em></tt>
4186 Returns the value of the symbolic link given by <tt><em>name</em></tt> (i.e. the
4187 name of the file it points to). If
4188 <tt><em>name</em></tt> isn’t a symbolic link or its value cannot be read, then
4189 an error is returned. On systems that don’t support symbolic links
4190 this option is undefined.
4193 <dt class="hdlist1
">
4194 <tt><strong>file rename</strong> <em>oldname</em> <em>newname</em></tt>
4198 Renames the file from the old name to the new name.
4201 <dt class="hdlist1
">
4202 <tt><strong>file rootname</strong> <em>name</em></tt>
4206 Return all of the characters in <tt><em>name</em></tt> up to but not including
4207 the last <em>.</em> character in the name. If <tt><em>name</em></tt> doesn’t contain
4208 a dot, then return <tt><em>name</em></tt>.
4211 <dt class="hdlist1
">
4212 <tt><strong>file size</strong> <em>name</em></tt>
4216 Return a decimal string giving the size of file <tt><em>name</em></tt> in bytes.
4217 If the file doesn’t exist or its size cannot be queried then an
4221 <dt class="hdlist1
">
4222 <tt><strong>file stat</strong> <em>name ?varName?</em></tt>
4226 Invoke the <em>stat</em> kernel call on <tt><em>name</em></tt>, and return the result
4227 as a dictionary with the following keys: <em>atime</em>,
4228 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4229 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4230 Each element except <em>type</em> is a decimal string with the value of
4231 the corresponding field from the <em>stat</em> return structure; see the
4232 manual entry for <em>stat</em> for details on the meanings of the values.
4233 The <em>type</em> element gives the type of the file in the same form
4234 returned by the command <a href="#_file
"><strong><tt>file</tt></strong></a> <tt>type</tt>.
4235 If <tt><em>varName</em></tt> is specified, it is taken to be the name of an array
4236 variable and the values are also stored into the array.
4239 <dt class="hdlist1
">
4240 <tt><strong>file tail</strong> <em>name</em></tt>
4244 Return all of the characters in <tt><em>name</em></tt> after the last slash.
4245 If <tt><em>name</em></tt> contains no slashes then return <tt><em>name</em></tt>.
4248 <dt class="hdlist1
">
4249 <tt><strong>file tempfile</strong> <em>?template?</em></tt>
4253 Creates and returns the name of a unique temporary file. If <tt><em>template</em></tt> is omitted, a
4254 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4255 the format of the template and security concerns.
4258 <dt class="hdlist1
">
4259 <tt><strong>file type</strong> <em>name</em></tt>
4263 Returns a string giving the type of file <tt><em>name</em></tt>, which will be
4264 one of <tt>file</tt>, <tt>directory</tt>, <tt>characterSpecial</tt>,
4265 <tt>blockSpecial</tt>, <tt>fifo</tt>, <tt>link</tt>, or <tt>socket</tt>.
4268 <dt class="hdlist1
">
4269 <tt><strong>file writable</strong> <em>name</em></tt>
4273 Return <em>1</em> if file <tt><em>name</em></tt> is writable by
4274 the current user, <em>0</em> otherwise.
4278 <div class="paragraph
"><p>The <a href="#_file
"><strong><tt>file</tt></strong></a> commands that return 0/1 results are often used in
4279 conditional or looping commands, for example:</p></div>
4280 <div class="literalblock
">
4281 <div class="content
">
4282 <pre><tt>if {![file exists foo]} {
4283 error {bad file name}
4290 <h3 id="_finalize
">finalize</h3>
4291 <div class="paragraph
"><p><tt><strong>finalize</strong> <em>reference ?command?</em></tt></p></div>
4292 <div class="paragraph
"><p>If <tt><em>command</em></tt> is omitted, returns the finalizer command for the given reference.</p></div>
4293 <div class="paragraph
"><p>Otherwise, sets a new finalizer command for the given reference. <tt><em>command</em></tt> may be
4294 the empty string to remove the current finalizer.</p></div>
4295 <div class="paragraph
"><p>The reference must be a valid reference create with the <a href="#_ref
"><strong><tt>ref</tt></strong></a>
4297 <div class="paragraph
"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4300 <h3 id="_flush
">flush</h3>
4301 <div class="paragraph
"><p><tt><strong>flush</strong> <em>fileId</em></tt></p></div>
4302 <div class="paragraph
"><p><tt><em>fileId</em> <strong>flush</strong></tt></p></div>
4303 <div class="paragraph
"><p>Flushes any output that has been buffered for <tt><em>fileId</em></tt>. <tt><em>fileId</em></tt> must
4304 have been the return value from a previous call to <a href="#_open
"><strong><tt>open</tt></strong></a>, or it may be
4305 <tt>stdout</tt> or <tt>stderr</tt> to access one of the standard I/O streams; it must
4306 refer to a file that was opened for writing. This command returns an
4307 empty string.</p></div>
4310 <h3 id="_for
">for</h3>
4311 <div class="paragraph
"><p><tt><strong>for</strong> <em>start test next body</em></tt></p></div>
4312 <div class="paragraph
"><p><a href="#_for
"><strong><tt>for</tt></strong></a> is a looping command, similar in structure to the C <a href="#_for
"><strong><tt>for</tt></strong></a> statement.
4313 The <tt><em>start</em></tt>, <tt><em>next</em></tt>, and <tt><em>body</em></tt> arguments must be Tcl command strings,
4314 and <tt><em>test</em></tt> is an expression string.</p></div>
4315 <div class="paragraph
"><p>The <a href="#_for
"><strong><tt>for</tt></strong></a> command first invokes the Tcl interpreter to execute <tt><em>start</em></tt>.
4316 Then it repeatedly evaluates <tt><em>test</em></tt> as an expression; if the result is
4317 non-zero it invokes the Tcl interpreter on <tt><em>body</em></tt>, then invokes the Tcl
4318 interpreter on <tt><em>next</em></tt>, then repeats the loop. The command terminates
4319 when <tt><em>test</em></tt> evaluates to 0.</p></div>
4320 <div class="paragraph
"><p>If a <a href="#_continue
"><strong><tt>continue</tt></strong></a> command is invoked within <tt><em>body</em></tt> then any remaining
4321 commands in the current execution of <tt><em>body</em></tt> are skipped; processing
4322 continues by invoking the Tcl interpreter on <tt><em>next</em></tt>, then evaluating
4323 <tt><em>test</em></tt>, and so on.</p></div>
4324 <div class="paragraph
"><p>If a <a href="#_break
"><strong><tt>break</tt></strong></a> command is invoked within <tt><em>body</em></tt> or <tt><em>next</em></tt>, then the <a href="#_for
"><strong><tt>for</tt></strong></a>
4325 command will return immediately.</p></div>
4326 <div class="paragraph
"><p>The operation of <a href="#_break
"><strong><tt>break</tt></strong></a> and <a href="#_continue
"><strong><tt>continue</tt></strong></a> are similar to the corresponding
4327 statements in C.</p></div>
4328 <div class="paragraph
"><p><a href="#_for
"><strong><tt>for</tt></strong></a> returns an empty string.</p></div>
4331 <h3 id="_foreach
">foreach</h3>
4332 <div class="paragraph
"><p><tt><strong>foreach</strong> <em>varName list body</em></tt></p></div>
4333 <div class="paragraph
"><p><tt><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></tt></p></div>
4334 <div class="paragraph
"><p>In this command, <tt><em>varName</em></tt> is the name of a variable, <tt><em>list</em></tt>
4335 is a list of values to assign to <tt><em>varName</em></tt>, and <tt><em>body</em></tt> is a
4336 collection of Tcl commands.</p></div>
4337 <div class="paragraph
"><p>For each field in <tt><em>list</em></tt> (in order from left to right), <a href="#_foreach
"><strong><tt>foreach</tt></strong></a> assigns
4338 the contents of the field to <tt><em>varName</em></tt> (as if the <a href="#_lindex
"><strong><tt>lindex</tt></strong></a> command
4339 had been used to extract the field), then calls the Tcl interpreter to
4340 execute <tt><em>body</em></tt>.</p></div>
4341 <div class="paragraph
"><p>If instead of being a simple name, <tt><em>varList</em></tt> is used, multiple assignments
4342 are made each time through the loop, one for each element of <tt><em>varList</em></tt>.</p></div>
4343 <div class="paragraph
"><p>For example, if there are two elements in <tt><em>varList</em></tt> and six elements in
4344 the list, the loop will be executed three times.</p></div>
4345 <div class="paragraph
"><p>If the length of the list doesn’t evenly divide by the number of elements
4346 in <tt><em>varList</em></tt>, the value of the remaining variables in the last iteration
4347 of the loop are undefined.</p></div>
4348 <div class="paragraph
"><p>The <a href="#_break
"><strong><tt>break</tt></strong></a> and <a href="#_continue
"><strong><tt>continue</tt></strong></a> statements may be invoked inside <tt><em>body</em></tt>,
4349 with the same effect as in the <a href="#_for
"><strong><tt>for</tt></strong></a> command.</p></div>
4350 <div class="paragraph
"><p><a href="#_foreach
"><strong><tt>foreach</tt></strong></a> returns an empty string.</p></div>
4353 <h3 id="_format
">format</h3>
4354 <div class="paragraph
"><p><tt><strong>format</strong> <em>formatString ?arg ...?</em></tt></p></div>
4355 <div class="paragraph
"><p>This command generates a formatted string in the same way as the
4356 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4357 implementation). <tt><em>formatString</em></tt> indicates how to format
4358 the result, using <tt>%</tt> fields as in <em>sprintf</em>, and the additional
4359 arguments, if any, provide values to be substituted into the result.</p></div>
4360 <div class="paragraph
"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4361 man page for details. Each <tt><em>arg</em></tt> must match the expected type
4362 from the <tt>%</tt> field in <tt><em>formatString</em></tt>; the <a href="#_format
"><strong><tt>format</tt></strong></a> command
4363 converts each argument to the correct type (floating, integer, etc.)
4364 before passing it to <em>sprintf</em> for formatting.</p></div>
4365 <div class="paragraph
"><p>The only unusual conversion is for <tt>%c</tt>; in this case the argument
4366 must be a decimal string, which will then be converted to the corresponding
4367 ASCII (or UTF-8) character value.</p></div>
4368 <div class="paragraph
"><p>In addition, Jim Tcl provides basic support for conversion to binary with <tt>%b</tt>.</p></div>
4369 <div class="paragraph
"><p><a href="#_format
"><strong><tt>format</tt></strong></a> does backslash substitution on its <tt><em>formatString</em></tt>
4370 argument, so backslash sequences in <tt><em>formatString</em></tt> will be handled
4371 correctly even if the argument is in braces.</p></div>
4372 <div class="paragraph
"><p>The return value from <a href="#_format
"><strong><tt>format</tt></strong></a> is the formatted string.</p></div>
4375 <h3 id="_getref
">getref</h3>
4376 <div class="paragraph
"><p><tt><strong>getref</strong> <em>reference</em></tt></p></div>
4377 <div class="paragraph
"><p>Returns the string associated with <tt><em>reference</em></tt>. The reference must
4378 be a valid reference create with the <a href="#_ref
"><strong><tt>ref</tt></strong></a> command.</p></div>
4379 <div class="paragraph
"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4382 <h3 id="_gets
">gets</h3>
4383 <div class="paragraph
"><p><tt><strong>gets</strong> <em>fileId ?varName?</em></tt></p></div>
4384 <div class="paragraph
"><p><tt><em>fileId</em> <strong>gets</strong> <em>?varName?</em></tt></p></div>
4385 <div class="paragraph
"><p>Reads the next line from the file given by <tt><em>fileId</em></tt> and discards
4386 the terminating newline character.</p></div>
4387 <div class="paragraph
"><p>If <tt><em>varName</em></tt> is specified, then the line is placed in the variable
4388 by that name and the return value is a count of the number of characters
4389 read (not including the newline).</p></div>
4390 <div class="paragraph
"><p>If the end of the file is reached before reading
4391 any characters then -1 is returned and <tt><em>varName</em></tt> is set to an
4392 empty string.</p></div>
4393 <div class="paragraph
"><p>If <tt><em>varName</em></tt> is not specified then the return value will be
4394 the line (minus the newline character) or an empty string if
4395 the end of the file is reached before reading any characters.</p></div>
4396 <div class="paragraph
"><p>An empty string will also be returned if a line contains no characters
4397 except the newline, so <a href="#_eof
"><strong><tt>eof</tt></strong></a> may have to be used to determine
4398 what really happened.</p></div>
4399 <div class="paragraph
"><p>If the last character in the file is not a newline character, then
4400 <a href="#_gets
"><strong><tt>gets</tt></strong></a> behaves as if there were an additional newline character
4401 at the end of the file.</p></div>
4402 <div class="paragraph
"><p><tt><em>fileId</em></tt> must be <tt>stdin</tt> or the return value from a previous
4403 call to <a href="#_open
"><strong><tt>open</tt></strong></a>; it must refer to a file that was opened
4404 for reading.</p></div>
4407 <h3 id="_glob
">glob</h3>
4408 <div class="paragraph
"><p><tt><strong>glob</strong> ?<strong>-nocomplain</strong>? ?<strong>-directory</strong> <em>dir</em>? ?<strong>--</strong>? <em>pattern ?pattern ...?</em></tt></p></div>
4409 <div class="paragraph
"><p>This command performs filename globbing, using csh rules. The returned
4410 value from <a href="#_glob
"><strong><tt>glob</tt></strong></a> is the list of expanded filenames.</p></div>
4411 <div class="paragraph
"><p>If <tt>-nocomplain</tt> is specified as the first argument then an empty
4412 list may be returned; otherwise an error is returned if the expanded
4413 list is empty. The <tt>-nocomplain</tt> argument must be provided
4414 exactly: an abbreviation will not be accepted.</p></div>
4415 <div class="paragraph
"><p>If <tt>-directory</tt> is given, the <tt><em>dir</em></tt> is understood to contain a
4416 directory name to search in. This allows globbing inside directories
4417 whose names may contain glob-sensitive characters. The returned names
4418 are specified relative to this directory.</p></div>
4421 <h3 id="_global
">global</h3>
4422 <div class="paragraph
"><p><tt><strong>global</strong> <em>varName ?varName ...?</em></tt></p></div>
4423 <div class="paragraph
"><p>This command is ignored unless a Tcl procedure is being interpreted.
4424 If so, then it declares each given <tt><em>varName</em></tt> to be a global variable
4425 rather than a local one. For the duration of the current procedure
4426 (and only while executing in the current procedure), any reference to
4427 <tt><em>varName</em></tt> will be bound to a global variable instead
4428 of a local one.</p></div>
4429 <div class="paragraph
"><p>An alternative to using <a href="#_global
"><strong><tt>global</tt></strong></a> is to use the <tt>::</tt> prefix
4430 to explicitly name a variable in the global scope.</p></div>
4433 <h3 id="_if
">if</h3>
4434 <div class="paragraph
"><p><tt><strong>if</strong> <em>expr1</em> ?<strong>then</strong>? <em>body1</em> <strong>elseif</strong> <em>expr2</em> ?<strong>then</strong>? <em>body2</em> <strong>elseif</strong> ... ?<strong>else</strong>? ?<em>bodyN</em>?</tt></p></div>
4435 <div class="paragraph
"><p>The <a href="#_if
"><strong><tt>if</tt></strong></a> command evaluates <tt><em>expr1</em></tt> as an expression (in the same way
4436 that <a href="#_expr
"><strong><tt>expr</tt></strong></a> evaluates its argument). The value of the expression must
4437 be numeric; if it is non-zero then <tt><em>body1</em></tt> is executed by passing it to
4438 the Tcl interpreter.</p></div>
4439 <div class="paragraph
"><p>Otherwise <tt><em>expr2</em></tt> is evaluated as an expression and if it is non-zero
4440 then <tt><em>body2</em></tt> is executed, and so on.</p></div>
4441 <div class="paragraph
"><p>If none of the expressions evaluates to non-zero then <tt><em>bodyN</em></tt> is executed.</p></div>
4442 <div class="paragraph
"><p>The <tt>then</tt> and <tt>else</tt> arguments are optional "noise words
" to make the
4443 command easier to read.</p></div>
4444 <div class="paragraph
"><p>There may be any number of <tt>elseif</tt> clauses, including zero. <tt><em>bodyN</em></tt>
4445 may also be omitted as long as <tt>else</tt> is omitted too.</p></div>
4446 <div class="paragraph
"><p>The return value from the command is the result of the body script that
4447 was executed, or an empty string if none of the expressions was non-zero
4448 and there was no <tt><em>bodyN</em></tt>.</p></div>
4451 <h3 id="_incr
">incr</h3>
4452 <div class="paragraph
"><p><tt><strong>incr</strong> <em>varName ?increment?</em></tt></p></div>
4453 <div class="paragraph
"><p>Increment the value stored in the variable whose name is <tt><em>varName</em></tt>.
4454 The value of the variable must be integral.</p></div>
4455 <div class="paragraph
"><p>If <tt><em>increment</em></tt> is supplied then its value (which must be an
4456 integer) is added to the value of variable <tt><em>varName</em></tt>; otherwise
4457 1 is added to <tt><em>varName</em></tt>.</p></div>
4458 <div class="paragraph
"><p>The new value is stored as a decimal string in variable <tt><em>varName</em></tt>
4459 and also returned as result.</p></div>
4460 <div class="paragraph
"><p>If the variable does not exist, the variable is implicitly created
4461 and set to <tt>0</tt> first.</p></div>
4464 <h3 id="_info
">info</h3>
4465 <div class="dlist
"><dl>
4466 <dt class="hdlist1
">
4467 <tt><strong>info</strong> <em>option ?arg...?</em></tt>
4471 Provide information about various internals to the Tcl interpreter.
4472 The legal <tt><em>option</em></tt>'s (which may be abbreviated) are:
4475 <dt class="hdlist1
">
4476 <tt><strong>info args</strong> <em>procname</em></tt>
4480 Returns a list containing the names of the arguments to procedure
4481 <tt><em>procname</em></tt>, in order. <tt><em>procname</em></tt> must be the name of a
4482 Tcl command procedure.
4485 <dt class="hdlist1
">
4486 <tt><strong>info alias</strong> <em>command</em></tt>
4490 <tt><em>command</em></tt> must be an alias created with <a href="#_alias
"><strong><tt>alias</tt></strong></a>. In which case the target
4491 command and arguments, as passed to <a href="#_alias
"><strong><tt>alias</tt></strong></a> are returned. See <a href="#_exists
"><strong><tt>exists</tt></strong></a> <tt>-alias</tt>
4494 <dt class="hdlist1
">
4495 <tt><strong>info body</strong> <em>procname</em></tt>
4499 Returns the body of procedure <tt><em>procname</em></tt>. <tt><em>procname</em></tt> must be
4500 the name of a Tcl command procedure.
4503 <dt class="hdlist1
">
4504 <tt><strong>info channels</strong></tt>
4508 Returns a list of all open file handles from <a href="#_open
"><strong><tt>open</tt></strong></a> or <a href="#_socket
"><strong><tt>socket</tt></strong></a>
4511 <dt class="hdlist1
">
4512 <tt><strong>info commands</strong> ?<em>pattern</em>?</tt>
4516 If <tt><em>pattern</em></tt> isn’t specified, returns a list of names of all the
4517 Tcl commands, including both the built-in commands written in C and
4518 the command procedures defined using the <a href="#_proc
"><strong><tt>proc</tt></strong></a> command.
4519 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4520 are returned. Matching is determined using the same rules as for
4521 <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4524 <dt class="hdlist1
">
4525 <tt><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</tt>
4529 Returns 1 if <tt><em>command</em></tt> is a complete Tcl command in the sense of
4530 having no unclosed quotes, braces, brackets or array element names,
4531 If the command doesn’t appear to be complete then 0 is returned.
4532 This command is typically used in line-oriented input environments
4533 to allow users to type in commands that span multiple lines; if the
4534 command isn’t complete, the script can delay evaluating it until additional
4535 lines have been typed to complete the command. If <tt><em>varName</em></tt> is specified, the
4536 missing character is stored in the variable with that name.
4539 <dt class="hdlist1
">
4540 <tt><strong>info exists</strong> <em>varName</em></tt>
4544 Returns <em>1</em> if the variable named <tt><em>varName</em></tt> exists in the
4545 current context (either as a global or local variable), returns <em>0</em>
4549 <dt class="hdlist1
">
4550 <tt><strong>info frame</strong> ?<em>number</em>?</tt>
4554 If <tt><em>number</em></tt> is not specified, this command returns a number
4555 which is the same result as <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>level</tt> - the current stack frame level.
4556 If <tt><em>number</em></tt> is specified, then the result is a list consisting of the procedure,
4557 filename and line number for the procedure call at level <tt><em>number</em></tt> on the stack.
4558 If <tt><em>number</em></tt> is positive then it selects a particular stack level (1 refers
4559 to the top-most active procedure, 2 to the procedure it called, and
4560 so on); otherwise it gives a level relative to the current level
4561 (0 refers to the current procedure, -1 to its caller, and so on).
4562 The level has an identical meaning to <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>level</tt>.
4565 <dt class="hdlist1
">
4566 <tt><strong>info globals</strong> ?<em>pattern</em>?</tt>
4570 If <tt><em>pattern</em></tt> isn’t specified, returns a list of all the names
4571 of currently-defined global variables.
4572 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4573 are returned. Matching is determined using the same rules as for
4574 <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4577 <dt class="hdlist1
">
4578 <tt><strong>info hostname</strong></tt>
4582 An alias for <a href="#cmd_1
"><strong><tt>os.gethostname</tt></strong></a> for compatibility with Tcl 6.x
4585 <dt class="hdlist1
">
4586 <tt><strong>info level</strong> ?<em>number</em>?</tt>
4590 If <tt><em>number</em></tt> is not specified, this command returns a number
4591 giving the stack level of the invoking procedure, or 0 if the
4592 command is invoked at top-level. If <tt><em>number</em></tt> is specified,
4593 then the result is a list consisting of the name and arguments for the
4594 procedure call at level <tt><em>number</em></tt> on the stack. If <tt><em>number</em></tt>
4595 is positive then it selects a particular stack level (1 refers
4596 to the top-most active procedure, 2 to the procedure it called, and
4597 so on); otherwise it gives a level relative to the current level
4598 (0 refers to the current procedure, -1 to its caller, and so on).
4599 See the <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> command for more information on what stack
4603 <dt class="hdlist1
">
4604 <tt><strong>info locals</strong> ?<em>pattern</em>?</tt>
4608 If <tt><em>pattern</em></tt> isn’t specified, returns a list of all the names
4609 of currently-defined local variables, including arguments to the
4610 current procedure, if any. Variables defined with the <a href="#_global
"><strong><tt>global</tt></strong></a>
4611 and <a href="#_upvar
"><strong><tt>upvar</tt></strong></a> commands will not be returned. If <tt><em>pattern</em></tt> is
4612 specified, only those names matching <tt><em>pattern</em></tt> are returned.
4613 Matching is determined using the same rules as for <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4616 <dt class="hdlist1
">
4617 <tt><strong>info nameofexecutable</strong></tt>
4621 Returns the name of the binary file from which the application
4622 was invoked. A full path will be returned, unless the path
4623 can’t be determined, in which case the empty string will be returned.
4626 <dt class="hdlist1
">
4627 <tt><strong>info procs</strong> ?<em>pattern</em>?</tt>
4631 If <tt><em>pattern</em></tt> isn’t specified, returns a list of all the
4632 names of Tcl command procedures.
4633 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4634 are returned. Matching is determined using the same rules as for
4635 <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4638 <dt class="hdlist1
">
4639 <tt><strong>info references</strong></tt>
4643 Returns a list of all references which have not yet been garbage
4647 <dt class="hdlist1
">
4648 <tt><strong>info returncodes</strong> ?<em>code</em>?</tt>
4652 Returns a list representing the mapping of standard return codes
4653 to names. e.g. <tt>{0 ok 1 error 2 return ...}</tt>. If a code is given,
4654 instead returns the name for the given code.
4657 <dt class="hdlist1
">
4658 <tt><strong>info script</strong></tt>
4662 If a Tcl script file is currently being evaluated (i.e. there is a
4663 call to <em>Jim_EvalFile</em> active or there is an active invocation
4664 of the <a href="#_source
"><strong><tt>source</tt></strong></a> command), then this command returns the name
4665 of the innermost file being processed. Otherwise the command returns an
4669 <dt class="hdlist1
">
4670 <tt><strong>info source</strong> <em>script</em></tt>
4674 Returns the original source location of the given script as a list of
4675 <tt>{filename linenumber}</tt>. If the source location can’t be determined, the
4676 list <tt>{{} 0}</tt> is returned.
4679 <dt class="hdlist1
">
4680 <tt><strong>info stacktrace</strong></tt>
4684 After an error is caught with <a href="#_catch
"><strong><tt>catch</tt></strong></a>, returns the stack trace as a list
4685 of <tt>{procedure filename line ...}</tt>.
4688 <dt class="hdlist1
">
4689 <tt><strong>info statics</strong> <em>procname</em></tt>
4693 Returns a dictionary of the static variables of procedure
4694 <tt><em>procname</em></tt>. <tt><em>procname</em></tt> must be the name of a Tcl command
4695 procedure. An empty dictionary is returned if the procedure has
4696 no static variables.
4699 <dt class="hdlist1
">
4700 <tt><strong>info version</strong></tt>
4704 Returns the version number for this version of Jim in the form <tt><strong>x.yy</strong></tt>.
4707 <dt class="hdlist1
">
4708 <tt><strong>info vars</strong> ?<em>pattern</em>?</tt>
4712 If <tt><em>pattern</em></tt> isn’t specified,
4713 returns a list of all the names of currently-visible variables, including
4714 both locals and currently-visible globals.
4715 If <tt><em>pattern</em></tt> is specified, only those names matching <tt><em>pattern</em></tt>
4716 are returned. Matching is determined using the same rules as for
4717 <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>match</tt>.
4723 <h3 id="_join
">join</h3>
4724 <div class="paragraph
"><p><tt><strong>join</strong> <em>list ?joinString?</em></tt></p></div>
4725 <div class="paragraph
"><p>The <tt><em>list</em></tt> argument must be a valid Tcl list. This command returns the
4726 string formed by joining all of the elements of <tt><em>list</em></tt> together with
4727 <tt><em>joinString</em></tt> separating each adjacent pair of elements.</p></div>
4728 <div class="paragraph
"><p>The <tt><em>joinString</em></tt> argument defaults to a space character.</p></div>
4731 <h3 id="_kill
">kill</h3>
4732 <div class="paragraph
"><p><tt><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></tt></p></div>
4733 <div class="paragraph
"><p>Sends the given signal to the process identified by <tt><em>pid</em></tt>.</p></div>
4734 <div class="paragraph
"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4735 <div class="ulist
"><ul>
4762 <div class="paragraph
"><p>The signal name may be in either upper or lower case.</p></div>
4763 <div class="paragraph
"><p>The special signal name <tt>-0</tt> simply checks that a signal <tt><em>could</em></tt> be sent.</p></div>
4764 <div class="paragraph
"><p>If no signal is specified, SIGTERM is used.</p></div>
4765 <div class="paragraph
"><p>An error is raised if the signal could not be delivered.</p></div>
4768 <h3 id="_lambda_2
">lambda</h3>
4769 <div class="paragraph
"><p><tt><strong>lambda</strong> <em>args ?statics? body</em></tt></p></div>
4770 <div class="paragraph
"><p>The <a href="#_lambda
"><strong><tt>lambda</tt></strong></a> command is identical to <a href="#_proc
"><strong><tt>proc</tt></strong></a>, except rather than
4771 creating a named procedure, it creates an anonymous procedure and returns
4772 the name of the procedure.</p></div>
4773 <div class="paragraph
"><p>See <a href="#_proc
"><strong><tt>proc</tt></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4776 <h3 id="_lappend
">lappend</h3>
4777 <div class="paragraph
"><p><tt><strong>lappend</strong> <em>varName value ?value value ...?</em></tt></p></div>
4778 <div class="paragraph
"><p>Treat the variable given by <tt><em>varName</em></tt> as a list and append each of
4779 the <tt><em>value</em></tt> arguments to that list as a separate element, with spaces
4780 between elements.</p></div>
4781 <div class="paragraph
"><p>If <tt><em>varName</em></tt> doesn’t exist, it is created as a list with elements given
4782 by the <tt><em>value</em></tt> arguments. <a href="#_lappend
"><strong><tt>lappend</tt></strong></a> is similar to <a href="#_append
"><strong><tt>append</tt></strong></a> except that
4783 each <tt><em>value</em></tt> is appended as a list element rather than raw text.</p></div>
4784 <div class="paragraph
"><p>This command provides a relatively efficient way to build up large lists.
4785 For example,</p></div>
4786 <div class="literalblock
">
4787 <div class="content
">
4788 <pre><tt>lappend a $b</tt></pre>
4790 <div class="paragraph
"><p>is much more efficient than</p></div>
4791 <div class="literalblock
">
4792 <div class="content
">
4793 <pre><tt>set a [concat $a [list $b]]</tt></pre>
4795 <div class="paragraph
"><p>when <tt>$a</tt> is long.</p></div>
4798 <h3 id="_lassign
">lassign</h3>
4799 <div class="paragraph
"><p><tt><strong>lassign</strong> <em>list varName ?varName ...?</em></tt></p></div>
4800 <div class="paragraph
"><p>This command treats the value <tt><em>list</em></tt> as a list and assigns successive elements from that list to
4801 the variables given by the <tt><em>varName</em></tt> arguments in order. If there are more variable names than
4802 list elements, the remaining variables are set to the empty string. If there are more list ele-
4803 ments than variables, a list of unassigned elements is returned.</p></div>
4804 <div class="literalblock
">
4805 <div class="content
">
4806 <pre><tt>jim> lassign {1 2 3} a b; puts a=$a,b=$b
4812 <h3 id="_local
">local</h3>
4813 <div class="paragraph
"><p><tt><strong>local</strong> <em>cmd ?arg...?</em></tt></p></div>
4814 <div class="paragraph
"><p>First, <a href="#_local
"><strong><tt>local</tt></strong></a> evaluates <tt><em>cmd</em></tt> with the given arguments. The return value must
4815 be the name of an existing command, which is marked as having local scope.
4816 This means that when the current procedure exits, the specified
4817 command is deleted. This can be useful with <a href="#_lambda
"><strong><tt>lambda</tt></strong></a>, local procedures or
4818 to automatically close a filehandle.</p></div>
4819 <div class="paragraph
"><p>In addition, if a command already exists with the same name,
4820 the existing command will be kept rather than deleted, and may be called
4821 via <a href="#_upcall
"><strong><tt>upcall</tt></strong></a>. The previous command will be restored when the current
4822 procedure exits. See <a href="#_upcall
"><strong><tt>upcall</tt></strong></a> for more details.</p></div>
4823 <div class="paragraph
"><p>In this example, a local procedure is created. Note that the procedure
4824 continues to have global scope while it is active.</p></div>
4825 <div class="literalblock
">
4826 <div class="content
">
4827 <pre><tt>proc outer {} {
4828 # proc ... returns "inner
" which is marked local
4829 local proc inner {} {
4830 # will be deleted when 'outer' exits
4833 <div class="literalblock
">
4834 <div class="content
">
4839 <div class="paragraph
"><p>In this example, the lambda is deleted at the end of the procedure rather
4840 than waiting until garbage collection.</p></div>
4841 <div class="literalblock
">
4842 <div class="content
">
4843 <pre><tt>proc outer {} {
4844 set x [lambda inner {args} {
4845 # will be deleted when 'outer' exits
4847 # Use 'function' here which simply returns $x
4848 local function $x</tt></pre>
4850 <div class="literalblock
">
4851 <div class="content
">
4858 <h3 id="_loop
">loop</h3>
4859 <div class="paragraph
"><p><tt><strong>loop</strong> <em>var first limit ?incr? body</em></tt></p></div>
4860 <div class="paragraph
"><p>Similar to <a href="#_for
"><strong><tt>for</tt></strong></a> except simpler and possibly more efficient.
4861 With a positive increment, equivalent to:</p></div>
4862 <div class="literalblock
">
4863 <div class="content
">
4864 <pre><tt>for {set var $first} {$var < $limit} {incr var $incr} $body</tt></pre>
4866 <div class="paragraph
"><p>If <tt><em>incr</em></tt> is not specified, 1 is used.
4867 Note that setting the loop variable inside the loop does not
4868 affect the loop count.</p></div>
4871 <h3 id="_lindex
">lindex</h3>
4872 <div class="paragraph
"><p><tt><strong>lindex</strong> <em>list index</em></tt></p></div>
4873 <div class="paragraph
"><p>Treats <tt><em>list</em></tt> as a Tcl list and returns element <tt><em>index</em></tt> from it
4874 (0 refers to the first element of the list).
4875 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4876 <div class="paragraph
"><p>In extracting the element, <tt><em>lindex</em></tt> observes the same rules concerning
4877 braces and quotes and backslashes as the Tcl command interpreter; however,
4878 variable substitution and command substitution do not occur.</p></div>
4879 <div class="paragraph
"><p>If <tt><em>index</em></tt> is negative or greater than or equal to the number of elements
4880 in <tt><em>value</em></tt>, then an empty string is returned.</p></div>
4883 <h3 id="_linsert
">linsert</h3>
4884 <div class="paragraph
"><p><tt><strong>linsert</strong> <em>list index element ?element element ...?</em></tt></p></div>
4885 <div class="paragraph
"><p>This command produces a new list from <tt><em>list</em></tt> by inserting all
4886 of the <tt><em>element</em></tt> arguments just before the element <tt><em>index</em></tt>
4887 of <tt><em>list</em></tt>. Each <tt><em>element</em></tt> argument will become
4888 a separate element of the new list. If <tt><em>index</em></tt> is less than
4889 or equal to zero, then the new elements are inserted at the
4890 beginning of the list. If <tt><em>index</em></tt> is greater than or equal
4891 to the number of elements in the list, then the new elements are
4892 appended to the list.</p></div>
4893 <div class="paragraph
"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4896 <h3 id="_list
">list</h3>
4897 <div class="paragraph
"><p><tt><strong>list</strong> <em>arg ?arg ...?</em></tt></p></div>
4898 <div class="paragraph
"><p>This command returns a list comprised of all the arguments, <tt><em>arg</em></tt>. Braces
4899 and backslashes get added as necessary, so that the <a href="#_lindex
"><strong><tt>lindex</tt></strong></a> command
4900 may be used on the result to re-extract the original arguments, and also
4901 so that <a href="#_eval
"><strong><tt>eval</tt></strong></a> may be used to execute the resulting list, with
4902 <tt><em>arg1</em></tt> comprising the command’s name and the other args comprising
4903 its arguments. <a href="#_list
"><strong><tt>list</tt></strong></a> produces slightly different results than
4904 <a href="#_concat
"><strong><tt>concat</tt></strong></a>: <a href="#_concat
"><strong><tt>concat</tt></strong></a> removes one level of grouping before forming
4905 the list, while <a href="#_list
"><strong><tt>list</tt></strong></a> works directly from the original arguments.
4906 For example, the command</p></div>
4907 <div class="literalblock
">
4908 <div class="content
">
4909 <pre><tt>list a b {c d e} {f {g h}}</tt></pre>
4911 <div class="paragraph
"><p>will return</p></div>
4912 <div class="literalblock
">
4913 <div class="content
">
4914 <pre><tt>a b {c d e} {f {g h}}</tt></pre>
4916 <div class="paragraph
"><p>while <a href="#_concat
"><strong><tt>concat</tt></strong></a> with the same arguments will return</p></div>
4917 <div class="literalblock
">
4918 <div class="content
">
4919 <pre><tt>a b c d e f {g h}</tt></pre>
4923 <h3 id="_llength
">llength</h3>
4924 <div class="paragraph
"><p><tt><strong>llength</strong> <em>list</em></tt></p></div>
4925 <div class="paragraph
"><p>Treats <tt><em>list</em></tt> as a list and returns a decimal string giving
4926 the number of elements in it.</p></div>
4929 <h3 id="_lset
">lset</h3>
4930 <div class="paragraph
"><p><tt><strong>lset</strong> <em>varName ?index ..? newValue</em></tt></p></div>
4931 <div class="paragraph
"><p>Sets an element in a list.</p></div>
4932 <div class="paragraph
"><p>The <a href="#_lset
"><strong><tt>lset</tt></strong></a> command accepts a parameter, <tt><em>varName</em></tt>, which it interprets
4933 as the name of a variable containing a Tcl list. It also accepts
4934 zero or more indices into the list. Finally, it accepts a new value
4935 for an element of varName. If no indices are presented, the command
4936 takes the form:</p></div>
4937 <div class="literalblock
">
4938 <div class="content
">
4939 <pre><tt>lset varName newValue</tt></pre>
4941 <div class="paragraph
"><p>In this case, newValue replaces the old value of the variable
4943 <div class="paragraph
"><p>When presented with a single index, the <a href="#_lset
"><strong><tt>lset</tt></strong></a> command
4944 treats the content of the varName variable as a Tcl list. It addresses
4945 the index’th element in it (0 refers to the first element of the
4946 list). When interpreting the list, <a href="#_lset
"><strong><tt>lset</tt></strong></a> observes the same rules
4947 concerning braces and quotes and backslashes as the Tcl command
4948 interpreter; however, variable substitution and command substitution
4949 do not occur. The command constructs a new list in which the
4950 designated element is replaced with newValue. This new list is
4951 stored in the variable varName, and is also the return value from
4952 the <a href="#_lset
"><strong><tt>lset</tt></strong></a> command.</p></div>
4953 <div class="paragraph
"><p>If index is negative or greater than or equal to the number of
4954 elements in $varName, then an error occurs.</p></div>
4955 <div class="paragraph
"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
4956 <div class="paragraph
"><p>If additional index arguments are supplied, then each argument is
4957 used in turn to address an element within a sublist designated by
4958 the previous indexing operation, allowing the script to alter
4959 elements in sublists. The command,</p></div>
4960 <div class="literalblock
">
4961 <div class="content
">
4962 <pre><tt>lset a 1 2 newValue</tt></pre>
4964 <div class="paragraph
"><p>replaces element 2 of sublist 1 with <tt><em>newValue</em></tt>.</p></div>
4965 <div class="paragraph
"><p>The integer appearing in each index argument must be greater than
4966 or equal to zero. The integer appearing in each index argument must
4967 be strictly less than the length of the corresponding list. In other
4968 words, the <a href="#_lset
"><strong><tt>lset</tt></strong></a> command cannot change the size of a list. If an
4969 index is outside the permitted range, an error is reported.</p></div>
4972 <h3 id="_lmap
">lmap</h3>
4973 <div class="paragraph
"><p><tt><strong>lmap</strong> <em>varName list body</em></tt></p></div>
4974 <div class="paragraph
"><p><tt><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></tt></p></div>
4975 <div class="paragraph
"><p><a href="#_lmap
"><strong><tt>lmap</tt></strong></a> is a "collecting
" <a href="#_foreach
"><strong><tt>foreach</tt></strong></a> which returns a list of its results.</p></div>
4976 <div class="paragraph
"><p>For example:</p></div>
4977 <div class="literalblock
">
4978 <div class="content
">
4979 <pre><tt>jim> lmap i {1 2 3 4 5} {expr $i*$i}
4981 jim> lmap a {1 2 3} b {A B C} {list $a $b}
4982 {1 A} {2 B} {3 C}</tt></pre>
4984 <div class="paragraph
"><p>If the body invokes <a href="#_continue
"><strong><tt>continue</tt></strong></a>, no value is added for this iteration.
4985 If the body invokes <a href="#_break
"><strong><tt>break</tt></strong></a>, the loop ends and no more values are added.</p></div>
4988 <h3 id="_load
">load</h3>
4989 <div class="paragraph
"><p><tt><strong>load</strong> <em>filename</em></tt></p></div>
4990 <div class="paragraph
"><p>Loads the dynamic extension, <tt><em>filename</em></tt>. Generally the filename should have
4991 the extension <tt>.so</tt>. The initialisation function for the module must be based
4992 on the name of the file. For example loading <tt>hwaccess.so</tt> will invoke
4993 the initialisation function, <tt>Jim_hwaccessInit</tt>. Normally the <a href="#_load
"><strong><tt>load</tt></strong></a> command
4994 should not be used directly. Instead it is invoked automatically by <a href="#_package
"><strong><tt>package</tt></strong></a> <tt>require</tt>.</p></div>
4997 <h3 id="_lrange
">lrange</h3>
4998 <div class="paragraph
"><p><tt><strong>lrange</strong> <em>list first last</em></tt></p></div>
4999 <div class="paragraph
"><p><tt><em>list</em></tt> must be a valid Tcl list. This command will return a new
5000 list consisting of elements <tt><em>first</em></tt> through <tt><em>last</em></tt>, inclusive.</p></div>
5001 <div class="paragraph
"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.</p></div>
5002 <div class="paragraph
"><p>If <tt><em>last</em></tt> is greater than or equal to the number of elements
5003 in the list, then it is treated as if it were <tt>end</tt>.</p></div>
5004 <div class="paragraph
"><p>If <tt><em>first</em></tt> is greater than <tt><em>last</em></tt> then an empty string
5005 is returned.</p></div>
5006 <div class="paragraph
"><p>Note: <tt>"<a href=
"#_lrange"><strong><tt>lrange
</tt></strong></a> <em>list first first
</em>"</tt> does not always produce the
5007 same result as <tt>"<a href=
"#_lindex"><strong><tt>lindex
</tt></strong></a> <em>list first
</em>"</tt> (although it often does
5008 for simple fields that aren’t enclosed in braces); it does, however,
5009 produce exactly the same results as <tt>"<a href=
"#_list"><strong><tt>list
</tt></strong></a> [
<a href=
"#_lindex"><strong><tt>lindex
</tt></strong></a> <em>list first
</em>]
"</tt></p></div>
5012 <h3 id="_lreplace
">lreplace</h3>
5013 <div class="paragraph
"><p><tt><strong>lreplace</strong> <em>list first last ?element element ...?</em></tt></p></div>
5014 <div class="paragraph
"><p>Returns a new list formed by replacing one or more elements of
5015 <tt><em>list</em></tt> with the <tt><em>element</em></tt> arguments.</p></div>
5016 <div class="paragraph
"><p><tt><em>first</em></tt> gives the index in <tt><em>list</em></tt> of the first element
5017 to be replaced.</p></div>
5018 <div class="paragraph
"><p>If <tt><em>first</em></tt> is less than zero then it refers to the first
5019 element of <tt><em>list</em></tt>; the element indicated by <tt><em>first</em></tt>
5020 must exist in the list.</p></div>
5021 <div class="paragraph
"><p><tt><em>last</em></tt> gives the index in <tt><em>list</em></tt> of the last element
5022 to be replaced; it must be greater than or equal to <tt><em>first</em></tt>.</p></div>
5023 <div class="paragraph
"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.</p></div>
5024 <div class="paragraph
"><p>The <tt><em>element</em></tt> arguments specify zero or more new arguments to
5025 be added to the list in place of those that were deleted.</p></div>
5026 <div class="paragraph
"><p>Each <tt><em>element</em></tt> argument will become a separate element of
5028 <div class="paragraph
"><p>If no <tt><em>element</em></tt> arguments are specified, then the elements
5029 between <tt><em>first</em></tt> and <tt><em>last</em></tt> are simply deleted.</p></div>
5032 <h3 id="_lrepeat
">lrepeat</h3>
5033 <div class="paragraph
"><p><tt><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></tt></p></div>
5034 <div class="paragraph
"><p>Build a list by repeating elements <tt><em>number</em></tt> times (which must be
5035 a positive integer).</p></div>
5036 <div class="literalblock
">
5037 <div class="content
">
5038 <pre><tt>jim> lrepeat 3 a b
5039 a b a b a b</tt></pre>
5043 <h3 id="_lreverse
">lreverse</h3>
5044 <div class="paragraph
"><p><tt><strong>lreverse</strong> <em>list</em></tt></p></div>
5045 <div class="paragraph
"><p>Returns the list in reverse order.</p></div>
5046 <div class="literalblock
">
5047 <div class="content
">
5048 <pre><tt>jim> lreverse {1 2 3}
5053 <h3 id="_lsearch
">lsearch</h3>
5054 <div class="paragraph
"><p><tt><strong>lsearch</strong> <em>?options? list pattern</em></tt></p></div>
5055 <div class="paragraph
"><p>This command searches the elements <tt><em>list</em></tt> to see if one of them matches <tt><em>pattern</em></tt>. If so, the
5056 command returns the index of the first matching element (unless the options <tt>-all</tt>, <tt>-inline</tt> or <tt>-bool</tt> are
5057 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5058 the list are to be matched against pattern and must have one of the values below:</p></div>
5059 <div class="paragraph
"><p><strong>Note</strong> that this command is different from Tcl in that default match type is <tt>-exact</tt> rather than <tt>-glob</tt>.</p></div>
5060 <div class="dlist
"><dl>
5061 <dt class="hdlist1
">
5062 <tt><strong>-exact</strong></tt>
5066 <tt><em>pattern</em></tt> is a literal string that is compared for exact equality against each list element.
5067 This is the default.
5070 <dt class="hdlist1
">
5071 <tt><strong>-glob</strong></tt>
5075 <tt><em>pattern</em></tt> is a glob-style pattern which is matched against each list element using the same
5076 rules as the string match command.
5079 <dt class="hdlist1
">
5080 <tt><strong>-regexp</strong></tt>
5084 <tt><em>pattern</em></tt> is treated as a regular expression and matched against each list element using
5085 the rules described by <a href="#_regexp
"><strong><tt>regexp</tt></strong></a>.
5088 <dt class="hdlist1
">
5089 <tt><strong>-command</strong> <em>cmdname</em></tt>
5093 <tt><em>cmdname</em></tt> is a command which is used to match the pattern against each element of the
5094 list. It is invoked as <tt><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></tt> and should return 1
5095 for a match, or 0 for no match.
5098 <dt class="hdlist1
">
5099 <tt><strong>-all</strong></tt>
5103 Changes the result to be the list of all matching indices (or all matching values if
5104 <tt>-inline</tt> is specified as well). If indices are returned, the indices will be in numeric
5105 order. If values are returned, the order of the values will be the order of those values
5106 within the input list.
5109 <dt class="hdlist1
">
5110 <tt><strong>-inline</strong></tt>
5114 The matching value is returned instead of its index (or an empty string if no value
5115 matches). If <tt>-all</tt> is also specified, then the result of the command is the list of all
5116 values that matched. The <tt>-inline</tt> and <tt>-bool</tt> options are mutually exclusive.
5119 <dt class="hdlist1
">
5120 <tt><strong>-bool</strong></tt>
5124 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <tt>-all</tt> is also specified,
5125 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5126 the corresponding element matches. The <tt>-inline</tt> and <tt>-bool</tt> options are mutually exclusive.
5129 <dt class="hdlist1
">
5130 <tt><strong>-not</strong></tt>
5134 This negates the sense of the match, returning the index (or value
5135 if <tt>-inline</tt> is specified) of the first non-matching value in the
5136 list. If <tt>-bool</tt> is also specified, the <em>0</em> will be returned if a
5137 match is found, or <em>1</em> otherwise. If <tt>-all</tt> is also specified,
5138 non-matches will be returned rather than matches.
5141 <dt class="hdlist1
">
5142 <tt><strong>-nocase</strong></tt>
5146 Causes comparisons to be handled in a case-insensitive manner.
5152 <h3 id="_lsort
">lsort</h3>
5153 <div class="paragraph
"><p><tt><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-nocase!-integer|-real|-command</strong> <em>cmdname</em>? ?<strong>-unique</strong>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></tt></p></div>
5154 <div class="paragraph
"><p>Sort the elements of <tt><em>list</em></tt>, returning a new list in sorted order.
5155 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5156 <div class="paragraph
"><p>If <tt>-nocase</tt> is specified, comparisons are case-insenstive.</p></div>
5157 <div class="paragraph
"><p>If <tt>-integer</tt> is specified, numeric sorting is used.</p></div>
5158 <div class="paragraph
"><p>If <tt>-real</tt> is specified, floating point number sorting is used.</p></div>
5159 <div class="paragraph
"><p>If <tt>-command <em>cmdname</em></tt> is specified, <tt><em>cmdname</em></tt> is treated as a command
5160 name. For each comparison, <tt><em>cmdname $value1 $value2</tt></em> is called which
5161 should compare the values and return an integer less than, equal
5162 to, or greater than zero if the <tt><em>$value1</em></tt> is to be considered less
5163 than, equal to, or greater than <tt><em>$value2</em></tt>, respectively.</p></div>
5164 <div class="paragraph
"><p>If <tt>-decreasing</tt> is specified, the resulting list is in the opposite
5165 order to what it would be otherwise. <tt>-increasing</tt> is the default.</p></div>
5166 <div class="paragraph
"><p>If <tt>-unique</tt> is specified, then only the last set of duplicate elements found in the list will be retained.
5167 Note that duplicates are determined relative to the comparison used in the sort. Thus if <tt>-index 0</tt> is used,
5168 <tt>{1 a}</tt> and <tt>{1 b}</tt> would be considered duplicates and only the second element, <tt>{1 b}</tt>, would be retained.</p></div>
5169 <div class="paragraph
"><p>If <tt>-index <em>listindex</em></tt> is specified, each element of the list is treated as a list and
5170 the given index is extracted from the list for comparison. The list index may
5171 be any valid list index, such as <tt>1</tt>, <tt>end</tt> or <tt>end-2</tt>.</p></div>
5174 <h3 id="_open
">open</h3>
5175 <div class="paragraph
"><p><tt><strong>open</strong> <em>fileName ?access?</em></tt></p></div>
5176 <div class="paragraph
"><p><tt><strong>open</strong> <em>|command-pipeline ?access?</em></tt></p></div>
5177 <div class="paragraph
"><p>Opens a file and returns an identifier
5178 that may be used in future invocations
5179 of commands like <a href="#_read
"><strong><tt>read</tt></strong></a>, <a href="#_puts
"><strong><tt>puts</tt></strong></a>, and <a href="#_close
"><strong><tt>close</tt></strong></a>.
5180 <tt><em>fileName</em></tt> gives the name of the file to open.</p></div>
5181 <div class="paragraph
"><p>The <tt><em>access</em></tt> argument indicates the way in which the file is to be accessed.
5182 It may have any of the following values:</p></div>
5183 <div class="dlist
"><dl>
5184 <dt class="hdlist1
">
5189 Open the file for reading only; the file must already exist.
5192 <dt class="hdlist1
">
5197 Open the file for both reading and writing; the file must
5201 <dt class="hdlist1
">
5206 Open the file for writing only. Truncate it if it exists. If it doesn’t
5207 exist, create a new file.
5210 <dt class="hdlist1
">
5215 Open the file for reading and writing. Truncate it if it exists.
5216 If it doesn’t exist, create a new file.
5219 <dt class="hdlist1
">
5224 Open the file for writing only. The file must already exist, and the file
5225 is positioned so that new data is appended to the file.
5228 <dt class="hdlist1
">
5233 Open the file for reading and writing. If the file doesn’t
5234 exist, create a new empty file. Set the initial access position
5235 to the end of the file.
5239 <div class="paragraph
"><p><tt><em>access</em></tt> defaults to <em>r</em>.</p></div>
5240 <div class="paragraph
"><p>If a file is opened for both reading and writing, then <a href="#_seek
"><strong><tt>seek</tt></strong></a>
5241 must be invoked between a read and a write, or vice versa.</p></div>
5242 <div class="paragraph
"><p>If the first character of <tt><em>fileName</em></tt> is "|
" then the remaining
5243 characters of <tt><em>fileName</em></tt> are treated as a list of arguments that
5244 describe a command pipeline to invoke, in the same style as the
5245 arguments for exec. In this case, the channel identifier returned
5246 by open may be used to write to the command’s input pipe or read
5247 from its output pipe, depending on the value of <tt><em>access</em></tt>. If write-only
5248 access is used (e.g. <tt><em>access</em></tt> is <em>w</em>), then standard output for the
5249 pipeline is directed to the current standard output unless overridden
5250 by the command. If read-only access is used (e.g. <tt><em>access</em></tt> is r),
5251 standard input for the pipeline is taken from the current standard
5252 input unless overridden by the command.</p></div>
5253 <div class="paragraph
"><p>The <a href="#_pid
"><strong><tt>pid</tt></strong></a> command may be used to return the process ids of the commands
5254 forming the command pipeline.</p></div>
5255 <div class="paragraph
"><p>See also <a href="#_socket
"><strong><tt>socket</tt></strong></a>, <a href="#_pid
"><strong><tt>pid</tt></strong></a>, <a href="#_exec
"><strong><tt>exec</tt></strong></a></p></div>
5258 <h3 id="_package
">package</h3>
5259 <div class="paragraph
"><p><tt><strong>package provide</strong> <em>name ?version?</em></tt></p></div>
5260 <div class="paragraph
"><p>Indicates that the current script provides the package named <tt><em>name</em></tt>.
5261 If no version is specified, <em>1.0</em> is used.</p></div>
5262 <div class="paragraph
"><p>Any script which provides a package may include this statement
5263 as the first statement, although it is not required.</p></div>
5264 <div class="paragraph
"><p><tt><strong>package require</strong> <em>name ?version?</em>*</tt></p></div>
5265 <div class="paragraph
"><p>Searches for the package with the given <tt><em>name</em></tt> by examining each path
5266 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5267 or <em>$path/$name.tcl</em> as a script package.</p></div>
5268 <div class="paragraph
"><p>The first such file which is found is considered to provide the the package.
5269 (The version number is ignored).</p></div>
5270 <div class="paragraph
"><p>If <em>$name.so</em> exists, it is loaded with the <a href="#_load
"><strong><tt>load</tt></strong></a> command,
5271 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source
"><strong><tt>source</tt></strong></a> command.</p></div>
5272 <div class="paragraph
"><p>If <a href="#_load
"><strong><tt>load</tt></strong></a> or <a href="#_source
"><strong><tt>source</tt></strong></a> fails, <a href="#_package
"><strong><tt>package</tt></strong></a> <tt>require</tt> will fail immediately.
5273 No further attempt will be made to locate the file.</p></div>
5276 <h3 id="_pid
">pid</h3>
5277 <div class="paragraph
"><p><tt><strong>pid</strong></tt></p></div>
5278 <div class="paragraph
"><p><tt><strong>pid</strong> <em>fileId</em></tt></p></div>
5279 <div class="paragraph
"><p>The first form returns the process identifier of the current process.</p></div>
5280 <div class="paragraph
"><p>The second form accepts a handle returned by <a href="#_open
"><strong><tt>open</tt></strong></a> and returns a list
5281 of the process ids forming the pipeline in the same form as <a href="#_exec
"><strong><tt>exec</tt></strong></a> <tt>... &</tt>.
5282 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5283 the empty string is returned instead.</p></div>
5284 <div class="paragraph
"><p>See also <a href="#_open
"><strong><tt>open</tt></strong></a>, <a href="#_exec
"><strong><tt>exec</tt></strong></a></p></div>
5287 <h3 id="_proc
">proc</h3>
5288 <div class="paragraph
"><p><tt><strong>proc</strong> <em>name args ?statics? body</em></tt></p></div>
5289 <div class="paragraph
"><p>The <a href="#_proc
"><strong><tt>proc</tt></strong></a> command creates a new Tcl command procedure, <tt><em>name</em></tt>.
5290 When the new command is invoked, the contents of <tt><em>body</em></tt> will be executed.
5291 Tcl interpreter. <tt><em>args</em></tt> specifies the formal arguments to the procedure.
5292 If specified, <tt><em>static</em></tt>, declares static variables which are bound to the
5293 procedure.</p></div>
5294 <div class="paragraph
"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5295 <div class="paragraph
"><p>The <a href="#_proc
"><strong><tt>proc</tt></strong></a> command returns <tt><em>name</em></tt> (which is useful with <a href="#_local
"><strong><tt>local</tt></strong></a>).</p></div>
5296 <div class="paragraph
"><p>When a procedure is invoked, the procedure’s return value is the
5297 value specified in a <a href="#_return
"><strong><tt>return</tt></strong></a> command. If the procedure doesn’t
5298 execute an explicit <a href="#_return
"><strong><tt>return</tt></strong></a>, then its return value is the value
5299 of the last command executed in the procedure’s body.</p></div>
5300 <div class="paragraph
"><p>If an error occurs while executing the procedure body, then the
5301 procedure-as-a-whole will return that same error.</p></div>
5304 <h3 id="_puts
">puts</h3>
5305 <div class="paragraph
"><p><tt><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></tt></p></div>
5306 <div class="paragraph
"><p><tt><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></tt></p></div>
5307 <div class="paragraph
"><p>Writes the characters given by <tt><em>string</em></tt> to the file given
5308 by <tt><em>fileId</em></tt>. <tt><em>fileId</em></tt> must have been the return
5309 value from a previous call to <a href="#_open
"><strong><tt>open</tt></strong></a>, or it may be
5310 <tt>stdout</tt> or <tt>stderr</tt> to refer to one of the standard I/O
5311 channels; it must refer to a file that was opened for
5313 <div class="paragraph
"><p>In the first form, if no <tt><em>fileId</em></tt> is specified then it defaults to <tt>stdout</tt>.
5314 <a href="#_puts
"><strong><tt>puts</tt></strong></a> normally outputs a newline character after <tt><em>string</em></tt>,
5315 but this feature may be suppressed by specifying the <tt>-nonewline</tt>
5317 <div class="paragraph
"><p>Output to files is buffered internally by Tcl; the <a href="#_flush
"><strong><tt>flush</tt></strong></a>
5318 command may be used to force buffered characters to be output.</p></div>
5321 <h3 id="_pwd
">pwd</h3>
5322 <div class="paragraph
"><p><tt><strong>pwd</strong></tt></p></div>
5323 <div class="paragraph
"><p>Returns the path name of the current working directory.</p></div>
5326 <h3 id="_rand
">rand</h3>
5327 <div class="paragraph
"><p><tt><strong>rand</strong> <em>?min? ?max?</em></tt></p></div>
5328 <div class="paragraph
"><p>Returns a random integer between <tt><em>min</em></tt> (defaults to 0) and <tt><em>max</em></tt>
5329 (defaults to the maximum integer).</p></div>
5330 <div class="paragraph
"><p>If only one argument is given, it is interpreted as <tt><em>max</em></tt>.</p></div>
5333 <h3 id="_range
">range</h3>
5334 <div class="paragraph
"><p><tt><strong>range</strong> <em>?start? end ?step?</em></tt></p></div>
5335 <div class="paragraph
"><p>Returns a list of integers starting at <tt><em>start</em></tt> (defaults to 0)
5336 and ranging up to but not including <tt><em>end</em></tt> in steps of <tt><em>step</em></tt> defaults to 1).</p></div>
5337 <div class="literalblock
">
5338 <div class="content
">
5339 <pre><tt>jim> range 5
5343 jim> range 2 10 4
5345 jim> range 7 4 -2
5350 <h3 id="_read
">read</h3>
5351 <div class="paragraph
"><p><tt><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></tt></p></div>
5352 <div class="paragraph
"><p><tt><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</tt></p></div>
5353 <div class="paragraph
"><p><tt><strong>read</strong> <em>fileId numBytes</em></tt></p></div>
5354 <div class="paragraph
"><p><tt><em>fileId</em> <strong>read</strong> <em>numBytes</em></tt></p></div>
5355 <div class="paragraph
"><p>In the first form, all of the remaining bytes are read from the file
5356 given by <tt><em>fileId</em></tt>; they are returned as the result of the command.
5357 If the <tt>-nonewline</tt> switch is specified then the last
5358 character of the file is discarded if it is a newline.</p></div>
5359 <div class="paragraph
"><p>In the second form, the extra argument specifies how many bytes to read;
5360 exactly this many bytes will be read and returned, unless there are fewer than
5361 <tt><em>numBytes</em></tt> bytes left in the file; in this case, all the remaining
5362 bytes are returned.</p></div>
5363 <div class="paragraph
"><p><tt><em>fileId</em></tt> must be <tt>stdin</tt> or the return value from a previous call
5364 to <a href="#_open
"><strong><tt>open</tt></strong></a>; it must refer to a file that was opened for reading.</p></div>
5367 <h3 id="_regexp
">regexp</h3>
5368 <div class="paragraph
"><p><tt><strong>regexp ?-nocase? ?-line? ?-indices? ?-start</strong> <em>offset</em>? <strong>?-all? ?-inline? ?--?</strong> <em>exp string ?matchVar? ?subMatchVar subMatchVar ...?</em></tt></p></div>
5369 <div class="paragraph
"><p>Determines whether the regular expression <tt><em>exp</em></tt> matches part or
5370 all of <tt><em>string</em></tt> and returns 1 if it does, 0 if it doesn’t.</p></div>
5371 <div class="paragraph
"><p>See REGULAR EXPRESSIONS above for complete information on the
5372 syntax of <tt><em>exp</em></tt> and how it is matched against <tt><em>string</em></tt>.</p></div>
5373 <div class="paragraph
"><p>If additional arguments are specified after <tt><em>string</em></tt> then they
5374 are treated as the names of variables to use to return
5375 information about which part(s) of <tt><em>string</em></tt> matched <tt><em>exp</em></tt>.
5376 <tt><em>matchVar</em></tt> will be set to the range of <tt><em>string</em></tt> that
5377 matched all of <tt><em>exp</em></tt>. The first <tt><em>subMatchVar</em></tt> will contain
5378 the characters in <tt><em>string</em></tt> that matched the leftmost parenthesized
5379 subexpression within <tt><em>exp</em></tt>, the next <tt><em>subMatchVar</em></tt> will
5380 contain the characters that matched the next parenthesized
5381 subexpression to the right in <tt><em>exp</em></tt>, and so on.</p></div>
5382 <div class="paragraph
"><p>Normally, <tt><em>matchVar</em></tt> and the each <tt><em>subMatchVar</em></tt> are set to hold the
5383 matching characters from <a href="#_string
"><strong><tt>string</tt></strong></a>, however see <tt>-indices</tt> and
5384 <tt>-inline</tt> below.</p></div>
5385 <div class="paragraph
"><p>If there are more values for <tt><em>subMatchVar</em></tt> than parenthesized subexpressions
5386 within <tt><em>exp</em></tt>, or if a particular subexpression in <tt><em>exp</em></tt> doesn’t
5387 match the string (e.g. because it was in a portion of the expression
5388 that wasn’t matched), then the corresponding <tt><em>subMatchVar</em></tt> will be
5389 set to <tt>"-
1 -
1"</tt> if <tt>-indices</tt> has been specified or to an empty
5390 string otherwise.</p></div>
5391 <div class="paragraph
"><p>The following switches modify the behaviour of <tt><em>regexp</em></tt></p></div>
5392 <div class="dlist
"><dl>
5393 <dt class="hdlist1
">
5394 <tt><strong>-nocase</strong></tt>
5398 Causes upper-case and lower-case characters to be treated as
5399 identical during the matching process.
5402 <dt class="hdlist1
">
5403 <tt><strong>-line</strong></tt>
5407 Use newline-sensitive matching. By default, newline
5408 is a completely ordinary character with no special meaning in
5409 either REs or strings. With this flag, <tt>[<sup></tt> bracket expressions
5410 and <tt>.</tt> never match newline, a <tt></sup></tt> anchor matches the null
5411 string after any newline in the string in addition to its normal
5412 function, and the <tt>$</tt> anchor matches the null string before any
5413 newline in the string in addition to its normal function.
5416 <dt class="hdlist1
">
5417 <tt><strong>-indices</strong></tt>
5421 Changes what is stored in the subMatchVars. Instead of
5422 storing the matching characters from string, each variable
5423 will contain a list of two decimal strings giving the indices
5424 in string of the first and last characters in the matching
5425 range of characters.
5428 <dt class="hdlist1
">
5429 <tt><strong>-start</strong> <em>offset</em></tt>
5433 Specifies a character index offset into the string at which to start
5434 matching the regular expression. If <tt>-indices</tt> is
5435 specified, the indices will be indexed starting from the
5436 absolute beginning of the input string. <tt><em>offset</em></tt> will be
5437 constrained to the bounds of the input string.
5440 <dt class="hdlist1
">
5441 <tt><strong>-all</strong></tt>
5445 Causes the regular expression to be matched as many times as possible
5446 in the string, returning the total number of matches found. If this
5447 is specified with match variables, they will contain information
5448 for the last match only.
5451 <dt class="hdlist1
">
5452 <tt><strong>-inline</strong></tt>
5456 Causes the command to return, as a list, the data that would otherwise
5457 be placed in match variables. When using <tt>-inline</tt>, match variables
5458 may not be specified. If used with <tt>-all</tt>, the list will be concatenated
5459 at each iteration, such that a flat list is always returned. For
5460 each match iteration, the command will append the overall match
5461 data, plus one element for each subexpression in the regular
5465 <dt class="hdlist1
">
5466 <tt><strong>--</strong></tt>
5470 Marks the end of switches. The argument following this one will be
5471 treated as <tt><em>exp</em></tt> even if it starts with a <tt>-</tt>.
5477 <h3 id="_regsub
">regsub</h3>
5478 <div class="paragraph
"><p><tt><strong>regsub ?-nocase? ?-all? ?-line? ?-start</strong> <em>offset</em>? ?<strong>--</strong>? <em>exp string subSpec ?varName?</em></tt></p></div>
5479 <div class="paragraph
"><p>This command matches the regular expression <tt><em>exp</em></tt> against
5480 <tt><em>string</em></tt> using the rules described in REGULAR EXPRESSIONS
5482 <div class="paragraph
"><p>If <tt><em>varName</em></tt> is specified, the commands stores <tt><em>string</em></tt> to <tt><em>varName</em></tt>
5483 with the substitutions detailed below, and returns the number of
5484 substitutions made (normally 1 unless <tt>-all</tt> is specified).
5485 This is 0 if there were no matches.</p></div>
5486 <div class="paragraph
"><p>If <tt><em>varName</em></tt> is not specified, the substituted string will be returned
5488 <div class="paragraph
"><p>When copying <tt><em>string</em></tt>, the portion of <tt><em>string</em></tt> that
5489 matched <tt><em>exp</em></tt> is replaced with <tt><em>subSpec</em></tt>.
5490 If <tt><em>subSpec</em></tt> contains a <tt>&</tt> or <tt>\0</tt>, then it is replaced
5491 in the substitution with the portion of <tt><em>string</em></tt> that
5492 matched <tt><em>exp</em></tt>.</p></div>
5493 <div class="paragraph
"><p>If <tt><em>subSpec</em></tt> contains a <tt>\n</tt>, where <tt><em>n</em></tt> is a digit
5494 between 1 and 9, then it is replaced in the substitution with
5495 the portion of <tt><em>string</em></tt> that matched the <tt><em>n</em></tt>'-th
5496 parenthesized subexpression of <tt><em>exp</em></tt>.
5497 Additional backslashes may be used in <tt><em>subSpec</em></tt> to prevent special
5498 interpretation of <tt>&</tt> or <tt>\0</tt> or <tt>\n</tt> or
5499 backslash.</p></div>
5500 <div class="paragraph
"><p>The use of backslashes in <tt><em>subSpec</em></tt> tends to interact badly
5501 with the Tcl parser’s use of backslashes, so it’s generally
5502 safest to enclose <tt><em>subSpec</em></tt> in braces if it includes
5503 backslashes.</p></div>
5504 <div class="paragraph
"><p>The following switches modify the behaviour of <tt><em>regsub</em></tt></p></div>
5505 <div class="dlist
"><dl>
5506 <dt class="hdlist1
">
5507 <tt><strong>-nocase</strong></tt>
5511 Upper-case characters in <tt><em>string</em></tt> are converted to lower-case
5512 before matching against <tt><em>exp</em></tt>; however, substitutions
5513 specified by <tt><em>subSpec</em></tt> use the original unconverted form
5514 of <tt><em>string</em></tt>.
5517 <dt class="hdlist1
">
5518 <tt><strong>-all</strong></tt>
5522 All ranges in <tt><em>string</em></tt> that match <tt><em>exp</em></tt> are found and substitution
5523 is performed for each of these ranges, rather than only the
5524 first. The <tt>&</tt> and <tt>\n</tt> sequences are handled for
5525 each substitution using the information from the corresponding
5529 <dt class="hdlist1
">
5530 <tt><strong>-line</strong></tt>
5534 Use newline-sensitive matching. By default, newline
5535 is a completely ordinary character with no special meaning in
5536 either REs or strings. With this flag, <tt>[<sup></tt> bracket expressions
5537 and <tt>.</tt> never match newline, a <tt></sup></tt> anchor matches the null
5538 string after any newline in the string in addition to its normal
5539 function, and the <tt>$</tt> anchor matches the null string before any
5540 newline in the string in addition to its normal function.
5543 <dt class="hdlist1
">
5544 <tt><strong>-start</strong> <em>offset</em></tt>
5548 Specifies a character index offset into the string at which to
5549 start matching the regular expression. <tt><em>offset</em></tt> will be
5550 constrained to the bounds of the input string.
5553 <dt class="hdlist1
">
5554 <tt><strong>--</strong></tt>
5558 Marks the end of switches. The argument following this one will be
5559 treated as <tt><em>exp</em></tt> even if it starts with a <tt>-</tt>.
5565 <h3 id="_ref
">ref</h3>
5566 <div class="paragraph
"><p><tt><strong>ref</strong> <em>string tag ?finalizer?</em></tt></p></div>
5567 <div class="paragraph
"><p>Create a new reference containing <tt><em>string</em></tt> of type <tt><em>tag</em></tt>.
5568 If <tt><em>finalizer</em></tt> is specified, it is a command which will be invoked
5569 when the a garbage collection cycle runs and this reference is
5570 no longer accessible.</p></div>
5571 <div class="paragraph
"><p>The finalizer is invoked as:</p></div>
5572 <div class="literalblock
">
5573 <div class="content
">
5574 <pre><tt>finalizer reference string</tt></pre>
5576 <div class="paragraph
"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5579 <h3 id="_rename
">rename</h3>
5580 <div class="paragraph
"><p><tt><strong>rename</strong> <em>oldName newName</em></tt></p></div>
5581 <div class="paragraph
"><p>Rename the command that used to be called <tt><em>oldName</em></tt> so that it
5582 is now called <tt><em>newName</em></tt>. If <tt><em>newName</em></tt> is an empty string
5583 (e.g. {}) then <tt><em>oldName</em></tt> is deleted. The <a href="#_rename
"><strong><tt>rename</tt></strong></a> command
5584 returns an empty string as result.</p></div>
5587 <h3 id="_return
">return</h3>
5588 <div class="paragraph
"><p><tt><strong>return</strong> ?<strong>-code</strong> <em>code</em>? ?<strong>-errorinfo</strong> <em>stacktrace</em>? ?<strong>-errorcode</strong> <em>errorcode</em>? ?<strong>-level</strong> <em>n</em>? ?<em>value</em>?</tt></p></div>
5589 <div class="paragraph
"><p>Return immediately from the current procedure (or top-level command
5590 or <a href="#_source
"><strong><tt>source</tt></strong></a> command), with <tt><em>value</em></tt> as the return value. If <tt><em>value</em></tt>
5591 is not specified, an empty string will be returned as result.</p></div>
5592 <div class="paragraph
"><p>If <tt>-code</tt> is specified (as either a number or ok, error, break,
5593 continue, signal, return or exit), this code will be used instead
5594 of <tt>JIM_OK</tt>. This is generally useful when implementing flow of control
5596 <div class="paragraph
"><p>If <tt>-level</tt> is specified and greater than 1, it has the effect of delaying
5597 the new return code from <tt>-code</tt>. This is useful when rethrowing an error
5598 from <a href="#_catch
"><strong><tt>catch</tt></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5599 an example of how this is done.</p></div>
5600 <div class="paragraph
"><p>Note: The following options are only used when <tt>-code</tt> is JIM_ERR.</p></div>
5601 <div class="paragraph
"><p>If <tt>-errorinfo</tt> is specified (as returned from <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt>)
5602 it is used to initialize the stacktrace.</p></div>
5603 <div class="paragraph
"><p>If <tt>-errorcode</tt> is specified, it is used to set the global variable $::errorCode.</p></div>
5606 <h3 id="_scan
">scan</h3>
5607 <div class="paragraph
"><p><tt><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></tt></p></div>
5608 <div class="paragraph
"><p>This command parses fields from an input string in the same fashion
5609 as the C <em>sscanf</em> procedure. <tt><em>string</em></tt> gives the input to be parsed
5610 and <tt><em>format</em></tt> indicates how to parse it, using <em>%</em> fields as in
5611 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5612 man page for details. Each <tt><em>varName</em></tt> gives the name of a variable;
5613 when a field is scanned from <tt><em>string</em></tt>, the result is converted back
5614 into a string and assigned to the corresponding <tt><em>varName</em></tt>. The
5615 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5616 character value is converted to a decimal string, which is then
5617 assigned to the corresponding <tt><em>varName</em></tt>; no field width may be
5618 specified for this conversion.</p></div>
5621 <h3 id="_seek
">seek</h3>
5622 <div class="paragraph
"><p><tt><strong>seek</strong> <em>fileId offset ?origin?</em></tt></p></div>
5623 <div class="paragraph
"><p><tt><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></tt></p></div>
5624 <div class="paragraph
"><p>Change the current access position for <tt><em>fileId</em></tt>.
5625 The <tt><em>offset</em></tt> and <tt><em>origin</em></tt> arguments specify the position at
5626 which the next read or write will occur for <tt><em>fileId</em></tt>.
5627 <tt><em>offset</em></tt> must be a number (which may be negative) and <tt><em>origin</em></tt>
5628 must be one of the following:</p></div>
5629 <div class="dlist
"><dl>
5630 <dt class="hdlist1
">
5631 <tt><strong>start</strong></tt>
5635 The new access position will be <tt><em>offset</em></tt> bytes from the start
5639 <dt class="hdlist1
">
5640 <tt><strong>current</strong></tt>
5644 The new access position will be <tt><em>offset</em></tt> bytes from the current
5645 access position; a negative <tt><em>offset</em></tt> moves the access position
5646 backwards in the file.
5649 <dt class="hdlist1
">
5650 <tt><strong>end</strong></tt>
5654 The new access position will be <tt><em>offset</em></tt> bytes from the end of
5655 the file. A negative <tt><em>offset</em></tt> places the access position before
5656 the end-of-file, and a positive <tt><em>offset</em></tt> places the access position
5657 after the end-of-file.
5661 <div class="paragraph
"><p>The <tt><em>origin</em></tt> argument defaults to <tt>start</tt>.</p></div>
5662 <div class="paragraph
"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to
5663 <a href="#_open
"><strong><tt>open</tt></strong></a>, or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one
5664 of the standard I/O channels.</p></div>
5665 <div class="paragraph
"><p>This command returns an empty string.</p></div>
5668 <h3 id="_set
">set</h3>
5669 <div class="paragraph
"><p><tt><strong>set</strong> <em>varName ?value?</em></tt></p></div>
5670 <div class="paragraph
"><p>Returns the value of variable <tt><em>varName</em></tt>.</p></div>
5671 <div class="paragraph
"><p>If <tt><em>value</em></tt> is specified, then set the value of <tt><em>varName</em></tt> to <tt><em>value</em></tt>,
5672 creating a new variable if one doesn’t already exist, and return
5673 its value.</p></div>
5674 <div class="paragraph
"><p>If <tt><em>varName</em></tt> contains an open parenthesis and ends with a
5675 close parenthesis, then it refers to an array element: the characters
5676 before the open parenthesis are the name of the array, and the characters
5677 between the parentheses are the index within the array.
5678 Otherwise <tt><em>varName</em></tt> refers to a scalar variable.</p></div>
5679 <div class="paragraph
"><p>If no procedure is active, then <tt><em>varName</em></tt> refers to a global
5681 <div class="paragraph
"><p>If a procedure is active, then <tt><em>varName</em></tt> refers to a parameter
5682 or local variable of the procedure, unless the <tt><em>global</em></tt> command
5683 has been invoked to declare <tt><em>varName</em></tt> to be global.</p></div>
5684 <div class="paragraph
"><p>The <tt>::</tt> prefix may also be used to explicitly reference a variable
5685 in the global scope.</p></div>
5688 <h3 id="_setref
">setref</h3>
5689 <div class="paragraph
"><p><tt><strong>setref</strong> <em>reference string</em></tt></p></div>
5690 <div class="paragraph
"><p>Store a new string in <tt><em>reference</em></tt>, replacing the existing string.
5691 The reference must be a valid reference create with the <a href="#_ref
"><strong><tt>ref</tt></strong></a>
5693 <div class="paragraph
"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5696 <h3 id="_signal
">signal</h3>
5697 <div class="paragraph
"><p>Command for signal handling.</p></div>
5698 <div class="paragraph
"><p>See <a href="#_kill
"><strong><tt>kill</tt></strong></a> for the different forms which may be used to specify signals.</p></div>
5699 <div class="paragraph
"><p>Commands which return a list of signal names do so using the canonical form:
5700 "<tt>SIGINT SIGTERM
</tt>".</p></div>
5701 <div class="dlist
"><dl>
5702 <dt class="hdlist1
">
5703 <tt><strong>signal handle</strong> ?<em>signals ...</em>?</tt>
5707 If no signals are given, returns a list of all signals which are currently
5709 If signals are specified, these are added to the list of signals currently
5713 <dt class="hdlist1
">
5714 <tt><strong>signal ignore</strong> ?<em>signals ...</em>?</tt>
5718 If no signals are given, returns a lists all signals which are currently
5720 If signals are specified, these are added to the list of signals
5721 currently being ignored. These signals are still delivered, but
5722 are not considered by <a href="#_catch
"><strong><tt>catch</tt></strong></a> <tt>-signal</tt> or <a href="#_try
"><strong><tt>try</tt></strong></a> <tt>-signal</tt>. Use
5723 <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>check</tt> to determine which signals have occurred but
5727 <dt class="hdlist1
">
5728 <tt><strong>signal default</strong> ?<em>signals ...</em>?</tt>
5732 If no signals are given, returns a lists all signals which are currently have
5733 the default behaviour.
5734 If signals are specified, these are added to the list of signals which have
5735 the default behaviour.
5738 <dt class="hdlist1
">
5739 <tt><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</tt>
5743 Returns a list of signals which have been delivered to the process
5744 but are <em>ignored</em>. If signals are specified, only that set of signals will
5745 be checked, otherwise all signals will be checked.
5746 If <tt>-clear</tt> is specified, any signals returned are removed and will not be
5747 returned by subsequent calls to <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>check</tt> unless delivered again.
5750 <dt class="hdlist1
">
5751 <tt><strong>signal throw</strong> ?<em>signal</em>?</tt>
5755 Raises the given signal, which defaults to <tt>SIGINT</tt> if not specified.
5756 The behaviour is identical to:
5758 <div class="literalblock
">
5759 <div class="content
">
5760 <pre><tt>kill signal [pid]</tt></pre>
5764 <div class="paragraph
"><p>Note that <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>handle</tt> and <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>ignore</tt> represent two forms of signal
5765 handling. <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>handle</tt> is used in conjunction with <a href="#_catch
"><strong><tt>catch</tt></strong></a> <tt>-signal</tt> or <a href="#_try
"><strong><tt>try</tt></strong></a> <tt>-signal</tt>
5766 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>ignore</tt>
5767 is used in conjunction with <a href="#_signal
"><strong><tt>signal</tt></strong></a> <tt>check</tt> to handle signal synchronously. Consider the
5768 two examples below.</p></div>
5769 <div class="paragraph
"><p>Prevent a processing from taking too long</p></div>
5770 <div class="literalblock
">
5771 <div class="content
">
5772 <pre><tt>signal handle SIGALRM
5775 .. possibly long running process ..
5778 puts stderr "Process took too long
"
5781 <div class="paragraph
"><p>Handle SIGHUP to reconfigure:</p></div>
5782 <div class="literalblock
">
5783 <div class="content
">
5784 <pre><tt>signal ignore SIGHUP
5786 ... handle configuration/reconfiguration ...
5787 while {[signal check -clear SIGHUP] eq ""} {
5788 ... do processing ..
5790 # Received SIGHUP, so reconfigure
5795 <h3 id="_sleep
">sleep</h3>
5796 <div class="paragraph
"><p><tt><strong>sleep</strong> <em>seconds</em></tt></p></div>
5797 <div class="paragraph
"><p>Pauses for the given number of seconds, which may be a floating
5798 point value less than one to sleep for less than a second, or an
5799 integer to sleep for one or more seconds.</p></div>
5802 <h3 id="_source
">source</h3>
5803 <div class="paragraph
"><p><tt><strong>source</strong> <em>fileName</em></tt></p></div>
5804 <div class="paragraph
"><p>Read file <tt><em>fileName</em></tt> and pass the contents to the Tcl interpreter
5805 as a sequence of commands to execute in the normal fashion. The return
5806 value of <a href="#_source
"><strong><tt>source</tt></strong></a> is the return value of the last command executed
5807 from the file. If an error occurs in executing the contents of the
5808 file, then the <a href="#_source
"><strong><tt>source</tt></strong></a> command will return that error.</p></div>
5809 <div class="paragraph
"><p>If a <a href="#_return
"><strong><tt>return</tt></strong></a> command is invoked from within the file, the remainder of
5810 the file will be skipped and the <a href="#_source
"><strong><tt>source</tt></strong></a> command will return
5811 normally with the result from the <a href="#_return
"><strong><tt>return</tt></strong></a> command.</p></div>
5814 <h3 id="_split
">split</h3>
5815 <div class="paragraph
"><p><tt><strong>split</strong> <em>string ?splitChars?</em></tt></p></div>
5816 <div class="paragraph
"><p>Returns a list created by splitting <tt><em>string</em></tt> at each character
5817 that is in the <tt><em>splitChars</em></tt> argument.</p></div>
5818 <div class="paragraph
"><p>Each element of the result list will consist of the
5819 characters from <tt><em>string</em></tt> between instances of the
5820 characters in <tt><em>splitChars</em></tt>.</p></div>
5821 <div class="paragraph
"><p>Empty list elements will be generated if <tt><em>string</em></tt> contains
5822 adjacent characters in <tt><em>splitChars</em></tt>, or if the first or last
5823 character of <tt><em>string</em></tt> is in <tt><em>splitChars</em></tt>.</p></div>
5824 <div class="paragraph
"><p>If <tt><em>splitChars</em></tt> is an empty string then each character of
5825 <tt><em>string</em></tt> becomes a separate element of the result list.</p></div>
5826 <div class="paragraph
"><p><tt><em>splitChars</em></tt> defaults to the standard white-space characters.
5827 For example,</p></div>
5828 <div class="literalblock
">
5829 <div class="content
">
5830 <pre><tt>split "comp.unix.misc
" .</tt></pre>
5832 <div class="paragraph
"><p>returns <tt><em>"comp unix misc
"</em></tt> and</p></div>
5833 <div class="literalblock
">
5834 <div class="content
">
5835 <pre><tt>split "Hello world
" {}</tt></pre>
5837 <div class="paragraph
"><p>returns <tt><em>"H e l l o { } w o r l d
"</em></tt>.</p></div>
5840 <h3 id="_stackdump
">stackdump</h3>
5841 <div class="paragraph
"><p><tt><strong>stackdump</strong> <em>stacktrace</em></tt></p></div>
5842 <div class="paragraph
"><p>Creates a human readable representation of a stack trace.</p></div>
5845 <h3 id="_stacktrace
">stacktrace</h3>
5846 <div class="paragraph
"><p><tt><strong>stacktrace</strong></tt></p></div>
5847 <div class="paragraph
"><p>Returns a live stack trace as a list of <tt>proc file line proc file line ...</tt>.
5848 Iteratively uses <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>frame</tt> to create the stack trace. This stack trace is in the
5849 same form as produced by <a href="#_catch
"><strong><tt>catch</tt></strong></a> and <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>stacktrace</tt></p></div>
5850 <div class="paragraph
"><p>See also <a href="#_stackdump
"><strong><tt>stackdump</tt></strong></a>.</p></div>
5853 <h3 id="_string
">string</h3>
5854 <div class="paragraph
"><p><tt><strong>string</strong> <em>option arg ?arg ...?</em></tt></p></div>
5855 <div class="paragraph
"><p>Perform one of several string operations, depending on <tt><em>option</em></tt>.
5856 The legal options (which may be abbreviated) are:</p></div>
5857 <div class="dlist
"><dl>
5858 <dt class="hdlist1
">
5859 <tt><strong>string bytelength</strong> <em>string</em></tt>
5863 Returns the length of the string in bytes. This will return
5864 the same value as <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>length</tt> if UTF-8 support is not enabled,
5865 or if the string is composed entirely of ASCII characters.
5866 See UTF-8 AND UNICODE.
5869 <dt class="hdlist1
">
5870 <tt><strong>string byterange</strong> <em>string first last</em></tt>
5874 Like <a href="#_string
"><strong><tt>string</tt></strong></a> <tt>range</tt> except works on bytes rather than characters.
5875 These commands are identical if UTF-8 support is not enabled.
5878 <dt class="hdlist1
">
5879 <tt><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></tt>
5883 Perform a character-by-character comparison of strings <tt><em>string1</em></tt> and
5884 <tt><em>string2</em></tt> in the same way as the C <em>strcmp</em> procedure. Return
5885 -1, 0, or 1, depending on whether <tt><em>string1</em></tt> is lexicographically
5886 less than, equal to, or greater than <tt><em>string2</em></tt>. If <tt>-length</tt>
5887 is specified, then only the first <tt><em>len</em></tt> characters are used
5888 in the comparison. If <tt><em>len</em></tt> is negative, it is ignored.
5889 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
5892 <dt class="hdlist1
">
5893 <tt><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></tt>
5897 Returns 1 if the strings are equal, or 0 otherwise. If <tt>-length</tt>
5898 is specified, then only the first <tt><em>len</em></tt> characters are used
5899 in the comparison. If <tt><em>len</em></tt> is negative, it is ignored.
5900 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
5903 <dt class="hdlist1
">
5904 <tt><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></tt>
5908 Search <tt><em>string2</em></tt> for a sequence of characters that exactly match
5909 the characters in <tt><em>string1</em></tt>. If found, return the index of the
5910 first character in the first such match within <tt><em>string2</em></tt>. If not
5911 found, return -1. If <tt><em>firstIndex</em></tt> is specified, matching will start
5912 from <tt><em>firstIndex</em></tt> of <tt><em>string1</em></tt>.
5915 <dt class="hdlist1
">
5920 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>firstIndex</em></tt>.
5923 <dt class="hdlist1
">
5924 <tt><strong>string index</strong> <em>string charIndex</em></tt>
5928 Returns the <tt><em>charIndex</em></tt><em>th character of the <tt>'string</em></tt>
5929 argument. A <tt><em>charIndex</em></tt> of 0 corresponds to the first
5930 character of the string.
5931 If <tt><em>charIndex</em></tt> is less than 0 or greater than
5932 or equal to the length of the string then an empty string is
5936 <dt class="hdlist1
">
5941 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>charIndex</em></tt>.
5944 <dt class="hdlist1
">
5945 <tt><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></tt>
5949 Returns 1 if <tt><em>string</em></tt> is a valid member of the specified character
5950 class, otherwise returns 0. If <tt>-strict</tt> is specified, then an
5951 empty string returns 0, otherwise an empty string will return 1
5952 on any class. The following character classes are recognized
5953 (the class name can be abbreviated):
5956 <dt class="hdlist1
">
5960 <div class="dlist
"><dl>
5961 <dt class="hdlist1
">
5966 Any alphabet or digit character.
5969 <dt class="hdlist1
">
5974 Any alphabet character.
5977 <dt class="hdlist1
">
5982 Any character with a value less than 128 (those that are in the 7-bit ascii range).
5985 <dt class="hdlist1
">
5990 Any control character.
5993 <dt class="hdlist1
">
5998 Any digit character.
6001 <dt class="hdlist1
">
6006 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6007 In case of under/overflow in the value, 0 is returned.
6010 <dt class="hdlist1
">
6015 Any printing character, except space.
6018 <dt class="hdlist1
">
6023 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6026 <dt class="hdlist1
">
6031 Any lower case alphabet character.
6034 <dt class="hdlist1
">
6039 Any printing character, including space.
6042 <dt class="hdlist1
">
6047 Any punctuation character.
6050 <dt class="hdlist1
">
6055 Any space character.
6058 <dt class="hdlist1
">
6063 Any upper case alphabet character.
6066 <dt class="hdlist1
">
6071 Any hexadecimal digit character ([0-9A-Fa-f]).
6076 <dt class="hdlist1
">
6081 Note that string classification does <tt><em>not</em></tt> respect UTF-8. See UTF-8 AND UNICODE
6084 <dt class="hdlist1
">
6085 <tt><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></tt>
6089 Search <tt><em>string2</em></tt> for a sequence of characters that exactly match
6090 the characters in <tt><em>string1</em></tt>. If found, return the index of the
6091 first character in the last such match within <tt><em>string2</em></tt>. If there
6092 is no match, then return -1. If <tt><em>lastIndex</em></tt> is specified, only characters
6093 up to <tt><em>lastIndex</em></tt> of <tt><em>string2</em></tt> will be considered in the match.
6096 <dt class="hdlist1
">
6101 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>lastIndex</em></tt>.
6104 <dt class="hdlist1
">
6105 <tt><strong>string length</strong> <em>string</em></tt>
6109 Returns a decimal string giving the number of characters in <tt><em>string</em></tt>.
6110 If UTF-8 support is enabled, this may be different than the number of bytes.
6111 See UTF-8 AND UNICODE
6114 <dt class="hdlist1
">
6115 <tt><strong>string map ?-nocase?</strong> <em>mapping string</em></tt>
6119 Replaces substrings in <tt><em>string</em></tt> based on the key-value pairs in
6120 <tt><em>mapping</em></tt>, which is a list of <tt>key value key value ...</tt> as in the form
6121 returned by <a href="#_array
"><strong><tt>array</tt></strong></a> <tt>get</tt>. Each instance of a key in the string will be
6122 replaced with its corresponding value. If <tt>-nocase</tt> is specified, then
6123 matching is done without regard to case differences. Both key and value may
6124 be multiple characters. Replacement is done in an ordered manner, so the
6125 key appearing first in the list will be checked first, and so on. <tt><em>string</em></tt> is
6126 only iterated over once, so earlier key replacements will have no affect for
6127 later key matches. For example,
6129 <div class="literalblock
">
6130 <div class="content
">
6131 <pre><tt>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</tt></pre>
6134 <dt class="hdlist1
">
6139 will return the string <tt>01321221</tt>.
6142 <dt class="hdlist1
">
6147 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6148 one. So if the previous example is reordered like this,
6150 <div class="literalblock
">
6151 <div class="content
">
6152 <pre><tt>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</tt></pre>
6155 <dt class="hdlist1
">
6160 it will return the string <tt>02c322c222c</tt>.
6163 <dt class="hdlist1
">
6164 <tt><strong>string match ?-nocase?</strong> <em>pattern string</em></tt>
6168 See if <tt><em>pattern</em></tt> matches <tt><em>string</em></tt>; return 1 if it does, 0
6169 if it doesn’t. Matching is done in a fashion similar to that
6170 used by the C-shell. For the two strings to match, their contents
6171 must be identical except that the following special sequences
6172 may appear in <tt><em>pattern</em></tt>:
6174 <div class="dlist
"><dl>
6175 <dt class="hdlist1
">
6180 Matches any sequence of characters in <tt><em>string</em></tt>,
6181 including a null string.
6184 <dt class="hdlist1
">
6189 Matches any single character in <tt><em>string</em></tt>.
6192 <dt class="hdlist1
">
6193 <tt>[<em>chars</em>]</tt>
6197 Matches any character in the set given by <tt><em>chars</em></tt>.
6198 If a sequence of the form <tt><em>x-y</em></tt> appears in <tt><em>chars</em></tt>,
6199 then any character between <tt><em>x</em></tt> and <tt><em>y</em></tt>, inclusive,
6203 <dt class="hdlist1
">
6208 Matches the single character <tt><em>x</em></tt>. This provides a way of
6209 avoiding the special interpretation of the characters <tt>\*?[]</tt>
6210 in <tt><em>pattern</em></tt>.
6215 <dt class="hdlist1
">
6220 Performs a case-insensitive comparison if <tt>-nocase</tt> is specified.
6223 <dt class="hdlist1
">
6224 <tt><strong>string range</strong> <em>string first last</em></tt>
6228 Returns a range of consecutive characters from <tt><em>string</em></tt>, starting
6229 with the character whose index is <tt><em>first</em></tt> and ending with the
6230 character whose index is <tt><em>last</em></tt>. An index of 0 refers to the
6231 first character of the string.
6234 <dt class="hdlist1
">
6239 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>first</em></tt> and <tt><em>last</em></tt>.
6242 <dt class="hdlist1
">
6247 If <tt><em>first</em></tt> is less than zero then it is treated as if it were zero, and
6248 if <tt><em>last</em></tt> is greater than or equal to the length of the string then
6249 it is treated as if it were <tt>end</tt>. If <tt><em>first</em></tt> is greater than
6250 <tt><em>last</em></tt> then an empty string is returned.
6253 <dt class="hdlist1
">
6254 <tt><strong>string repeat</strong> <em>string count</em></tt>
6258 Returns a new string consisting of <tt><em>string</em></tt> repeated <tt><em>count</em></tt> times.
6261 <dt class="hdlist1
">
6262 <tt><strong>string replace</strong> <em>string first last ?newstring?</em></tt>
6266 Removes a range of consecutive characters from <tt><em>string</em></tt>, starting
6267 with the character whose index is <tt><em>first</em></tt> and ending with the
6268 character whose index is <tt><em>last</em></tt>. If <tt><em>newstring</em></tt> is specified,
6269 then it is placed in the removed character range. If <tt><em>first</em></tt> is
6270 less than zero then it is treated as if it were zero, and if <tt><em>last</em></tt>
6271 is greater than or equal to the length of the string then it is
6272 treated as if it were <tt>end</tt>. If <tt><em>first</em></tt> is greater than <tt><em>last</em></tt>
6273 or the length of the initial string, or <tt><em>last</em></tt> is less than 0,
6274 then the initial string is returned untouched.
6277 <dt class="hdlist1
">
6278 <tt><strong>string reverse</strong> <em>string</em></tt>
6282 Returns a string that is the same length as <tt><em>string</em></tt> but
6283 with its characters in the reverse order.
6286 <dt class="hdlist1
">
6287 <tt><strong>string tolower</strong> <em>string</em></tt>
6291 Returns a value equal to <tt><em>string</em></tt> except that all upper case
6292 letters have been converted to lower case.
6295 <dt class="hdlist1
">
6296 <tt><strong>string totitle</strong> <em>string</em></tt>
6300 Returns a value equal to <tt><em>string</em></tt> except that the first character
6301 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6302 and all remaining characters have been converted to lower case.
6305 <dt class="hdlist1
">
6306 <tt><strong>string toupper</strong> <em>string</em></tt>
6310 Returns a value equal to <tt><em>string</em></tt> except that all lower case
6311 letters have been converted to upper case.
6314 <dt class="hdlist1
">
6315 <tt><strong>string trim</strong> <em>string ?chars?</em></tt>
6319 Returns a value equal to <tt><em>string</em></tt> except that any leading
6320 or trailing characters from the set given by <tt><em>chars</em></tt> are
6322 If <tt><em>chars</em></tt> is not specified then white space is removed
6323 (spaces, tabs, newlines, and carriage returns).
6326 <dt class="hdlist1
">
6327 <tt><strong>string trimleft</strong> <em>string ?chars?</em></tt>
6331 Returns a value equal to <tt><em>string</em></tt> except that any
6332 leading characters from the set given by <tt><em>chars</em></tt> are
6334 If <tt><em>chars</em></tt> is not specified then white space is removed
6335 (spaces, tabs, newlines, and carriage returns).
6338 <dt class="hdlist1
">
6339 <tt><strong>string trimright</strong> <em>string ?chars?</em></tt>
6343 Returns a value equal to <tt><em>string</em></tt> except that any
6344 trailing characters from the set given by <tt><em>chars</em></tt> are
6346 If <tt><em>chars</em></tt> is not specified then white space is removed
6347 (spaces, tabs, newlines, and carriage returns).
6348 Null characters are always removed.
6354 <h3 id="_subst
">subst</h3>
6355 <div class="paragraph
"><p><tt><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></tt></p></div>
6356 <div class="paragraph
"><p>This command performs variable substitutions, command substitutions,
6357 and backslash substitutions on its string argument and returns the
6358 fully-substituted result. The substitutions are performed in exactly
6359 the same way as for Tcl commands. As a result, the string argument
6360 is actually substituted twice, once by the Tcl parser in the usual
6361 fashion for Tcl commands, and again by the subst command.</p></div>
6362 <div class="paragraph
"><p>If any of the <tt>-nobackslashes</tt>, <tt>-nocommands</tt>, or <tt>-novariables</tt> are
6363 specified, then the corresponding substitutions are not performed.
6364 For example, if <tt>-nocommands</tt> is specified, no command substitution
6365 is performed: open and close brackets are treated as ordinary
6366 characters with no special interpretation.</p></div>
6367 <div class="paragraph
"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6368 special treatment to double quotes or curly braces. For example,
6369 the following script returns <tt>xyz {44}</tt>, not <tt>xyz {$a}</tt>.</p></div>
6370 <div class="literalblock
">
6371 <div class="content
">
6373 subst {xyz {$a}}</tt></pre>
6377 <h3 id="_switch
">switch</h3>
6378 <div class="paragraph
"><p><tt><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></tt></p></div>
6379 <div class="paragraph
"><p><tt><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></tt></p></div>
6380 <div class="paragraph
"><p>The <a href="#_switch
"><strong><tt>switch</tt></strong></a> command matches its string argument against each of
6381 the pattern arguments in order. As soon as it finds a pattern that
6382 matches string it evaluates the following body and returns the
6383 result of that evaluation. If the last pattern argument is default
6384 then it matches anything. If no pattern argument matches string and
6385 no default is given, then the <a href="#_switch
"><strong><tt>switch</tt></strong></a> command returns an empty string.
6386 If the initial arguments to switch start with - then they are treated
6387 as options. The following options are currently supported:</p></div>
6388 <div class="dlist
"><dl>
6389 <dt class="hdlist1
">
6394 Use exact matching when comparing string to a
6395 pattern. This is the default.
6398 <dt class="hdlist1
">
6403 When matching string to the patterns, use glob-style
6404 matching (i.e. the same as implemented by the string
6408 <dt class="hdlist1
">
6413 When matching string to the patterns, use regular
6414 expression matching (i.e. the same as implemented
6415 by the regexp command).
6418 <dt class="hdlist1
">
6419 <tt>-command <em>commandname</em></tt>
6423 When matching string to the patterns, use the given command, which
6424 must be a single word. The command is invoked as
6425 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6426 and must return 1 if matched, or 0 if not.
6429 <dt class="hdlist1
">
6434 Marks the end of options. The argument following
6435 this one will be treated as string even if it starts
6440 <div class="paragraph
"><p>Two syntaxes are provided for the pattern and body arguments. The
6441 first uses a separate argument for each of the patterns and commands;
6442 this form is convenient if substitutions are desired on some of the
6443 patterns or commands. The second form places all of the patterns
6444 and commands together into a single argument; the argument must
6445 have proper list structure, with the elements of the list being the
6446 patterns and commands. The second form makes it easy to construct
6447 multi-line <a href="#_switch
"><strong><tt>switch</tt></strong></a> commands, since the braces around the whole list
6448 make it unnecessary to include a backslash at the end of each line.
6449 Since the pattern arguments are in braces in the second form, no
6450 command or variable substitutions are performed on them; this makes
6451 the behaviour of the second form different than the first form in
6452 some cases.</p></div>
6453 <div class="paragraph
"><p>If a body is specified as <tt>-</tt> it means that the body for the next
6454 pattern should also be used as the body for this pattern (if the
6455 next pattern also has a body of <tt>-</tt> then the body after that is
6456 used, and so on). This feature makes it possible to share a single
6457 body among several patterns.</p></div>
6458 <div class="paragraph
"><p>Below are some examples of <a href="#_switch
"><strong><tt>switch</tt></strong></a> commands:</p></div>
6459 <div class="literalblock
">
6460 <div class="content
">
6461 <pre><tt>switch abc a - b {format 1} abc {format 2} default {format 3}</tt></pre>
6463 <div class="paragraph
"><p>will return 2,</p></div>
6464 <div class="literalblock
">
6465 <div class="content
">
6466 <pre><tt>switch -regexp aaab {
6473 <div class="paragraph
"><p>will return 1, and</p></div>
6474 <div class="literalblock
">
6475 <div class="content
">
6476 <pre><tt>switch xyz {
6483 <div class="paragraph
"><p>will return 3.</p></div>
6486 <h3 id="_tailcall
">tailcall</h3>
6487 <div class="paragraph
"><p><tt><strong>tailcall</strong> <em>cmd ?arg...?</em></tt></p></div>
6488 <div class="paragraph
"><p>The <a href="#_tailcall
"><strong><tt>tailcall</tt></strong></a> command provides an optimised way of invoking a command whilst replacing
6489 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6490 <div class="paragraph
"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6491 <div class="literalblock
">
6492 <div class="content
">
6493 <pre><tt>tailcall a b c</tt></pre>
6495 <div class="literalblock
">
6496 <div class="content
">
6497 <pre><tt>return [uplevel 1 [list a b c]]</tt></pre>
6499 <div class="paragraph
"><p><a href="#_tailcall
"><strong><tt>tailcall</tt></strong></a> is useful as a dispatch mechanism:</p></div>
6500 <div class="literalblock
">
6501 <div class="content
">
6502 <pre><tt>proc a {cmd args} {
6503 tailcall sub_$cmd {*}$args
6506 proc sub_cmd2 ...</tt></pre>
6510 <h3 id="_tell
">tell</h3>
6511 <div class="paragraph
"><p><tt><strong>tell</strong> <em>fileId</em></tt></p></div>
6512 <div class="paragraph
"><p><tt><em>fileId</em> <strong>tell</strong></tt></p></div>
6513 <div class="paragraph
"><p>Returns a decimal string giving the current access position in
6514 <tt><em>fileId</em></tt>.</p></div>
6515 <div class="paragraph
"><p><tt><em>fileId</em></tt> must have been the return value from a previous call to
6516 <a href="#_open
"><strong><tt>open</tt></strong></a>, or it may be <tt>stdin</tt>, <tt>stdout</tt>, or <tt>stderr</tt> to refer to one
6517 of the standard I/O channels.</p></div>
6520 <h3 id="_throw
">throw</h3>
6521 <div class="paragraph
"><p><tt><strong>throw</strong> <em>code ?msg?</em></tt></p></div>
6522 <div class="paragraph
"><p>This command throws an exception (return) code along with an optional message.
6523 This command is mostly for convenient usage with <a href="#_try
"><strong><tt>try</tt></strong></a>.</p></div>
6524 <div class="paragraph
"><p>The command <tt>throw break</tt> is equivalent to <tt>break</tt>.
6525 The command <tt>throw 20 message</tt> can be caught with an <tt>on 20 ...</tt> clause to <a href="#_try
"><strong><tt>try</tt></strong></a>.</p></div>
6528 <h3 id="_time
">time</h3>
6529 <div class="paragraph
"><p><tt><strong>time</strong> <em>command ?count?</em></tt></p></div>
6530 <div class="paragraph
"><p>This command will call the Tcl interpreter <tt><em>count</em></tt>
6531 times to execute <tt><em>command</em></tt> (or once if <tt><em>count</em></tt> isn’t
6532 specified). It will then return a string of the form</p></div>
6533 <div class="literalblock
">
6534 <div class="content
">
6535 <pre><tt>503 microseconds per iteration</tt></pre>
6537 <div class="paragraph
"><p>which indicates the average amount of time required per iteration,
6538 in microseconds.</p></div>
6539 <div class="paragraph
"><p>Time is measured in elapsed time, not CPU time.</p></div>
6542 <h3 id="_try
">try</h3>
6543 <div class="paragraph
"><p><tt><strong>try</strong> <em>?catchopts? tryscript</em> ?<strong>on</strong> <em>returncodes {?resultvar? ?optsvar?} handlerscript ...</em>? ?<strong>finally</strong> <em>finalscript</em>?</tt></p></div>
6544 <div class="paragraph
"><p>The <a href="#_try
"><strong><tt>try</tt></strong></a> command is provided as a convenience for exception handling.</p></div>
6545 <div class="paragraph
"><p>This interpeter first evaluates <tt><em>tryscript</em></tt> under the effect of the catch
6546 options <tt><em>catchopts</em></tt> (e.g. <tt>-signal -noexit --</tt>, see <a href="#_catch
"><strong><tt>catch</tt></strong></a>).</p></div>
6547 <div class="paragraph
"><p>It then evaluates the script for the first matching <em>on</em> handler
6548 (there many be zero or more) based on the return code from the <a href="#_try
"><strong><tt>try</tt></strong></a>
6549 section. For example a normal <tt>JIM_ERR</tt> error will be matched by
6550 an <em>on error</em> handler.</p></div>
6551 <div class="paragraph
"><p>Finally, any <tt><em>finalscript</em></tt> is evaluated.</p></div>
6552 <div class="paragraph
"><p>The result of this command is the result of <tt><em>tryscript</em></tt>, except in the
6553 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6554 in which case the result is this new exception.</p></div>
6555 <div class="paragraph
"><p>The specified <tt><em>returncodes</em></tt> is a list of return codes either as names (<em>ok</em>, <em>error</em>, <em>break</em>, etc.)
6556 or as integers.</p></div>
6557 <div class="paragraph
"><p>If <tt><em>resultvar</em></tt> and <tt><em>optsvar</em></tt> are specified, they are set as for <a href="#_catch
"><strong><tt>catch</tt></strong></a> before evaluating
6558 the matching handler.</p></div>
6559 <div class="paragraph
"><p>For example:</p></div>
6560 <div class="literalblock
">
6561 <div class="content
">
6562 <pre><tt>set f [open input]
6565 } on {continue break} {} {
6566 error "Unexpected break/continue
"
6567 } on error {msg opts} {
6568 puts "Dealing with error
"
6569 return {*}$opts $msg
6571 puts "Got signal: $sig
"
6576 <div class="paragraph
"><p>If break, continue or error are raised, they are dealt with by the matching
6578 <div class="paragraph
"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6579 <div class="paragraph
"><p>See also <a href="#_throw
"><strong><tt>throw</tt></strong></a>, <a href="#_catch
"><strong><tt>catch</tt></strong></a>, <a href="#_return
"><strong><tt>return</tt></strong></a>, <a href="#_error
"><strong><tt>error</tt></strong></a>.</p></div>
6582 <h3 id="_unknown
">unknown</h3>
6583 <div class="paragraph
"><p><tt><strong>unknown</strong> <em>cmdName ?arg arg …?</em></tt></p></div>
6584 <div class="paragraph
"><p>This command doesn’t actually exist as part of Tcl, but Tcl will
6585 invoke it if it does exist.</p></div>
6586 <div class="paragraph
"><p>If the Tcl interpreter encounters a command name for which there
6587 is not a defined command, then Tcl checks for the existence of
6588 a command named <a href="#_unknown
"><strong><tt>unknown</tt></strong></a>.</p></div>
6589 <div class="paragraph
"><p>If there is no such command, then the interpreter returns an
6591 <div class="paragraph
"><p>If the <a href="#_unknown
"><strong><tt>unknown</tt></strong></a> command exists, then it is invoked with
6592 arguments consisting of the fully-substituted name and arguments
6593 for the original non-existent command.</p></div>
6594 <div class="paragraph
"><p>The <a href="#_unknown
"><strong><tt>unknown</tt></strong></a> command typically does things like searching
6595 through library directories for a command procedure with the name
6596 <tt><em>cmdName</em></tt>, or expanding abbreviated command names to full-length,
6597 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6598 <div class="paragraph
"><p>In some cases (such as expanding abbreviations) <a href="#_unknown
"><strong><tt>unknown</tt></strong></a> will
6599 change the original command slightly and then (re-)execute it.
6600 The result of the <a href="#_unknown
"><strong><tt>unknown</tt></strong></a> command is used as the result for
6601 the original non-existent command.</p></div>
6604 <h3 id="_unset
">unset</h3>
6605 <div class="paragraph
"><p><tt><strong>unset ?-nocomplain? ?--?</strong> <em>?name name …?</em></tt></p></div>
6606 <div class="paragraph
"><p>Remove variables.
6607 Each <tt><em>name</em></tt> is a variable name, specified in any of the
6608 ways acceptable to the <a href="#_set
"><strong><tt>set</tt></strong></a> command.</p></div>
6609 <div class="paragraph
"><p>If a <tt><em>name</em></tt> refers to an element of an array, then that
6610 element is removed without affecting the rest of the array.</p></div>
6611 <div class="paragraph
"><p>If a <tt><em>name</em></tt> consists of an array name with no parenthesized
6612 index, then the entire array is deleted.</p></div>
6613 <div class="paragraph
"><p>The <a href="#_unset
"><strong><tt>unset</tt></strong></a> command returns an empty string as result.</p></div>
6614 <div class="paragraph
"><p>An error occurs if any of the variables doesn’t exist, unless <em>-nocomplain</em>
6615 is specified. The <em>--</em> argument may be specified to stop option processing
6616 in case the variable name may be <em>-nocomplain</em>.</p></div>
6619 <h3 id="_upcall
">upcall</h3>
6620 <div class="paragraph
"><p><tt><strong>upcall</strong> <em>command ?args …?</em></tt></p></div>
6621 <div class="paragraph
"><p>May be used from within a proc defined as <a href="#_local
"><strong><tt>local</tt></strong></a> <a href="#_proc
"><strong><tt>proc</tt></strong></a> in order to call
6622 the previous, hidden version of the same command.</p></div>
6623 <div class="paragraph
"><p>If there is no previous definition of the command, an error is returned.</p></div>
6626 <h3 id="_uplevel
">uplevel</h3>
6627 <div class="paragraph
"><p><tt><strong>uplevel</strong> <em>?level? command ?command …?</em></tt></p></div>
6628 <div class="paragraph
"><p>All of the <tt><em>command</em></tt> arguments are concatenated as if they had
6629 been passed to <a href="#_concat
"><strong><tt>concat</tt></strong></a>; the result is then evaluated in the
6630 variable context indicated by <tt><em>level</em></tt>. <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> returns
6631 the result of that evaluation. If <tt><em>level</em></tt> is an integer, then
6632 it gives a distance (up the procedure calling stack) to move before
6633 executing the command. If <tt><em>level</em></tt> consists of <tt>#</tt> followed by
6634 a number then the number gives an absolute level number. If <tt><em>level</em></tt>
6635 is omitted then it defaults to <tt>1</tt>. <tt><em>level</em></tt> cannot be
6636 defaulted if the first <tt><em>command</em></tt> argument starts with a digit or <tt>#</tt>.</p></div>
6637 <div class="paragraph
"><p>For example, suppose that procedure <em>a</em> was invoked
6638 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6639 Suppose that <em>c</em> invokes the <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> command. If <tt><em>level</em></tt>
6640 is <tt>1</tt> or <tt>#2</tt> or omitted, then the command will be executed
6641 in the variable context of <em>b</em>. If <tt><em>level</em></tt> is <tt>2</tt> or <tt>#1</tt>
6642 then the command will be executed in the variable context of <em>a</em>.</p></div>
6643 <div class="paragraph
"><p>If <tt><em>level</em></tt> is <em>3</em> or <tt>#0</tt> then the command will be executed
6644 at top-level (only global variables will be visible).
6645 The <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> command causes the invoking procedure to disappear
6646 from the procedure calling stack while the command is being executed.
6647 In the above example, suppose <em>c</em> invokes the command</p></div>
6648 <div class="literalblock
">
6649 <div class="content
">
6650 <pre><tt>uplevel 1 {set x 43; d}</tt></pre>
6652 <div class="paragraph
"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set
"><strong><tt>set</tt></strong></a> command will
6653 modify the variable <em>x</em> in <em>b’s context, and 'd</em> will execute
6654 at level 3, as if called from <em>b</em>. If it in turn executes
6655 the command</p></div>
6656 <div class="literalblock
">
6657 <div class="content
">
6658 <pre><tt>uplevel {set x 42}</tt></pre>
6660 <div class="paragraph
"><p>then the <a href="#_set
"><strong><tt>set</tt></strong></a> command will modify the same variable <em>x</em> in <em>b’s
6661 context: the procedure 'c</em> does not appear to be on the call stack
6662 when <em>d</em> is executing. The command <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>level</tt> may
6663 be used to obtain the level of the current procedure.</p></div>
6664 <div class="paragraph
"><p><a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> makes it possible to implement new control
6665 constructs as Tcl procedures (for example, <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a> could
6666 be used to implement the <a href="#_while
"><strong><tt>while</tt></strong></a> construct as a Tcl procedure).</p></div>
6669 <h3 id="_upvar
">upvar</h3>
6670 <div class="paragraph
"><p><tt><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar …?</em></tt></p></div>
6671 <div class="paragraph
"><p>This command arranges for one or more local variables in the current
6672 procedure to refer to variables in an enclosing procedure call or
6673 to global variables.</p></div>
6674 <div class="paragraph
"><p><tt><em>level</em></tt> may have any of the forms permitted for the <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a>
6675 command, and may be omitted if the first letter of the first <tt><em>otherVar</em></tt>
6676 isn’t <tt>#</tt> or a digit (it defaults to <em>1</em>).</p></div>
6677 <div class="paragraph
"><p>For each <tt><em>otherVar</em></tt> argument, <a href="#_upvar
"><strong><tt>upvar</tt></strong></a> makes the variable
6678 by that name in the procedure frame given by <tt><em>level</em></tt> (or at
6679 global level, if <tt><em>level</em></tt> is <tt>#0</tt>) accessible
6680 in the current procedure by the name given in the corresponding
6681 <tt><em>myVar</em></tt> argument.</p></div>
6682 <div class="paragraph
"><p>The variable named by <tt><em>otherVar</em></tt> need not exist at the time of the
6683 call; it will be created the first time <tt><em>myVar</em></tt> is referenced, just like
6684 an ordinary variable.</p></div>
6685 <div class="paragraph
"><p><a href="#_upvar
"><strong><tt>upvar</tt></strong></a> may only be invoked from within procedures.</p></div>
6686 <div class="paragraph
"><p><a href="#_upvar
"><strong><tt>upvar</tt></strong></a> returns an empty string.</p></div>
6687 <div class="paragraph
"><p>The <a href="#_upvar
"><strong><tt>upvar</tt></strong></a> command simplifies the implementation of call-by-name
6688 procedure calling and also makes it easier to build new control constructs
6690 For example, consider the following procedure:</p></div>
6691 <div class="literalblock
">
6692 <div class="content
">
6693 <pre><tt>proc add2 name {
6698 <div class="paragraph
"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6699 and it adds two to the value of that variable.
6700 Although <em>add2</em> could have been implemented using <a href="#_uplevel
"><strong><tt>uplevel</tt></strong></a>
6701 instead of <a href="#_upvar
"><strong><tt>upvar</tt></strong></a>, <a href="#_upvar
"><strong><tt>upvar</tt></strong></a> makes it simpler for <em>add2</em>
6702 to access the variable in the caller’s procedure frame.</p></div>
6705 <h3 id="_while
">while</h3>
6706 <div class="paragraph
"><p><tt><strong>while</strong> <em>test body</em></tt></p></div>
6707 <div class="paragraph
"><p>The <tt><em>while</em></tt> command evaluates <tt><em>test</em></tt> as an expression
6708 (in the same way that <a href="#_expr
"><strong><tt>expr</tt></strong></a> evaluates its argument).
6709 The value of the expression must be numeric; if it is non-zero
6710 then <tt><em>body</em></tt> is executed by passing it to the Tcl interpreter.</p></div>
6711 <div class="paragraph
"><p>Once <tt><em>body</em></tt> has been executed then <tt><em>test</em></tt> is evaluated
6712 again, and the process repeats until eventually <tt><em>test</em></tt>
6713 evaluates to a zero numeric value. <a href="#_continue
"><strong><tt>continue</tt></strong></a>
6714 commands may be executed inside <tt><em>body</em></tt> to terminate the current
6715 iteration of the loop, and <a href="#_break
"><strong><tt>break</tt></strong></a>
6716 commands may be executed inside <tt><em>body</em></tt> to cause immediate
6717 termination of the <a href="#_while
"><strong><tt>while</tt></strong></a> command.</p></div>
6718 <div class="paragraph
"><p>The <a href="#_while
"><strong><tt>while</tt></strong></a> command always returns an empty string.</p></div>
6723 <h2 id="_optional_extensions
">OPTIONAL-EXTENSIONS</h2>
6724 <div class="sectionbody
">
6725 <div class="paragraph
"><p>The following extensions may or may not be available depending upon
6726 what options were selected when Jim Tcl was built.</p></div>
6728 <h3 id="cmd_1
">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6729 <div class="dlist
"><dl>
6730 <dt class="hdlist1
">
6731 <tt><strong>os.fork</strong></tt>
6735 Invokes <em>fork(2)</em> and returns the result.
6738 <dt class="hdlist1
">
6739 <tt><strong>os.wait -nohang</strong> <em>pid</em></tt>
6743 Invokes waitpid(2), with WNOHANG if <tt>-nohang</tt> is specified.
6744 Returns a list of 3 elements.
6746 <div class="literalblock
">
6747 <div class="content
">
6748 <pre><tt>{0 none 0} if -nohang is specified, and the process is still alive.</tt></pre>
6750 <div class="literalblock
">
6751 <div class="content
">
6752 <pre><tt>{-1 error <error-description>} if the process does not exist or has already been waited for.</tt></pre>
6754 <div class="literalblock
">
6755 <div class="content
">
6756 <pre><tt>{<pid> exit <exit-status>} if the process exited normally.</tt></pre>
6758 <div class="literalblock
">
6759 <div class="content
">
6760 <pre><tt>{<pid> signal <signal-number>} if the process terminated on a signal.</tt></pre>
6762 <div class="literalblock
">
6763 <div class="content
">
6764 <pre><tt>{<pid> other 0} otherwise (core dump, stopped, continued, etc.)</tt></pre>
6767 <dt class="hdlist1
">
6768 <tt><strong>os.gethostname</strong></tt>
6772 Invokes <em>gethostname(3)</em> and returns the result.
6775 <dt class="hdlist1
">
6776 <tt><strong>os.getids</strong></tt>
6780 Returns the various user/group ids for the current process.
6782 <div class="literalblock
">
6783 <div class="content
">
6784 <pre><tt>jim> os.getids
6785 uid 1000 euid 1000 gid 100 egid 100</tt></pre>
6788 <dt class="hdlist1
">
6789 <tt><strong>os.uptime</strong></tt>
6793 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6801 <h2 id="_ansi_i_o_aio_and_eventloop_api
">ANSI I/O (aio) and EVENTLOOP API</h2>
6802 <div class="sectionbody
">
6803 <div class="paragraph
"><p>Jim provides an alternative object-based API for I/O.</p></div>
6804 <div class="paragraph
"><p>See <a href="#_open
"><strong><tt>open</tt></strong></a> and <a href="#_socket
"><strong><tt>socket</tt></strong></a> for commands which return an I/O handle.</p></div>
6806 <h3 id="_aio
">aio</h3>
6807 <div class="dlist
"><dl>
6808 <dt class="hdlist1
">
6809 <tt>$handle <strong>accept</strong></tt>
6813 Server socket only: Accept a connection and return stream
6816 <dt class="hdlist1
">
6817 <tt>$handle <strong>buffering none|line|full</strong></tt>
6821 Sets the buffering mode of the stream.
6824 <dt class="hdlist1
">
6825 <tt>$handle <strong>close</strong> ?r(ead)|w(rite)?</tt>
6830 The two-argument form is a "half-close
" on a socket. See the <tt>shutdown(2)</tt> man page.
6833 <dt class="hdlist1
">
6834 <tt>$handle <strong>copyto</strong> <em>tofd ?size?</em></tt>
6838 Copy bytes to the file descriptor <tt><em>tofd</em></tt>. If <tt><em>size</em></tt> is specified, at most
6839 that many bytes will be copied. Otherwise copying continues until the end
6840 of the input file. Returns the number of bytes actually copied.
6843 <dt class="hdlist1
">
6844 <tt>$handle <strong>eof</strong></tt>
6848 Returns 1 if stream is at eof
6851 <dt class="hdlist1
">
6852 <tt>$handle <strong>filename</strong></tt>
6856 Returns the original filename associated with the handle.
6857 Handles returned by <a href="#_socket
"><strong><tt>socket</tt></strong></a> give the socket type instead of a filename.
6860 <dt class="hdlist1
">
6861 <tt>$handle <strong>flush</strong></tt>
6868 <dt class="hdlist1
">
6869 <tt>$handle <strong>gets</strong> <em>?var?</em></tt>
6873 Read one line and return it or store it in the var
6876 <dt class="hdlist1
">
6877 <tt>$handle <strong>isatty</strong></tt>
6881 Returns 1 if the stream is a tty device.
6884 <dt class="hdlist1
">
6885 <tt>$handle <strong>ndelay ?0|1?</strong></tt>
6889 Set O_NDELAY (if arg). Returns current/new setting.
6890 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6894 <dt class="hdlist1
">
6895 <tt>$handle <strong>puts ?-nonewline?</strong> <em>str</em></tt>
6899 Write the string, with newline unless -nonewline
6902 <dt class="hdlist1
">
6903 <tt>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></tt>
6907 Read and return bytes from the stream. To eof if no len.
6910 <dt class="hdlist1
">
6911 <tt>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></tt>
6915 Receives a message from the handle via recvfrom(2) and returns it.
6916 At most <tt><em>maxlen</em></tt> bytes are read.
6917 If <tt><em>addrvar</em></tt> is specified, the sending address of the message is stored in
6918 the named variable in the form <em>addr:port</em>. See <a href="#_socket
"><strong><tt>socket</tt></strong></a> for details.
6921 <dt class="hdlist1
">
6922 <tt>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></tt>
6926 Seeks in the stream (default <em>current</em>)
6929 <dt class="hdlist1
">
6930 <tt>$handle <strong>sendto</strong> <em>str ?addr:?port</em></tt>
6934 Sends the string, <tt><em>str</em></tt>, to the given address via the socket using sendto(2).
6935 This is intended for udp/dgram sockets and may give an error or behave in unintended
6936 ways for other handle types.
6937 Returns the number of bytes written.
6940 <dt class="hdlist1
">
6941 <tt>$handle <strong>tell</strong></tt>
6945 Returns the current seek position
6951 <h3 id="_fconfigure
">fconfigure</h3>
6952 <div class="dlist
"><dl>
6953 <dt class="hdlist1
">
6954 <tt><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</tt>
6958 For compatibility with Tcl, a limited form of the <a href="#_fconfigure
"><strong><tt>fconfigure</tt></strong></a>
6959 command is supported.
6961 <div class="ulist
"><ul>
6964 <a href="#_fconfigure
"><strong><tt>fconfigure</tt></strong></a> <tt>... -blocking</tt> maps to <a href="#_aio
"><strong><tt>aio</tt></strong></a> <tt>ndelay</tt>
6969 <a href="#_fconfigure
"><strong><tt>fconfigure</tt></strong></a> <tt>... -buffering</tt> maps to <a href="#_aio
"><strong><tt>aio</tt></strong></a> <tt>buffering</tt>
6974 <a href="#_fconfigure
"><strong><tt>fconfigure</tt></strong></a> <tt>... -translation</tt> is accepted but ignored
6982 <h3 id="cmd_2
">eventloop: after, vwait, update</h3>
6983 <div class="paragraph
"><p>The following commands allow a script to be invoked when the given condition occurs.
6984 If no script is given, returns the current script. If the given script is the empty, the
6985 handler is removed.</p></div>
6986 <div class="dlist
"><dl>
6987 <dt class="hdlist1
">
6988 <tt>$handle <strong>readable</strong> <em>?readable-script?</em></tt>
6992 Sets or returns the script for when the socket is readable.
6995 <dt class="hdlist1
">
6996 <tt>$handle <strong>writable</strong> <em>?writable-script?</em></tt>
7000 Sets or returns the script for when the socket is writable.
7003 <dt class="hdlist1
">
7004 <tt>$handle <strong>onexception</strong> <em>?exception-script?</em></tt>
7008 Sets or returns the script for when when oob data received.
7012 <div class="paragraph
"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <tt>fileevent</tt>. e.g.</p></div>
7013 <div class="dlist
"><dl>
7014 <dt class="hdlist1
">
7019 <tt>fileevent $handle <strong>readable</strong> <em>...</em></tt>
7023 <div class="paragraph
"><p>Time-based execution is also available via the eventloop API.</p></div>
7024 <div class="dlist
"><dl>
7025 <dt class="hdlist1
">
7026 <tt><strong>after</strong> <em>ms</em></tt>
7030 Sleeps for the given number of milliseconds. No events are
7031 processed during this time.
7034 <dt class="hdlist1
">
7035 <tt><strong>after</strong> <em>ms</em>|<strong>idle</strong> script ?script ...?'</tt>
7039 The scripts are concatenated and executed after the given
7040 number of milliseconds have elapsed. If <em>idle</em> is specified,
7041 the script will run the next time the event loop is processed
7042 with <a href="#cmd_2
"><strong><tt>vwait</tt></strong></a> or <a href="#cmd_2
"><strong><tt>update</tt></strong></a>. The script is only run once and
7043 then removed. Returns an event id.
7046 <dt class="hdlist1
">
7047 <tt><strong>after cancel</strong> <em>id|command</em></tt>
7051 Cancels an <a href="#cmd_2
"><strong><tt>after</tt></strong></a> event with the given event id or matching
7052 command (script). Returns the number of milliseconds
7053 remaining until the event would have fired. Returns the
7054 empty string if no matching event is found.
7057 <dt class="hdlist1
">
7058 <tt><strong>after info</strong> <em>?id?</em></tt>
7062 If <tt><em>id</em></tt> is not given, returns a list of current <a href="#cmd_2
"><strong><tt>after</tt></strong></a>
7063 events. If <tt><em>id</em></tt> is given, returns a list containing the
7064 associated script and either <em>timer</em> or <em>idle</em> to indicated
7065 the type of the event. An error occurs if <tt><em>id</em></tt> does not
7069 <dt class="hdlist1
">
7070 <tt><strong>vwait</strong> <em>variable</em></tt>
7074 A call to <a href="#cmd_2
"><strong><tt>vwait</tt></strong></a> is enters the eventloop. <a href="#cmd_2
"><strong><tt>vwait</tt></strong></a> processes
7075 events until the named (global) variable changes or all
7076 event handlers are removed. The variable need not exist
7077 beforehand. If there are no event handlers defined, <a href="#cmd_2
"><strong><tt>vwait</tt></strong></a>
7078 returns immediately.
7081 <dt class="hdlist1
">
7082 <tt><strong>update ?idletasks?</strong></tt>
7086 A call to <a href="#cmd_2
"><strong><tt>update</tt></strong></a> enters the eventloop to process expired events, but
7087 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7089 Returns once handlers have been run for all expired events.
7093 <div class="paragraph
"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7094 an attempt is made to call (the user-defined command) <tt>bgerror</tt> with the details of the error.
7095 If the <tt>bgerror</tt> command does not exist, the error message details are printed to stderr instead.</p></div>
7096 <div class="paragraph
"><p>If a file event handler script generates an error, the handler is automatically removed
7097 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7098 <div class="dlist
"><dl>
7099 <dt class="hdlist1
">
7100 <tt><strong>bgerror</strong> <em>msg</em></tt>
7104 Called when an event handler script generates an error. Note that the normal command resolution
7105 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7112 <h3 id="_socket
">socket</h3>
7113 <div class="paragraph
"><p>Various socket types may be created.</p></div>
7114 <div class="dlist
"><dl>
7115 <dt class="hdlist1
">
7116 <tt><strong>socket unix</strong> <em>path</em></tt>
7120 A unix domain socket client.
7123 <dt class="hdlist1
">
7124 <tt><strong>socket unix.server</strong> <em>path</em></tt>
7128 A unix domain socket server.
7131 <dt class="hdlist1
">
7132 <tt><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></tt>
7136 A TCP socket client. (See the forms for <tt><em>addr</em></tt> below)
7139 <dt class="hdlist1
">
7140 <tt><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></tt>
7144 A TCP socket server (<tt><em>addr</em></tt> defaults to <tt>0.0.0.0</tt> for IPv4 or <tt>[::]</tt> for IPv6).
7147 <dt class="hdlist1
">
7148 <tt><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</tt>
7152 A UDP socket client. If the address is not specified,
7153 the client socket will be unbound and <em>sendto</em> must be used
7154 to indicated the destination.
7157 <dt class="hdlist1
">
7158 <tt><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></tt>
7162 A UDP socket server.
7165 <dt class="hdlist1
">
7166 <tt><strong>socket pipe</strong></tt>
7170 A pipe. Note that unlike all other socket types, this command returns
7171 a list of two channels: {read write}
7174 <dt class="hdlist1
">
7175 <tt><strong>socket pair</strong></tt>
7179 A socketpair (see socketpair(2)). Like <a href="#_socket
"><strong><tt>socket</tt></strong></a> <tt>pipe</tt>, this command returns
7180 a list of two channels: {s1 s2}. These channels are both readable and writable.
7184 <div class="paragraph
"><p>This command creates a socket connected (client) or bound (server) to the given
7186 <div class="paragraph
"><p>The returned value is channel and may generally be used with the various file I/O
7187 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7188 <div class="literalblock
">
7189 <div class="content
">
7190 <pre><tt>set f [socket stream www.google.com:80]
7192 $f puts -nonewline "GET / HTTP/
1.0\r\n\r\n
"
7197 <div class="paragraph
"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7198 the EVENTLOOP API.</p></div>
7199 <div class="literalblock
">
7200 <div class="content
">
7201 <pre><tt>set f [socket stream.server 80]
7203 set client [$f accept]
7206 $client puts -nonewline "HTTP/
1.1 404 Not found\r\n
"
7209 vwait done</tt></pre>
7211 <div class="paragraph
"><p>The address, <tt><em>addr</em></tt>, can be given in one of the following forms:</p></div>
7212 <div class="olist arabic
"><ol class="arabic
">
7215 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7220 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7229 <div class="paragraph
"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7230 also accept requests via IPv4.</p></div>
7231 <div class="paragraph
"><p>Where a hostname is specified, the <tt><em>first</em></tt> returned address is used
7232 which matches the socket type is used.</p></div>
7233 <div class="paragraph
"><p>The special type <em>pipe</em> isn’t really a socket.</p></div>
7234 <div class="literalblock
">
7235 <div class="content
">
7236 <pre><tt>lassign [socket pipe] r w</tt></pre>
7238 <div class="literalblock
">
7239 <div class="content
">
7240 <pre><tt># Must close $w after exec
7241 exec ps >@$w &
7244 <div class="literalblock
">
7245 <div class="content
">
7246 <pre><tt>$r readable ...</tt></pre>
7250 <h3 id="_syslog
">syslog</h3>
7251 <div class="paragraph
"><p><tt><strong>syslog</strong> <em>?options? ?priority? message</em></tt></p></div>
7252 <div class="paragraph
"><p>This command sends message to system syslog facility with given
7253 priority. Valid priorities are:</p></div>
7254 <div class="literalblock
">
7255 <div class="content
">
7256 <pre><tt>emerg, alert, crit, err, error, warning, notice, info, debug</tt></pre>
7258 <div class="paragraph
"><p>If a message is specified, but no priority is specified, then a
7259 priority of info is used.</p></div>
7260 <div class="paragraph
"><p>By default, facility user is used and the value of global tcl variable
7261 argv0 is used as ident string. However, any of the following options
7262 may be specified before priority to control these parameters:</p></div>
7263 <div class="dlist
"><dl>
7264 <dt class="hdlist1
">
7265 <tt><strong>-facility</strong> <em>value</em></tt>
7269 Use specified facility instead of user. The following
7270 values for facility are recognized:
7272 <div class="literalblock
">
7273 <div class="content
">
7274 <pre><tt>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7275 uucp, local0-local7</tt></pre>
7278 <dt class="hdlist1
">
7279 <tt><strong>-ident</strong> <em>string</em></tt>
7283 Use given string instead of argv0 variable for ident string.
7286 <dt class="hdlist1
">
7287 <tt><strong>-options</strong> <em>integer</em></tt>
7291 Set syslog options such as <tt>LOG_CONS</tt>, <tt>LOG_NDELAY</tt>. You should
7292 use numeric values of those from your system syslog.h file,
7293 because I haven’t got time to implement yet another hash
7300 <h3 id="cmd_3
">pack: pack, unpack</h3>
7301 <div class="paragraph
"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7302 <div class="dlist
"><dl>
7303 <dt class="hdlist1
">
7304 <tt><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></tt>
7308 Packs the binary representation of <tt><em>value</em></tt> into the variable
7309 <tt><em>varName</em></tt>. The value is packed according to the given type
7310 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7311 The variable is created if necessary (like <a href="#_append
"><strong><tt>append</tt></strong></a>).
7312 Ihe variable is expanded if necessary.
7315 <dt class="hdlist1
">
7316 <tt><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></tt>
7320 Unpacks bits from <tt><em>binvalue</em></tt> at bit position <tt><em>bitpos</em></tt> and with <tt><em>bitwidth</em></tt>.
7321 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7322 and signed/unsigned) and returns it. For integer types, <tt><em>bitwidth</em></tt>
7323 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7324 <tt><em>bitwidth</em></tt> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7325 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7326 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7327 or the empty string for the string type.
7333 <h3 id="_binary
">binary</h3>
7334 <div class="paragraph
"><p>The optional, pure-Tcl <em>binary</em> extension provides the Tcl-compatible <a href="#_binary
"><strong><tt>binary</tt></strong></a> <tt>scan</tt> and <a href="#_binary
"><strong><tt>binary</tt></strong></a> <tt>format</tt>
7335 commands based on the low-level <a href="#cmd_3
"><strong><tt>pack</tt></strong></a> and <a href="#cmd_3
"><strong><tt>unpack</tt></strong></a> commands.</p></div>
7336 <div class="paragraph
"><p>See the Tcl documentation at: <a href="http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm
">http://www.tcl.tk/man/tcl8.5/TclCmd/binary.htm</a></p></div>
7337 <div class="paragraph
"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7338 in case of overflow.</p></div>
7341 <h3 id="cmd_4
">oo: class, super</h3>
7342 <div class="paragraph
"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7343 <div class="paragraph
"><p>See the online documentation (<a href="http://jim.berlios.de/documentation/oo/
">http://jim.berlios.de/documentation/oo/</a>) for more details.</p></div>
7344 <div class="dlist
"><dl>
7345 <dt class="hdlist1
">
7346 <tt><strong>class</strong> <em>classname ?baseclasses? classvars</em></tt>
7350 Create a new class, <tt><em>classname</em></tt>, with the given dictionary
7351 (<tt><em>classvars</em></tt>) as class variables. These are the initial variables
7352 which all newly created objects of this class are initialised with.
7353 If a list of baseclasses is given, methods and instance variables
7357 <dt class="hdlist1
">
7358 <tt><strong>super</strong> <em>method ?args ...?</em></tt>
7362 From within a method, invokes the given method on the base class.
7363 Note that this will only call the last baseclass given.
7369 <h3 id="_tree
">tree</h3>
7370 <div class="paragraph
"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7371 similar to that provided by tcllib ::struct::tree (<a href="http://tcllib.sourceforge.net/doc/struct_tree.html
">http://tcllib.sourceforge.net/doc/struct_tree.html</a>)</p></div>
7372 <div class="paragraph
"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7373 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7374 <div class="dlist
"><dl>
7375 <dt class="hdlist1
">
7376 <tt><strong>tree</strong></tt>
7380 Creates and returns a new tree object with a single node named "root
".
7381 All operations on the tree are invoked through this object.
7384 <dt class="hdlist1
">
7385 <tt>$tree <strong>destroy</strong></tt>
7389 Destroy the tree and all it’s nodes. (Note that the the tree will also
7390 be automatically garbage collected once it goes out of scope).
7393 <dt class="hdlist1
">
7394 <tt>$tree <strong>set</strong> <em>nodename key value</em></tt>
7398 Set the value for the given attribute key.
7401 <dt class="hdlist1
">
7402 <tt>$tree <strong>lappend</strong> <em>nodename key value ...</em></tt>
7406 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7409 <dt class="hdlist1
">
7410 <tt>$tree <strong>keyexists</strong> <em>nodename key</em></tt>
7414 Returns 1 if the given attribute key exists.
7417 <dt class="hdlist1
">
7418 <tt>$tree <strong>get</strong> <em>nodename key</em></tt>
7422 Returns the value associated with the given attribute key.
7425 <dt class="hdlist1
">
7426 <tt>$tree <strong>getall</strong> <em>nodename</em></tt>
7430 Returns the entire attribute dictionary associated with the given key.
7433 <dt class="hdlist1
">
7434 <tt>$tree <strong>depth</strong> <em>nodename</em></tt>
7438 Returns the depth of the given node. The depth of "root
" is 0.
7441 <dt class="hdlist1
">
7442 <tt>$tree <strong>parent</strong> <em>nodename</em></tt>
7446 Returns the node name of the parent node, or "" for the root node.
7449 <dt class="hdlist1
">
7450 <tt>$tree <strong>numchildren</strong> <em>nodename</em></tt>
7454 Returns the number of child nodes.
7457 <dt class="hdlist1
">
7458 <tt>$tree <strong>children</strong> <em>nodename</em></tt>
7462 Returns a list of the child nodes.
7465 <dt class="hdlist1
">
7466 <tt>$tree <strong>next</strong> <em>nodename</em></tt>
7470 Returns the next sibling node, or "" if none.
7473 <dt class="hdlist1
">
7474 <tt>$tree <strong>insert</strong> <em>nodename ?index?</em></tt>
7478 Add a new child node to the given node. The index is a list index
7479 such as <tt>3</tt> or <tt>end-2</tt>. The default index is <tt>end</tt>.
7480 Returns the name of the newly added node.
7483 <dt class="hdlist1
">
7484 <tt>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></tt>
7488 Walks the tree starting from the given node, either breadth first (<tt>bfs</tt>)
7489 depth first (<tt>dfs</tt>).
7490 The value <tt>"enter
"</tt> or <tt>"exit
"</tt> is stored in variable <tt><em>actionvar</em></tt>.
7491 The name of each node is stored in <tt><em>nodevar</em></tt>.
7492 The script is evaluated twice for each node, on entry and exit.
7495 <dt class="hdlist1
">
7496 <tt>$tree <strong>dump</strong></tt>
7500 Dumps the tree contents to stdout
7506 <h3 id="_tcl_prefix
">tcl::prefix</h3>
7507 <div class="paragraph
"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7508 (<a href="http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm
">http://www.tcl.tk/man/tcl8.6/TclCmd/prefix.htm</a>) for matching strings against a table
7509 of possible values (typically commands or options).</p></div>
7510 <div class="dlist
"><dl>
7511 <dt class="hdlist1
">
7512 <tt><strong>tcl::prefix all</strong> <em>table string</em></tt>
7516 Returns a list of all elements in <tt><em>table</em></tt> that begin with the prefix <tt><em>string</em></tt>.
7519 <dt class="hdlist1
">
7520 <tt><strong>tcl::prefix longest</strong> <em>table string</em></tt>
7524 Returns the longest common prefix of all elements in <tt><em>table</em></tt> that begin with the prefix <tt><em>string</em></tt>.
7527 <dt class="hdlist1
">
7528 <tt><strong>tcl::prefix match</strong> <em>?options? table string</em></tt>
7532 If <tt><em>string</em></tt> equals one element in <tt><em>table</em></tt> or is a prefix to
7533 exactly one element, the matched element is returned. If not, the
7534 result depends on the <tt>-error</tt> option.
7536 <div class="ulist
"><ul>
7539 <tt><strong>-exact</strong></tt> Accept only exact matches.
7544 <tt><strong>-message</strong> <em>string</em></tt> Use <tt><em>string</em></tt> in the error message at a mismatch. Default is "option
".
7549 <tt><strong>-error</strong> <em>options</em></tt> The options are used when no match is found. If <tt><em>options</em></tt> is
7550 empty, no error is generated and an empty string is returned.
7551 Otherwise the options are used as return options when
7552 generating the error message. The default corresponds to
7553 setting <tt>-level 0</tt>.
7561 <h3 id="_history
">history</h3>
7562 <div class="paragraph
"><p>The optional history extension provides script access to the command line editing
7563 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7564 Note: if line editing support is not available, <a href="#_history
"><strong><tt>history</tt></strong></a> <tt>getline</tt> acts like <a href="#_gets
"><strong><tt>gets</tt></strong></a> and
7565 the remaining subcommands do nothing.</p></div>
7566 <div class="dlist
"><dl>
7567 <dt class="hdlist1
">
7568 <tt><strong>history load</strong> <em>filename</em></tt>
7572 Load history from a (text) file. If the file does not exist or is not readable,
7576 <dt class="hdlist1
">
7577 <tt><strong>history getline</strong> <em>prompt ?varname?</em></tt>
7581 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets
"><strong><tt>gets</tt></strong></a>,
7582 if <tt><em>varname</em></tt> is given, it receives the line and the length of the line is returned,
7583 or -1 on EOF. If <tt><em>varname</em></tt> is not given, the line is returned directly.
7586 <dt class="hdlist1
">
7587 <tt><strong>history add</strong> <em>line</em></tt>
7591 Adds the given line to the history buffer.
7594 <dt class="hdlist1
">
7595 <tt><strong>history save</strong> <em>filename</em></tt>
7599 Saves the current history buffer to the given file.
7602 <dt class="hdlist1
">
7603 <tt><strong>history show</strong></tt>
7607 Displays the current history buffer to standard output.
7613 <h3 id="_namespace
">namespace</h3>
7614 <div class="paragraph
"><p>Provides namespace-related functions. See also: <a href="http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm
">http://www.tcl.tk/man/tcl8.6/TclCmd/namespace.htm</a></p></div>
7615 <div class="dlist
"><dl>
7616 <dt class="hdlist1
">
7617 <tt><strong>namespace code</strong> <em>script</em></tt>
7621 Captures the current namespace context for later execution of
7622 the script <tt><em>script</em></tt>. It returns a new script in which script has
7623 been wrapped in a <tt><strong>namespace inscope</strong></tt> command.
7626 <dt class="hdlist1
">
7627 <tt><strong>namespace current</strong></tt>
7631 Returns the fully-qualified name for the current namespace.
7634 <dt class="hdlist1
">
7635 <tt><strong>namespace delete</strong> <em>?namespace …?</em></tt>
7639 Deletes all commands and variables with the given namespace prefixes.
7642 <dt class="hdlist1
">
7643 <tt><strong>namespace eval</strong> <em>namespace arg ?arg…?</em></tt>
7647 Activates a namespace called <tt><em>namespace</em></tt> and evaluates some code in that context.
7650 <dt class="hdlist1
">
7651 <tt><strong>namespace origin</strong> <em>command</em></tt>
7655 Returns the fully-qualified name of the original command to which the imported command <tt><em>command</em></tt> refers.
7658 <dt class="hdlist1
">
7659 <tt><strong>namespace parent</strong> ?namespace?</tt>
7663 Returns the fully-qualified name of the parent namespace for namespace <tt><em>namespace</em></tt>, if given, otherwise
7664 for the current namespace.
7667 <dt class="hdlist1
">
7668 <tt><strong>namespace qualifiers</strong> <em>string</em></tt>
7672 Returns any leading namespace qualifiers for <tt><em>string</em></tt>
7675 <dt class="hdlist1
">
7676 <tt><strong>namespace tail</strong> <em>string</em></tt>
7680 Returns the simple name at the end of a qualified string.
7683 <dt class="hdlist1
">
7684 <tt><strong>namespace upvar</strong> <em>namespace ?arg…?</em></tt>
7688 This command arranges for zero or more local variables in the current procedure to refer to variables in <tt><em>namespace</em></tt>
7691 <dt class="hdlist1
">
7692 <tt><strong>namespace which</strong> <em>?-command|-variable? name</em></tt>
7696 Looks up <tt><em>name</em></tt> as either a command (the default) or variable and returns its fully-qualified name.
7704 <h2 id="BuiltinVariables
">BUILT-IN VARIABLES</h2>
7705 <div class="sectionbody
">
7706 <div class="paragraph
"><p>The following global variables are created automatically
7707 by the Tcl library.</p></div>
7708 <div class="dlist
"><dl>
7709 <dt class="hdlist1
">
7710 <tt><strong>env</strong></tt>
7714 This variable is set by Jim as an array
7715 whose elements are the environment variables for the process.
7716 Reading an element will return the value of the corresponding
7717 environment variable.
7718 This array is initialised at startup from the <a href="#_env
"><strong><tt>env</tt></strong></a> command.
7719 It may be modified and will affect the environment passed to
7720 commands invoked with <a href="#_exec
"><strong><tt>exec</tt></strong></a>.
7723 <dt class="hdlist1
">
7724 <tt><strong>platform_tcl</strong></tt>
7728 This variable is set by Jim as an array containing information
7729 about the platform on which Jim was built. Currently this includes
7730 <em>os</em> and <em>platform</em>.
7733 <dt class="hdlist1
">
7734 <tt><strong>auto_path</strong></tt>
7738 This variable contains a list of paths to search for packages.
7739 It defaults to a location based on where jim is installed
7740 (e.g. <tt>/usr/local/lib/jim</tt>), but may be changed by <tt>jimsh</tt>
7741 or the embedding application. Note that <tt>jimsh</tt> will consider
7742 the environment variable <tt>$JIMLIB</tt> to be a list of colon-separated
7743 list of paths to add to <tt><strong>auto_path</strong></tt>.
7746 <dt class="hdlist1
">
7747 <tt><strong>errorCode</strong></tt>
7751 This variable holds the value of the -errorcode return
7752 option set by the most recent error that occurred in this
7753 interpreter. This list value represents additional information
7754 about the error in a form that is easy to process with
7755 programs. The first element of the list identifies a general
7756 class of errors, and determines the format of the rest of
7757 the list. The following formats for -errorcode return options
7758 are used by the Tcl core; individual applications may define
7759 additional formats. Currently only <a href="#_exec
"><strong><tt>exec</tt></strong></a> sets this variable.
7760 Otherwise it will be <tt>NONE</tt>.
7764 <div class="paragraph
"><p>The following global variables are set by jimsh.</p></div>
7765 <div class="dlist
"><dl>
7766 <dt class="hdlist1
">
7767 <tt><strong>tcl_interactive</strong></tt>
7771 This variable is set to 1 if jimsh is started in interactive mode
7775 <dt class="hdlist1
">
7776 <tt><strong>tcl_platform</strong></tt>
7780 This variable is set by Jim as an array containing information
7781 about the platform upon which Jim was built. The following is an
7782 example of the contents of this array.
7784 <div class="literalblock
">
7785 <div class="content
">
7786 <pre><tt>tcl_platform(byteOrder) = littleEndian
7787 tcl_platform(os) = Darwin
7788 tcl_platform(platform) = unix
7789 tcl_platform(pointerSize) = 8
7790 tcl_platform(threaded) = 0
7791 tcl_platform(wordSize) = 8
7792 tcl_platform(pathSeparator) = :</tt></pre>
7795 <dt class="hdlist1
">
7796 <tt><strong>argv0</strong></tt>
7800 If jimsh is invoked to run a script, this variable contains the name
7804 <dt class="hdlist1
">
7805 <tt><strong>argv</strong></tt>
7809 If jimsh is invoked to run a script, this variable contains a list
7810 of any arguments supplied to the script.
7813 <dt class="hdlist1
">
7814 <tt><strong>argc</strong></tt>
7818 If jimsh is invoked to run a script, this variable contains the number
7819 of arguments supplied to the script.
7822 <dt class="hdlist1
">
7823 <tt><strong>jim_argv0</strong></tt>
7827 The value of argv[0] when jimsh was invoked.
7834 <h2 id="_changes_in_previous_releases
">CHANGES IN PREVIOUS RELEASES</h2>
7835 <div class="sectionbody
">
7837 <h3 id="_in_v0_70
">In v0.70</h3>
7838 <div class="olist arabic
"><ol class="arabic
">
7841 <tt>platform_tcl()</tt> settings are now automatically determined
7846 Add aio <tt>$handle filename</tt>
7851 Add <a href="#_info
"><strong><tt>info</tt></strong></a> <tt>channels</tt>
7856 The <em>bio</em> extension is gone. Now <a href="#_aio
"><strong><tt>aio</tt></strong></a> supports <em>copyto</em>.
7861 Add <a href="#_exists
"><strong><tt>exists</tt></strong></a> command
7866 Add the pure-Tcl <em>oo</em> extension
7871 The <a href="#_exec
"><strong><tt>exec</tt></strong></a> command now only uses vfork(), not fork()
7876 Unit test framework is less verbose and more Tcl-compatible
7881 Optional UTF-8 support
7886 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
7891 Command line editing in interactive mode, e.g. <em>jimsh</em>
7897 <h3 id="_in_v0_63
">In v0.63</h3>
7898 <div class="olist arabic
"><ol class="arabic
">
7901 <a href="#_source
"><strong><tt>source</tt></strong></a> now checks that a script is complete (.i.e. not missing a brace)
7906 <em>info complete</em> now uses the real parser and so is 100% accurate
7911 Better access to live stack frames with <em>info frame</em>, <a href="#_stacktrace
"><strong><tt>stacktrace</tt></strong></a> and <a href="#_stackdump
"><strong><tt>stackdump</tt></strong></a>
7916 <a href="#_tailcall
"><strong><tt>tailcall</tt></strong></a> no longer loses stack trace information
7921 Add <a href="#_alias
"><strong><tt>alias</tt></strong></a> and <a href="#_curry
"><strong><tt>curry</tt></strong></a>
7926 <a href="#_lambda
"><strong><tt>lambda</tt></strong></a>, <a href="#_alias
"><strong><tt>alias</tt></strong></a> and <a href="#_curry
"><strong><tt>curry</tt></strong></a> are implemented via <a href="#_tailcall
"><strong><tt>tailcall</tt></strong></a> for efficiency
7931 <a href="#_local
"><strong><tt>local</tt></strong></a> allows procedures to be deleted automatically at the end of the current procedure
7936 udp sockets are now supported for both clients and servers.
7941 vfork-based exec is now working correctly
7946 Add <em>file tempfile</em>
7951 Add <em>socket pipe</em>
7956 Enhance <em>try … on … finally</em> to be more Tcl 8.6 compatible
7961 It is now possible to <a href="#_return
"><strong><tt>return</tt></strong></a> from within <a href="#_try
"><strong><tt>try</tt></strong></a>
7966 IPv6 support is now included
7971 Add <em>string is</em>
7976 Event handlers works better if an error occurs. eof handler has been removed.
7981 <a href="#_exec
"><strong><tt>exec</tt></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
7986 Command pipelines via open "|
…" are now supported
7991 <a href="#_pid
"><strong><tt>pid</tt></strong></a> can now return pids of a command pipeline
7996 Add <em>info references</em>
8001 Add support for <em>after <tt>'ms</em></tt><em>, 'after idle</em>, <em>after info</em>, <a href="#cmd_2
"><strong><tt>update</tt></strong></a>
8006 <a href="#_exec
"><strong><tt>exec</tt></strong></a> now sets environment based on $::env
8011 Add <em>dict keys</em>
8016 Add support for <em>lsort -index</em>
8022 <h3 id="_in_v0_62
">In v0.62</h3>
8023 <div class="olist arabic
"><ol class="arabic
">
8026 Add support to <a href="#_exec
"><strong><tt>exec</tt></strong></a> for <em>>&</em>, <em>>>&</em>, <em>|&</em>, <em>2>@1</em>
8031 Fix <a href="#_exec
"><strong><tt>exec</tt></strong></a> error messages when special token (e.g. <em>></em>) is the last token
8036 Fix <a href="#_subst
"><strong><tt>subst</tt></strong></a> handling of backslash escapes.
8041 Allow abbreviated options for <a href="#_subst
"><strong><tt>subst</tt></strong></a>
8046 Add support for <a href="#_return
"><strong><tt>return</tt></strong></a>, <a href="#_break
"><strong><tt>break</tt></strong></a>, <a href="#_continue
"><strong><tt>continue</tt></strong></a> in subst
8051 Many <a href="#_expr
"><strong><tt>expr</tt></strong></a> bug fixes
8056 Add support for functions in <a href="#_expr
"><strong><tt>expr</tt></strong></a> (e.g. int(), abs()), and also <em>in</em>, <em>ni</em> list operations
8061 The variable name argument to <a href="#_regsub
"><strong><tt>regsub</tt></strong></a> is now optional
8066 Add support for <em>unset -nocomplain</em>
8071 Add support for list commands: <a href="#_lassign
"><strong><tt>lassign</tt></strong></a>, <a href="#_lrepeat
"><strong><tt>lrepeat</tt></strong></a>
8076 Fully-functional <a href="#_lsearch
"><strong><tt>lsearch</tt></strong></a> is now implemented
8081 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8086 Allow <a href="#_catch
"><strong><tt>catch</tt></strong></a> to determine what return codes are caught
8091 Allow <a href="#_incr
"><strong><tt>incr</tt></strong></a> to increment an unset variable by first setting to 0
8096 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc
"><strong><tt>proc</tt></strong></a>
8101 Add <em>file copy</em>
8106 Add <em>try … finally</em> command
8114 <h2 id="_licence
">LICENCE</h2>
8115 <div class="sectionbody
">
8116 <div class="literalblock
">
8117 <div class="content
">
8118 <pre><tt>Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
8119 Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
8120 Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
8121 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8122 Copyright 2008 Andrew Lunn <andrew@lunn.ch>
8123 Copyright 2008 Duane Ellis <openocd@duaneellis.com>
8124 Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
8125 Copyright 2009 Steve Bennett <steveb@workware.net.au></tt></pre>
8127 <div class="literalblock
">
8128 <div class="content
">
8129 <pre><tt>Redistribution and use in source and binary forms, with or without
8130 modification, are permitted provided that the following conditions
8132 1. Redistributions of source code must retain the above copyright
8133 notice, this list of conditions and the following disclaimer.
8134 2. Redistributions in binary form must reproduce the above
8135 copyright notice, this list of conditions and the following
8136 disclaimer in the documentation and/or other materials
8137 provided with the distribution.</tt></pre>
8139 <div class="literalblock
">
8140 <div class="content
">
8141 <pre><tt>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8142 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8143 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8144 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8145 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8146 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8147 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8148 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8149 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8150 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8151 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8152 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
8154 <div class="literalblock
">
8155 <div class="content
">
8156 <pre><tt>The views and conclusions contained in the software and documentation
8157 are those of the authors and should not be interpreted as representing
8158 official policies, either expressed or implied, of the Jim Tcl Project.</tt></pre>
8163 <div id="footnotes
"><hr /></div>
8165 <div id="footer-text
">
8166 Last updated 2014-01-22 10:17:31 EST