jim.c: fix a compiler warning for gcc/glibc
[jimtcl.git] / Tcl_shipped.html
blobfddfea82a937941d9750924d77c0b1bfed9f252c
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">
4 <head>
5 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.6.8" />
7 <title>Jim Tcl(n)</title>
8 <style type="text/css">
9 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
11 /* Default font. */
12 body {
13 font-family: Georgia,serif;
16 /* Title font. */
17 h1, h2, h3, h4, h5, h6,
18 div.title, caption.title,
19 thead, p.table.header,
20 #toctitle,
21 #author, #revnumber, #revdate, #revremark,
22 #footer {
23 font-family: Arial,Helvetica,sans-serif;
26 body {
27 margin: 1em 5% 1em 5%;
30 a {
31 color: blue;
32 text-decoration: underline;
34 a:visited {
35 color: fuchsia;
38 em {
39 font-style: italic;
40 color: navy;
43 strong {
44 font-weight: bold;
45 color: #083194;
48 h1, h2, h3, h4, h5, h6 {
49 color: #527bbd;
50 margin-top: 1.2em;
51 margin-bottom: 0.5em;
52 line-height: 1.3;
55 h1, h2, h3 {
56 border-bottom: 2px solid silver;
58 h2 {
59 padding-top: 0.5em;
61 h3 {
62 float: left;
64 h3 + * {
65 clear: left;
67 h5 {
68 font-size: 1.0em;
71 div.sectionbody {
72 margin-left: 0;
75 hr {
76 border: 1px solid silver;
79 p {
80 margin-top: 0.5em;
81 margin-bottom: 0.5em;
84 ul, ol, li > p {
85 margin-top: 0;
87 ul > li { color: #aaa; }
88 ul > li > * { color: black; }
90 .monospaced, code, pre {
91 font-family: "Courier New", Courier, monospace;
92 font-size: inherit;
93 color: navy;
94 padding: 0;
95 margin: 0;
99 #author {
100 color: #527bbd;
101 font-weight: bold;
102 font-size: 1.1em;
104 #email {
106 #revnumber, #revdate, #revremark {
109 #footer {
110 font-size: small;
111 border-top: 2px solid silver;
112 padding-top: 0.5em;
113 margin-top: 4.0em;
115 #footer-text {
116 float: left;
117 padding-bottom: 0.5em;
119 #footer-badges {
120 float: right;
121 padding-bottom: 0.5em;
124 #preamble {
125 margin-top: 1.5em;
126 margin-bottom: 1.5em;
128 div.imageblock, div.exampleblock, div.verseblock,
129 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
130 div.admonitionblock {
131 margin-top: 1.0em;
132 margin-bottom: 1.5em;
134 div.admonitionblock {
135 margin-top: 2.0em;
136 margin-bottom: 2.0em;
137 margin-right: 10%;
138 color: #606060;
141 div.content { /* Block element content. */
142 padding: 0;
145 /* Block element titles. */
146 div.title, caption.title {
147 color: #527bbd;
148 font-weight: bold;
149 text-align: left;
150 margin-top: 1.0em;
151 margin-bottom: 0.5em;
153 div.title + * {
154 margin-top: 0;
157 td div.title:first-child {
158 margin-top: 0.0em;
160 div.content div.title:first-child {
161 margin-top: 0.0em;
163 div.content + div.title {
164 margin-top: 0.0em;
167 div.sidebarblock > div.content {
168 background: #ffffee;
169 border: 1px solid #dddddd;
170 border-left: 4px solid #f0f0f0;
171 padding: 0.5em;
174 div.listingblock > div.content {
175 border: 1px solid #dddddd;
176 border-left: 5px solid #f0f0f0;
177 background: #f8f8f8;
178 padding: 0.5em;
181 div.quoteblock, div.verseblock {
182 padding-left: 1.0em;
183 margin-left: 1.0em;
184 margin-right: 10%;
185 border-left: 5px solid #f0f0f0;
186 color: #888;
189 div.quoteblock > div.attribution {
190 padding-top: 0.5em;
191 text-align: right;
194 div.verseblock > pre.content {
195 font-family: inherit;
196 font-size: inherit;
198 div.verseblock > div.attribution {
199 padding-top: 0.75em;
200 text-align: left;
202 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
203 div.verseblock + div.attribution {
204 text-align: left;
207 div.admonitionblock .icon {
208 vertical-align: top;
209 font-size: 1.1em;
210 font-weight: bold;
211 text-decoration: underline;
212 color: #527bbd;
213 padding-right: 0.5em;
215 div.admonitionblock td.content {
216 padding-left: 0.5em;
217 border-left: 3px solid #dddddd;
220 div.exampleblock > div.content {
221 border-left: 3px solid #dddddd;
222 padding-left: 0.5em;
225 div.imageblock div.content { padding-left: 0; }
226 span.image img { border-style: none; }
227 a.image:visited { color: white; }
229 dl {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 dt {
234 margin-top: 0.5em;
235 margin-bottom: 0;
236 font-style: normal;
237 color: navy;
239 dd > *:first-child {
240 margin-top: 0.1em;
243 ul, ol {
244 list-style-position: outside;
246 ol.arabic {
247 list-style-type: decimal;
249 ol.loweralpha {
250 list-style-type: lower-alpha;
252 ol.upperalpha {
253 list-style-type: upper-alpha;
255 ol.lowerroman {
256 list-style-type: lower-roman;
258 ol.upperroman {
259 list-style-type: upper-roman;
262 div.compact ul, div.compact ol,
263 div.compact p, div.compact p,
264 div.compact div, div.compact div {
265 margin-top: 0.1em;
266 margin-bottom: 0.1em;
269 tfoot {
270 font-weight: bold;
272 td > div.verse {
273 white-space: pre;
276 div.hdlist {
277 margin-top: 0.8em;
278 margin-bottom: 0.8em;
280 div.hdlist tr {
281 padding-bottom: 15px;
283 dt.hdlist1.strong, td.hdlist1.strong {
284 font-weight: bold;
286 td.hdlist1 {
287 vertical-align: top;
288 font-style: normal;
289 padding-right: 0.8em;
290 color: navy;
292 td.hdlist2 {
293 vertical-align: top;
295 div.hdlist.compact tr {
296 margin: 0;
297 padding-bottom: 0;
300 .comment {
301 background: yellow;
304 .footnote, .footnoteref {
305 font-size: 0.8em;
308 span.footnote, span.footnoteref {
309 vertical-align: super;
312 #footnotes {
313 margin: 20px 0 20px 0;
314 padding: 7px 0 0 0;
317 #footnotes div.footnote {
318 margin: 0 0 5px 0;
321 #footnotes hr {
322 border: none;
323 border-top: 1px solid silver;
324 height: 1px;
325 text-align: left;
326 margin-left: 0;
327 width: 20%;
328 min-width: 100px;
331 div.colist td {
332 padding-right: 0.5em;
333 padding-bottom: 0.3em;
334 vertical-align: top;
336 div.colist td img {
337 margin-top: 0.3em;
340 @media print {
341 #footer-badges { display: none; }
344 #toc {
345 margin-bottom: 2.5em;
348 #toctitle {
349 color: #527bbd;
350 font-size: 1.1em;
351 font-weight: bold;
352 margin-top: 1.0em;
353 margin-bottom: 0.1em;
356 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
357 margin-top: 0;
358 margin-bottom: 0;
360 div.toclevel2 {
361 margin-left: 2em;
362 font-size: 0.9em;
364 div.toclevel3 {
365 margin-left: 4em;
366 font-size: 0.9em;
368 div.toclevel4 {
369 margin-left: 6em;
370 font-size: 0.9em;
373 span.aqua { color: aqua; }
374 span.black { color: black; }
375 span.blue { color: blue; }
376 span.fuchsia { color: fuchsia; }
377 span.gray { color: gray; }
378 span.green { color: green; }
379 span.lime { color: lime; }
380 span.maroon { color: maroon; }
381 span.navy { color: navy; }
382 span.olive { color: olive; }
383 span.purple { color: purple; }
384 span.red { color: red; }
385 span.silver { color: silver; }
386 span.teal { color: teal; }
387 span.white { color: white; }
388 span.yellow { color: yellow; }
390 span.aqua-background { background: aqua; }
391 span.black-background { background: black; }
392 span.blue-background { background: blue; }
393 span.fuchsia-background { background: fuchsia; }
394 span.gray-background { background: gray; }
395 span.green-background { background: green; }
396 span.lime-background { background: lime; }
397 span.maroon-background { background: maroon; }
398 span.navy-background { background: navy; }
399 span.olive-background { background: olive; }
400 span.purple-background { background: purple; }
401 span.red-background { background: red; }
402 span.silver-background { background: silver; }
403 span.teal-background { background: teal; }
404 span.white-background { background: white; }
405 span.yellow-background { background: yellow; }
407 span.big { font-size: 2em; }
408 span.small { font-size: 0.6em; }
410 span.underline { text-decoration: underline; }
411 span.overline { text-decoration: overline; }
412 span.line-through { text-decoration: line-through; }
414 div.unbreakable { page-break-inside: avoid; }
418 * xhtml11 specific
420 * */
422 div.tableblock {
423 margin-top: 1.0em;
424 margin-bottom: 1.5em;
426 div.tableblock > table {
427 border: 3px solid #527bbd;
429 thead, p.table.header {
430 font-weight: bold;
431 color: #527bbd;
433 p.table {
434 margin-top: 0;
436 /* Because the table frame attribute is overriden by CSS in most browsers. */
437 div.tableblock > table[frame="void"] {
438 border-style: none;
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;
451 * html5 specific
453 * */
455 table.tableblock {
456 margin-top: 1.0em;
457 margin-bottom: 1.5em;
459 thead, p.tableblock.header {
460 font-weight: bold;
461 color: #527bbd;
463 p.tableblock {
464 margin-top: 0;
466 table.tableblock {
467 border-width: 3px;
468 border-spacing: 0px;
469 border-style: solid;
470 border-color: #527bbd;
471 border-collapse: collapse;
473 th.tableblock, td.tableblock {
474 border-width: 1px;
475 padding: 4px;
476 border-style: solid;
477 border-color: #527bbd;
480 table.tableblock.frame-topbot {
481 border-left-style: hidden;
482 border-right-style: hidden;
484 table.tableblock.frame-sides {
485 border-top-style: hidden;
486 border-bottom-style: hidden;
488 table.tableblock.frame-none {
489 border-style: hidden;
492 th.tableblock.halign-left, td.tableblock.halign-left {
493 text-align: left;
495 th.tableblock.halign-center, td.tableblock.halign-center {
496 text-align: center;
498 th.tableblock.halign-right, td.tableblock.halign-right {
499 text-align: right;
502 th.tableblock.valign-top, td.tableblock.valign-top {
503 vertical-align: top;
505 th.tableblock.valign-middle, td.tableblock.valign-middle {
506 vertical-align: middle;
508 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
509 vertical-align: bottom;
514 * manpage specific
516 * */
518 body.manpage h1 {
519 padding-top: 0.5em;
520 padding-bottom: 0.5em;
521 border-top: 2px solid silver;
522 border-bottom: 2px solid silver;
524 body.manpage h2 {
525 border-style: none;
527 body.manpage div.sectionbody {
528 margin-left: 3em;
531 @media print {
532 body.manpage div#toc { display: none; }
536 </style>
537 <script type="text/javascript">
538 /*<![CDATA[*/
539 var asciidoc = { // Namespace.
541 /////////////////////////////////////////////////////////////////////
542 // Table Of Contents generator
543 /////////////////////////////////////////////////////////////////////
545 /* Author: Mihai Bazon, September 2002
546 * http://students.infoiasi.ro/~mishoo
548 * Table Of Content generator
549 * Version: 0.4
551 * Feel free to use this script under the terms of the GNU General Public
552 * License, as long as you do not remove or alter this notice.
555 /* modified by Troy D. Hanson, September 2006. License: GPL */
556 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
558 // toclevels = 1..4.
559 toc: function (toclevels) {
561 function getText(el) {
562 var text = "";
563 for (var i = el.firstChild; i != null; i = i.nextSibling) {
564 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
565 text += i.data;
566 else if (i.firstChild != null)
567 text += getText(i);
569 return text;
572 function TocEntry(el, text, toclevel) {
573 this.element = el;
574 this.text = text;
575 this.toclevel = toclevel;
578 function tocEntries(el, toclevels) {
579 var result = new Array;
580 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
581 // Function that scans the DOM tree for header elements (the DOM2
582 // nodeIterator API would be a better technique but not supported by all
583 // browsers).
584 var iterate = function (el) {
585 for (var i = el.firstChild; i != null; i = i.nextSibling) {
586 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
587 var mo = re.exec(i.tagName);
588 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
589 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
591 iterate(i);
595 iterate(el);
596 return result;
599 var toc = document.getElementById("toc");
600 if (!toc) {
601 return;
604 // Delete existing TOC entries in case we're reloading the TOC.
605 var tocEntriesToRemove = [];
606 var i;
607 for (i = 0; i < toc.childNodes.length; i++) {
608 var entry = toc.childNodes[i];
609 if (entry.nodeName.toLowerCase() == 'div'
610 && entry.getAttribute("class")
611 && entry.getAttribute("class").match(/^toclevel/))
612 tocEntriesToRemove.push(entry);
614 for (i = 0; i < tocEntriesToRemove.length; i++) {
615 toc.removeChild(tocEntriesToRemove[i]);
618 // Rebuild TOC entries.
619 var entries = tocEntries(document.getElementById("content"), toclevels);
620 for (var i = 0; i < entries.length; ++i) {
621 var entry = entries[i];
622 if (entry.element.id == "")
623 entry.element.id = "_toc_" + i;
624 var a = document.createElement("a");
625 a.href = "#" + entry.element.id;
626 a.appendChild(document.createTextNode(entry.text));
627 var div = document.createElement("div");
628 div.appendChild(a);
629 div.className = "toclevel" + entry.toclevel;
630 toc.appendChild(div);
632 if (entries.length == 0)
633 toc.parentNode.removeChild(toc);
637 /////////////////////////////////////////////////////////////////////
638 // Footnotes generator
639 /////////////////////////////////////////////////////////////////////
641 /* Based on footnote generation code from:
642 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
645 footnotes: function () {
646 // Delete existing footnote entries in case we're reloading the footnodes.
647 var i;
648 var noteholder = document.getElementById("footnotes");
649 if (!noteholder) {
650 return;
652 var entriesToRemove = [];
653 for (i = 0; i < noteholder.childNodes.length; i++) {
654 var entry = noteholder.childNodes[i];
655 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
656 entriesToRemove.push(entry);
658 for (i = 0; i < entriesToRemove.length; i++) {
659 noteholder.removeChild(entriesToRemove[i]);
662 // Rebuild footnote entries.
663 var cont = document.getElementById("content");
664 var spans = cont.getElementsByTagName("span");
665 var refs = {};
666 var n = 0;
667 for (i=0; i<spans.length; i++) {
668 if (spans[i].className == "footnote") {
669 n++;
670 var note = spans[i].getAttribute("data-note");
671 if (!note) {
672 // Use [\s\S] in place of . so multi-line matches work.
673 // Because JavaScript has no s (dotall) regex flag.
674 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
675 spans[i].innerHTML =
676 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
677 "' title='View footnote' class='footnote'>" + n + "</a>]";
678 spans[i].setAttribute("data-note", note);
680 noteholder.innerHTML +=
681 "<div class='footnote' id='_footnote_" + n + "'>" +
682 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
683 n + "</a>. " + note + "</div>";
684 var id =spans[i].getAttribute("id");
685 if (id != null) refs["#"+id] = n;
688 if (n == 0)
689 noteholder.parentNode.removeChild(noteholder);
690 else {
691 // Process footnoterefs.
692 for (i=0; i<spans.length; i++) {
693 if (spans[i].className == "footnoteref") {
694 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
695 href = href.match(/#.*/)[0]; // Because IE return full URL.
696 n = refs[href];
697 spans[i].innerHTML =
698 "[<a href='#_footnote_" + n +
699 "' title='View footnote' class='footnote'>" + n + "</a>]";
705 install: function(toclevels) {
706 var timerId;
708 function reinstall() {
709 asciidoc.footnotes();
710 if (toclevels) {
711 asciidoc.toc(toclevels);
715 function reinstallAndRemoveTimer() {
716 clearInterval(timerId);
717 reinstall();
720 timerId = setInterval(reinstall, 500);
721 if (document.addEventListener)
722 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
723 else
724 window.onload = reinstallAndRemoveTimer;
728 asciidoc.install();
729 /*]]>*/
730 </script>
731 </head>
732 <body class="manpage">
733 <div id="header">
734 <h1>
735 Jim Tcl(n) Manual Page
736 </h1>
737 <h2>NAME</h2>
738 <div class="sectionbody">
739 <p>Jim Tcl v0.74 -
740 reference manual for the Jim Tcl scripting language
741 </p>
742 </div>
743 </div>
744 <div id="content">
745 <div class="sect1">
746 <h2 id="_synopsis">SYNOPSIS</h2>
747 <div class="sectionbody">
748 <div class="literalblock">
749 <div class="content">
750 <pre><code>cc &lt;source&gt; -ljim</code></pre>
751 </div></div>
752 <div class="paragraph"><p>or</p></div>
753 <div class="literalblock">
754 <div class="content">
755 <pre><code>jimsh [&lt;scriptfile&gt;]
756 jimsh -e '&lt;immediate-script&gt;'
757 jimsh --version</code></pre>
758 </div></div>
759 <div class="ulist"><div class="title">Quick Index</div><ul>
760 <li>
762 <a href="#CommandIndex">Command Reference</a>
763 </p>
764 </li>
765 <li>
767 <a href="#OperatorPrecedence">Operator Precedence</a>
768 </p>
769 </li>
770 <li>
772 <a href="#BuiltinVariables">Builtin Variables</a>
773 </p>
774 </li>
775 <li>
777 <a href="#BackslashSequences">Backslash Sequences</a>
778 </p>
779 </li>
780 </ul></div>
781 </div>
782 </div>
783 <div class="sect1">
784 <h2 id="_introduction">INTRODUCTION</h2>
785 <div class="sectionbody">
786 <div class="paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
787 The core language engine is compatible with Tcl 8.5+, while implementing
788 a significant subset of the Tcl 8.6 command set, plus additional features
789 available only in Jim Tcl.</p></div>
790 <div class="paragraph"><p>Some notable differences with Tcl 8.5/8.6 are:</p></div>
791 <div class="olist arabic"><ol class="arabic">
792 <li>
794 Object-based I/O (aio), but with a Tcl-compatibility layer
795 </p>
796 </li>
797 <li>
799 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
800 </p>
801 </li>
802 <li>
804 Integers are 64bit
805 </p>
806 </li>
807 <li>
809 Support for references (<a href="#_ref"><strong><code>ref</code></strong></a>/<a href="#_getref"><strong><code>getref</code></strong></a>/<a href="#_setref"><strong><code>setref</code></strong></a>) and garbage collection
810 </p>
811 </li>
812 <li>
814 Builtin dictionary type (<a href="#_dict"><strong><code>dict</code></strong></a>) with some limitations compared to Tcl 8.6
815 </p>
816 </li>
817 <li>
819 <a href="#_env"><strong><code>env</code></strong></a> command to access environment variables
820 </p>
821 </li>
822 <li>
824 Operating system features: <a href="#cmd_1"><strong><code>os.fork</code></strong></a>, <a href="#cmd_1"><strong><code>os.wait</code></strong></a>, <a href="#cmd_1"><strong><code>os.uptime</code></strong></a>, <a href="#_signal"><strong><code>signal</code></strong></a>, <a href="#_alarm"><strong><code>alarm</code></strong></a>, <a href="#_sleep"><strong><code>sleep</code></strong></a>
825 </p>
826 </li>
827 <li>
829 Much better error reporting. <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code> as a replacement for <em>$errorInfo</em>, <em>$errorCode</em>
830 </p>
831 </li>
832 <li>
834 Support for "static" variables in procedures
835 </p>
836 </li>
837 <li>
839 Threads and coroutines are not supported
840 </p>
841 </li>
842 <li>
844 Command and variable traces are not supported
845 </p>
846 </li>
847 <li>
849 Built-in command line editing
850 </p>
851 </li>
852 <li>
854 Expression shorthand syntax: <code>$(&#8230;)</code>
855 </p>
856 </li>
857 <li>
859 Modular build allows many features to be omitted or built as dynamic, loadable modules
860 </p>
861 </li>
862 <li>
864 Highly suitable for use in an embedded environment
865 </p>
866 </li>
867 <li>
869 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
870 </p>
871 </li>
872 </ol></div>
873 </div>
874 </div>
875 <div class="sect1">
876 <h2 id="_recent_changes">RECENT CHANGES</h2>
877 <div class="sectionbody">
878 <div class="sect2">
879 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
880 <div class="olist arabic"><ol class="arabic">
881 <li>
883 Numbers with leading zeros are treated as decimal, not octal
884 </p>
885 </li>
886 <li>
888 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
889 </p>
890 </li>
891 <li>
893 Add LFS (64 bit) support for <a href="#_aio"><strong><code>aio</code></strong></a> <code>seek</code>, <a href="#_aio"><strong><code>aio</code></strong></a> <code>tell</code>, <a href="#_aio"><strong><code>aio</code></strong></a> <code>copyto</code>, <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code>
894 </p>
895 </li>
896 <li>
898 <a href="#_string"><strong><code>string</code></strong></a> <code>compare</code> and <a href="#_string"><strong><code>string</code></strong></a> <code>equal</code> now support <em>-length</em>
899 </p>
900 </li>
901 <li>
903 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
904 </p>
905 </li>
906 </ol></div>
907 </div>
908 <div class="sect2">
909 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
910 <div class="olist arabic"><ol class="arabic">
911 <li>
913 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
914 </p>
915 </li>
916 <li>
918 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
919 </p>
920 </li>
921 <li>
923 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
924 </p>
925 </li>
926 <li>
928 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
929 </p>
930 </li>
931 <li>
933 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
934 </p>
935 </li>
936 <li>
938 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
939 </p>
940 </li>
941 <li>
943 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
944 </p>
945 </li>
946 <li>
948 UTF-8 encoding past the basic multilingual plane (BMP) is supported
949 </p>
950 </li>
951 <li>
953 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
954 </p>
955 </li>
956 <li>
958 Add <a href="#_history"><strong><code>history</code></strong></a>
959 </p>
960 </li>
961 <li>
963 Most extensions are now enabled by default
964 </p>
965 </li>
966 <li>
968 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
969 </p>
970 </li>
971 <li>
973 Add <a href="#_apply"><strong><code>apply</code></strong></a>
974 </p>
975 </li>
976 </ol></div>
977 </div>
978 <div class="sect2">
979 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
980 <div class="olist arabic"><ol class="arabic">
981 <li>
983 procs now allow <em>args</em> and optional parameters in any position
984 </p>
985 </li>
986 <li>
988 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
989 </p>
990 </li>
991 <li>
993 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
994 </p>
995 </li>
996 <li>
998 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
999 </p>
1000 </li>
1001 <li>
1003 New <code>tcl_platform(pathSeparator)</code>
1004 </p>
1005 </li>
1006 <li>
1008 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1009 </p>
1010 </li>
1011 <li>
1013 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1014 </p>
1015 </li>
1016 <li>
1018 <a href="#_file"><strong><code>file</code></strong></a> <code>join</code>, <a href="#_pwd"><strong><code>pwd</code></strong></a>, <a href="#_glob"><strong><code>glob</code></strong></a> etc. now work for mingw32
1019 </p>
1020 </li>
1021 <li>
1023 Line editing is now supported for the win32 console (mingw32)
1024 </p>
1025 </li>
1026 <li>
1028 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1029 </p>
1030 </li>
1031 </ol></div>
1032 </div>
1033 <div class="sect2">
1034 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1035 <div class="olist arabic"><ol class="arabic">
1036 <li>
1038 Allow <em>args</em> to be renamed in procs
1039 </p>
1040 </li>
1041 <li>
1043 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1044 </p>
1045 </li>
1046 <li>
1048 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1049 </p>
1050 </li>
1051 <li>
1053 Support <code>jimsh --version</code>
1054 </p>
1055 </li>
1056 <li>
1058 Additional variables in <code>tcl_platform()</code>
1059 </p>
1060 </li>
1061 <li>
1063 <a href="#_local"><strong><code>local</code></strong></a> procs now push existing commands and <a href="#_upcall"><strong><code>upcall</code></strong></a> can call them
1064 </p>
1065 </li>
1066 <li>
1068 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1069 </p>
1070 </li>
1071 <li>
1073 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1074 </p>
1075 </li>
1076 <li>
1078 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1079 </p>
1080 </li>
1081 <li>
1083 <a href="#_binary"><strong><code>binary</code></strong></a> <code>format</code> and <a href="#_binary"><strong><code>binary</code></strong></a> <code>scan</code> are now (optionally) supported
1084 </p>
1085 </li>
1086 <li>
1088 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1089 </p>
1090 </li>
1091 <li>
1093 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1094 </p>
1095 </li>
1096 </ol></div>
1097 </div>
1098 </div>
1099 </div>
1100 <div class="sect1">
1101 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1102 <div class="sectionbody">
1103 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced <em>tickle.</em>
1104 It is actually two things: a language and a library.</p></div>
1105 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1106 issuing commands to interactive programs such as text editors,
1107 debuggers, illustrators, and shells. It has a simple syntax and is also
1108 programmable, so Tcl users can write command procedures to provide more
1109 powerful commands than those in the built-in set.</p></div>
1110 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1111 programs. The Tcl library consists of a parser for the Tcl language,
1112 routines to implement the Tcl built-in commands, and procedures that
1113 allow each application to extend Tcl with additional commands specific
1114 to that application. The application program generates Tcl commands and
1115 passes them to the Tcl parser for execution. Commands may be generated
1116 by reading characters from an input source, or by associating command
1117 strings with elements of the application&#8217;s user interface, such as menu
1118 entries, buttons, or keystrokes.</p></div>
1119 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1120 fields and executes built-in commands directly. For commands implemented
1121 by the application, Tcl calls back to the application to execute the
1122 commands. In many cases commands will invoke recursive invocations of the
1123 Tcl interpreter by passing in additional strings to execute (procedures,
1124 looping commands, and conditional commands all work in this way).</p></div>
1125 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1126 language. First, Tcl provides a standard syntax: once users know Tcl,
1127 they will be able to issue commands easily to any Tcl-based application.
1128 Second, Tcl provides programmability. All a Tcl application needs
1129 to do is to implement a few application-specific low-level commands.
1130 Tcl provides many utility commands plus a general programming interface
1131 for building up complex command procedures. By using Tcl, applications
1132 need not re-implement these features.</p></div>
1133 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1134 applications. Inter-application communication is not built into the
1135 Tcl core described here, but various add-on libraries, such as the Tk
1136 toolkit, allow applications to issue commands to each other. This makes
1137 it possible for applications to work together in much more powerful ways
1138 than was previously possible.</p></div>
1139 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1140 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1141 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1142 the language syntax and the built-in commands that will be available
1143 in any application based on Tcl. The individual library procedures are
1144 described in more detail in separate manual pages, one per procedure.</p></div>
1145 </div>
1146 </div>
1147 <div class="sect1">
1148 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1149 <div class="sectionbody">
1150 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1151 It may be invoked in interactive mode as:</p></div>
1152 <div class="literalblock">
1153 <div class="content">
1154 <pre><code>jimsh</code></pre>
1155 </div></div>
1156 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1157 <div class="literalblock">
1158 <div class="content">
1159 <pre><code>jimsh filename</code></pre>
1160 </div></div>
1161 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1162 <div class="literalblock">
1163 <div class="content">
1164 <pre><code>jimsh -e "script"</code></pre>
1165 </div></div>
1166 <div class="sect2">
1167 <h3 id="_interactive_mode">Interactive Mode</h3>
1168 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1169 those commands and prints the results.</p></div>
1170 <div class="literalblock">
1171 <div class="content">
1172 <pre><code>$ jimsh
1173 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1174 . info version
1175 0.73
1176 . lsort [info commands p*]
1177 package parray pid popen proc puts pwd
1178 . foreach i {a b c} {
1179 {&gt; puts $i
1180 {&gt; }
1184 . bad
1185 invalid command name "bad"
1186 [error] . exit
1187 $</code></pre>
1188 </div></div>
1189 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1190 terminal is detected, Emacs-style line editing commands are available, including:
1191 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1192 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1193 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1194 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1195 if it exists.</p></div>
1196 </div>
1197 </div>
1198 </div>
1199 <div class="sect1">
1200 <h2 id="_interpreters">INTERPRETERS</h2>
1201 <div class="sectionbody">
1202 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1203 An interpreter consists of a set of command bindings, a set of variable
1204 values, and a few other miscellaneous pieces of state. Each Tcl command
1205 is interpreted in the context of a particular interpreter.</p></div>
1206 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1207 simultaneously, each associated with a different widget or portion of
1208 the application. Interpreters are relatively lightweight structures.
1209 They can be created and deleted quickly, so application programmers should
1210 feel free to use multiple interpreters if that simplifies the application.</p></div>
1211 </div>
1212 </div>
1213 <div class="sect1">
1214 <h2 id="_data_types">DATA TYPES</h2>
1215 <div class="sectionbody">
1216 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1217 to commands, all command results, and all variable values are strings.</p></div>
1218 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1219 the arguments and results are passed as strings. Many commands expect
1220 their string arguments to have certain formats, but this interpretation
1221 is up to the individual commands. For example, arguments often contain
1222 Tcl command strings, which may get executed as part of the commands.
1223 The easiest way to understand the Tcl interpreter is to remember that
1224 everything is just an operation on a string. In many cases Tcl constructs
1225 will look similar to more structured constructs from other languages.
1226 However, the Tcl constructs are not structured at all; they are just
1227 strings of characters, and this gives them a different behaviour than
1228 the structures they may look like.</p></div>
1229 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1230 the interpretation, there are three common forms that strings take:
1231 commands, expressions, and lists. The major sections below discuss
1232 these three forms in more detail.</p></div>
1233 </div>
1234 </div>
1235 <div class="sect1">
1236 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1237 <div class="sectionbody">
1238 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1239 and Lisp. However, the interpretation of commands is different
1240 in Tcl than in either of those other two systems.
1241 A Tcl command string consists of one or more commands separated
1242 by newline characters or semi-colons.
1243 Each command consists of a collection of fields separated by
1244 white space (spaces or tabs).
1245 The first field must be the name of a command, and the
1246 additional fields, if any, are arguments that will be passed to
1247 that command. For example, the command:</p></div>
1248 <div class="literalblock">
1249 <div class="content">
1250 <pre><code>set a 22</code></pre>
1251 </div></div>
1252 <div class="paragraph"><p>has three fields: the first, <a href="#_set"><strong><code>set</code></strong></a>, is the name of a Tcl command, and
1253 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1254 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1255 Tcl command, an application-specific command bound in with the library
1256 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1257 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1258 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1259 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1260 for example, will treat its first argument as the name of a variable
1261 and its second argument as a string value to assign to that variable.
1262 For other commands arguments may be interpreted as integers, lists,
1263 file names, or Tcl commands.</p></div>
1264 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1265 However, if the Tcl interpreter cannot locate a command it invokes a
1266 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1267 command.</p></div>
1268 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1269 directories for the desired command and create it as a Tcl procedure if
1270 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1271 of abbreviated commands, but usually only for commands that were typed
1272 interactively.</p></div>
1273 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1274 other forms that will be re-used over time: changes to the command set
1275 may cause abbreviations to become ambiguous, resulting in scripts that
1276 no longer work.</p></div>
1277 </div>
1278 </div>
1279 <div class="sect1">
1280 <h2 id="_comments">COMMENTS</h2>
1281 <div class="sectionbody">
1282 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1283 from the <code>#</code> up through the next newline character is treated as
1284 a comment and ignored. When comments are embedded inside nested
1285 commands (e.g. fields enclosed in braces) they must have properly-matched
1286 braces (this is necessary because when Tcl parses the top-level command
1287 it doesn&#8217;t yet know that the nested field will be used as a command so
1288 it cannot process the nested comment character as a comment).</p></div>
1289 </div>
1290 </div>
1291 <div class="sect1">
1292 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1293 <div class="sectionbody">
1294 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1295 double-quotes may be used to create arguments with embedded space.</p></div>
1296 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1297 terminated by white space (including newlines) or a semi-colon (see below
1298 for information on semi-colons); instead it ends at the next double-quote
1299 character. The double-quotes are not included in the resulting argument.
1300 For example, the command</p></div>
1301 <div class="literalblock">
1302 <div class="content">
1303 <pre><code>set a "This is a single argument"</code></pre>
1304 </div></div>
1305 <div class="paragraph"><p>will pass two arguments to <a href="#_set"><strong><code>set</code></strong></a>: <em>a</em> and <em>This is a single argument</em>.</p></div>
1306 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1307 and backslash substitutions still occur, as described below. If the
1308 first character of a command field is not a quote, then quotes receive
1309 no special interpretation in the parsing of that field.</p></div>
1310 </div>
1311 </div>
1312 <div class="sect1">
1313 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1314 <div class="sectionbody">
1315 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1316 to quotes except for two differences. First, they nest; this makes them
1317 easier to use for complicated arguments like nested Tcl command strings.
1318 Second, the substitutions described below for commands, variables, and
1319 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1320 can be used to prevent substitutions where they are undesirable.</p></div>
1321 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1322 at the matching right brace. Tcl will strip off the outermost layer
1323 of braces and pass the information between the braces to the command
1324 without any further modification. For example, in the command</p></div>
1325 <div class="literalblock">
1326 <div class="content">
1327 <pre><code>set a {xyz a {b c d}}</code></pre>
1328 </div></div>
1329 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1330 and <em>xyz a {b c d}</em>.</p></div>
1331 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1332 not be on the same line as the starting quote or brace; in this case
1333 the newline will be included in the argument field along with any other
1334 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1335 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1336 the Tcl interpreter to execute the command string. The command</p></div>
1337 <div class="literalblock">
1338 <div class="content">
1339 <pre><code>eval {
1340 set a 22
1341 set b 33
1342 }</code></pre>
1343 </div></div>
1344 <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>
1345 <div class="paragraph"><p>If the first character of a command field is not a left
1346 brace, then neither left nor right
1347 braces in the field will be treated specially (except as part of
1348 variable substitution; see below).</p></div>
1349 </div>
1350 </div>
1351 <div class="sect1">
1352 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1353 <div class="sectionbody">
1354 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1355 substitution occurs (except for fields enclosed in braces). All of the
1356 text up to the matching close bracket is treated as a Tcl command and
1357 executed immediately. Then the result of that command is substituted
1358 for the bracketed text. For example, consider the command</p></div>
1359 <div class="literalblock">
1360 <div class="content">
1361 <pre><code>set a [set b]</code></pre>
1362 </div></div>
1363 <div class="paragraph"><p>When the <a href="#_set"><strong><code>set</code></strong></a> command has only a single argument, it is the name of a
1364 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1365 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1366 to the command</p></div>
1367 <div class="literalblock">
1368 <div class="content">
1369 <pre><code>set a foo</code></pre>
1370 </div></div>
1371 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1372 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1373 then the command</p></div>
1374 <div class="literalblock">
1375 <div class="content">
1376 <pre><code>set a xyz[set b].[set c]</code></pre>
1377 </div></div>
1378 <div class="paragraph"><p>is equivalent to the command</p></div>
1379 <div class="literalblock">
1380 <div class="content">
1381 <pre><code>set a xyzfoo.gorp</code></pre>
1382 </div></div>
1383 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1384 or semi-colons in the usual fashion. In this case the value of the last
1385 command is used for substitution. For example, the command</p></div>
1386 <div class="literalblock">
1387 <div class="content">
1388 <pre><code>set a x[set b 22
1389 expr $b+2]x</code></pre>
1390 </div></div>
1391 <div class="paragraph"><p>is equivalent to the command</p></div>
1392 <div class="literalblock">
1393 <div class="content">
1394 <pre><code>set a x24x</code></pre>
1395 </div></div>
1396 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1397 between them are not interpreted specially; they are passed through to
1398 the argument verbatim.</p></div>
1399 </div>
1400 </div>
1401 <div class="sect1">
1402 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1403 <div class="sectionbody">
1404 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1405 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1406 enclosed in braces then variable substitution will occur. The characters
1407 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1408 or underscore, are taken as a variable name and the string value of that
1409 variable is substituted for the name.</p></div>
1410 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1411 <div class="literalblock">
1412 <div class="content">
1413 <pre><code>set a $foo.c</code></pre>
1414 </div></div>
1415 <div class="paragraph"><p>is equivalent to the command</p></div>
1416 <div class="literalblock">
1417 <div class="content">
1418 <pre><code>set a test.c</code></pre>
1419 </div></div>
1420 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1421 character after the name of the variable is an open parenthesis, then
1422 the variable is assumed to be an array name, and all of the characters
1423 between the open parenthesis and the next close parenthesis are taken as
1424 an index into the array. Command substitutions and variable substitutions
1425 are performed on the information between the parentheses before it is
1426 used as an index.</p></div>
1427 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1428 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1429 then the command</p></div>
1430 <div class="literalblock">
1431 <div class="content">
1432 <pre><code>set a xyz$x(first)zyx</code></pre>
1433 </div></div>
1434 <div class="paragraph"><p>is equivalent to the command</p></div>
1435 <div class="literalblock">
1436 <div class="content">
1437 <pre><code>set a xyz87zyx</code></pre>
1438 </div></div>
1439 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1440 <div class="literalblock">
1441 <div class="content">
1442 <pre><code>set a xyz$x($index)zyx</code></pre>
1443 </div></div>
1444 <div class="paragraph"><p>is equivalent to the command</p></div>
1445 <div class="literalblock">
1446 <div class="content">
1447 <pre><code>set a xyzmorezyx</code></pre>
1448 </div></div>
1449 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1450 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1451 followed by an open curly brace. In this case the variable name consists
1452 of all the characters up to the next curly brace.</p></div>
1453 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1454 is assumed to refer to a scalar variable. For example, if variable
1455 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1456 <div class="literalblock">
1457 <div class="content">
1458 <pre><code>set a abc${foo}bar</code></pre>
1459 </div></div>
1460 <div class="paragraph"><p>is equivalent to the command</p></div>
1461 <div class="literalblock">
1462 <div class="content">
1463 <pre><code>set a abctestbar</code></pre>
1464 </div></div>
1465 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1466 braces: the dollar sign and variable name are passed through to the
1467 argument verbatim.</p></div>
1468 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1469 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1470 to reduce typing.</p></div>
1471 </div>
1472 </div>
1473 <div class="sect1">
1474 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1475 <div class="sectionbody">
1476 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1477 newline character). However, semi-colon (<code>;</code>) is treated as a command
1478 separator character; multiple commands may be placed on one line by
1479 separating them with a semi-colon. Semi-colons are not treated as
1480 command separators if they appear within curly braces or double-quotes.</p></div>
1481 </div>
1482 </div>
1483 <div class="sect1">
1484 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1485 <div class="sectionbody">
1486 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1487 fields and also to insert special characters like braces and brackets
1488 into fields without them being interpreted specially as described above.</p></div>
1489 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1490 listed below. In each case, the backslash
1491 sequence is replaced by the given character:</p></div>
1492 <div class="dlist" id="BackslashSequences"><dl>
1493 <dt class="hdlist1">
1494 <code>\b</code>
1495 </dt>
1496 <dd>
1498 Backspace (0x8)
1499 </p>
1500 </dd>
1501 <dt class="hdlist1">
1502 <code>\f</code>
1503 </dt>
1504 <dd>
1506 Form feed (0xc)
1507 </p>
1508 </dd>
1509 <dt class="hdlist1">
1510 <code>\n</code>
1511 </dt>
1512 <dd>
1514 Newline (0xa)
1515 </p>
1516 </dd>
1517 <dt class="hdlist1">
1518 <code>\r</code>
1519 </dt>
1520 <dd>
1522 Carriage-return (0xd).
1523 </p>
1524 </dd>
1525 <dt class="hdlist1">
1526 <code>\t</code>
1527 </dt>
1528 <dd>
1530 Tab (0x9).
1531 </p>
1532 </dd>
1533 <dt class="hdlist1">
1534 <code>\v</code>
1535 </dt>
1536 <dd>
1538 Vertical tab (0xb).
1539 </p>
1540 </dd>
1541 <dt class="hdlist1">
1542 <code>\{</code>
1543 </dt>
1544 <dd>
1546 Left brace ({).
1547 </p>
1548 </dd>
1549 <dt class="hdlist1">
1550 <code>\}</code>
1551 </dt>
1552 <dd>
1554 Right brace (}).
1555 </p>
1556 </dd>
1557 <dt class="hdlist1">
1558 <code>\[</code>
1559 </dt>
1560 <dd>
1562 Open bracket ([).
1563 </p>
1564 </dd>
1565 <dt class="hdlist1">
1566 <code>\]</code>
1567 </dt>
1568 <dd>
1570 Close bracket (]).
1571 </p>
1572 </dd>
1573 <dt class="hdlist1">
1574 <code>\$</code>
1575 </dt>
1576 <dd>
1578 Dollar sign ($).
1579 </p>
1580 </dd>
1581 <dt class="hdlist1">
1582 <code>\&lt;space&gt;</code>
1583 </dt>
1584 <dd>
1586 Space ( ): doesn&#8217;t terminate argument.
1587 </p>
1588 </dd>
1589 <dt class="hdlist1">
1590 <code>\;</code>
1591 </dt>
1592 <dd>
1594 Semi-colon: doesn&#8217;t terminate command.
1595 </p>
1596 </dd>
1597 <dt class="hdlist1">
1598 <code>\"</code>
1599 </dt>
1600 <dd>
1602 Double-quote.
1603 </p>
1604 </dd>
1605 <dt class="hdlist1">
1606 <code>\&lt;newline&gt;</code>
1607 </dt>
1608 <dd>
1610 Nothing: this joins two lines together
1611 into a single line. This backslash feature is unique in that
1612 it will be applied even when the sequence occurs within braces.
1613 </p>
1614 </dd>
1615 <dt class="hdlist1">
1616 <code>\\</code>
1617 </dt>
1618 <dd>
1620 Backslash (<em>\</em>).
1621 </p>
1622 </dd>
1623 <dt class="hdlist1">
1624 <code>\ddd</code>
1625 </dt>
1626 <dd>
1628 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1629 the character. Note that Jim supports null characters in strings.
1630 </p>
1631 </dd>
1632 <dt class="hdlist1">
1633 <code>\unnnn</code>
1634 </dt>
1635 <dt class="hdlist1">
1636 <code>\u{nnn}</code>
1637 </dt>
1638 <dt class="hdlist1">
1639 <code>\Unnnnnnnn</code>
1640 </dt>
1641 <dd>
1643 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1644 The <em>u</em> form allows for one to four hex digits.
1645 The <em>U</em> form allows for one to eight hex digits.
1646 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1647 characters UTF-8 characters which are followed by a hex digit.
1648 </p>
1649 </dd>
1650 </dl></div>
1651 <div class="paragraph"><p>For example, in the command</p></div>
1652 <div class="literalblock">
1653 <div class="content">
1654 <pre><code>set a \{x\[\ yz\141</code></pre>
1655 </div></div>
1656 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>{x[ yza</code>.</p></div>
1657 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1658 described above, then the backslash is transmitted to the argument
1659 field without any special processing, and the Tcl scanner continues
1660 normal processing with the next character. For example, in the
1661 command</p></div>
1662 <div class="literalblock">
1663 <div class="content">
1664 <pre><code>set \*a \\\{foo</code></pre>
1665 </div></div>
1666 <div class="paragraph"><p>The first argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\*a</code> and the second
1667 argument will be <code>\{foo</code>.</p></div>
1668 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1669 the argument are parsed but no substitution occurs (except for
1670 backslash-newline): the backslash
1671 sequence is passed through to the argument as is, without making
1672 any special interpretation of the characters in the backslash sequence.
1673 In particular, backslashed braces are not counted in locating the
1674 matching right brace that terminates the argument.
1675 For example, in the
1676 command</p></div>
1677 <div class="literalblock">
1678 <div class="content">
1679 <pre><code>set a {\{abc}</code></pre>
1680 </div></div>
1681 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1682 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1683 any argument structure; it only covers the
1684 most common cases. To produce particularly complicated arguments
1685 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1686 command substitution.</p></div>
1687 </div>
1688 </div>
1689 <div class="sect1">
1690 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1691 <div class="sectionbody">
1692 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1693 specify a position in the string relative to the start or end of the string/list.</p></div>
1694 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1695 <div class="dlist"><dl>
1696 <dt class="hdlist1">
1697 <code>integer</code>
1698 </dt>
1699 <dd>
1701 A simple integer, where <em>0</em> refers to the first element of the string
1702 or list.
1703 </p>
1704 </dd>
1705 <dt class="hdlist1">
1706 <code>integer+integer</code> or
1707 </dt>
1708 <dt class="hdlist1">
1709 <code>integer-integer</code>
1710 </dt>
1711 <dd>
1713 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1714 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1715 <code>[expr {$i+1}]</code>
1716 </p>
1717 </dd>
1718 <dt class="hdlist1">
1719 <code>end</code>
1720 </dt>
1721 <dd>
1723 The last element of the string or list.
1724 </p>
1725 </dd>
1726 <dt class="hdlist1">
1727 <code>end-integer</code>
1728 </dt>
1729 <dd>
1731 The <em>nth-from-last</em> element of the string or list.
1732 </p>
1733 </dd>
1734 </dl></div>
1735 </div>
1736 </div>
1737 <div class="sect1">
1738 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1739 <div class="sectionbody">
1740 <div class="olist arabic"><ol class="arabic">
1741 <li>
1743 A command is just a string.
1744 </p>
1745 </li>
1746 <li>
1748 Within a string commands are separated by newlines or semi-colons
1749 (unless the newline or semi-colon is within braces or brackets
1750 or is backslashed).
1751 </p>
1752 </li>
1753 <li>
1755 A command consists of fields. The first field is the name of the command.
1756 The other fields are strings that are passed to that command as arguments.
1757 </p>
1758 </li>
1759 <li>
1761 Fields are normally separated by white space.
1762 </p>
1763 </li>
1764 <li>
1766 Double-quotes allow white space and semi-colons to appear within
1767 a single argument.
1768 Command substitution, variable substitution, and backslash substitution
1769 still occur inside quotes.
1770 </p>
1771 </li>
1772 <li>
1774 Braces defer interpretation of special characters.
1775 If a field begins with a left brace, then it consists of everything
1776 between the left brace and the matching right brace. The
1777 braces themselves are not included in the argument.
1778 No further processing is done on the information between the braces
1779 except that backslash-newline sequences are eliminated.
1780 </p>
1781 </li>
1782 <li>
1784 If a field doesn&#8217;t begin with a brace then backslash,
1785 variable, and command substitution are done on the field. Only a
1786 single level of processing is done: the results of one substitution
1787 are not scanned again for further substitutions or any other
1788 special treatment. Substitution can
1789 occur on any field of a command, including the command name
1790 as well as the arguments.
1791 </p>
1792 </li>
1793 <li>
1795 If the first non-blank character of a command is a <code>#</code>, everything
1796 from the <code>#</code> up through the next newline is treated as a comment
1797 and ignored.
1798 </p>
1799 </li>
1800 </ol></div>
1801 </div>
1802 </div>
1803 <div class="sect1">
1804 <h2 id="_expressions">EXPRESSIONS</h2>
1805 <div class="sectionbody">
1806 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1807 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
1808 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1809 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1810 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1811 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1812 the operators permitted in C expressions, and they have the
1813 same meaning and precedence as the corresponding C operators.
1814 Expressions almost always yield numeric results
1815 (integer or floating-point values).
1816 For example, the expression</p></div>
1817 <div class="literalblock">
1818 <div class="content">
1819 <pre><code>8.2 + 6</code></pre>
1820 </div></div>
1821 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1822 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1823 operands are specified, and in that Tcl expressions support
1824 non-numeric operands and string comparisons.</p></div>
1825 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1826 and parentheses.</p></div>
1827 <div class="paragraph"><p>White space may be used between the operands and operators and
1828 parentheses; it is ignored by the expression processor.
1829 Where possible, operands are interpreted as integer values.</p></div>
1830 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
1831 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1832 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1833 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1834 above, then it is treated as a floating-point number if that is
1835 possible. Floating-point numbers may be specified in any of the
1836 ways accepted by an ANSI-compliant C compiler (except that the
1837 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1838 most installations). For example, all of the
1839 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1840 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1841 as a string (and only a limited set of operators may be applied to
1842 it).</p></div>
1843 <div class="olist arabic"><ol class="arabic">
1844 <li>
1846 Operands may be specified in any of the following ways:
1847 </p>
1848 </li>
1849 <li>
1851 As a numeric value, either integer or floating-point.
1852 </p>
1853 </li>
1854 <li>
1856 As a Tcl variable, using standard <em>$</em> notation.
1857 The variable&#8217;s value will be used as the operand.
1858 </p>
1859 </li>
1860 <li>
1862 As a string enclosed in double-quotes.
1863 The expression parser will perform backslash, variable, and
1864 command substitutions on the information between the quotes,
1865 and use the resulting value as the operand
1866 </p>
1867 </li>
1868 <li>
1870 As a string enclosed in braces.
1871 The characters between the open brace and matching close brace
1872 will be used as the operand without any substitutions.
1873 </p>
1874 </li>
1875 <li>
1877 As a Tcl command enclosed in brackets.
1878 The command will be executed and its result will be used as
1879 the operand.
1880 </p>
1881 </li>
1882 </ol></div>
1883 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1884 are performed by the expression processor.
1885 However, an additional layer of substitution may already have
1886 been performed by the command parser before the expression
1887 processor was called.</p></div>
1888 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1889 in braces to prevent the command parser from performing substitutions
1890 on the contents.</p></div>
1891 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1892 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1893 on the left side of each of the lines below will evaluate to the value
1894 on the right side of the line:</p></div>
1895 <div class="literalblock">
1896 <div class="content">
1897 <pre><code>$a + 3.1 6.1
1898 2 + "$a.$b" 5.6
1899 4*[llength "6 2"] 8
1900 {word one} &lt; "word $a" 0</code></pre>
1901 </div></div>
1902 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1903 of precedence:</p></div>
1904 <div class="dlist" id="OperatorPrecedence"><dl>
1905 <dt class="hdlist1">
1906 <code>int() double() round() abs(), rand(), srand()</code>
1907 </dt>
1908 <dd>
1910 Unary functions (except rand() which takes no arguments)
1911 </p>
1912 <div class="ulist"><ul>
1913 <li>
1915 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
1916 </p>
1917 </li>
1918 <li>
1920 <code><em>double()</em></code> converts the numeric argument to floating point.
1921 </p>
1922 </li>
1923 <li>
1925 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
1926 </p>
1927 </li>
1928 <li>
1930 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
1931 </p>
1932 </li>
1933 <li>
1935 <code><em>rand()</em></code> takes the absolute value of the numeric argument.
1936 </p>
1937 </li>
1938 <li>
1940 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
1941 </p>
1942 </li>
1943 <li>
1945 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
1946 </p>
1947 </li>
1948 </ul></div>
1949 </dd>
1950 <dt class="hdlist1">
1951 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
1952 </dt>
1953 <dd>
1955 Unary math functions.
1956 If Jim is compiled with math support, these functions are available.
1957 </p>
1958 </dd>
1959 <dt class="hdlist1">
1960 <code>- + ~ !</code>
1961 </dt>
1962 <dd>
1964 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
1965 may be applied to string operands, and bit-wise NOT may be
1966 applied only to integers.
1967 </p>
1968 </dd>
1969 <dt class="hdlist1">
1970 <code>** pow(x,y)</code>
1971 </dt>
1972 <dd>
1974 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
1975 integers. Otherwise supports integers only. (Note that the math-function form
1976 has the same highest precedence)
1977 </p>
1978 </dd>
1979 <dt class="hdlist1">
1980 <code>* / %</code>
1981 </dt>
1982 <dd>
1984 Multiply, divide, remainder. None of these operands may be
1985 applied to string operands, and remainder may be applied only
1986 to integers.
1987 </p>
1988 </dd>
1989 <dt class="hdlist1">
1990 <code>+ -</code>
1991 </dt>
1992 <dd>
1994 Add and subtract. Valid for any numeric operands.
1995 </p>
1996 </dd>
1997 <dt class="hdlist1">
1998 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
1999 </dt>
2000 <dd>
2002 Left and right shift, left and right rotate. Valid for integer operands only.
2003 </p>
2004 </dd>
2005 <dt class="hdlist1">
2006 <code>&lt; &gt; &lt;= &gt;=</code>
2007 </dt>
2008 <dd>
2010 Boolean less, greater, less than or equal, and greater than or equal.
2011 Each operator produces 1 if the condition is true, 0 otherwise.
2012 These operators may be applied to strings as well as numeric operands,
2013 in which case string comparison is used.
2014 </p>
2015 </dd>
2016 <dt class="hdlist1">
2017 <code>== !=</code>
2018 </dt>
2019 <dd>
2021 Boolean equal and not equal. Each operator produces a zero/one result.
2022 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2023 if possible, then floating point types, and finally strings will be compared.
2024 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2025 </p>
2026 </dd>
2027 <dt class="hdlist1">
2028 <code>eq ne</code>
2029 </dt>
2030 <dd>
2032 String equal and not equal. Uses the string value directly without
2033 attempting to convert to a number first.
2034 </p>
2035 </dd>
2036 <dt class="hdlist1">
2037 <code>in ni</code>
2038 </dt>
2039 <dd>
2041 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2042 is contained in the right operand (as a list), or 0 otherwise. The result for
2043 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2044 </p>
2045 </dd>
2046 <dt class="hdlist1">
2047 <code>&amp;</code>
2048 </dt>
2049 <dd>
2051 Bit-wise AND. Valid for integer operands only.
2052 </p>
2053 </dd>
2054 <dt class="hdlist1">
2055 <code>|</code>
2056 </dt>
2057 <dd>
2059 Bit-wise OR. Valid for integer operands only.
2060 </p>
2061 </dd>
2062 <dt class="hdlist1">
2063 <code>^</code>
2064 </dt>
2065 <dd>
2067 Bit-wise exclusive OR. Valid for integer operands only.
2068 </p>
2069 </dd>
2070 <dt class="hdlist1">
2071 <code>&amp;&amp;</code>
2072 </dt>
2073 <dd>
2075 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2076 Valid for numeric operands only (integers or floating-point).
2077 </p>
2078 </dd>
2079 <dt class="hdlist1">
2080 <code>||</code>
2081 </dt>
2082 <dd>
2084 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2085 Valid for numeric operands only (integers or floating-point).
2086 </p>
2087 </dd>
2088 <dt class="hdlist1">
2089 <code>x ? y : z</code>
2090 </dt>
2091 <dd>
2093 If-then-else, as in C. If <code><em>x</em></code>
2094 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2095 Otherwise the result is the value of <code><em>z</em></code>.
2096 The <code><em>x</em></code> operand must have a numeric value, while <code><em>y</em></code> and <code><em>z</em></code> can
2097 be of any type.
2098 </p>
2099 </dd>
2100 </dl></div>
2101 <div class="paragraph"><p>See the C manual for more details on the results
2102 produced by each operator.
2103 All of the binary operators group left-to-right within the same
2104 precedence level. For example, the expression</p></div>
2105 <div class="literalblock">
2106 <div class="content">
2107 <pre><code>4*2 &lt; 7</code></pre>
2108 </div></div>
2109 <div class="paragraph"><p>evaluates to 0.</p></div>
2110 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2111 in C, which means that operands are not evaluated if they are not
2112 needed to determine the outcome. For example, in</p></div>
2113 <div class="literalblock">
2114 <div class="content">
2115 <pre><code>$v ? [a] : [b]</code></pre>
2116 </div></div>
2117 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2118 depending on the value of <code>$v</code>.</p></div>
2119 <div class="paragraph"><p>All internal computations involving integers are done with the C
2120 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2121 computations involving floating-point are done with the C type
2122 <em>double</em>.</p></div>
2123 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2124 detected and results in a Tcl error.
2125 For conversion to integer from string, detection of overflow depends
2126 on the behaviour of some routines in the local C library, so it should
2127 be regarded as unreliable.
2128 In any case, overflow and underflow are generally not detected
2129 reliably for intermediate results.</p></div>
2130 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2131 and string operands is done automatically as needed.
2132 For arithmetic computations, integers are used until some
2133 floating-point number is introduced, after which floating-point is used.
2134 For example,</p></div>
2135 <div class="literalblock">
2136 <div class="content">
2137 <pre><code>5 / 4</code></pre>
2138 </div></div>
2139 <div class="paragraph"><p>yields the result 1, while</p></div>
2140 <div class="literalblock">
2141 <div class="content">
2142 <pre><code>5 / 4.0
2143 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2144 </div></div>
2145 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2146 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2147 although the expression evaluator tries to do comparisons as integer
2148 or floating-point when it can.
2149 If one of the operands of a comparison is a string and the other
2150 has a numeric value, the numeric operand is converted back to
2151 a string using the C <em>sprintf</em> format specifier
2152 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2153 For example, the expressions</p></div>
2154 <div class="literalblock">
2155 <div class="content">
2156 <pre><code>"0x03" &gt; "2"
2157 "0y" &lt; "0x12"</code></pre>
2158 </div></div>
2159 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2160 comparison, and the second is done using string comparison after
2161 the second operand is converted to the string <em>18</em>.</p></div>
2162 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2163 entering it in a command: otherwise, if the expression contains
2164 any white space then the Tcl interpreter will split it
2165 among several arguments. For example, the command</p></div>
2166 <div class="literalblock">
2167 <div class="content">
2168 <pre><code>expr $a + $b</code></pre>
2169 </div></div>
2170 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2171 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2172 then the Tcl interpreter will perform variable and command substitution
2173 immediately (it will happen in the command parser rather than in
2174 the expression parser). In many cases the expression is being
2175 passed to a command that will evaluate the expression later (or
2176 even many times if, for example, the expression is to be used to
2177 decide when to exit a loop). Usually the desired goal is to re-do
2178 the variable or command substitutions each time the expression is
2179 evaluated, rather than once and for all at the beginning. For example,
2180 the command</p></div>
2181 <div class="literalblock">
2182 <div class="content">
2183 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2184 </div></div>
2185 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2186 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2187 its second argument to the expression evaluator to see whether or not
2188 to continue processing. Unfortunately, in this case the value of <code>i</code>
2189 in the second argument will be substituted once and for all when the
2190 <a href="#_for"><strong><code>for</code></strong></a> command is parsed. If <code>i</code> was 0 before the <a href="#_for"><strong><code>for</code></strong></a>
2191 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2192 which will always evaluate to 1, even though <code>i</code> eventually
2193 becomes greater than 10. In the above case the loop will never
2194 terminate. Instead, the expression should be placed in braces:</p></div>
2195 <div class="literalblock">
2196 <div class="content">
2197 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2198 </div></div>
2199 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2200 to be delayed; it will be re-done each time the expression is
2201 evaluated, which is the desired result.</p></div>
2202 </div>
2203 </div>
2204 <div class="sect1">
2205 <h2 id="_lists">LISTS</h2>
2206 <div class="sectionbody">
2207 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2208 A list is just a string with a list-like structure
2209 consisting of fields separated by white space. For example, the
2210 string</p></div>
2211 <div class="literalblock">
2212 <div class="content">
2213 <pre><code>Al Sue Anne John</code></pre>
2214 </div></div>
2215 <div class="paragraph"><p>is a list with four elements or fields.
2216 Lists have the same basic structure as command strings, except
2217 that a newline character in a list is treated as a field separator
2218 just like space or tab. Conventions for braces and quotes
2219 and backslashes are the same for lists as for commands. For example,
2220 the string</p></div>
2221 <div class="literalblock">
2222 <div class="content">
2223 <pre><code>a b\ c {d e {f g h}}</code></pre>
2224 </div></div>
2225 <div class="paragraph"><p>is a list with three elements: <code>a</code>, <code>b c</code>, and <code>d e {f g h}</code>.</p></div>
2226 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2227 braces and quotes and backslashes are applied as for commands. Thus in
2228 the example above when the third element is extracted from the list,
2229 the result is</p></div>
2230 <div class="literalblock">
2231 <div class="content">
2232 <pre><code>d e {f g h}</code></pre>
2233 </div></div>
2234 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2235 the outermost layer of braces). Command substitution and
2236 variable substitution are never
2237 made on a list (at least, not by the list-processing commands; the
2238 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2239 <div class="paragraph"><p>The Tcl commands <a href="#_concat"><strong><code>concat</code></strong></a>, <a href="#_foreach"><strong><code>foreach</code></strong></a>, <a href="#_lappend"><strong><code>lappend</code></strong></a>, <a href="#_lindex"><strong><code>lindex</code></strong></a>, <a href="#_linsert"><strong><code>linsert</code></strong></a>,
2240 <a href="#_list"><strong><code>list</code></strong></a>, <a href="#_llength"><strong><code>llength</code></strong></a>, <a href="#_lrange"><strong><code>lrange</code></strong></a>, <a href="#_lreplace"><strong><code>lreplace</code></strong></a>, <a href="#_lsearch"><strong><code>lsearch</code></strong></a>, and <a href="#_lsort"><strong><code>lsort</code></strong></a> allow
2241 you to build lists, extract elements from them, search them, and perform
2242 other list-related functions.</p></div>
2243 <div class="paragraph"><p>Advanced list commands include <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>, <a href="#_lreverse"><strong><code>lreverse</code></strong></a>, <a href="#_lmap"><strong><code>lmap</code></strong></a>, <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lset"><strong><code>lset</code></strong></a>.</p></div>
2244 </div>
2245 </div>
2246 <div class="sect1">
2247 <h2 id="_list_expansion">LIST EXPANSION</h2>
2248 <div class="sectionbody">
2249 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2250 arguments. Support for this feature is also available in Jim.</p></div>
2251 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2252 <div class="literalblock">
2253 <div class="content">
2254 <pre><code>set cmd {ls -l}
2255 exec $cmd</code></pre>
2256 </div></div>
2257 <div class="paragraph"><p>This will attempt to exec the a command named "ls -l", which will clearly not
2258 work. Typically eval and concat are required to solve this problem, however
2259 it can be solved much more easily with <code>{*}</code>.</p></div>
2260 <div class="literalblock">
2261 <div class="content">
2262 <pre><code>exec {*}$cmd</code></pre>
2263 </div></div>
2264 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2265 the resulting command.</p></div>
2266 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2267 for backward compatibility with experimental versions of this feature.</p></div>
2268 </div>
2269 </div>
2270 <div class="sect1">
2271 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2272 <div class="sectionbody">
2273 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2274 expressions, <a href="#_regexp"><strong><code>regexp</code></strong></a> and <a href="#_regsub"><strong><code>regsub</code></strong></a>, as well as <a href="#_switch"><strong><code>switch</code></strong></a> <code>-regexp</code> and
2275 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2276 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2277 POSIX regular expression support, or using the built-in regular expression engine.
2278 The differences between these are described below.</p></div>
2279 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2280 <div class="sect2">
2281 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2282 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2283 this support will be used by default. The type of regular expressions supported are
2284 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2285 See REG_EXTENDED in the documentation.</p></div>
2286 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2287 make for the smallest code size, but some features such as UTF-8
2288 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported.</p></div>
2289 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2290 </div>
2291 <div class="sect2">
2292 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2293 <div class="paragraph"><p>The Jim built-in regulare expression engine may be selected with <code>./configure --with-jim-regexp</code>
2294 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2295 <div class="paragraph"><p>This engine supports UTF-8 as well as some <code>ARE</code> features. The differences with both Tcl 7.x/8.x
2296 and POSIX are highlighted below.</p></div>
2297 <div class="olist arabic"><ol class="arabic">
2298 <li>
2300 UTF-8 strings and patterns are both supported
2301 </p>
2302 </li>
2303 <li>
2305 Supported character classes: <code>[:alnum:]</code>, <code>[:digit:]</code> and <code>[:space:]</code>
2306 </p>
2307 </li>
2308 <li>
2310 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>
2311 </p>
2312 </li>
2313 <li>
2315 Character classes apply to ASCII characters only
2316 </p>
2317 </li>
2318 <li>
2320 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2321 </p>
2322 </li>
2323 <li>
2325 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2326 </p>
2327 </li>
2328 <li>
2330 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2331 </p>
2332 </li>
2333 <li>
2335 Support for non-capuring parentheses <code>(?:&#8230;)</code>
2336 </p>
2337 </li>
2338 </ol></div>
2339 </div>
2340 </div>
2341 </div>
2342 <div class="sect1">
2343 <h2 id="_command_results">COMMAND RESULTS</h2>
2344 <div class="sectionbody">
2345 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2346 code indicates whether the command completed successfully or not,
2347 and the string gives additional information. The valid codes are
2348 defined in jim.h, and are:</p></div>
2349 <div class="dlist"><dl>
2350 <dt class="hdlist1">
2351 <code>JIM_OK(0)</code>
2352 </dt>
2353 <dd>
2355 This is the normal return code, and indicates that the command completed
2356 successfully. The string gives the command&#8217;s return value.
2357 </p>
2358 </dd>
2359 <dt class="hdlist1">
2360 <code>JIM_ERR(1)</code>
2361 </dt>
2362 <dd>
2364 Indicates that an error occurred; the string gives a message describing
2365 the error.
2366 </p>
2367 </dd>
2368 <dt class="hdlist1">
2369 <code>JIM_RETURN(2)</code>
2370 </dt>
2371 <dd>
2373 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2374 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2375 should return immediately. The
2376 string gives the return value for the procedure or command.
2377 </p>
2378 </dd>
2379 <dt class="hdlist1">
2380 <code>JIM_BREAK(3)</code>
2381 </dt>
2382 <dd>
2384 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2385 innermost loop should abort immediately. The string should always
2386 be empty.
2387 </p>
2388 </dd>
2389 <dt class="hdlist1">
2390 <code>JIM_CONTINUE(4)</code>
2391 </dt>
2392 <dd>
2394 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2395 innermost loop should go on to the next iteration. The string
2396 should always be empty.
2397 </p>
2398 </dd>
2399 <dt class="hdlist1">
2400 <code>JIM_SIGNAL(5)</code>
2401 </dt>
2402 <dd>
2404 Indicates that a signal was caught while executing a commands.
2405 The string contains the name of the signal caught.
2406 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2407 </p>
2408 </dd>
2409 <dt class="hdlist1">
2410 <code>JIM_EXIT(6)</code>
2411 </dt>
2412 <dd>
2414 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2415 The string contains the exit code.
2416 </p>
2417 </dd>
2418 </dl></div>
2419 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2420 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2421 by a command, then the Tcl interpreter immediately stops processing
2422 commands and returns to its caller. If there are several nested
2423 invocations of the Tcl interpreter in progress, then each nested
2424 command will usually return the error to its caller, until eventually
2425 the error is reported to the top-level application code. The
2426 application will then display the error message for the user.</p></div>
2427 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2428 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2429 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2430 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2431 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2432 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2433 command allows Tcl programs to catch errors and handle them without
2434 aborting command interpretation any further.</p></div>
2435 <div class="paragraph"><p>The <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command may be used to programmatically map between
2436 return codes and names.</p></div>
2437 </div>
2438 </div>
2439 <div class="sect1">
2440 <h2 id="_procedures">PROCEDURES</h2>
2441 <div class="sectionbody">
2442 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2443 procedures. A Tcl procedure can be invoked just like any other Tcl
2444 command (it has a name and it receives one or more arguments).
2445 The only difference is that its body isn&#8217;t a piece of C code linked
2446 into the program; it is a string containing one or more other
2447 Tcl commands.</p></div>
2448 <div class="paragraph"><p>The <a href="#_proc"><strong><code>proc</code></strong></a> command is used to create a new Tcl command procedure:</p></div>
2449 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2450 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2451 there may have been by that name. Whenever the new command is
2452 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2453 interpreter.</p></div>
2454 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2455 It consists of a list, possibly empty, of the following
2456 argument specifiers:</p></div>
2457 <div class="dlist"><dl>
2458 <dt class="hdlist1">
2459 <code>name</code>
2460 </dt>
2461 <dd>
2463 Required Argument - A simple argument name.
2464 </p>
2465 </dd>
2466 <dt class="hdlist1">
2467 <code>name default</code>
2468 </dt>
2469 <dd>
2471 Optional Argument - A two-element list consisting of the
2472 argument name, followed by the default value, which will
2473 be used if the corresponding argument is not supplied.
2474 </p>
2475 </dd>
2476 <dt class="hdlist1">
2477 <code>&amp;name</code>
2478 </dt>
2479 <dd>
2481 Reference Argument - The caller is expected to pass the name of
2482 an existing variable. An implicit <a href="#_upvar"><strong><code>upvar</code></strong></a> <code>1 'origname' 'name'</code> is done
2483 to make the variable available in the proc scope.
2484 </p>
2485 </dd>
2486 <dt class="hdlist1">
2487 <code><strong>args</strong></code>
2488 </dt>
2489 <dd>
2491 Variable Argument - The special name <code><em>args</em></code>, which is
2492 assigned all remaining arguments (including none) as a list. The
2493 variable argument may only be specified once. Note that
2494 the syntax <code>args newname</code> may be used to retain the special
2495 behaviour of <code><em>args</em></code> with a different local name. In this case,
2496 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2497 </p>
2498 </dd>
2499 </dl></div>
2500 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2501 the formal arguments to the procedure; its value will be the value
2502 of corresponding argument in the invoking command or the argument&#8217;s
2503 default value.</p></div>
2504 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2505 invocation. However, there must be enough actual arguments for all
2506 required arguments, and there must not be any extra actual arguments
2507 (unless the Variable Argument is specified).</p></div>
2508 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2509 order with the following precedence.</p></div>
2510 <div class="olist arabic"><ol class="arabic">
2511 <li>
2513 Required Arguments (including Reference Arguments)
2514 </p>
2515 </li>
2516 <li>
2518 Optional Arguments
2519 </p>
2520 </li>
2521 <li>
2523 Variable Argument
2524 </p>
2525 </li>
2526 </ol></div>
2527 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2528 <div class="literalblock">
2529 <div class="content">
2530 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2531 </div></div>
2532 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2533 The following table shows how various numbers of arguments are assigned.
2534 Values marked as <code>-</code> are assigned the default value.</p></div>
2535 <div class="tableblock">
2536 <table rules="all"
2537 width="40%"
2538 frame="hsides"
2539 cellspacing="0" cellpadding="4">
2540 <col width="16%" />
2541 <col width="16%" />
2542 <col width="16%" />
2543 <col width="16%" />
2544 <col width="16%" />
2545 <col width="16%" />
2546 <thead>
2547 <tr>
2548 <th align="left" valign="top">Number of arguments</th>
2549 <th align="left" valign="top">a</th>
2550 <th align="left" valign="top">args</th>
2551 <th align="left" valign="top">b</th>
2552 <th align="left" valign="top">c</th>
2553 <th align="left" valign="top">d</th>
2554 </tr>
2555 </thead>
2556 <tbody>
2557 <tr>
2558 <td align="left" valign="top"><p class="table">2</p></td>
2559 <td align="left" valign="top"><p class="table">-</p></td>
2560 <td align="left" valign="top"><p class="table">-</p></td>
2561 <td align="left" valign="top"><p class="table">1</p></td>
2562 <td align="left" valign="top"><p class="table">-</p></td>
2563 <td align="left" valign="top"><p class="table">2</p></td>
2564 </tr>
2565 <tr>
2566 <td align="left" valign="top"><p class="table">3</p></td>
2567 <td align="left" valign="top"><p class="table">1</p></td>
2568 <td align="left" valign="top"><p class="table">-</p></td>
2569 <td align="left" valign="top"><p class="table">2</p></td>
2570 <td align="left" valign="top"><p class="table">-</p></td>
2571 <td align="left" valign="top"><p class="table">3</p></td>
2572 </tr>
2573 <tr>
2574 <td align="left" valign="top"><p class="table">4</p></td>
2575 <td align="left" valign="top"><p class="table">1</p></td>
2576 <td align="left" valign="top"><p class="table">-</p></td>
2577 <td align="left" valign="top"><p class="table">2</p></td>
2578 <td align="left" valign="top"><p class="table">3</p></td>
2579 <td align="left" valign="top"><p class="table">4</p></td>
2580 </tr>
2581 <tr>
2582 <td align="left" valign="top"><p class="table">5</p></td>
2583 <td align="left" valign="top"><p class="table">1</p></td>
2584 <td align="left" valign="top"><p class="table">2</p></td>
2585 <td align="left" valign="top"><p class="table">3</p></td>
2586 <td align="left" valign="top"><p class="table">4</p></td>
2587 <td align="left" valign="top"><p class="table">5</p></td>
2588 </tr>
2589 <tr>
2590 <td align="left" valign="top"><p class="table">6</p></td>
2591 <td align="left" valign="top"><p class="table">1</p></td>
2592 <td align="left" valign="top"><p class="table">2,3</p></td>
2593 <td align="left" valign="top"><p class="table">4</p></td>
2594 <td align="left" valign="top"><p class="table">5</p></td>
2595 <td align="left" valign="top"><p class="table">6</p></td>
2596 </tr>
2597 </tbody>
2598 </table>
2599 </div>
2600 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2601 variables, which are created automatically when referenced and deleted
2602 when the procedure returns. One local variable is automatically created
2603 for each of the procedure&#8217;s arguments. Global variables can be
2604 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2605 <div class="sect2">
2606 <h3 id="_new_in_jim">New in Jim</h3>
2607 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2608 These variables scoped to the procedure and initialised at procedure definition.
2609 Either from the static variable definition, or from the enclosing scope.</p></div>
2610 <div class="paragraph"><p>Consider the following example:</p></div>
2611 <div class="literalblock">
2612 <div class="content">
2613 <pre><code>jim&gt; set a 1
2614 jim&gt; proc a {} {a {b 2}} {
2615 set c 1
2616 puts "$a $b $c"
2617 incr a
2618 incr b
2619 incr c
2621 jim&gt; a
2622 1 2 1
2623 jim&gt; a
2624 2 3 1</code></pre>
2625 </div></div>
2626 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2627 the enclosing scope with the value 1. (Note that it is an error if there
2628 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2629 has an initialiser, so it is initialised to 2.</p></div>
2630 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2631 invocations of the procedure.</p></div>
2632 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2633 and what happens when they are invoked. See also NAMESPACES.</p></div>
2634 </div>
2635 </div>
2636 </div>
2637 <div class="sect1">
2638 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2639 <div class="sectionbody">
2640 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2641 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2642 command, or a few other mechanisms.</p></div>
2643 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2644 be created each time a new variable name is used.</p></div>
2645 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2646 A scalar variable has a single value, whereas an array variable
2647 can have any number of elements, each with a name (called
2648 its <em>index</em>) and a value.</p></div>
2649 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2650 Parentheses are used refer to array elements in Tcl commands.
2651 For example, the command</p></div>
2652 <div class="literalblock">
2653 <div class="content">
2654 <pre><code>set x(first) 44</code></pre>
2655 </div></div>
2656 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2657 so that its new value is <em>44</em>.</p></div>
2658 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2659 that contain multiple concatenated values.
2660 For example, the commands</p></div>
2661 <div class="literalblock">
2662 <div class="content">
2663 <pre><code>set a(2,3) 1
2664 set a(3,6) 2</code></pre>
2665 </div></div>
2666 <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>
2667 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2668 variables may be used.</p></div>
2669 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2670 not be a scalar variable with the same name.</p></div>
2671 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2672 name then it is not possible to make array references to the
2673 variable.</p></div>
2674 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2675 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2676 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2677 with arrays, such as querying the names of all the elements of
2678 the array and converting between an array and a list.</p></div>
2679 <div class="paragraph"><p>Variables may be either global or local. If a variable
2680 name is used when a procedure isn&#8217;t being executed, then it
2681 automatically refers to a global variable. Variable names used
2682 within a procedure normally refer to local variables associated with that
2683 invocation of the procedure. Local variables are deleted whenever
2684 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2685 that a name refer to a global variable for the duration of the current
2686 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2687 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2688 <div class="literalblock">
2689 <div class="content">
2690 <pre><code>set a 1
2691 set b 2
2692 proc p {} {
2693 set c 3
2694 global a</code></pre>
2695 </div></div>
2696 <div class="literalblock">
2697 <div class="content">
2698 <pre><code> puts "$a $::b $c"
2700 p</code></pre>
2701 </div></div>
2702 <div class="paragraph"><p>will output:</p></div>
2703 <div class="literalblock">
2704 <div class="content">
2705 <pre><code>1 2 3</code></pre>
2706 </div></div>
2707 </div>
2708 </div>
2709 <div class="sect1">
2710 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2711 <div class="sectionbody">
2712 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2713 number of elements) and an array value. This is similar to the way Tcl
2714 can convert between a string and a list.</p></div>
2715 <div class="paragraph"><p>For example:</p></div>
2716 <div class="literalblock">
2717 <div class="content">
2718 <pre><code>set a {1 one 2 two}
2719 puts $a(2)</code></pre>
2720 </div></div>
2721 <div class="paragraph"><p>will output:</p></div>
2722 <div class="literalblock">
2723 <div class="content">
2724 <pre><code>two</code></pre>
2725 </div></div>
2726 <div class="paragraph"><p>Thus <a href="#_array"><strong><code>array</code></strong></a> <code>set</code> is equivalent to <a href="#_set"><strong><code>set</code></strong></a> when the variable does not
2727 exist or is empty.</p></div>
2728 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2729 a list.</p></div>
2730 <div class="literalblock">
2731 <div class="content">
2732 <pre><code>set a(1) one; set a(2) two
2733 puts $a</code></pre>
2734 </div></div>
2735 <div class="paragraph"><p>will output:</p></div>
2736 <div class="literalblock">
2737 <div class="content">
2738 <pre><code>1 one 2 two</code></pre>
2739 </div></div>
2740 </div>
2741 </div>
2742 <div class="sect1">
2743 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2744 <div class="sectionbody">
2745 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2746 of this command. Dictionaries provide efficient access to key-value
2747 pairs, just like arrays, but dictionaries are pure values. This
2748 means that you can pass them to a procedure just as a list or a
2749 string. Tcl dictionaries are therefore much more like Tcl lists,
2750 except that they represent a mapping from keys to values, rather
2751 than an ordered sequence.</p></div>
2752 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2753 consists of another dictionary. That way you can elegantly build
2754 complicated data structures, such as hierarchical databases. You
2755 can also combine dictionaries with other Tcl data structures. For
2756 instance, you can build a list of dictionaries that themselves
2757 contain lists.</p></div>
2758 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2759 mapping from arbitrary keys to arbitrary values. Each key in the
2760 dictionary maps to a single value. They have a textual format that
2761 is exactly that of any list with an even number of elements, with
2762 each mapping in the dictionary being represented as two items in
2763 the list. When a command takes a dictionary and produces a new
2764 dictionary based on it (either returning it or writing it back into
2765 the variable that the starting dictionary was read from) the new
2766 dictionary will have the same order of keys, modulo any deleted
2767 keys and with new keys added on to the end. When a string is
2768 interpreted as a dictionary and it would otherwise have duplicate
2769 keys, only the last value for a particular key is used; the others
2770 are ignored, meaning that, "apple banana" and "apple carrot apple
2771 banana" are equivalent dictionaries (with different string
2772 representations).</p></div>
2773 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2774 Thus automatic conversion between lists and dictionaries applies
2775 as it does for arrays.</p></div>
2776 <div class="literalblock">
2777 <div class="content">
2778 <pre><code>jim&gt; dict set a 1 one
2779 1 one
2780 jim&gt; dict set a 2 two
2781 1 one 2 two
2782 jim&gt; puts $a
2783 1 one 2 two
2784 jim&gt; puts $a(2)
2786 jim&gt; dict set a 3 T three
2787 1 one 2 two 3 {T three}</code></pre>
2788 </div></div>
2789 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2790 </div>
2791 </div>
2792 <div class="sect1">
2793 <h2 id="_namespaces">NAMESPACES</h2>
2794 <div class="sectionbody">
2795 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2796 including a number of 3rd party components. While there is less need for namespaces
2797 in Jim Tcl (which does not strive to support large applications), it is convenient to
2798 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2799 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
2800 purposes. This feature is currently experimental. See README.namespaces for more information
2801 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
2802 </div>
2803 </div>
2804 <div class="sect1">
2805 <h2 id="_garbage_collection_references_lambda">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2806 <div class="sectionbody">
2807 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2808 These are described briefly below.</p></div>
2809 <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>
2810 <div class="sect2">
2811 <h3 id="_references">References</h3>
2812 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2813 where the value may be garbage collected when unreferenced.
2814 Consider the following example:</p></div>
2815 <div class="literalblock">
2816 <div class="content">
2817 <pre><code>jim&gt; set r [ref "One String" test]
2818 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2819 jim&gt; getref $r
2820 One String</code></pre>
2821 </div></div>
2822 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2823 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2824 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2825 stored in the reference.</p></div>
2826 <div class="literalblock">
2827 <div class="content">
2828 <pre><code>jim&gt; setref $r "New String"
2829 New String
2830 jim&gt; getref $r
2831 New String</code></pre>
2832 </div></div>
2833 <div class="paragraph"><p>The operation <a href="#_setref"><strong><code>setref</code></strong></a> replaces the value stored by the reference. If the old value
2834 is no longer accessible by any reference, it will eventually be automatically be garbage
2835 collected.</p></div>
2836 </div>
2837 <div class="sect2">
2838 <h3 id="_garbage_collection">Garbage Collection</h3>
2839 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2840 automatically as necessary.</p></div>
2841 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2842 transcend their scope. To support this, case, the Jim system will periodically identify
2843 and discard objects which are no longer accessible by any reference.</p></div>
2844 <div class="paragraph"><p>The <a href="#_collect"><strong><code>collect</code></strong></a> command may be used to force garbage collection. Consider a reference created
2845 with a finalizer:</p></div>
2846 <div class="literalblock">
2847 <div class="content">
2848 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2849 jim&gt; set r [ref "One String" test f]
2850 &lt;reference.&lt;test___&gt;.00000000000
2851 jim&gt; collect
2853 jim&gt; set r ""
2854 jim&gt; collect
2855 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2856 1</code></pre>
2857 </div></div>
2858 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2859 contained a reference to the value, the garbage collector discarded
2860 the value (after calling the finalizer).</p></div>
2861 <div class="paragraph"><p>The finalizer for a reference may be examined or changed with the <a href="#_finalize"><strong><code>finalize</code></strong></a> command</p></div>
2862 <div class="literalblock">
2863 <div class="content">
2864 <pre><code>jim&gt; finalize $r
2866 jim&gt; finalize $r newf
2867 newf</code></pre>
2868 </div></div>
2869 </div>
2870 <div class="sect2">
2871 <h3 id="_lambda">Lambda</h3>
2872 <div class="paragraph"><p>Jim provides a garbage collected lambda function. This is a procedure
2873 which is able to create an anonymous procedure. Consider:</p></div>
2874 <div class="literalblock">
2875 <div class="content">
2876 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2877 jim&gt; $f 1
2879 jim&gt; $f 2
2881 jim&gt; set f ""</code></pre>
2882 </div></div>
2883 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2884 which is incremented by the supplied value and the result returned.</p></div>
2885 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2886 when the garbage collector runs.</p></div>
2887 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2888 <div class="literalblock">
2889 <div class="content">
2890 <pre><code>jim&gt; rename $f ""</code></pre>
2891 </div></div>
2892 </div>
2893 </div>
2894 </div>
2895 <div class="sect1">
2896 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2897 <div class="sectionbody">
2898 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2899 then most string-related commands become UTF-8 aware. These include,
2900 but are not limited to, <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>, <a href="#_split"><strong><code>split</code></strong></a>, <a href="#_glob"><strong><code>glob</code></strong></a>, <a href="#_scan"><strong><code>scan</code></strong></a> and
2901 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
2902 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2903 characters can take a variable number of bytes. Thus the addition of
2904 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
2905 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
2906 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2907 and <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> returns the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code>.</p></div>
2908 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
2909 is still available to embed UTF-8 sequences.</p></div>
2910 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
2911 <div class="sect2">
2912 <h3 id="_string_matching">String Matching</h3>
2913 <div class="paragraph"><p>Commands such as <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>, <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-glob</code>, <a href="#_array"><strong><code>array</code></strong></a> <code>names</code> and others use string
2914 pattern matching rules. These commands support UTF-8. For example:</p></div>
2915 <div class="literalblock">
2916 <div class="content">
2917 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
2918 </div></div>
2919 </div>
2920 <div class="sect2">
2921 <h3 id="_format_and_scan">format and scan</h3>
2922 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
2923 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
2924 <div class="literalblock">
2925 <div class="content">
2926 <pre><code>format %c 0xb5</code></pre>
2927 </div></div>
2928 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> respects widths as character widths, not byte widths. For example, the following will
2929 return a string with three characters, not three bytes.</p></div>
2930 <div class="literalblock">
2931 <div class="content">
2932 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
2933 </div></div>
2934 <div class="paragraph"><p>Similarly, <code>scan &#8230; %c</code> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
2935 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
2936 <div class="literalblock">
2937 <div class="content">
2938 <pre><code>scan \u00b5A %c%c a b</code></pre>
2939 </div></div>
2940 <div class="paragraph"><p><a href="#_scan"><strong><code>scan</code></strong></a> <code>%s</code> will also accept a character class, including unicode ranges.</p></div>
2941 </div>
2942 <div class="sect2">
2943 <h3 id="_string_classes">String Classes</h3>
2944 <div class="paragraph"><p><a href="#_string"><strong><code>string</code></strong></a> <code>is</code> has <strong>not</strong> been extended to classify UTF-8 characters. Therefore, the following
2945 will return 0, even though the string may be considered to be alphabetic.</p></div>
2946 <div class="literalblock">
2947 <div class="content">
2948 <pre><code>string is alpha \ub5Test</code></pre>
2949 </div></div>
2950 <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>
2951 </div>
2952 <div class="sect2">
2953 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
2954 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
2955 and comparison will not increase or decrease the number of characters in a string.
2956 (Although it may change the number of bytes).</p></div>
2957 <div class="paragraph"><p><a href="#_string"><strong><code>string</code></strong></a> <code>toupper</code> will convert any lowercase letters to their uppercase equivalent.
2958 Any character which is not a letter or has no uppercase equivalent is left unchanged.
2959 Similarly for <a href="#_string"><strong><code>string</code></strong></a> <code>tolower</code> and <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>.</p></div>
2960 <div class="paragraph"><p>Commands which perform case insensitive matches, such as <a href="#_string"><strong><code>string</code></strong></a> <code>compare -nocase</code>
2961 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
2962 </div>
2963 <div class="sect2">
2964 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
2965 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
2966 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
2967 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
2968 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
2969 the following returns 2.</p></div>
2970 <div class="literalblock">
2971 <div class="content">
2972 <pre><code>string bytelength \xff\xff</code></pre>
2973 </div></div>
2974 </div>
2975 <div class="sect2">
2976 <h3 id="_regular_expressions_2">Regular Expressions</h3>
2977 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
2978 selected which supports UTF-8 strings and patterns.</p></div>
2979 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
2980 </div>
2981 </div>
2982 </div>
2983 <div class="sect1">
2984 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
2985 <div class="sectionbody">
2986 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
2987 be available in any application using Tcl. In addition to these
2988 built-in commands, there may be additional commands defined by each
2989 application, plus commands defined as Tcl procedures.</p></div>
2990 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
2991 literals that you type verbatim to Tcl.</p></div>
2992 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
2993 a range of values that you can type.</p></div>
2994 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
2995 in <code>?question-marks?</code>.</p></div>
2996 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
2997 arguments or groups of arguments may appear, in the same format
2998 as the preceding argument(s).</p></div>
2999 <div class="sect2">
3000 <h3 id="CommandIndex">Command Index</h3>
3001 <div class="tableblock">
3002 <table rules="none"
3003 width="100%"
3004 frame="void"
3005 cellspacing="0" cellpadding="4">
3006 <col width="12%" />
3007 <col width="12%" />
3008 <col width="12%" />
3009 <col width="12%" />
3010 <col width="12%" />
3011 <col width="12%" />
3012 <col width="12%" />
3013 <col width="12%" />
3014 <tbody>
3015 <tr>
3016 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3017 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3018 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3019 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3020 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3021 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3022 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3023 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3024 </tr>
3025 <tr>
3026 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3027 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3028 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3029 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3030 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3031 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3032 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3033 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3034 </tr>
3035 <tr>
3036 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3037 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3038 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3039 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3040 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3041 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3042 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3043 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3044 </tr>
3045 <tr>
3046 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3047 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3048 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3049 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3050 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3051 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3052 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3053 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3054 </tr>
3055 <tr>
3056 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3057 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3058 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3059 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3060 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3061 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3062 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3063 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3064 </tr>
3065 <tr>
3066 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3067 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3068 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3069 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3070 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3071 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3072 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3073 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3074 </tr>
3075 <tr>
3076 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3077 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3078 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3079 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3080 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3081 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3082 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3083 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3084 </tr>
3085 <tr>
3086 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3087 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3088 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3089 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3090 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3091 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3092 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3093 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3094 </tr>
3095 <tr>
3096 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3097 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3098 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3099 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3100 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3101 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3102 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3103 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.wait</code></strong></a></p></td>
3104 </tr>
3105 <tr>
3106 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3107 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3108 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3109 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3110 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3111 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3112 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3113 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3114 </tr>
3115 <tr>
3116 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3117 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3118 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3119 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3120 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3121 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3122 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3123 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3124 </tr>
3125 <tr>
3126 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3127 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3128 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3129 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3130 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3131 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3132 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3133 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3134 </tr>
3135 <tr>
3136 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3137 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3138 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3139 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3140 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3141 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3142 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3143 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3144 </tr>
3145 <tr>
3146 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3147 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3148 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3149 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3150 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3151 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3152 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3153 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3154 </tr>
3155 <tr>
3156 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3157 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3158 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3159 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3160 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3161 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3162 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3163 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3164 </tr>
3165 </tbody>
3166 </table>
3167 </div>
3168 </div>
3169 <div class="sect2">
3170 <h3 id="_alarm">alarm</h3>
3171 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3172 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3173 number of seconds. If the platform supports <em>ualarm(3)</em> then
3174 the argument may be a floating point value. Otherwise it must
3175 be an integer.</p></div>
3176 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3177 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3178 </div>
3179 <div class="sect2">
3180 <h3 id="_alias">alias</h3>
3181 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3182 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3183 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3184 <div class="literalblock">
3185 <div class="content">
3186 <pre><code>alias e info exists
3187 if {[e var]} {
3189 }</code></pre>
3190 </div></div>
3191 <div class="paragraph"><p><a href="#_alias"><strong><code>alias</code></strong></a> returns <code><em>name</em></code>, allowing it to be used with <a href="#_local"><strong><code>local</code></strong></a>.</p></div>
3192 <div class="paragraph"><p>See also <a href="#_proc"><strong><code>proc</code></strong></a>, <a href="#_curry"><strong><code>curry</code></strong></a>, <a href="#_lambda"><strong><code>lambda</code></strong></a>, <a href="#_local"><strong><code>local</code></strong></a>, <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code>, <a href="#_exists"><strong><code>exists</code></strong></a> <code>-alias</code></p></div>
3193 </div>
3194 <div class="sect2">
3195 <h3 id="_append">append</h3>
3196 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3197 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3198 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3199 it is given a value equal to the concatenation of all the
3200 <code><em>value</em></code> arguments.</p></div>
3201 <div class="paragraph"><p>This command provides an efficient way to build up long
3202 variables incrementally.
3203 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3204 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3205 </div>
3206 <div class="sect2">
3207 <h3 id="_apply">apply</h3>
3208 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3209 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3210 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3211 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3212 or a three element list <code>{args body namespace}</code>. The first element
3213 args specifies the formal arguments, in the same form as the <a href="#_proc"><strong><code>proc</code></strong></a> and <a href="#_lambda"><strong><code>lambda</code></strong></a> commands.</p></div>
3214 </div>
3215 <div class="sect2">
3216 <h3 id="_array">array</h3>
3217 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3218 <div class="paragraph"><p>This command performs one of several operations on the
3219 variable given by <code><em>arrayName</em></code>.</p></div>
3220 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3221 as though the array exists but is empty.</p></div>
3222 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3223 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3224 <div class="dlist"><dl>
3225 <dt class="hdlist1">
3226 <code><strong>array exists</strong> <em>arrayName</em></code>
3227 </dt>
3228 <dd>
3230 Returns 1 if arrayName is an array variable, 0 if there is
3231 no variable by that name. This command is essentially
3232 identical to <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>
3233 </p>
3234 </dd>
3235 <dt class="hdlist1">
3236 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3237 </dt>
3238 <dd>
3240 Returns a list containing pairs of elements. The first
3241 element in each pair is the name of an element in arrayName
3242 and the second element of each pair is the value of the
3243 array element. The order of the pairs is undefined. If
3244 pattern is not specified, then all of the elements of the
3245 array are included in the result. If pattern is specified,
3246 then only those elements whose names match pattern (using
3247 the matching rules of string match) are included. If arrayName
3248 isn&#8217;t the name of an array variable, or if the array contains
3249 no elements, then an empty list is returned.
3250 </p>
3251 </dd>
3252 <dt class="hdlist1">
3253 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3254 </dt>
3255 <dd>
3257 Returns a list containing the names of all of the elements
3258 in the array that match pattern. If pattern is omitted then
3259 the command returns all of the element names in the array.
3260 If pattern is specified, then only those elements whose
3261 names match pattern (using the matching rules of string
3262 match) are included. If there are no (matching) elements
3263 in the array, or if arrayName isn&#8217;t the name of an array
3264 variable, then an empty string is returned.
3265 </p>
3266 </dd>
3267 <dt class="hdlist1">
3268 <code><strong>array set</strong> <em>arrayName list</em></code>
3269 </dt>
3270 <dd>
3272 Sets the values of one or more elements in arrayName. list
3273 must have a form like that returned by array get, consisting
3274 of an even number of elements. Each odd-numbered element
3275 in list is treated as an element name within arrayName, and
3276 the following element in list is used as a new value for
3277 that array element. If the variable arrayName does not
3278 already exist and list is empty, arrayName is created with
3279 an empty array value.
3280 </p>
3281 </dd>
3282 <dt class="hdlist1">
3283 <code><strong>array size</strong> <em>arrayName</em></code>
3284 </dt>
3285 <dd>
3287 Returns the number of elements in the array. If arrayName
3288 isn&#8217;t the name of an array then 0 is returned.
3289 </p>
3290 </dd>
3291 <dt class="hdlist1">
3292 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3293 </dt>
3294 <dd>
3296 Unsets all of the elements in the array that match pattern
3297 (using the matching rules of string match). If arrayName
3298 isn&#8217;t the name of an array variable or there are no matching
3299 elements in the array, no error will be raised. If pattern
3300 is omitted and arrayName is an array variable, then the
3301 command unsets the entire array. The command always returns
3302 an empty string.
3303 </p>
3304 </dd>
3305 </dl></div>
3306 </div>
3307 <div class="sect2">
3308 <h3 id="_break">break</h3>
3309 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3310 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3311 such as <a href="#_for"><strong><code>for</code></strong></a> or <a href="#_foreach"><strong><code>foreach</code></strong></a> or <a href="#_while"><strong><code>while</code></strong></a>. It returns a <code>JIM_BREAK</code> code
3312 to signal the innermost containing loop command to return immediately.</p></div>
3313 </div>
3314 <div class="sect2">
3315 <h3 id="_case">case</h3>
3316 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3317 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3318 <div class="paragraph"><p><strong>Note</strong> that the <a href="#_switch"><strong><code>switch</code></strong></a> command should generally be preferred unless compatibility
3319 with Tcl 6.x is desired.</p></div>
3320 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3321 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3322 by passing it recursively to the Tcl interpreter, and return the result
3323 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3324 pattern or list of patterns. Each pattern may contain any of the wild-cards
3325 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3326 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3327 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3328 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3329 an empty string.</p></div>
3330 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3331 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3332 this form is convenient if substitutions are desired on some of the
3333 patterns or commands.</p></div>
3334 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3335 a single argument; the argument must have proper list structure, with
3336 the elements of the list being the patterns and commands.</p></div>
3337 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3338 since the braces around the whole list make it unnecessary to include a
3339 backslash at the end of each line.</p></div>
3340 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3341 no command or variable substitutions are performed on them; this makes
3342 the behaviour of the second form different than the first form in some
3343 cases.</p></div>
3344 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3345 <div class="literalblock">
3346 <div class="content">
3347 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3348 </div></div>
3349 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3350 <div class="literalblock">
3351 <div class="content">
3352 <pre><code>case a in {
3353 {a b} {format 1}
3354 default {format 2}
3355 a* {format 3}
3356 }</code></pre>
3357 </div></div>
3358 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3359 <div class="literalblock">
3360 <div class="content">
3361 <pre><code>case xyz {
3362 {a b}
3363 {format 1}
3364 default
3365 {format 2}
3367 {format 3}
3368 }</code></pre>
3369 </div></div>
3370 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3371 </div>
3372 <div class="sect2">
3373 <h3 id="_catch">catch</h3>
3374 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3375 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3376 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3377 <code>JIM_OK</code> code, regardless of any errors that might occur while
3378 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3379 see below).</p></div>
3380 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3381 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3382 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3383 it will have a non-zero value corresponding to one of the exceptional
3384 return codes (see jim.h for the definitions of code values, or the
3385 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3386 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3387 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3388 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3389 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3390 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3391 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3392 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3393 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3394 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3395 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3396 the value of the key <code>-errorcode</code> will contain the
3397 same value as the global variable $::errorCode, and the value of
3398 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3399 This can be useful to rethrow an error:</p></div>
3400 <div class="literalblock">
3401 <div class="content">
3402 <pre><code>if {[catch {...} msg opts]} {
3403 ...maybe do something with the error...
3404 incr opts(-level)
3405 return {*}$opts $msg
3406 }</code></pre>
3407 </div></div>
3408 <div class="paragraph"><p>Normally <a href="#_catch"><strong><code>catch</code></strong></a> will <code><em>not</em></code> catch any of the codes <code>JIM_EXIT</code>, <code>JIM_EVAL</code> or <code>JIM_SIGNAL</code>.
3409 The set of codes which will be caught may be modified by specifying the one more codes before
3410 <code><em>command</em></code>.</p></div>
3411 <div class="paragraph"><p>e.g. To catch <code>JIM_EXIT</code> but not <code>JIM_BREAK</code> or <code>JIM_CONTINUE</code></p></div>
3412 <div class="literalblock">
3413 <div class="content">
3414 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3415 </div></div>
3416 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3417 <div class="paragraph"><p>Note that if a signal marked as <a href="#_signal"><strong><code>signal</code></strong></a> <code>handle</code> is caught with <a href="#_catch"><strong><code>catch</code></strong></a> <code>-signal</code>, the return value
3418 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3419 </div>
3420 <div class="sect2">
3421 <h3 id="_cd">cd</h3>
3422 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3423 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3424 <div class="paragraph"><p>Returns an empty string.</p></div>
3425 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3426 be removed in some applications.</p></div>
3427 </div>
3428 <div class="sect2">
3429 <h3 id="_clock">clock</h3>
3430 <div class="dlist"><dl>
3431 <dt class="hdlist1">
3432 <code><strong>clock seconds</strong></code>
3433 </dt>
3434 <dd>
3436 Returns the current time as seconds since the epoch.
3437 </p>
3438 </dd>
3439 <dt class="hdlist1">
3440 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3441 </dt>
3442 <dd>
3444 Format the given time (seconds since the epoch) according to the given
3445 format. See strftime(3) for supported formats.
3446 If no format is supplied, "%c" is used.
3447 </p>
3448 </dd>
3449 <dt class="hdlist1">
3450 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3451 </dt>
3452 <dd>
3454 Scan the given time string using the given format string.
3455 See strptime(3) for supported formats.
3456 </p>
3457 </dd>
3458 </dl></div>
3459 </div>
3460 <div class="sect2">
3461 <h3 id="_close">close</h3>
3462 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3463 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3464 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3465 <code><em>fileId</em></code> must be the return value from a previous invocation
3466 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3467 used anymore.</p></div>
3468 </div>
3469 <div class="sect2">
3470 <h3 id="_collect">collect</h3>
3471 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3472 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3473 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3474 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3475 </div>
3476 <div class="sect2">
3477 <h3 id="_concat">concat</h3>
3478 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3479 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3480 into a single list. It permits any number of arguments. For example,
3481 the command</p></div>
3482 <div class="literalblock">
3483 <div class="content">
3484 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3485 </div></div>
3486 <div class="paragraph"><p>will return</p></div>
3487 <div class="literalblock">
3488 <div class="content">
3489 <pre><code>a b c d e f {g h}</code></pre>
3490 </div></div>
3491 <div class="paragraph"><p>as its result.</p></div>
3492 </div>
3493 <div class="sect2">
3494 <h3 id="_continue">continue</h3>
3495 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3496 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3497 as <a href="#_for"><strong><code>for</code></strong></a> or <a href="#_foreach"><strong><code>foreach</code></strong></a> or <a href="#_while"><strong><code>while</code></strong></a>. It returns a <code>JIM_CONTINUE</code> code to
3498 signal the innermost containing loop command to skip the remainder of
3499 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3500 </div>
3501 <div class="sect2">
3502 <h3 id="_curry">curry</h3>
3503 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3504 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3505 a named procedure.</p></div>
3506 <div class="paragraph"><p>the following creates a local, unnamed alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3507 <div class="literalblock">
3508 <div class="content">
3509 <pre><code>set e [local curry info exists]
3510 if {[$e var]} {
3512 }</code></pre>
3513 </div></div>
3514 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3515 <div class="paragraph"><p>See also <a href="#_proc"><strong><code>proc</code></strong></a>, <a href="#_alias"><strong><code>alias</code></strong></a>, <a href="#_lambda"><strong><code>lambda</code></strong></a>, <a href="#_local"><strong><code>local</code></strong></a>.</p></div>
3516 </div>
3517 <div class="sect2">
3518 <h3 id="_dict">dict</h3>
3519 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3520 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3521 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3522 command. The legal <code><em>options</em></code> are:</p></div>
3523 <div class="dlist"><dl>
3524 <dt class="hdlist1">
3525 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3526 </dt>
3527 <dd>
3529 Create and return a new dictionary value that contains each of
3530 the key/value mappings listed as arguments (keys and values
3531 alternating, with each key being followed by its associated
3532 value.)
3533 </p>
3534 </dd>
3535 <dt class="hdlist1">
3536 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3537 </dt>
3538 <dd>
3540 Returns a boolean value indicating whether the given key (or path
3541 of keys through a set of nested dictionaries) exists in the given
3542 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3543 on that path will succeed.
3544 </p>
3545 </dd>
3546 <dt class="hdlist1">
3547 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3548 </dt>
3549 <dd>
3551 Given a dictionary value (first argument) and a key (second argument),
3552 this will retrieve the value for that key. Where several keys are
3553 supplied, the behaviour of the command shall be as if the result
3554 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3555 dict get with the remaining arguments as second (and possibly
3556 subsequent) arguments. This facilitates lookups in nested dictionaries.
3557 If no keys are provided, dict would return a list containing pairs
3558 of elements in a man- ner similar to array get. That is, the first
3559 element of each pair would be the key and the second element would
3560 be the value for that key. It is an error to attempt to retrieve
3561 a value for a key that is not present in the dictionary.
3562 </p>
3563 </dd>
3564 <dt class="hdlist1">
3565 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3566 </dt>
3567 <dd>
3569 Returns a list of the keys in the dictionary.
3570 If pattern is specified, then only those keys whose
3571 names match <code><em>pattern</em></code> (using the matching rules of string
3572 match) are included.
3573 </p>
3574 </dd>
3575 <dt class="hdlist1">
3576 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3577 </dt>
3578 <dd>
3580 Return a dictionary that contains the contents of each of the
3581 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3582 contain a mapping for the same key, the resulting dictionary
3583 maps that key to the value according to the last dictionary on
3584 the command line containing a mapping for that key.
3585 </p>
3586 </dd>
3587 <dt class="hdlist1">
3588 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3589 </dt>
3590 <dd>
3592 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3593 value and places an updated dictionary value in that variable
3594 containing a mapping from the given key to the given value. When
3595 multiple keys are present, this operation creates or updates a chain
3596 of nested dictionaries.
3597 </p>
3598 </dd>
3599 <dt class="hdlist1">
3600 <code><strong>dict size</strong> <em>dictionary</em></code>
3601 </dt>
3602 <dd>
3604 Return the number of key/value mappings in the given dictionary value.
3605 </p>
3606 </dd>
3607 <dt class="hdlist1">
3608 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3609 </dt>
3610 <dd>
3612 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3613 variable containing a dictionary value and places an updated
3614 dictionary value in that variable that does not contain a mapping
3615 for the given key. Where multiple keys are present, this describes
3616 a path through nested dictionaries to the mapping to remove. At
3617 least one key must be specified, but the last key on the key-path
3618 need not exist. All other components on the path must exist.
3619 </p>
3620 </dd>
3621 <dt class="hdlist1">
3622 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3623 </dt>
3624 <dd>
3626 Execute the Tcl script in <code><em>script</em></code> with the value for each
3627 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3628 name. Where one or more keys are given, these indicate a chain
3629 of nested dictionaries, with the innermost dictionary being the
3630 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3631 unreadable will make the updates to the dictionary be discarded,
3632 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3633 adjusted so that the chain of dictionaries no longer exists.
3634 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3635 the result of the evaluation of body.
3636 </p>
3637 </dd>
3638 <dt class="hdlist1">
3640 </dt>
3641 <dd>
3643 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3644 it is recommended that this command only be used in a local
3645 scope (procedure). Because of this, the variables set by
3646 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3647 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3648 only happen when <code><em>script</em></code> terminates.
3649 </p>
3650 </dd>
3651 </dl></div>
3652 </div>
3653 <div class="sect2">
3654 <h3 id="_env">env</h3>
3655 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3656 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3657 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3658 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3659 that value is returned instead.</p></div>
3660 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3661 and their values as <code>{name value ...}</code></p></div>
3662 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3663 </div>
3664 <div class="sect2">
3665 <h3 id="_eof">eof</h3>
3666 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3667 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3668 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3669 0 otherwise.</p></div>
3670 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>,
3671 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3672 standard I/O channels.</p></div>
3673 </div>
3674 <div class="sect2">
3675 <h3 id="_error">error</h3>
3676 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3677 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3678 unwound. <code><em>message</em></code> is a string that is returned to the application
3679 to indicate what went wrong.</p></div>
3680 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3681 it is used to initialize the stacktrace.</p></div>
3682 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3683 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3684 to return a stack trace reflecting the original point of occurrence
3685 of the error:</p></div>
3686 <div class="literalblock">
3687 <div class="content">
3688 <pre><code>catch {...} errMsg
3690 error $errMsg [info stacktrace]</code></pre>
3691 </div></div>
3692 <div class="paragraph"><p>See also <code>errorInfo</code>, <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>, <a href="#_catch"><strong><code>catch</code></strong></a> and <a href="#_return"><strong><code>return</code></strong></a></p></div>
3693 </div>
3694 <div class="sect2">
3695 <h3 id="_errorinfo">errorInfo</h3>
3696 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3697 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3698 Typical usage is:</p></div>
3699 <div class="literalblock">
3700 <div class="content">
3701 <pre><code>if {[catch {...} error]} {
3702 puts stderr [errorInfo $error [info stacktrace]]
3703 exit 1
3704 }</code></pre>
3705 </div></div>
3706 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3707 </div>
3708 <div class="sect2">
3709 <h3 id="_eval">eval</h3>
3710 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3711 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3712 command (or collection of Tcl commands separated by newlines in the
3713 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3714 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3715 Tcl interpreter recursively, and returns the result of that
3716 evaluation (or any error generated by it).</p></div>
3717 </div>
3718 <div class="sect2">
3719 <h3 id="_exec">exec</h3>
3720 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3721 <div class="paragraph"><p>This command treats its arguments as the specification
3722 of one or more UNIX commands to execute as subprocesses.
3723 The commands take the form of a standard shell pipeline;
3724 <code>|</code> arguments separate commands in the
3725 pipeline and cause standard output of the preceding command
3726 to be piped into standard input of the next command (or <code>|&amp;</code> for
3727 both standard output and standard error).</p></div>
3728 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3729 consists of the standard output produced by the last command
3730 in the pipeline.</p></div>
3731 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3732 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error
3733 and the error message will include the pipeline&#8217;s output followed by
3734 error messages describing the abnormal terminations.</p></div>
3735 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3736 then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error, and the error message
3737 will include the pipeline&#8217;s output, followed by messages
3738 about abnormal terminations (if any), followed by the standard error
3739 output.</p></div>
3740 <div class="paragraph"><p>If the last character of the result or error message
3741 is a newline then that character is deleted from the result
3742 or error message for consistency with normal
3743 Tcl return values.</p></div>
3744 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3745 <div class="dlist"><dl>
3746 <dt class="hdlist1">
3747 <code>&gt;filename</code>
3748 </dt>
3749 <dd>
3751 The standard output of the last command in the pipeline
3752 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3753 will normally return an empty string.
3754 </p>
3755 </dd>
3756 <dt class="hdlist1">
3757 <code>&gt;&gt;filename</code>
3758 </dt>
3759 <dd>
3761 As above, but append to the file.
3762 </p>
3763 </dd>
3764 <dt class="hdlist1">
3765 <code>&gt;@fileId</code>
3766 </dt>
3767 <dd>
3769 The standard output of the last command in the pipeline is
3770 redirected to the given (writable) file descriptor (e.g. stdout,
3771 stderr, or the result of <a href="#_open"><strong><code>open</code></strong></a>). In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3772 will normally return an empty string.
3773 </p>
3774 </dd>
3775 <dt class="hdlist1">
3776 <code>2&gt;filename</code>
3777 </dt>
3778 <dd>
3780 The standard error of the last command in the pipeline
3781 is redirected to the file.
3782 </p>
3783 </dd>
3784 <dt class="hdlist1">
3785 <code>2&gt;&gt;filename</code>
3786 </dt>
3787 <dd>
3789 As above, but append to the file.
3790 </p>
3791 </dd>
3792 <dt class="hdlist1">
3793 <code>2&gt;@fileId</code>
3794 </dt>
3795 <dd>
3797 The standard error of the last command in the pipeline is
3798 redirected to the given (writable) file descriptor.
3799 </p>
3800 </dd>
3801 <dt class="hdlist1">
3802 <code>2&gt;@1</code>
3803 </dt>
3804 <dd>
3806 The standard error of the last command in the pipeline is
3807 redirected to the same file descriptor as the standard output.
3808 </p>
3809 </dd>
3810 <dt class="hdlist1">
3811 <code>&gt;&amp;filename</code>
3812 </dt>
3813 <dd>
3815 Both the standard output and standard error of the last command
3816 in the pipeline is redirected to the file.
3817 </p>
3818 </dd>
3819 <dt class="hdlist1">
3820 <code>&gt;&gt;&amp;filename</code>
3821 </dt>
3822 <dd>
3824 As above, but append to the file.
3825 </p>
3826 </dd>
3827 <dt class="hdlist1">
3828 <code>&lt;filename</code>
3829 </dt>
3830 <dd>
3832 The standard input of the first command in the pipeline
3833 is taken from the file.
3834 </p>
3835 </dd>
3836 <dt class="hdlist1">
3837 <code>&lt;&lt;string</code>
3838 </dt>
3839 <dd>
3841 The standard input of the first command is taken as the
3842 given immediate value.
3843 </p>
3844 </dd>
3845 <dt class="hdlist1">
3846 <code>&lt;@fileId</code>
3847 </dt>
3848 <dd>
3850 The standard input of the first command in the pipeline
3851 is taken from the given (readable) file descriptor.
3852 </p>
3853 </dd>
3854 </dl></div>
3855 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3856 or standard output, these are connected to the corresponding
3857 input or output of the application.</p></div>
3858 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
3859 executed in background.
3860 In this case the standard output from the last command
3861 in the pipeline will
3862 go to the application&#8217;s standard output unless
3863 redirected in the command, and error output from all
3864 the commands in the pipeline will go to the application&#8217;s
3865 standard error file. The return value of exec in this case
3866 is a list of process ids (pids) in the pipeline.</p></div>
3867 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
3868 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
3869 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
3870 <div class="paragraph"><p>The first word in each command is taken as the command name;
3871 the directories in the PATH environment variable are searched for
3872 an executable by the given name.</p></div>
3873 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
3874 are performed on the arguments to commands.</p></div>
3875 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3876 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
3877 <div class="dlist"><dl>
3878 <dt class="hdlist1">
3879 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
3880 </dt>
3881 <dd>
3883 This format is used when a child process has been killed
3884 because of a signal. The pid element will be the process&#8217;s
3885 identifier (in decimal). The sigName element will be the
3886 symbolic name of the signal that caused the process to
3887 terminate; it will be one of the names from the include
3888 file signal.h, such as SIGPIPE. The msg element will be a
3889 short human-readable message describing the signal, such
3890 as "write on pipe with no readers" for SIGPIPE.
3891 </p>
3892 </dd>
3893 <dt class="hdlist1">
3894 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
3895 </dt>
3896 <dd>
3898 This format is used when a child process has been suspended
3899 because of a signal. The pid element will be the process&#8217;s
3900 identifier, in decimal. The sigName element will be the
3901 symbolic name of the signal that caused the process to
3902 suspend; this will be one of the names from the include
3903 file signal.h, such as SIGTTIN. The msg element will be a
3904 short human-readable message describing the signal, such
3905 as "background tty read" for SIGTTIN.
3906 </p>
3907 </dd>
3908 <dt class="hdlist1">
3909 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
3910 </dt>
3911 <dd>
3913 This format is used when a child process has exited with a
3914 non-zero exit status. The pid element will be the process&#8217;s
3915 identifier (in decimal) and the code element will be the
3916 exit code returned by the process (also in decimal).
3917 </p>
3918 </dd>
3919 </dl></div>
3920 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
3921 this variable is unset, in which case the original environment is used).</p></div>
3922 </div>
3923 <div class="sect2">
3924 <h3 id="_exists">exists</h3>
3925 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
3926 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
3927 or alias respectively and returns 1 if it exists or 0 if not. This command
3928 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
3929 <a href="#_info"><strong><code>info</code></strong></a> <code>procs</code> and <a href="#_info"><strong><code>info</code></strong></a> <code>commands</code>.</p></div>
3930 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
3931 </div>
3932 <div class="sect2">
3933 <h3 id="_exit">exit</h3>
3934 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
3935 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
3936 parent as the exit status.</p></div>
3937 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
3938 to 0.</p></div>
3939 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
3940 </div>
3941 <div class="sect2">
3942 <h3 id="_expr">expr</h3>
3943 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
3944 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
3945 the result as a string. See the section EXPRESSIONS above.</p></div>
3946 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
3947 The following two are identical.</p></div>
3948 <div class="literalblock">
3949 <div class="content">
3950 <pre><code>set x [expr {3 * 2 + 1}]
3951 set x $(3 * 2 + 1)</code></pre>
3952 </div></div>
3953 </div>
3954 <div class="sect2">
3955 <h3 id="_file">file</h3>
3956 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
3957 <div class="paragraph"><p>Operate on a file or a file name. <code><em>name</em></code> is the name of a file.</p></div>
3958 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
3959 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
3960 <div class="dlist"><dl>
3961 <dt class="hdlist1">
3962 <code><strong>file atime</strong> <em>name</em></code>
3963 </dt>
3964 <dd>
3966 Return a decimal string giving the time at which file <code><em>name</em></code>
3967 was last accessed. The time is measured in the standard UNIX
3968 fashion as seconds from a fixed starting time (often January 1, 1970).
3969 If the file doesn&#8217;t exist or its access time cannot be queried then an
3970 error is generated.
3971 </p>
3972 </dd>
3973 <dt class="hdlist1">
3974 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
3975 </dt>
3976 <dd>
3978 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
3979 The target file must not exist, unless <code>-force</code> is specified.
3980 </p>
3981 </dd>
3982 <dt class="hdlist1">
3983 <code><strong>file delete ?-force?</strong> <em>name...</em></code>
3984 </dt>
3985 <dd>
3987 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
3988 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
3989 unless the <code>-force</code> options is given. In this case no errors will be generated, even
3990 if the file/directory can&#8217;t be deleted.
3991 </p>
3992 </dd>
3993 <dt class="hdlist1">
3994 <code><strong>file dirname</strong> <em>name</em></code>
3995 </dt>
3996 <dd>
3998 Return all of the characters in <code><em>name</em></code> up to but not including
3999 the last slash character. If there are no slashes in <code><em>name</em></code>
4000 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4001 character, then return <code>/</code>.
4002 </p>
4003 </dd>
4004 <dt class="hdlist1">
4005 <code><strong>file executable</strong> <em>name</em></code>
4006 </dt>
4007 <dd>
4009 Return <em>1</em> if file <code><em>name</em></code> is executable by
4010 the current user, <em>0</em> otherwise.
4011 </p>
4012 </dd>
4013 <dt class="hdlist1">
4014 <code><strong>file exists</strong> <em>name</em></code>
4015 </dt>
4016 <dd>
4018 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4019 search privileges for the directories leading to it, <em>0</em> otherwise.
4020 </p>
4021 </dd>
4022 <dt class="hdlist1">
4023 <code><strong>file extension</strong> <em>name</em></code>
4024 </dt>
4025 <dd>
4027 Return all of the characters in <code><em>name</em></code> after and including the
4028 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4029 the empty string.
4030 </p>
4031 </dd>
4032 <dt class="hdlist1">
4033 <code><strong>file isdirectory</strong> <em>name</em></code>
4034 </dt>
4035 <dd>
4037 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4038 <em>0</em> otherwise.
4039 </p>
4040 </dd>
4041 <dt class="hdlist1">
4042 <code><strong>file isfile</strong> <em>name</em></code>
4043 </dt>
4044 <dd>
4046 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4047 <em>0</em> otherwise.
4048 </p>
4049 </dd>
4050 <dt class="hdlist1">
4051 <code><strong>file join</strong> <em>arg...</em></code>
4052 </dt>
4053 <dd>
4055 Joins multiple path components. Note that if any components is
4056 an absolute path, the preceding components are ignored.
4057 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4058 </p>
4059 </dd>
4060 <dt class="hdlist1">
4061 <code><strong>file lstat</strong> <em>name varName</em></code>
4062 </dt>
4063 <dd>
4065 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4066 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4067 refers to a symbolic link the information returned in <code><em>varName</em></code>
4068 is for the link rather than the file it refers to. On systems that
4069 don&#8217;t support symbolic links this option behaves exactly the same
4070 as the <em>stat</em> option.
4071 </p>
4072 </dd>
4073 <dt class="hdlist1">
4074 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4075 </dt>
4076 <dd>
4078 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4079 this command will create all non-existing parent directories
4080 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4081 then no action is taken and no error is returned. Trying to
4082 overwrite an existing file with a directory will result in an
4083 error. Arguments are processed in the order specified, halting
4084 at the first error, if any.
4085 </p>
4086 </dd>
4087 <dt class="hdlist1">
4088 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4089 </dt>
4090 <dd>
4092 Return a decimal string giving the time at which file <code><em>name</em></code>
4093 was last modified. The time is measured in the standard UNIX
4094 fashion as seconds from a fixed starting time (often January 1, 1970).
4095 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4096 error is generated. If <code><em>time</em></code> is given, sets the modification time
4097 of the file to the given value.
4098 </p>
4099 </dd>
4100 <dt class="hdlist1">
4101 <code><strong>file normalize</strong> <em>name</em></code>
4102 </dt>
4103 <dd>
4105 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4106 </p>
4107 </dd>
4108 <dt class="hdlist1">
4109 <code><strong>file owned</strong> <em>name</em></code>
4110 </dt>
4111 <dd>
4113 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4114 <em>0</em> otherwise.
4115 </p>
4116 </dd>
4117 <dt class="hdlist1">
4118 <code><strong>file readable</strong> <em>name</em></code>
4119 </dt>
4120 <dd>
4122 Return <em>1</em> if file <code><em>name</em></code> is readable by
4123 the current user, <em>0</em> otherwise.
4124 </p>
4125 </dd>
4126 <dt class="hdlist1">
4127 <code><strong>file readlink</strong> <em>name</em></code>
4128 </dt>
4129 <dd>
4131 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4132 name of the file it points to). If
4133 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4134 an error is returned. On systems that don&#8217;t support symbolic links
4135 this option is undefined.
4136 </p>
4137 </dd>
4138 <dt class="hdlist1">
4139 <code><strong>file rename</strong> <em>oldname</em> <em>newname</em></code>
4140 </dt>
4141 <dd>
4143 Renames the file from the old name to the new name.
4144 </p>
4145 </dd>
4146 <dt class="hdlist1">
4147 <code><strong>file rootname</strong> <em>name</em></code>
4148 </dt>
4149 <dd>
4151 Return all of the characters in <code><em>name</em></code> up to but not including
4152 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4153 a dot, then return <code><em>name</em></code>.
4154 </p>
4155 </dd>
4156 <dt class="hdlist1">
4157 <code><strong>file size</strong> <em>name</em></code>
4158 </dt>
4159 <dd>
4161 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4162 If the file doesn&#8217;t exist or its size cannot be queried then an
4163 error is generated.
4164 </p>
4165 </dd>
4166 <dt class="hdlist1">
4167 <code><strong>file stat</strong> <em>name varName</em></code>
4168 </dt>
4169 <dd>
4171 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and use the
4172 variable given by <code><em>varName</em></code> to hold information returned from
4173 the kernel call.
4174 <code><em>varName</em></code> is treated as an array variable,
4175 and the following elements of that variable are set: <em>atime</em>,
4176 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4177 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4178 Each element except <em>type</em> is a decimal string with the value of
4179 the corresponding field from the <em>stat</em> return structure; see the
4180 manual entry for <em>stat</em> for details on the meanings of the values.
4181 The <em>type</em> element gives the type of the file in the same form
4182 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4183 This command returns an empty string.
4184 </p>
4185 </dd>
4186 <dt class="hdlist1">
4187 <code><strong>file tail</strong> <em>name</em></code>
4188 </dt>
4189 <dd>
4191 Return all of the characters in <code><em>name</em></code> after the last slash.
4192 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4193 </p>
4194 </dd>
4195 <dt class="hdlist1">
4196 <code><strong>file tempfile</strong> <em>?template?</em></code>
4197 </dt>
4198 <dd>
4200 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4201 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4202 the format of the template and security concerns.
4203 </p>
4204 </dd>
4205 <dt class="hdlist1">
4206 <code><strong>file type</strong> <em>name</em></code>
4207 </dt>
4208 <dd>
4210 Returns a string giving the type of file <code><em>name</em></code>, which will be
4211 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4212 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4213 </p>
4214 </dd>
4215 <dt class="hdlist1">
4216 <code><strong>file writable</strong> <em>name</em></code>
4217 </dt>
4218 <dd>
4220 Return <em>1</em> if file <code><em>name</em></code> is writable by
4221 the current user, <em>0</em> otherwise.
4222 </p>
4223 </dd>
4224 </dl></div>
4225 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4226 conditional or looping commands, for example:</p></div>
4227 <div class="literalblock">
4228 <div class="content">
4229 <pre><code>if {![file exists foo]} {
4230 error {bad file name}
4231 } else {
4233 }</code></pre>
4234 </div></div>
4235 </div>
4236 <div class="sect2">
4237 <h3 id="_finalize">finalize</h3>
4238 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4239 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4240 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4241 the empty string to remove the current finalizer.</p></div>
4242 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4243 command.</p></div>
4244 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4245 </div>
4246 <div class="sect2">
4247 <h3 id="_flush">flush</h3>
4248 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4249 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4250 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4251 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4252 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4253 refer to a file that was opened for writing. This command returns an
4254 empty string.</p></div>
4255 </div>
4256 <div class="sect2">
4257 <h3 id="_for">for</h3>
4258 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4259 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> is a looping command, similar in structure to the C <a href="#_for"><strong><code>for</code></strong></a> statement.
4260 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4261 and <code><em>test</em></code> is an expression string.</p></div>
4262 <div class="paragraph"><p>The <a href="#_for"><strong><code>for</code></strong></a> command first invokes the Tcl interpreter to execute <code><em>start</em></code>.
4263 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4264 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4265 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4266 when <code><em>test</em></code> evaluates to 0.</p></div>
4267 <div class="paragraph"><p>If a <a href="#_continue"><strong><code>continue</code></strong></a> command is invoked within <code><em>body</em></code> then any remaining
4268 commands in the current execution of <code><em>body</em></code> are skipped; processing
4269 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4270 <code><em>test</em></code>, and so on.</p></div>
4271 <div class="paragraph"><p>If a <a href="#_break"><strong><code>break</code></strong></a> command is invoked within <code><em>body</em></code> or <code><em>next</em></code>, then the <a href="#_for"><strong><code>for</code></strong></a>
4272 command will return immediately.</p></div>
4273 <div class="paragraph"><p>The operation of <a href="#_break"><strong><code>break</code></strong></a> and <a href="#_continue"><strong><code>continue</code></strong></a> are similar to the corresponding
4274 statements in C.</p></div>
4275 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4276 </div>
4277 <div class="sect2">
4278 <h3 id="_foreach">foreach</h3>
4279 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4280 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4281 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4282 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4283 collection of Tcl commands.</p></div>
4284 <div class="paragraph"><p>For each field in <code><em>list</em></code> (in order from left to right), <a href="#_foreach"><strong><code>foreach</code></strong></a> assigns
4285 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4286 had been used to extract the field), then calls the Tcl interpreter to
4287 execute <code><em>body</em></code>.</p></div>
4288 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4289 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4290 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4291 the list, the loop will be executed three times.</p></div>
4292 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4293 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4294 of the loop are undefined.</p></div>
4295 <div class="paragraph"><p>The <a href="#_break"><strong><code>break</code></strong></a> and <a href="#_continue"><strong><code>continue</code></strong></a> statements may be invoked inside <code><em>body</em></code>,
4296 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4297 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4298 </div>
4299 <div class="sect2">
4300 <h3 id="_format">format</h3>
4301 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4302 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4303 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4304 implementation). <code><em>formatString</em></code> indicates how to format
4305 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4306 arguments, if any, provide values to be substituted into the result.</p></div>
4307 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4308 man page for details. Each <code><em>arg</em></code> must match the expected type
4309 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4310 converts each argument to the correct type (floating, integer, etc.)
4311 before passing it to <em>sprintf</em> for formatting.</p></div>
4312 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4313 must be a decimal string, which will then be converted to the corresponding
4314 ASCII character value.</p></div>
4315 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4316 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4317 correctly even if the argument is in braces.</p></div>
4318 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4319 </div>
4320 <div class="sect2">
4321 <h3 id="_getref">getref</h3>
4322 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4323 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4324 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4325 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4326 </div>
4327 <div class="sect2">
4328 <h3 id="_gets">gets</h3>
4329 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4330 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4331 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4332 the terminating newline character.</p></div>
4333 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4334 by that name and the return value is a count of the number of characters
4335 read (not including the newline).</p></div>
4336 <div class="paragraph"><p>If the end of the file is reached before reading
4337 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4338 empty string.</p></div>
4339 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4340 the line (minus the newline character) or an empty string if
4341 the end of the file is reached before reading any characters.</p></div>
4342 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4343 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4344 what really happened.</p></div>
4345 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4346 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4347 at the end of the file.</p></div>
4348 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4349 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4350 for reading.</p></div>
4351 </div>
4352 <div class="sect2">
4353 <h3 id="_glob">glob</h3>
4354 <div class="paragraph"><p><code><strong>glob</strong> ?<strong>-nocomplain</strong>? ?<strong>-directory</strong> <em>dir</em>? ?<strong>--</strong>? <em>pattern ?pattern ...?</em></code></p></div>
4355 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4356 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4357 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4358 list may be returned; otherwise an error is returned if the expanded
4359 list is empty. The <code>-nocomplain</code> argument must be provided
4360 exactly: an abbreviation will not be accepted.</p></div>
4361 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4362 directory name to search in. This allows globbing inside directories
4363 whose names may contain glob-sensitive characters. The returned names
4364 are specified relative to this directory.</p></div>
4365 </div>
4366 <div class="sect2">
4367 <h3 id="_global">global</h3>
4368 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4369 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4370 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4371 rather than a local one. For the duration of the current procedure
4372 (and only while executing in the current procedure), any reference to
4373 <code><em>varName</em></code> will be bound to a global variable instead
4374 of a local one.</p></div>
4375 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4376 to explicitly name a variable in the global scope.</p></div>
4377 </div>
4378 <div class="sect2">
4379 <h3 id="_if">if</h3>
4380 <div class="paragraph"><p><code><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>?</code></p></div>
4381 <div class="paragraph"><p>The <a href="#_if"><strong><code>if</code></strong></a> command evaluates <code><em>expr1</em></code> as an expression (in the same way
4382 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4383 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4384 the Tcl interpreter.</p></div>
4385 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4386 then <code><em>body2</em></code> is executed, and so on.</p></div>
4387 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4388 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4389 command easier to read.</p></div>
4390 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4391 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4392 <div class="paragraph"><p>The return value from the command is the result of the body script that
4393 was executed, or an empty string if none of the expressions was non-zero
4394 and there was no <code><em>bodyN</em></code>.</p></div>
4395 </div>
4396 <div class="sect2">
4397 <h3 id="_incr">incr</h3>
4398 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4399 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4400 The value of the variable must be integral.</p></div>
4401 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4402 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4403 1 is added to <code><em>varName</em></code>.</p></div>
4404 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4405 and also returned as result.</p></div>
4406 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4407 and set to <code>0</code> first.</p></div>
4408 </div>
4409 <div class="sect2">
4410 <h3 id="_info">info</h3>
4411 <div class="dlist"><dl>
4412 <dt class="hdlist1">
4413 <code><strong>info</strong> <em>option ?arg...?</em></code>
4414 </dt>
4415 <dd>
4417 Provide information about various internals to the Tcl interpreter.
4418 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4419 </p>
4420 </dd>
4421 <dt class="hdlist1">
4422 <code><strong>info args</strong> <em>procname</em></code>
4423 </dt>
4424 <dd>
4426 Returns a list containing the names of the arguments to procedure
4427 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4428 Tcl command procedure.
4429 </p>
4430 </dd>
4431 <dt class="hdlist1">
4432 <code><strong>info alias</strong> <em>command</em></code>
4433 </dt>
4434 <dd>
4436 <code><em>command</em></code> must be an alias created with <a href="#_alias"><strong><code>alias</code></strong></a>. In which case the target
4437 command and arguments, as passed to <a href="#_alias"><strong><code>alias</code></strong></a> are returned. See <a href="#_exists"><strong><code>exists</code></strong></a> <code>-alias</code>
4438 </p>
4439 </dd>
4440 <dt class="hdlist1">
4441 <code><strong>info body</strong> <em>procname</em></code>
4442 </dt>
4443 <dd>
4445 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4446 the name of a Tcl command procedure.
4447 </p>
4448 </dd>
4449 <dt class="hdlist1">
4450 <code><strong>info channels</strong></code>
4451 </dt>
4452 <dd>
4454 Returns a list of all open file handles from <a href="#_open"><strong><code>open</code></strong></a> or <a href="#_socket"><strong><code>socket</code></strong></a>
4455 </p>
4456 </dd>
4457 <dt class="hdlist1">
4458 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4459 </dt>
4460 <dd>
4462 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4463 Tcl commands, including both the built-in commands written in C and
4464 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4465 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4466 are returned. Matching is determined using the same rules as for
4467 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4468 </p>
4469 </dd>
4470 <dt class="hdlist1">
4471 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4472 </dt>
4473 <dd>
4475 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4476 having no unclosed quotes, braces, brackets or array element names,
4477 If the command doesn&#8217;t appear to be complete then 0 is returned.
4478 This command is typically used in line-oriented input environments
4479 to allow users to type in commands that span multiple lines; if the
4480 command isn&#8217;t complete, the script can delay evaluating it until additional
4481 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4482 missing character is stored in the variable with that name.
4483 </p>
4484 </dd>
4485 <dt class="hdlist1">
4486 <code><strong>info exists</strong> <em>varName</em></code>
4487 </dt>
4488 <dd>
4490 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4491 current context (either as a global or local variable), returns <em>0</em>
4492 otherwise.
4493 </p>
4494 </dd>
4495 <dt class="hdlist1">
4496 <code><strong>info frame</strong> ?<em>number</em>?</code>
4497 </dt>
4498 <dd>
4500 If <code><em>number</em></code> is not specified, this command returns a number
4501 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4502 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4503 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4504 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4505 to the top-most active procedure, 2 to the procedure it called, and
4506 so on); otherwise it gives a level relative to the current level
4507 (0 refers to the current procedure, -1 to its caller, and so on).
4508 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4509 </p>
4510 </dd>
4511 <dt class="hdlist1">
4512 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4513 </dt>
4514 <dd>
4516 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4517 of currently-defined global variables.
4518 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4519 are returned. Matching is determined using the same rules as for
4520 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4521 </p>
4522 </dd>
4523 <dt class="hdlist1">
4524 <code><strong>info hostname</strong></code>
4525 </dt>
4526 <dd>
4528 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4529 </p>
4530 </dd>
4531 <dt class="hdlist1">
4532 <code><strong>info level</strong> ?<em>number</em>?</code>
4533 </dt>
4534 <dd>
4536 If <code><em>number</em></code> is not specified, this command returns a number
4537 giving the stack level of the invoking procedure, or 0 if the
4538 command is invoked at top-level. If <code><em>number</em></code> is specified,
4539 then the result is a list consisting of the name and arguments for the
4540 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4541 is positive then it selects a particular stack level (1 refers
4542 to the top-most active procedure, 2 to the procedure it called, and
4543 so on); otherwise it gives a level relative to the current level
4544 (0 refers to the current procedure, -1 to its caller, and so on).
4545 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4546 levels mean.
4547 </p>
4548 </dd>
4549 <dt class="hdlist1">
4550 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4551 </dt>
4552 <dd>
4554 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4555 of currently-defined local variables, including arguments to the
4556 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4557 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4558 specified, only those names matching <code><em>pattern</em></code> are returned.
4559 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4560 </p>
4561 </dd>
4562 <dt class="hdlist1">
4563 <code><strong>info nameofexecutable</strong></code>
4564 </dt>
4565 <dd>
4567 Returns the name of the binary file from which the application
4568 was invoked. A full path will be returned, unless the path
4569 can&#8217;t be determined, in which case the empty string will be returned.
4570 </p>
4571 </dd>
4572 <dt class="hdlist1">
4573 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4574 </dt>
4575 <dd>
4577 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4578 names of Tcl command procedures.
4579 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4580 are returned. Matching is determined using the same rules as for
4581 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4582 </p>
4583 </dd>
4584 <dt class="hdlist1">
4585 <code><strong>info references</strong></code>
4586 </dt>
4587 <dd>
4589 Returns a list of all references which have not yet been garbage
4590 collected.
4591 </p>
4592 </dd>
4593 <dt class="hdlist1">
4594 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4595 </dt>
4596 <dd>
4598 Returns a list representing the mapping of standard return codes
4599 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4600 instead returns the name for the given code.
4601 </p>
4602 </dd>
4603 <dt class="hdlist1">
4604 <code><strong>info script</strong></code>
4605 </dt>
4606 <dd>
4608 If a Tcl script file is currently being evaluated (i.e. there is a
4609 call to <em>Jim_EvalFile</em> active or there is an active invocation
4610 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4611 of the innermost file being processed. Otherwise the command returns an
4612 empty string.
4613 </p>
4614 </dd>
4615 <dt class="hdlist1">
4616 <code><strong>info source</strong> <em>script</em></code>
4617 </dt>
4618 <dd>
4620 Returns the original source location of the given script as a list of
4621 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4622 list <code>{{} 0}</code> is returned.
4623 </p>
4624 </dd>
4625 <dt class="hdlist1">
4626 <code><strong>info stacktrace</strong></code>
4627 </dt>
4628 <dd>
4630 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4631 of <code>{procedure filename line ...}</code>.
4632 </p>
4633 </dd>
4634 <dt class="hdlist1">
4635 <code><strong>info statics</strong> <em>procname</em></code>
4636 </dt>
4637 <dd>
4639 Returns a dictionary of the static variables of procedure
4640 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4641 procedure. An empty dictionary is returned if the procedure has
4642 no static variables.
4643 </p>
4644 </dd>
4645 <dt class="hdlist1">
4646 <code><strong>info version</strong></code>
4647 </dt>
4648 <dd>
4650 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4651 </p>
4652 </dd>
4653 <dt class="hdlist1">
4654 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4655 </dt>
4656 <dd>
4658 If <code><em>pattern</em></code> isn&#8217;t specified,
4659 returns a list of all the names of currently-visible variables, including
4660 both locals and currently-visible globals.
4661 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4662 are returned. Matching is determined using the same rules as for
4663 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4664 </p>
4665 </dd>
4666 </dl></div>
4667 </div>
4668 <div class="sect2">
4669 <h3 id="_join">join</h3>
4670 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4671 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4672 string formed by joining all of the elements of <code><em>list</em></code> together with
4673 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4674 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4675 </div>
4676 <div class="sect2">
4677 <h3 id="_kill">kill</h3>
4678 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4679 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4680 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4681 <div class="ulist"><ul>
4682 <li>
4684 <code>TERM</code>
4685 </p>
4686 </li>
4687 <li>
4689 <code>SIGTERM</code>
4690 </p>
4691 </li>
4692 <li>
4694 <code>-TERM</code>
4695 </p>
4696 </li>
4697 <li>
4699 <code>15</code>
4700 </p>
4701 </li>
4702 <li>
4704 <code>-15</code>
4705 </p>
4706 </li>
4707 </ul></div>
4708 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4709 <div class="paragraph"><p>The special signal name <code>-0</code> simply checks that a signal <code><em>could</em></code> be sent.</p></div>
4710 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4711 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4712 </div>
4713 <div class="sect2">
4714 <h3 id="_lambda_2">lambda</h3>
4715 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4716 <div class="paragraph"><p>The <a href="#_lambda"><strong><code>lambda</code></strong></a> command is identical to <a href="#_proc"><strong><code>proc</code></strong></a>, except rather than
4717 creating a named procedure, it creates an anonymous procedure and returns
4718 the name of the procedure.</p></div>
4719 <div class="paragraph"><p>See <a href="#_proc"><strong><code>proc</code></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4720 </div>
4721 <div class="sect2">
4722 <h3 id="_lappend">lappend</h3>
4723 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4724 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4725 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4726 between elements.</p></div>
4727 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4728 by the <code><em>value</em></code> arguments. <a href="#_lappend"><strong><code>lappend</code></strong></a> is similar to <a href="#_append"><strong><code>append</code></strong></a> except that
4729 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4730 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4731 For example,</p></div>
4732 <div class="literalblock">
4733 <div class="content">
4734 <pre><code>lappend a $b</code></pre>
4735 </div></div>
4736 <div class="paragraph"><p>is much more efficient than</p></div>
4737 <div class="literalblock">
4738 <div class="content">
4739 <pre><code>set a [concat $a [list $b]]</code></pre>
4740 </div></div>
4741 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
4742 </div>
4743 <div class="sect2">
4744 <h3 id="_lassign">lassign</h3>
4745 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4746 <div class="paragraph"><p>This command treats the value <code><em>list</em></code> as a list and assigns successive elements from that list to
4747 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4748 list elements, the remaining variables are set to the empty string. If there are more list ele-
4749 ments than variables, a list of unassigned elements is returned.</p></div>
4750 <div class="literalblock">
4751 <div class="content">
4752 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4754 a=1,b=2</code></pre>
4755 </div></div>
4756 </div>
4757 <div class="sect2">
4758 <h3 id="_local">local</h3>
4759 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4760 <div class="paragraph"><p>First, <a href="#_local"><strong><code>local</code></strong></a> evaluates <code><em>cmd</em></code> with the given arguments. The return value must
4761 be the name of an existing command, which is marked as having local scope.
4762 This means that when the current procedure exits, the specified
4763 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
4764 to automatically close a filehandle.</p></div>
4765 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4766 the existing command will be kept rather than deleted, and may be called
4767 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4768 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
4769 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4770 continues to have global scope while it is active.</p></div>
4771 <div class="literalblock">
4772 <div class="content">
4773 <pre><code>proc outer {} {
4774 # proc ... returns "inner" which is marked local
4775 local proc inner {} {
4776 # will be deleted when 'outer' exits
4777 }</code></pre>
4778 </div></div>
4779 <div class="literalblock">
4780 <div class="content">
4781 <pre><code> inner
4783 }</code></pre>
4784 </div></div>
4785 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4786 than waiting until garbage collection.</p></div>
4787 <div class="literalblock">
4788 <div class="content">
4789 <pre><code>proc outer {} {
4790 set x [lambda inner {args} {
4791 # will be deleted when 'outer' exits
4793 # Use 'function' here which simply returns $x
4794 local function $x</code></pre>
4795 </div></div>
4796 <div class="literalblock">
4797 <div class="content">
4798 <pre><code> $x ...
4800 }</code></pre>
4801 </div></div>
4802 </div>
4803 <div class="sect2">
4804 <h3 id="_loop">loop</h3>
4805 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4806 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4807 With a positive increment, equivalent to:</p></div>
4808 <div class="literalblock">
4809 <div class="content">
4810 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
4811 </div></div>
4812 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
4813 Note that setting the loop variable inside the loop does not
4814 affect the loop count.</p></div>
4815 </div>
4816 <div class="sect2">
4817 <h3 id="_lindex">lindex</h3>
4818 <div class="paragraph"><p><code><strong>lindex</strong> <em>list index</em></code></p></div>
4819 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
4820 (0 refers to the first element of the list).
4821 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4822 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
4823 braces and quotes and backslashes as the Tcl command interpreter; however,
4824 variable substitution and command substitution do not occur.</p></div>
4825 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
4826 in <code><em>value</em></code>, then an empty string is returned.</p></div>
4827 </div>
4828 <div class="sect2">
4829 <h3 id="_linsert">linsert</h3>
4830 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
4831 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
4832 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
4833 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
4834 a separate element of the new list. If <code><em>index</em></code> is less than
4835 or equal to zero, then the new elements are inserted at the
4836 beginning of the list. If <code><em>index</em></code> is greater than or equal
4837 to the number of elements in the list, then the new elements are
4838 appended to the list.</p></div>
4839 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4840 </div>
4841 <div class="sect2">
4842 <h3 id="_list">list</h3>
4843 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
4844 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
4845 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4846 may be used on the result to re-extract the original arguments, and also
4847 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
4848 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
4849 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
4850 <a href="#_concat"><strong><code>concat</code></strong></a>: <a href="#_concat"><strong><code>concat</code></strong></a> removes one level of grouping before forming
4851 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
4852 For example, the command</p></div>
4853 <div class="literalblock">
4854 <div class="content">
4855 <pre><code>list a b {c d e} {f {g h}}</code></pre>
4856 </div></div>
4857 <div class="paragraph"><p>will return</p></div>
4858 <div class="literalblock">
4859 <div class="content">
4860 <pre><code>a b {c d e} {f {g h}}</code></pre>
4861 </div></div>
4862 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
4863 <div class="literalblock">
4864 <div class="content">
4865 <pre><code>a b c d e f {g h}</code></pre>
4866 </div></div>
4867 </div>
4868 <div class="sect2">
4869 <h3 id="_llength">llength</h3>
4870 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
4871 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
4872 the number of elements in it.</p></div>
4873 </div>
4874 <div class="sect2">
4875 <h3 id="_lset">lset</h3>
4876 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
4877 <div class="paragraph"><p>Sets an element in a list.</p></div>
4878 <div class="paragraph"><p>The <a href="#_lset"><strong><code>lset</code></strong></a> command accepts a parameter, <code><em>varName</em></code>, which it interprets
4879 as the name of a variable containing a Tcl list. It also accepts
4880 zero or more indices into the list. Finally, it accepts a new value
4881 for an element of varName. If no indices are presented, the command
4882 takes the form:</p></div>
4883 <div class="literalblock">
4884 <div class="content">
4885 <pre><code>lset varName newValue</code></pre>
4886 </div></div>
4887 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
4888 varName.</p></div>
4889 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
4890 treats the content of the varName variable as a Tcl list. It addresses
4891 the index&#8217;th element in it (0 refers to the first element of the
4892 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
4893 concerning braces and quotes and backslashes as the Tcl command
4894 interpreter; however, variable substitution and command substitution
4895 do not occur. The command constructs a new list in which the
4896 designated element is replaced with newValue. This new list is
4897 stored in the variable varName, and is also the return value from
4898 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
4899 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
4900 elements in $varName, then an error occurs.</p></div>
4901 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4902 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4903 used in turn to address an element within a sublist designated by
4904 the previous indexing operation, allowing the script to alter
4905 elements in sublists. The command,</p></div>
4906 <div class="literalblock">
4907 <div class="content">
4908 <pre><code>lset a 1 2 newValue</code></pre>
4909 </div></div>
4910 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
4911 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
4912 or equal to zero. The integer appearing in each index argument must
4913 be strictly less than the length of the corresponding list. In other
4914 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
4915 index is outside the permitted range, an error is reported.</p></div>
4916 </div>
4917 <div class="sect2">
4918 <h3 id="_lmap">lmap</h3>
4919 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
4920 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4921 <div class="paragraph"><p><a href="#_lmap"><strong><code>lmap</code></strong></a> is a "collecting" <a href="#_foreach"><strong><code>foreach</code></strong></a> which returns a list of its results.</p></div>
4922 <div class="paragraph"><p>For example:</p></div>
4923 <div class="literalblock">
4924 <div class="content">
4925 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
4926 1 4 9 16 25
4927 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
4928 {1 A} {2 B} {3 C}</code></pre>
4929 </div></div>
4930 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
4931 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
4932 </div>
4933 <div class="sect2">
4934 <h3 id="_load">load</h3>
4935 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
4936 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
4937 the extension <code>.so</code>. The initialisation function for the module must be based
4938 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
4939 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
4940 should not be used directly. Instead it is invoked automatically by <a href="#_package"><strong><code>package</code></strong></a> <code>require</code>.</p></div>
4941 </div>
4942 <div class="sect2">
4943 <h3 id="_lrange">lrange</h3>
4944 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
4945 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
4946 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
4947 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
4948 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
4949 in the list, then it is treated as if it were <code>end</code>.</p></div>
4950 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
4951 is returned.</p></div>
4952 <div class="paragraph"><p>Note: <code>"<a href="#_lrange"><strong><code>lrange</code></strong></a> <em>list first first</em>"</code> does not always produce the
4953 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
4954 for simple fields that aren&#8217;t enclosed in braces); it does, however,
4955 produce exactly the same results as <code>"<a href="#_list"><strong><code>list</code></strong></a> [<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>]"</code></p></div>
4956 </div>
4957 <div class="sect2">
4958 <h3 id="_lreplace">lreplace</h3>
4959 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
4960 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
4961 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
4962 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
4963 to be replaced.</p></div>
4964 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
4965 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
4966 must exist in the list.</p></div>
4967 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
4968 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
4969 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.</p></div>
4970 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
4971 be added to the list in place of those that were deleted.</p></div>
4972 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
4973 the list.</p></div>
4974 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
4975 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
4976 </div>
4977 <div class="sect2">
4978 <h3 id="_lrepeat">lrepeat</h3>
4979 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
4980 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
4981 a positive integer).</p></div>
4982 <div class="literalblock">
4983 <div class="content">
4984 <pre><code>jim&gt; lrepeat 3 a b
4985 a b a b a b</code></pre>
4986 </div></div>
4987 </div>
4988 <div class="sect2">
4989 <h3 id="_lreverse">lreverse</h3>
4990 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
4991 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
4992 <div class="literalblock">
4993 <div class="content">
4994 <pre><code>jim&gt; lreverse {1 2 3}
4995 3 2 1</code></pre>
4996 </div></div>
4997 </div>
4998 <div class="sect2">
4999 <h3 id="_lsearch">lsearch</h3>
5000 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5001 <div class="paragraph"><p>This command searches the elements <code><em>list</em></code> to see if one of them matches <code><em>pattern</em></code>. If so, the
5002 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5003 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5004 the list are to be matched against pattern and must have one of the values below:</p></div>
5005 <div class="paragraph"><p><strong>Note</strong> that this command is different from Tcl in that default match type is <code>-exact</code> rather than <code>-glob</code>.</p></div>
5006 <div class="dlist"><dl>
5007 <dt class="hdlist1">
5008 <code><strong>-exact</strong></code>
5009 </dt>
5010 <dd>
5012 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5013 This is the default.
5014 </p>
5015 </dd>
5016 <dt class="hdlist1">
5017 <code><strong>-glob</strong></code>
5018 </dt>
5019 <dd>
5021 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5022 rules as the string match command.
5023 </p>
5024 </dd>
5025 <dt class="hdlist1">
5026 <code><strong>-regexp</strong></code>
5027 </dt>
5028 <dd>
5030 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5031 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5032 </p>
5033 </dd>
5034 <dt class="hdlist1">
5035 <code><strong>-command</strong> <em>cmdname</em></code>
5036 </dt>
5037 <dd>
5039 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5040 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5041 for a match, or 0 for no match.
5042 </p>
5043 </dd>
5044 <dt class="hdlist1">
5045 <code><strong>-all</strong></code>
5046 </dt>
5047 <dd>
5049 Changes the result to be the list of all matching indices (or all matching values if
5050 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5051 order. If values are returned, the order of the values will be the order of those values
5052 within the input list.
5053 </p>
5054 </dd>
5055 <dt class="hdlist1">
5056 <code><strong>-inline</strong></code>
5057 </dt>
5058 <dd>
5060 The matching value is returned instead of its index (or an empty string if no value
5061 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5062 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5063 </p>
5064 </dd>
5065 <dt class="hdlist1">
5066 <code><strong>-bool</strong></code>
5067 </dt>
5068 <dd>
5070 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5071 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5072 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5073 </p>
5074 </dd>
5075 <dt class="hdlist1">
5076 <code><strong>-not</strong></code>
5077 </dt>
5078 <dd>
5080 This negates the sense of the match, returning the index (or value
5081 if <code>-inline</code> is specified) of the first non-matching value in the
5082 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5083 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5084 non-matches will be returned rather than matches.
5085 </p>
5086 </dd>
5087 <dt class="hdlist1">
5088 <code><strong>-nocase</strong></code>
5089 </dt>
5090 <dd>
5092 Causes comparisons to be handled in a case-insensitive manner.
5093 </p>
5094 </dd>
5095 </dl></div>
5096 </div>
5097 <div class="sect2">
5098 <h3 id="_lsort">lsort</h3>
5099 <div class="paragraph"><p><code><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-integer</strong>|<strong>-command</strong> <em>cmdname</em>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></code></p></div>
5100 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5101 By default, ASCII sorting is used, with the result in increasing order.</p></div>
5102 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5103 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5104 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5105 should compare the values and return an integer less than, equal
5106 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5107 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5108 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5109 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5110 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5111 the given index is extracted from the list for comparison. The list index may
5112 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5113 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5114 the given index is extracted from the list for comparison. The list index may
5115 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5116 </div>
5117 <div class="sect2">
5118 <h3 id="_open">open</h3>
5119 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5120 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5121 <div class="paragraph"><p>Opens a file and returns an identifier
5122 that may be used in future invocations
5123 of commands like <a href="#_read"><strong><code>read</code></strong></a>, <a href="#_puts"><strong><code>puts</code></strong></a>, and <a href="#_close"><strong><code>close</code></strong></a>.
5124 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5125 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5126 It may have any of the following values:</p></div>
5127 <div class="dlist"><dl>
5128 <dt class="hdlist1">
5129 <code>r</code>
5130 </dt>
5131 <dd>
5133 Open the file for reading only; the file must already exist.
5134 </p>
5135 </dd>
5136 <dt class="hdlist1">
5137 <code>r</code>+
5138 </dt>
5139 <dd>
5141 Open the file for both reading and writing; the file must
5142 already exist.
5143 </p>
5144 </dd>
5145 <dt class="hdlist1">
5146 <code>w</code>
5147 </dt>
5148 <dd>
5150 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5151 exist, create a new file.
5152 </p>
5153 </dd>
5154 <dt class="hdlist1">
5155 <code>w</code>+
5156 </dt>
5157 <dd>
5159 Open the file for reading and writing. Truncate it if it exists.
5160 If it doesn&#8217;t exist, create a new file.
5161 </p>
5162 </dd>
5163 <dt class="hdlist1">
5164 <code>a</code>
5165 </dt>
5166 <dd>
5168 Open the file for writing only. The file must already exist, and the file
5169 is positioned so that new data is appended to the file.
5170 </p>
5171 </dd>
5172 <dt class="hdlist1">
5173 <code>a</code>+
5174 </dt>
5175 <dd>
5177 Open the file for reading and writing. If the file doesn&#8217;t
5178 exist, create a new empty file. Set the initial access position
5179 to the end of the file.
5180 </p>
5181 </dd>
5182 </dl></div>
5183 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5184 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5185 must be invoked between a read and a write, or vice versa.</p></div>
5186 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5187 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5188 describe a command pipeline to invoke, in the same style as the
5189 arguments for exec. In this case, the channel identifier returned
5190 by open may be used to write to the command&#8217;s input pipe or read
5191 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5192 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5193 pipeline is directed to the current standard output unless overridden
5194 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5195 standard input for the pipeline is taken from the current standard
5196 input unless overridden by the command.</p></div>
5197 <div class="paragraph"><p>The <a href="#_pid"><strong><code>pid</code></strong></a> command may be used to return the process ids of the commands
5198 forming the command pipeline.</p></div>
5199 <div class="paragraph"><p>See also <a href="#_socket"><strong><code>socket</code></strong></a>, <a href="#_pid"><strong><code>pid</code></strong></a>, <a href="#_exec"><strong><code>exec</code></strong></a></p></div>
5200 </div>
5201 <div class="sect2">
5202 <h3 id="_package">package</h3>
5203 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5204 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5205 If no version is specified, <em>1.0</em> is used.</p></div>
5206 <div class="paragraph"><p>Any script which provides a package may include this statement
5207 as the first statement, although it is not required.</p></div>
5208 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5209 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5210 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5211 or <em>$path/$name.tcl</em> as a script package.</p></div>
5212 <div class="paragraph"><p>The first such file which is found is considered to provide the the package.
5213 (The version number is ignored).</p></div>
5214 <div class="paragraph"><p>If <em>$name.so</em> exists, it is loaded with the <a href="#_load"><strong><code>load</code></strong></a> command,
5215 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5216 <div class="paragraph"><p>If <a href="#_load"><strong><code>load</code></strong></a> or <a href="#_source"><strong><code>source</code></strong></a> fails, <a href="#_package"><strong><code>package</code></strong></a> <code>require</code> will fail immediately.
5217 No further attempt will be made to locate the file.</p></div>
5218 </div>
5219 <div class="sect2">
5220 <h3 id="_pid">pid</h3>
5221 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5222 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5223 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5224 <div class="paragraph"><p>The second form accepts a handle returned by <a href="#_open"><strong><code>open</code></strong></a> and returns a list
5225 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5226 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5227 the empty string is returned instead.</p></div>
5228 <div class="paragraph"><p>See also <a href="#_open"><strong><code>open</code></strong></a>, <a href="#_exec"><strong><code>exec</code></strong></a></p></div>
5229 </div>
5230 <div class="sect2">
5231 <h3 id="_proc">proc</h3>
5232 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5233 <div class="paragraph"><p>The <a href="#_proc"><strong><code>proc</code></strong></a> command creates a new Tcl command procedure, <code><em>name</em></code>.
5234 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5235 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5236 If specified, <code><em>static</em></code>, declares static variables which are bound to the
5237 procedure.</p></div>
5238 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5239 <div class="paragraph"><p>The <a href="#_proc"><strong><code>proc</code></strong></a> command returns <code><em>name</em></code> (which is useful with <a href="#_local"><strong><code>local</code></strong></a>).</p></div>
5240 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5241 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5242 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5243 of the last command executed in the procedure&#8217;s body.</p></div>
5244 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5245 procedure-as-a-whole will return that same error.</p></div>
5246 </div>
5247 <div class="sect2">
5248 <h3 id="_puts">puts</h3>
5249 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5250 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5251 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5252 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5253 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5254 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5255 channels; it must refer to a file that was opened for
5256 writing.</p></div>
5257 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5258 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5259 but this feature may be suppressed by specifying the <code>-nonewline</code>
5260 switch.</p></div>
5261 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5262 command may be used to force buffered characters to be output.</p></div>
5263 </div>
5264 <div class="sect2">
5265 <h3 id="_pwd">pwd</h3>
5266 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5267 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5268 </div>
5269 <div class="sect2">
5270 <h3 id="_rand">rand</h3>
5271 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5272 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5273 (defaults to the maximum integer).</p></div>
5274 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5275 </div>
5276 <div class="sect2">
5277 <h3 id="_range">range</h3>
5278 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5279 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5280 and ranging up to but not including <code><em>end</em></code> in steps of <code><em>step</em></code> defaults to 1).</p></div>
5281 <div class="literalblock">
5282 <div class="content">
5283 <pre><code>jim&gt; range 5
5284 0 1 2 3 4
5285 jim&gt; range 2 5
5286 2 3 4
5287 jim&gt; range 2 10 4
5289 jim&gt; range 7 4 -2
5290 7 5</code></pre>
5291 </div></div>
5292 </div>
5293 <div class="sect2">
5294 <h3 id="_read">read</h3>
5295 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5296 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5297 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5298 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5299 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5300 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5301 If the <code>-nonewline</code> switch is specified then the last
5302 character of the file is discarded if it is a newline.</p></div>
5303 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5304 exactly this many bytes will be read and returned, unless there are fewer than
5305 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5306 bytes are returned.</p></div>
5307 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5308 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5309 </div>
5310 <div class="sect2">
5311 <h3 id="_regexp">regexp</h3>
5312 <div class="paragraph"><p><code><strong>regexp ?-nocase? ?-line? ?-indices? ?-start</strong> <em>offset</em>? <strong>?-all? ?-inline? ?--?</strong> <em>exp string ?matchVar? ?subMatchVar subMatchVar ...?</em></code></p></div>
5313 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5314 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5315 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5316 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5317 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5318 are treated as the names of variables to use to return
5319 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5320 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5321 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5322 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5323 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5324 contain the characters that matched the next parenthesized
5325 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5326 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5327 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5328 <code>-inline</code> below.</p></div>
5329 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5330 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5331 match the string (e.g. because it was in a portion of the expression
5332 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5333 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5334 string otherwise.</p></div>
5335 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5336 <div class="dlist"><dl>
5337 <dt class="hdlist1">
5338 <code><strong>-nocase</strong></code>
5339 </dt>
5340 <dd>
5342 Causes upper-case and lower-case characters to be treated as
5343 identical during the matching process.
5344 </p>
5345 </dd>
5346 <dt class="hdlist1">
5347 <code><strong>-line</strong></code>
5348 </dt>
5349 <dd>
5351 Use newline-sensitive matching. By default, newline
5352 is a completely ordinary character with no special meaning in
5353 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5354 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5355 string after any newline in the string in addition to its normal
5356 function, and the <code>$</code> anchor matches the null string before any
5357 newline in the string in addition to its normal function.
5358 </p>
5359 </dd>
5360 <dt class="hdlist1">
5361 <code><strong>-indices</strong></code>
5362 </dt>
5363 <dd>
5365 Changes what is stored in the subMatchVars. Instead of
5366 storing the matching characters from string, each variable
5367 will contain a list of two decimal strings giving the indices
5368 in string of the first and last characters in the matching
5369 range of characters.
5370 </p>
5371 </dd>
5372 <dt class="hdlist1">
5373 <code><strong>-start</strong> <em>offset</em></code>
5374 </dt>
5375 <dd>
5377 Specifies a character index offset into the string at which to start
5378 matching the regular expression. If <code>-indices</code> is
5379 specified, the indices will be indexed starting from the
5380 absolute beginning of the input string. <code><em>offset</em></code> will be
5381 constrained to the bounds of the input string.
5382 </p>
5383 </dd>
5384 <dt class="hdlist1">
5385 <code><strong>-all</strong></code>
5386 </dt>
5387 <dd>
5389 Causes the regular expression to be matched as many times as possible
5390 in the string, returning the total number of matches found. If this
5391 is specified with match variables, they will contain information
5392 for the last match only.
5393 </p>
5394 </dd>
5395 <dt class="hdlist1">
5396 <code><strong>-inline</strong></code>
5397 </dt>
5398 <dd>
5400 Causes the command to return, as a list, the data that would otherwise
5401 be placed in match variables. When using <code>-inline</code>, match variables
5402 may not be specified. If used with <code>-all</code>, the list will be concatenated
5403 at each iteration, such that a flat list is always returned. For
5404 each match iteration, the command will append the overall match
5405 data, plus one element for each subexpression in the regular
5406 expression.
5407 </p>
5408 </dd>
5409 <dt class="hdlist1">
5410 <code><strong>--</strong></code>
5411 </dt>
5412 <dd>
5414 Marks the end of switches. The argument following this one will be
5415 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5416 </p>
5417 </dd>
5418 </dl></div>
5419 </div>
5420 <div class="sect2">
5421 <h3 id="_regsub">regsub</h3>
5422 <div class="paragraph"><p><code><strong>regsub ?-nocase? ?-all? ?-line? ?-start</strong> <em>offset</em>? ?<strong>--</strong>? <em>exp string subSpec ?varName?</em></code></p></div>
5423 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5424 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5425 above.</p></div>
5426 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, the commands stores <code><em>string</em></code> to <code><em>varName</em></code>
5427 with the substitutions detailed below, and returns the number of
5428 substitutions made (normally 1 unless <code>-all</code> is specified).
5429 This is 0 if there were no matches.</p></div>
5430 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5431 instead.</p></div>
5432 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5433 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5434 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5435 in the substitution with the portion of <code><em>string</em></code> that
5436 matched <code><em>exp</em></code>.</p></div>
5437 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5438 between 1 and 9, then it is replaced in the substitution with
5439 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5440 parenthesized subexpression of <code><em>exp</em></code>.
5441 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5442 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5443 backslash.</p></div>
5444 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5445 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5446 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5447 backslashes.</p></div>
5448 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5449 <div class="dlist"><dl>
5450 <dt class="hdlist1">
5451 <code><strong>-nocase</strong></code>
5452 </dt>
5453 <dd>
5455 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5456 before matching against <code><em>exp</em></code>; however, substitutions
5457 specified by <code><em>subSpec</em></code> use the original unconverted form
5458 of <code><em>string</em></code>.
5459 </p>
5460 </dd>
5461 <dt class="hdlist1">
5462 <code><strong>-all</strong></code>
5463 </dt>
5464 <dd>
5466 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5467 is performed for each of these ranges, rather than only the
5468 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5469 each substitution using the information from the corresponding
5470 match.
5471 </p>
5472 </dd>
5473 <dt class="hdlist1">
5474 <code><strong>-line</strong></code>
5475 </dt>
5476 <dd>
5478 Use newline-sensitive matching. By default, newline
5479 is a completely ordinary character with no special meaning in
5480 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5481 and <code>.</code> never match newline, a <code></sup></code> anchor matches the null
5482 string after any newline in the string in addition to its normal
5483 function, and the <code>$</code> anchor matches the null string before any
5484 newline in the string in addition to its normal function.
5485 </p>
5486 </dd>
5487 <dt class="hdlist1">
5488 <code><strong>-start</strong> <em>offset</em></code>
5489 </dt>
5490 <dd>
5492 Specifies a character index offset into the string at which to
5493 start matching the regular expression. <code><em>offset</em></code> will be
5494 constrained to the bounds of the input string.
5495 </p>
5496 </dd>
5497 <dt class="hdlist1">
5498 <code><strong>--</strong></code>
5499 </dt>
5500 <dd>
5502 Marks the end of switches. The argument following this one will be
5503 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5504 </p>
5505 </dd>
5506 </dl></div>
5507 </div>
5508 <div class="sect2">
5509 <h3 id="_ref">ref</h3>
5510 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5511 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5512 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5513 when the a garbage collection cycle runs and this reference is
5514 no longer accessible.</p></div>
5515 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5516 <div class="literalblock">
5517 <div class="content">
5518 <pre><code>finalizer reference string</code></pre>
5519 </div></div>
5520 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5521 </div>
5522 <div class="sect2">
5523 <h3 id="_rename">rename</h3>
5524 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5525 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5526 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5527 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5528 returns an empty string as result.</p></div>
5529 </div>
5530 <div class="sect2">
5531 <h3 id="_return">return</h3>
5532 <div class="paragraph"><p><code><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>?</code></p></div>
5533 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5534 or <a href="#_source"><strong><code>source</code></strong></a> command), with <code><em>value</em></code> as the return value. If <code><em>value</em></code>
5535 is not specified, an empty string will be returned as result.</p></div>
5536 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5537 continue, signal, return or exit), this code will be used instead
5538 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5539 commands.</p></div>
5540 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5541 the new return code from <code>-code</code>. This is useful when rethrowing an error
5542 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5543 an example of how this is done.</p></div>
5544 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5545 <div class="paragraph"><p>If <code>-errorinfo</code> is specified (as returned from <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>)
5546 it is used to initialize the stacktrace.</p></div>
5547 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5548 </div>
5549 <div class="sect2">
5550 <h3 id="_scan">scan</h3>
5551 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5552 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5553 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5554 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5555 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5556 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5557 when a field is scanned from <code><em>string</em></code>, the result is converted back
5558 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5559 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5560 character value is converted to a decimal string, which is then
5561 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5562 specified for this conversion.</p></div>
5563 </div>
5564 <div class="sect2">
5565 <h3 id="_seek">seek</h3>
5566 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5567 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5568 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5569 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5570 which the next read or write will occur for <code><em>fileId</em></code>.
5571 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5572 must be one of the following:</p></div>
5573 <div class="dlist"><dl>
5574 <dt class="hdlist1">
5575 <code><strong>start</strong></code>
5576 </dt>
5577 <dd>
5579 The new access position will be <code><em>offset</em></code> bytes from the start
5580 of the file.
5581 </p>
5582 </dd>
5583 <dt class="hdlist1">
5584 <code><strong>current</strong></code>
5585 </dt>
5586 <dd>
5588 The new access position will be <code><em>offset</em></code> bytes from the current
5589 access position; a negative <code><em>offset</em></code> moves the access position
5590 backwards in the file.
5591 </p>
5592 </dd>
5593 <dt class="hdlist1">
5594 <code><strong>end</strong></code>
5595 </dt>
5596 <dd>
5598 The new access position will be <code><em>offset</em></code> bytes from the end of
5599 the file. A negative <code><em>offset</em></code> places the access position before
5600 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5601 after the end-of-file.
5602 </p>
5603 </dd>
5604 </dl></div>
5605 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5606 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5607 <a href="#_open"><strong><code>open</code></strong></a>, or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one
5608 of the standard I/O channels.</p></div>
5609 <div class="paragraph"><p>This command returns an empty string.</p></div>
5610 </div>
5611 <div class="sect2">
5612 <h3 id="_set">set</h3>
5613 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5614 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5615 <div class="paragraph"><p>If <code><em>value</em></code> is specified, then set the value of <code><em>varName</em></code> to <code><em>value</em></code>,
5616 creating a new variable if one doesn&#8217;t already exist, and return
5617 its value.</p></div>
5618 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5619 close parenthesis, then it refers to an array element: the characters
5620 before the open parenthesis are the name of the array, and the characters
5621 between the parentheses are the index within the array.
5622 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5623 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5624 variable.</p></div>
5625 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5626 or local variable of the procedure, unless the <code><em>global</em></code> command
5627 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5628 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5629 in the global scope.</p></div>
5630 </div>
5631 <div class="sect2">
5632 <h3 id="_setref">setref</h3>
5633 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5634 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5635 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5636 command.</p></div>
5637 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5638 </div>
5639 <div class="sect2">
5640 <h3 id="_signal">signal</h3>
5641 <div class="paragraph"><p>Command for signal handling.</p></div>
5642 <div class="paragraph"><p>See <a href="#_kill"><strong><code>kill</code></strong></a> for the different forms which may be used to specify signals.</p></div>
5643 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5644 "<code>SIGINT SIGTERM</code>".</p></div>
5645 <div class="dlist"><dl>
5646 <dt class="hdlist1">
5647 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5648 </dt>
5649 <dd>
5651 If no signals are given, returns a list of all signals which are currently
5652 being handled.
5653 If signals are specified, these are added to the list of signals currently
5654 being handled.
5655 </p>
5656 </dd>
5657 <dt class="hdlist1">
5658 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5659 </dt>
5660 <dd>
5662 If no signals are given, returns a lists all signals which are currently
5663 being ignored.
5664 If signals are specified, these are added to the list of signals
5665 currently being ignored. These signals are still delivered, but
5666 are not considered by <a href="#_catch"><strong><code>catch</code></strong></a> <code>-signal</code> or <a href="#_try"><strong><code>try</code></strong></a> <code>-signal</code>. Use
5667 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5668 been ignored.
5669 </p>
5670 </dd>
5671 <dt class="hdlist1">
5672 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5673 </dt>
5674 <dd>
5676 If no signals are given, returns a lists all signals which are currently have
5677 the default behaviour.
5678 If signals are specified, these are added to the list of signals which have
5679 the default behaviour.
5680 </p>
5681 </dd>
5682 <dt class="hdlist1">
5683 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5684 </dt>
5685 <dd>
5687 Returns a list of signals which have been delivered to the process
5688 but are <em>ignored</em>. If signals are specified, only that set of signals will
5689 be checked, otherwise all signals will be checked.
5690 If <code>-clear</code> is specified, any signals returned are removed and will not be
5691 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5692 </p>
5693 </dd>
5694 <dt class="hdlist1">
5695 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5696 </dt>
5697 <dd>
5699 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5700 The behaviour is identical to:
5701 </p>
5702 <div class="literalblock">
5703 <div class="content">
5704 <pre><code>kill signal [pid]</code></pre>
5705 </div></div>
5706 </dd>
5707 </dl></div>
5708 <div class="paragraph"><p>Note that <a href="#_signal"><strong><code>signal</code></strong></a> <code>handle</code> and <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code> represent two forms of signal
5709 handling. <a href="#_signal"><strong><code>signal</code></strong></a> <code>handle</code> is used in conjunction with <a href="#_catch"><strong><code>catch</code></strong></a> <code>-signal</code> or <a href="#_try"><strong><code>try</code></strong></a> <code>-signal</code>
5710 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5711 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5712 two examples below.</p></div>
5713 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5714 <div class="literalblock">
5715 <div class="content">
5716 <pre><code>signal handle SIGALRM
5717 alarm 20
5718 try -signal {
5719 .. possibly long running process ..
5720 alarm 0
5721 } on signal {sig} {
5722 puts stderr "Process took too long"
5723 }</code></pre>
5724 </div></div>
5725 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5726 <div class="literalblock">
5727 <div class="content">
5728 <pre><code>signal ignore SIGHUP
5729 while {1} {
5730 ... handle configuration/reconfiguration ...
5731 while {[signal check -clear SIGHUP] eq ""} {
5732 ... do processing ..
5734 # Received SIGHUP, so reconfigure
5735 }</code></pre>
5736 </div></div>
5737 </div>
5738 <div class="sect2">
5739 <h3 id="_sleep">sleep</h3>
5740 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5741 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5742 point value less than one to sleep for less than a second, or an
5743 integer to sleep for one or more seconds.</p></div>
5744 </div>
5745 <div class="sect2">
5746 <h3 id="_source">source</h3>
5747 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5748 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5749 as a sequence of commands to execute in the normal fashion. The return
5750 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
5751 from the file. If an error occurs in executing the contents of the
5752 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
5753 <div class="paragraph"><p>If a <a href="#_return"><strong><code>return</code></strong></a> command is invoked from within the file, the remainder of
5754 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
5755 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
5756 </div>
5757 <div class="sect2">
5758 <h3 id="_split">split</h3>
5759 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5760 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5761 that is in the <code><em>splitChars</em></code> argument.</p></div>
5762 <div class="paragraph"><p>Each element of the result list will consist of the
5763 characters from <code><em>string</em></code> between instances of the
5764 characters in <code><em>splitChars</em></code>.</p></div>
5765 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5766 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5767 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5768 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5769 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5770 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5771 For example,</p></div>
5772 <div class="literalblock">
5773 <div class="content">
5774 <pre><code>split "comp.unix.misc" .</code></pre>
5775 </div></div>
5776 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
5777 <div class="literalblock">
5778 <div class="content">
5779 <pre><code>split "Hello world" {}</code></pre>
5780 </div></div>
5781 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
5782 </div>
5783 <div class="sect2">
5784 <h3 id="_stackdump">stackdump</h3>
5785 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5786 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5787 </div>
5788 <div class="sect2">
5789 <h3 id="_stacktrace">stacktrace</h3>
5790 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
5791 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5792 Iteratively uses <a href="#_info"><strong><code>info</code></strong></a> <code>frame</code> to create the stack trace. This stack trace is in the
5793 same form as produced by <a href="#_catch"><strong><code>catch</code></strong></a> and <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code></p></div>
5794 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
5795 </div>
5796 <div class="sect2">
5797 <h3 id="_string">string</h3>
5798 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5799 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5800 The legal options (which may be abbreviated) are:</p></div>
5801 <div class="dlist"><dl>
5802 <dt class="hdlist1">
5803 <code><strong>string bytelength</strong> <em>string</em></code>
5804 </dt>
5805 <dd>
5807 Returns the length of the string in bytes. This will return
5808 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
5809 or if the string is composed entirely of ASCII characters.
5810 See UTF-8 AND UNICODE.
5811 </p>
5812 </dd>
5813 <dt class="hdlist1">
5814 <code><strong>string byterange</strong> <em>string first last</em></code>
5815 </dt>
5816 <dd>
5818 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
5819 These commands are identical if UTF-8 support is not enabled.
5820 </p>
5821 </dd>
5822 <dt class="hdlist1">
5823 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
5824 </dt>
5825 <dd>
5827 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
5828 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
5829 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
5830 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
5831 is specified, then only the first <code><em>len</em></code> characters are used
5832 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5833 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5834 </p>
5835 </dd>
5836 <dt class="hdlist1">
5837 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
5838 </dt>
5839 <dd>
5841 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
5842 is specified, then only the first <code><em>len</em></code> characters are used
5843 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5844 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5845 </p>
5846 </dd>
5847 <dt class="hdlist1">
5848 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
5849 </dt>
5850 <dd>
5852 Search <code><em>string2</em></code> for a sequence of characters that exactly match
5853 the characters in <code><em>string1</em></code>. If found, return the index of the
5854 first character in the first such match within <code><em>string2</em></code>. If not
5855 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
5856 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
5857 </p>
5858 </dd>
5859 <dt class="hdlist1">
5861 </dt>
5862 <dd>
5864 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
5865 </p>
5866 </dd>
5867 <dt class="hdlist1">
5868 <code><strong>string index</strong> <em>string charIndex</em></code>
5869 </dt>
5870 <dd>
5872 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
5873 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
5874 character of the string.
5875 If <code><em>charIndex</em></code> is less than 0 or greater than
5876 or equal to the length of the string then an empty string is
5877 returned.
5878 </p>
5879 </dd>
5880 <dt class="hdlist1">
5882 </dt>
5883 <dd>
5885 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
5886 </p>
5887 </dd>
5888 <dt class="hdlist1">
5889 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
5890 </dt>
5891 <dd>
5893 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
5894 class, otherwise returns 0. If <code>-strict</code> is specified, then an
5895 empty string returns 0, otherwise an empty string will return 1
5896 on any class. The following character classes are recognized
5897 (the class name can be abbreviated):
5898 </p>
5899 </dd>
5900 <dt class="hdlist1">
5902 </dt>
5903 <dd>
5904 <div class="dlist"><dl>
5905 <dt class="hdlist1">
5906 <code>alnum</code>
5907 </dt>
5908 <dd>
5910 Any alphabet or digit character.
5911 </p>
5912 </dd>
5913 <dt class="hdlist1">
5914 <code>alpha</code>
5915 </dt>
5916 <dd>
5918 Any alphabet character.
5919 </p>
5920 </dd>
5921 <dt class="hdlist1">
5922 <code>ascii</code>
5923 </dt>
5924 <dd>
5926 Any character with a value less than 128 (those that are in the 7-bit ascii range).
5927 </p>
5928 </dd>
5929 <dt class="hdlist1">
5930 <code>control</code>
5931 </dt>
5932 <dd>
5934 Any control character.
5935 </p>
5936 </dd>
5937 <dt class="hdlist1">
5938 <code>digit</code>
5939 </dt>
5940 <dd>
5942 Any digit character.
5943 </p>
5944 </dd>
5945 <dt class="hdlist1">
5946 <code>double</code>
5947 </dt>
5948 <dd>
5950 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
5951 In case of under/overflow in the value, 0 is returned.
5952 </p>
5953 </dd>
5954 <dt class="hdlist1">
5955 <code>graph</code>
5956 </dt>
5957 <dd>
5959 Any printing character, except space.
5960 </p>
5961 </dd>
5962 <dt class="hdlist1">
5963 <code>integer</code>
5964 </dt>
5965 <dd>
5967 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
5968 </p>
5969 </dd>
5970 <dt class="hdlist1">
5971 <code>lower</code>
5972 </dt>
5973 <dd>
5975 Any lower case alphabet character.
5976 </p>
5977 </dd>
5978 <dt class="hdlist1">
5979 <code>print</code>
5980 </dt>
5981 <dd>
5983 Any printing character, including space.
5984 </p>
5985 </dd>
5986 <dt class="hdlist1">
5987 <code>punct</code>
5988 </dt>
5989 <dd>
5991 Any punctuation character.
5992 </p>
5993 </dd>
5994 <dt class="hdlist1">
5995 <code>space</code>
5996 </dt>
5997 <dd>
5999 Any space character.
6000 </p>
6001 </dd>
6002 <dt class="hdlist1">
6003 <code>upper</code>
6004 </dt>
6005 <dd>
6007 Any upper case alphabet character.
6008 </p>
6009 </dd>
6010 <dt class="hdlist1">
6011 <code>xdigit</code>
6012 </dt>
6013 <dd>
6015 Any hexadecimal digit character ([0-9A-Fa-f]).
6016 </p>
6017 </dd>
6018 </dl></div>
6019 </dd>
6020 <dt class="hdlist1">
6022 </dt>
6023 <dd>
6025 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6026 </p>
6027 </dd>
6028 <dt class="hdlist1">
6029 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6030 </dt>
6031 <dd>
6033 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6034 the characters in <code><em>string1</em></code>. If found, return the index of the
6035 first character in the last such match within <code><em>string2</em></code>. If there
6036 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6037 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6038 </p>
6039 </dd>
6040 <dt class="hdlist1">
6042 </dt>
6043 <dd>
6045 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6046 </p>
6047 </dd>
6048 <dt class="hdlist1">
6049 <code><strong>string length</strong> <em>string</em></code>
6050 </dt>
6051 <dd>
6053 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6054 If UTF-8 support is enabled, this may be different than the number of bytes.
6055 See UTF-8 AND UNICODE
6056 </p>
6057 </dd>
6058 <dt class="hdlist1">
6059 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6060 </dt>
6061 <dd>
6063 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6064 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6065 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6066 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6067 matching is done without regard to case differences. Both key and value may
6068 be multiple characters. Replacement is done in an ordered manner, so the
6069 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6070 only iterated over once, so earlier key replacements will have no affect for
6071 later key matches. For example,
6072 </p>
6073 <div class="literalblock">
6074 <div class="content">
6075 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6076 </div></div>
6077 </dd>
6078 <dt class="hdlist1">
6080 </dt>
6081 <dd>
6083 will return the string <code>01321221</code>.
6084 </p>
6085 </dd>
6086 <dt class="hdlist1">
6088 </dt>
6089 <dd>
6091 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6092 one. So if the previous example is reordered like this,
6093 </p>
6094 <div class="literalblock">
6095 <div class="content">
6096 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6097 </div></div>
6098 </dd>
6099 <dt class="hdlist1">
6101 </dt>
6102 <dd>
6104 it will return the string <code>02c322c222c</code>.
6105 </p>
6106 </dd>
6107 <dt class="hdlist1">
6108 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6109 </dt>
6110 <dd>
6112 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6113 if it doesn&#8217;t. Matching is done in a fashion similar to that
6114 used by the C-shell. For the two strings to match, their contents
6115 must be identical except that the following special sequences
6116 may appear in <code><em>pattern</em></code>:
6117 </p>
6118 <div class="dlist"><dl>
6119 <dt class="hdlist1">
6120 <code>*</code>
6121 </dt>
6122 <dd>
6124 Matches any sequence of characters in <code><em>string</em></code>,
6125 including a null string.
6126 </p>
6127 </dd>
6128 <dt class="hdlist1">
6129 <code>?</code>
6130 </dt>
6131 <dd>
6133 Matches any single character in <code><em>string</em></code>.
6134 </p>
6135 </dd>
6136 <dt class="hdlist1">
6137 <code>[<em>chars</em>]</code>
6138 </dt>
6139 <dd>
6141 Matches any character in the set given by <code><em>chars</em></code>.
6142 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6143 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6144 will match.
6145 </p>
6146 </dd>
6147 <dt class="hdlist1">
6148 <code>\x</code>
6149 </dt>
6150 <dd>
6152 Matches the single character <code><em>x</em></code>. This provides a way of
6153 avoiding the special interpretation of the characters <code>\*?[]</code>
6154 in <code><em>pattern</em></code>.
6155 </p>
6156 </dd>
6157 </dl></div>
6158 </dd>
6159 <dt class="hdlist1">
6161 </dt>
6162 <dd>
6164 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6165 </p>
6166 </dd>
6167 <dt class="hdlist1">
6168 <code><strong>string range</strong> <em>string first last</em></code>
6169 </dt>
6170 <dd>
6172 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6173 with the character whose index is <code><em>first</em></code> and ending with the
6174 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6175 first character of the string.
6176 </p>
6177 </dd>
6178 <dt class="hdlist1">
6180 </dt>
6181 <dd>
6183 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6184 </p>
6185 </dd>
6186 <dt class="hdlist1">
6188 </dt>
6189 <dd>
6191 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6192 if <code><em>last</em></code> is greater than or equal to the length of the string then
6193 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6194 <code><em>last</em></code> then an empty string is returned.
6195 </p>
6196 </dd>
6197 <dt class="hdlist1">
6198 <code><strong>string repeat</strong> <em>string count</em></code>
6199 </dt>
6200 <dd>
6202 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6203 </p>
6204 </dd>
6205 <dt class="hdlist1">
6206 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6207 </dt>
6208 <dd>
6210 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6211 with the character whose index is <code><em>first</em></code> and ending with the
6212 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6213 then it is placed in the removed character range. If <code><em>first</em></code> is
6214 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6215 is greater than or equal to the length of the string then it is
6216 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6217 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6218 then the initial string is returned untouched.
6219 </p>
6220 </dd>
6221 <dt class="hdlist1">
6222 <code><strong>string reverse</strong> <em>string</em></code>
6223 </dt>
6224 <dd>
6226 Returns a string that is the same length as <code><em>string</em></code> but
6227 with its characters in the reverse order.
6228 </p>
6229 </dd>
6230 <dt class="hdlist1">
6231 <code><strong>string tolower</strong> <em>string</em></code>
6232 </dt>
6233 <dd>
6235 Returns a value equal to <code><em>string</em></code> except that all upper case
6236 letters have been converted to lower case.
6237 </p>
6238 </dd>
6239 <dt class="hdlist1">
6240 <code><strong>string totitle</strong> <em>string</em></code>
6241 </dt>
6242 <dd>
6244 Returns a value equal to <code><em>string</em></code> except that the first character
6245 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6246 and all remaining characters have been converted to lower case.
6247 </p>
6248 </dd>
6249 <dt class="hdlist1">
6250 <code><strong>string toupper</strong> <em>string</em></code>
6251 </dt>
6252 <dd>
6254 Returns a value equal to <code><em>string</em></code> except that all lower case
6255 letters have been converted to upper case.
6256 </p>
6257 </dd>
6258 <dt class="hdlist1">
6259 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6260 </dt>
6261 <dd>
6263 Returns a value equal to <code><em>string</em></code> except that any leading
6264 or trailing characters from the set given by <code><em>chars</em></code> are
6265 removed.
6266 If <code><em>chars</em></code> is not specified then white space is removed
6267 (spaces, tabs, newlines, and carriage returns).
6268 </p>
6269 </dd>
6270 <dt class="hdlist1">
6271 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6272 </dt>
6273 <dd>
6275 Returns a value equal to <code><em>string</em></code> except that any
6276 leading characters from the set given by <code><em>chars</em></code> are
6277 removed.
6278 If <code><em>chars</em></code> is not specified then white space is removed
6279 (spaces, tabs, newlines, and carriage returns).
6280 </p>
6281 </dd>
6282 <dt class="hdlist1">
6283 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6284 </dt>
6285 <dd>
6287 Returns a value equal to <code><em>string</em></code> except that any
6288 trailing characters from the set given by <code><em>chars</em></code> are
6289 removed.
6290 If <code><em>chars</em></code> is not specified then white space is removed
6291 (spaces, tabs, newlines, and carriage returns).
6292 Null characters are always removed.
6293 </p>
6294 </dd>
6295 </dl></div>
6296 </div>
6297 <div class="sect2">
6298 <h3 id="_subst">subst</h3>
6299 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6300 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6301 and backslash substitutions on its string argument and returns the
6302 fully-substituted result. The substitutions are performed in exactly
6303 the same way as for Tcl commands. As a result, the string argument
6304 is actually substituted twice, once by the Tcl parser in the usual
6305 fashion for Tcl commands, and again by the subst command.</p></div>
6306 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6307 specified, then the corresponding substitutions are not performed.
6308 For example, if <code>-nocommands</code> is specified, no command substitution
6309 is performed: open and close brackets are treated as ordinary
6310 characters with no special interpretation.</p></div>
6311 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6312 special treatment to double quotes or curly braces. For example,
6313 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6314 <div class="literalblock">
6315 <div class="content">
6316 <pre><code>set a 44
6317 subst {xyz {$a}}</code></pre>
6318 </div></div>
6319 </div>
6320 <div class="sect2">
6321 <h3 id="_switch">switch</h3>
6322 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6323 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6324 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6325 the pattern arguments in order. As soon as it finds a pattern that
6326 matches string it evaluates the following body and returns the
6327 result of that evaluation. If the last pattern argument is default
6328 then it matches anything. If no pattern argument matches string and
6329 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6330 If the initial arguments to switch start with - then they are treated
6331 as options. The following options are currently supported:</p></div>
6332 <div class="dlist"><dl>
6333 <dt class="hdlist1">
6334 <code>-exact</code>
6335 </dt>
6336 <dd>
6338 Use exact matching when comparing string to a
6339 pattern. This is the default.
6340 </p>
6341 </dd>
6342 <dt class="hdlist1">
6343 <code>-glob</code>
6344 </dt>
6345 <dd>
6347 When matching string to the patterns, use glob-style
6348 matching (i.e. the same as implemented by the string
6349 match command).
6350 </p>
6351 </dd>
6352 <dt class="hdlist1">
6353 <code>-regexp</code>
6354 </dt>
6355 <dd>
6357 When matching string to the patterns, use regular
6358 expression matching (i.e. the same as implemented
6359 by the regexp command).
6360 </p>
6361 </dd>
6362 <dt class="hdlist1">
6363 <code>-command <em>commandname</em></code>
6364 </dt>
6365 <dd>
6367 When matching string to the patterns, use the given command, which
6368 must be a single word. The command is invoked as
6369 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6370 and must return 1 if matched, or 0 if not.
6371 </p>
6372 </dd>
6373 <dt class="hdlist1">
6374 <code>--</code>
6375 </dt>
6376 <dd>
6378 Marks the end of options. The argument following
6379 this one will be treated as string even if it starts
6380 with a <code>-</code>.
6381 </p>
6382 </dd>
6383 </dl></div>
6384 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6385 first uses a separate argument for each of the patterns and commands;
6386 this form is convenient if substitutions are desired on some of the
6387 patterns or commands. The second form places all of the patterns
6388 and commands together into a single argument; the argument must
6389 have proper list structure, with the elements of the list being the
6390 patterns and commands. The second form makes it easy to construct
6391 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6392 make it unnecessary to include a backslash at the end of each line.
6393 Since the pattern arguments are in braces in the second form, no
6394 command or variable substitutions are performed on them; this makes
6395 the behaviour of the second form different than the first form in
6396 some cases.</p></div>
6397 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6398 pattern should also be used as the body for this pattern (if the
6399 next pattern also has a body of <code>-</code> then the body after that is
6400 used, and so on). This feature makes it possible to share a single
6401 body among several patterns.</p></div>
6402 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6403 <div class="literalblock">
6404 <div class="content">
6405 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6406 </div></div>
6407 <div class="paragraph"><p>will return 2,</p></div>
6408 <div class="literalblock">
6409 <div class="content">
6410 <pre><code>switch -regexp aaab {
6411 ^a.*b$ -
6412 b {format 1}
6413 a* {format 2}
6414 default {format 3}
6415 }</code></pre>
6416 </div></div>
6417 <div class="paragraph"><p>will return 1, and</p></div>
6418 <div class="literalblock">
6419 <div class="content">
6420 <pre><code>switch xyz {
6422 b {format 1}
6423 a* {format 2}
6424 default {format 3}
6425 }</code></pre>
6426 </div></div>
6427 <div class="paragraph"><p>will return 3.</p></div>
6428 </div>
6429 <div class="sect2">
6430 <h3 id="_tailcall">tailcall</h3>
6431 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6432 <div class="paragraph"><p>The <a href="#_tailcall"><strong><code>tailcall</code></strong></a> command provides an optimised way of invoking a command whilst replacing
6433 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6434 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6435 <div class="literalblock">
6436 <div class="content">
6437 <pre><code>tailcall a b c</code></pre>
6438 </div></div>
6439 <div class="literalblock">
6440 <div class="content">
6441 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6442 </div></div>
6443 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6444 <div class="literalblock">
6445 <div class="content">
6446 <pre><code>proc a {cmd args} {
6447 tailcall sub_$cmd {*}$args
6449 proc sub_cmd1 ...
6450 proc sub_cmd2 ...</code></pre>
6451 </div></div>
6452 </div>
6453 <div class="sect2">
6454 <h3 id="_tell">tell</h3>
6455 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6456 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6457 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6458 <code><em>fileId</em></code>.</p></div>
6459 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6460 <a href="#_open"><strong><code>open</code></strong></a>, or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one
6461 of the standard I/O channels.</p></div>
6462 </div>
6463 <div class="sect2">
6464 <h3 id="_throw">throw</h3>
6465 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6466 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6467 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6468 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6469 The command <code>throw 20 message</code> can be caught with an <code>on 20 ...</code> clause to <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6470 </div>
6471 <div class="sect2">
6472 <h3 id="_time">time</h3>
6473 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6474 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6475 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6476 specified). It will then return a string of the form</p></div>
6477 <div class="literalblock">
6478 <div class="content">
6479 <pre><code>503 microseconds per iteration</code></pre>
6480 </div></div>
6481 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6482 in microseconds.</p></div>
6483 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6484 </div>
6485 <div class="sect2">
6486 <h3 id="_try">try</h3>
6487 <div class="paragraph"><p><code><strong>try</strong> <em>?catchopts? tryscript</em> ?<strong>on</strong> <em>returncodes {?resultvar? ?optsvar?} handlerscript ...</em>? ?<strong>finally</strong> <em>finalscript</em>?</code></p></div>
6488 <div class="paragraph"><p>The <a href="#_try"><strong><code>try</code></strong></a> command is provided as a convenience for exception handling.</p></div>
6489 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6490 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6491 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6492 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6493 section. For example a normal <code>JIM_ERR</code> error will be matched by
6494 an <em>on error</em> handler.</p></div>
6495 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6496 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6497 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6498 in which case the result is this new exception.</p></div>
6499 <div class="paragraph"><p>The specified <code><em>returncodes</em></code> is a list of return codes either as names (<em>ok</em>, <em>error</em>, <em>break</em>, etc.)
6500 or as integers.</p></div>
6501 <div class="paragraph"><p>If <code><em>resultvar</em></code> and <code><em>optsvar</em></code> are specified, they are set as for <a href="#_catch"><strong><code>catch</code></strong></a> before evaluating
6502 the matching handler.</p></div>
6503 <div class="paragraph"><p>For example:</p></div>
6504 <div class="literalblock">
6505 <div class="content">
6506 <pre><code>set f [open input]
6507 try -signal {
6508 process $f
6509 } on {continue break} {} {
6510 error "Unexpected break/continue"
6511 } on error {msg opts} {
6512 puts "Dealing with error"
6513 return {*}$opts $msg
6514 } on signal sig {
6515 puts "Got signal: $sig"
6516 } finally {
6517 $f close
6518 }</code></pre>
6519 </div></div>
6520 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6521 handler.</p></div>
6522 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6523 <div class="paragraph"><p>See also <a href="#_throw"><strong><code>throw</code></strong></a>, <a href="#_catch"><strong><code>catch</code></strong></a>, <a href="#_return"><strong><code>return</code></strong></a>, <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
6524 </div>
6525 <div class="sect2">
6526 <h3 id="_unknown">unknown</h3>
6527 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6528 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6529 invoke it if it does exist.</p></div>
6530 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6531 is not a defined command, then Tcl checks for the existence of
6532 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6533 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6534 error.</p></div>
6535 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6536 arguments consisting of the fully-substituted name and arguments
6537 for the original non-existent command.</p></div>
6538 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6539 through library directories for a command procedure with the name
6540 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6541 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6542 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6543 change the original command slightly and then (re-)execute it.
6544 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6545 the original non-existent command.</p></div>
6546 </div>
6547 <div class="sect2">
6548 <h3 id="_unset">unset</h3>
6549 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6550 <div class="paragraph"><p>Remove variables.
6551 Each <code><em>name</em></code> is a variable name, specified in any of the
6552 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6553 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6554 element is removed without affecting the rest of the array.</p></div>
6555 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6556 index, then the entire array is deleted.</p></div>
6557 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6558 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6559 is specified. The <em>--</em> argument may be specified to stop option processing
6560 in case the variable name may be <em>-nocomplain</em>.</p></div>
6561 </div>
6562 <div class="sect2">
6563 <h3 id="_upcall">upcall</h3>
6564 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6565 <div class="paragraph"><p>May be used from within a proc defined as <a href="#_local"><strong><code>local</code></strong></a> <a href="#_proc"><strong><code>proc</code></strong></a> in order to call
6566 the previous, hidden version of the same command.</p></div>
6567 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6568 </div>
6569 <div class="sect2">
6570 <h3 id="_uplevel">uplevel</h3>
6571 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6572 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6573 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6574 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6575 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6576 it gives a distance (up the procedure calling stack) to move before
6577 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6578 a number then the number gives an absolute level number. If <code><em>level</em></code>
6579 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6580 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6581 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6582 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6583 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6584 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6585 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6586 then the command will be executed in the variable context of <em>a</em>.</p></div>
6587 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6588 at top-level (only global variables will be visible).
6589 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6590 from the procedure calling stack while the command is being executed.
6591 In the above example, suppose <em>c</em> invokes the command</p></div>
6592 <div class="literalblock">
6593 <div class="content">
6594 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6595 </div></div>
6596 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6597 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6598 at level 3, as if called from <em>b</em>. If it in turn executes
6599 the command</p></div>
6600 <div class="literalblock">
6601 <div class="content">
6602 <pre><code>uplevel {set x 42}</code></pre>
6603 </div></div>
6604 <div class="paragraph"><p>then the <a href="#_set"><strong><code>set</code></strong></a> command will modify the same variable <em>x</em> in <em>b&#8217;s
6605 context: the procedure 'c</em> does not appear to be on the call stack
6606 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6607 be used to obtain the level of the current procedure.</p></div>
6608 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6609 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6610 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6611 </div>
6612 <div class="sect2">
6613 <h3 id="_upvar">upvar</h3>
6614 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6615 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6616 procedure to refer to variables in an enclosing procedure call or
6617 to global variables.</p></div>
6618 <div class="paragraph"><p><code><em>level</em></code> may have any of the forms permitted for the <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6619 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6620 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6621 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6622 by that name in the procedure frame given by <code><em>level</em></code> (or at
6623 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6624 in the current procedure by the name given in the corresponding
6625 <code><em>myVar</em></code> argument.</p></div>
6626 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6627 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6628 an ordinary variable.</p></div>
6629 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6630 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6631 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6632 procedure calling and also makes it easier to build new control constructs
6633 as Tcl procedures.
6634 For example, consider the following procedure:</p></div>
6635 <div class="literalblock">
6636 <div class="content">
6637 <pre><code>proc add2 name {
6638 upvar $name x
6639 set x [expr $x+2]
6640 }</code></pre>
6641 </div></div>
6642 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6643 and it adds two to the value of that variable.
6644 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6645 instead of <a href="#_upvar"><strong><code>upvar</code></strong></a>, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes it simpler for <em>add2</em>
6646 to access the variable in the caller&#8217;s procedure frame.</p></div>
6647 </div>
6648 <div class="sect2">
6649 <h3 id="_while">while</h3>
6650 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6651 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6652 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6653 The value of the expression must be numeric; if it is non-zero
6654 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6655 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6656 again, and the process repeats until eventually <code><em>test</em></code>
6657 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6658 commands may be executed inside <code><em>body</em></code> to terminate the current
6659 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6660 commands may be executed inside <code><em>body</em></code> to cause immediate
6661 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6662 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6663 </div>
6664 </div>
6665 </div>
6666 <div class="sect1">
6667 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6668 <div class="sectionbody">
6669 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6670 what options were selected when Jim Tcl was built.</p></div>
6671 <div class="sect2">
6672 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6673 <div class="dlist"><dl>
6674 <dt class="hdlist1">
6675 <code><strong>os.fork</strong></code>
6676 </dt>
6677 <dd>
6679 Invokes <em>fork(2)</em> and returns the result.
6680 </p>
6681 </dd>
6682 <dt class="hdlist1">
6683 <code><strong>os.wait -nohang</strong> <em>pid</em></code>
6684 </dt>
6685 <dd>
6687 Invokes waitpid(2), with WNOHANG if <code>-nohang</code> is specified.
6688 Returns a list of 3 elements.
6689 </p>
6690 <div class="literalblock">
6691 <div class="content">
6692 <pre><code>{0 none 0} if -nohang is specified, and the process is still alive.</code></pre>
6693 </div></div>
6694 <div class="literalblock">
6695 <div class="content">
6696 <pre><code>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</code></pre>
6697 </div></div>
6698 <div class="literalblock">
6699 <div class="content">
6700 <pre><code>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</code></pre>
6701 </div></div>
6702 <div class="literalblock">
6703 <div class="content">
6704 <pre><code>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</code></pre>
6705 </div></div>
6706 <div class="literalblock">
6707 <div class="content">
6708 <pre><code>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</code></pre>
6709 </div></div>
6710 </dd>
6711 <dt class="hdlist1">
6712 <code><strong>os.gethostname</strong></code>
6713 </dt>
6714 <dd>
6716 Invokes <em>gethostname(3)</em> and returns the result.
6717 </p>
6718 </dd>
6719 <dt class="hdlist1">
6720 <code><strong>os.getids</strong></code>
6721 </dt>
6722 <dd>
6724 Returns the various user/group ids for the current process.
6725 </p>
6726 <div class="literalblock">
6727 <div class="content">
6728 <pre><code>jim&gt; os.getids
6729 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6730 </div></div>
6731 </dd>
6732 <dt class="hdlist1">
6733 <code><strong>os.uptime</strong></code>
6734 </dt>
6735 <dd>
6737 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6738 </p>
6739 </dd>
6740 </dl></div>
6741 </div>
6742 </div>
6743 </div>
6744 <div class="sect1">
6745 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6746 <div class="sectionbody">
6747 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6748 <div class="paragraph"><p>See <a href="#_open"><strong><code>open</code></strong></a> and <a href="#_socket"><strong><code>socket</code></strong></a> for commands which return an I/O handle.</p></div>
6749 <div class="sect2">
6750 <h3 id="_aio">aio</h3>
6751 <div class="dlist"><dl>
6752 <dt class="hdlist1">
6753 <code>$handle <strong>accept</strong></code>
6754 </dt>
6755 <dd>
6757 Server socket only: Accept a connection and return stream
6758 </p>
6759 </dd>
6760 <dt class="hdlist1">
6761 <code>$handle <strong>buffering none|line|full</strong></code>
6762 </dt>
6763 <dd>
6765 Sets the buffering mode of the stream.
6766 </p>
6767 </dd>
6768 <dt class="hdlist1">
6769 <code>$handle <strong>close</strong></code>
6770 </dt>
6771 <dd>
6773 Closes the stream
6774 </p>
6775 </dd>
6776 <dt class="hdlist1">
6777 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6778 </dt>
6779 <dd>
6781 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
6782 that many bytes will be copied. Otherwise copying continues until the end
6783 of the input file. Returns the number of bytes actually copied.
6784 </p>
6785 </dd>
6786 <dt class="hdlist1">
6787 <code>$handle <strong>eof</strong></code>
6788 </dt>
6789 <dd>
6791 Returns 1 if stream is at eof
6792 </p>
6793 </dd>
6794 <dt class="hdlist1">
6795 <code>$handle <strong>filename</strong></code>
6796 </dt>
6797 <dd>
6799 Returns the original filename associated with the handle.
6800 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
6801 </p>
6802 </dd>
6803 <dt class="hdlist1">
6804 <code>$handle <strong>flush</strong></code>
6805 </dt>
6806 <dd>
6808 Flush the stream
6809 </p>
6810 </dd>
6811 <dt class="hdlist1">
6812 <code>$handle <strong>gets</strong> <em>?var?</em></code>
6813 </dt>
6814 <dd>
6816 Read one line and return it or store it in the var
6817 </p>
6818 </dd>
6819 <dt class="hdlist1">
6820 <code>$handle <strong>isatty</strong></code>
6821 </dt>
6822 <dd>
6824 Returns 1 if the stream is a tty device.
6825 </p>
6826 </dd>
6827 <dt class="hdlist1">
6828 <code>$handle <strong>ndelay ?0|1?</strong></code>
6829 </dt>
6830 <dd>
6832 Set O_NDELAY (if arg). Returns current/new setting.
6833 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6834 Use with care.
6835 </p>
6836 </dd>
6837 <dt class="hdlist1">
6838 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
6839 </dt>
6840 <dd>
6842 Write the string, with newline unless -nonewline
6843 </p>
6844 </dd>
6845 <dt class="hdlist1">
6846 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
6847 </dt>
6848 <dd>
6850 Read and return bytes from the stream. To eof if no len.
6851 </p>
6852 </dd>
6853 <dt class="hdlist1">
6854 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
6855 </dt>
6856 <dd>
6858 Receives a message from the handle via recvfrom(2) and returns it.
6859 At most <code><em>maxlen</em></code> bytes are read.
6860 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
6861 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6862 </p>
6863 </dd>
6864 <dt class="hdlist1">
6865 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
6866 </dt>
6867 <dd>
6869 Seeks in the stream (default <em>current</em>)
6870 </p>
6871 </dd>
6872 <dt class="hdlist1">
6873 <code>$handle <strong>sendto</strong> <em>str ?hostname:?port</em></code>
6874 </dt>
6875 <dd>
6877 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
6878 This is intended for udp sockets and may give an error or behave in unintended
6879 ways for other handle types.
6880 Returns the number of bytes written.
6881 </p>
6882 </dd>
6883 <dt class="hdlist1">
6884 <code>$handle <strong>tell</strong></code>
6885 </dt>
6886 <dd>
6888 Returns the current seek position
6889 </p>
6890 </dd>
6891 </dl></div>
6892 </div>
6893 <div class="sect2">
6894 <h3 id="_fconfigure">fconfigure</h3>
6895 <div class="dlist"><dl>
6896 <dt class="hdlist1">
6897 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
6898 </dt>
6899 <dd>
6901 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
6902 command is supported.
6903 </p>
6904 <div class="ulist"><ul>
6905 <li>
6907 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -blocking</code> maps to <a href="#_aio"><strong><code>aio</code></strong></a> <code>ndelay</code>
6908 </p>
6909 </li>
6910 <li>
6912 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -buffering</code> maps to <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code>
6913 </p>
6914 </li>
6915 <li>
6917 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
6918 </p>
6919 </li>
6920 </ul></div>
6921 </dd>
6922 </dl></div>
6923 </div>
6924 <div class="sect2">
6925 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
6926 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
6927 If no script is given, returns the current script. If the given script is the empty, the
6928 handler is removed.</p></div>
6929 <div class="dlist"><dl>
6930 <dt class="hdlist1">
6931 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
6932 </dt>
6933 <dd>
6935 Sets or returns the script for when the socket is readable.
6936 </p>
6937 </dd>
6938 <dt class="hdlist1">
6939 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
6940 </dt>
6941 <dd>
6943 Sets or returns the script for when the socket is writable.
6944 </p>
6945 </dd>
6946 <dt class="hdlist1">
6947 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
6948 </dt>
6949 <dd>
6951 Sets or returns the script for when when oob data received.
6952 </p>
6953 </dd>
6954 </dl></div>
6955 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
6956 <div class="dlist"><dl>
6957 <dt class="hdlist1">
6959 </dt>
6960 <dd>
6962 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
6963 </p>
6964 </dd>
6965 </dl></div>
6966 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
6967 <div class="dlist"><dl>
6968 <dt class="hdlist1">
6969 <code><strong>after</strong> <em>ms</em></code>
6970 </dt>
6971 <dd>
6973 Sleeps for the given number of milliseconds. No events are
6974 processed during this time.
6975 </p>
6976 </dd>
6977 <dt class="hdlist1">
6978 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> script ?script ...?'</code>
6979 </dt>
6980 <dd>
6982 The scripts are concatenated and executed after the given
6983 number of milliseconds have elapsed. If <em>idle</em> is specified,
6984 the script will run the next time the event loop is processed
6985 with <a href="#cmd_2"><strong><code>vwait</code></strong></a> or <a href="#cmd_2"><strong><code>update</code></strong></a>. The script is only run once and
6986 then removed. Returns an event id.
6987 </p>
6988 </dd>
6989 <dt class="hdlist1">
6990 <code><strong>after cancel</strong> <em>id|command</em></code>
6991 </dt>
6992 <dd>
6994 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
6995 command (script). Returns the number of milliseconds
6996 remaining until the event would have fired. Returns the
6997 empty string if no matching event is found.
6998 </p>
6999 </dd>
7000 <dt class="hdlist1">
7001 <code><strong>after info</strong> <em>?id?</em></code>
7002 </dt>
7003 <dd>
7005 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7006 events. If <code><em>id</em></code> is given, returns a list containing the
7007 associated script and either <em>timer</em> or <em>idle</em> to indicated
7008 the type of the event. An error occurs if <code><em>id</em></code> does not
7009 match an event.
7010 </p>
7011 </dd>
7012 <dt class="hdlist1">
7013 <code><strong>vwait</strong> <em>variable</em></code>
7014 </dt>
7015 <dd>
7017 A call to <a href="#cmd_2"><strong><code>vwait</code></strong></a> is enters the eventloop. <a href="#cmd_2"><strong><code>vwait</code></strong></a> processes
7018 events until the named (global) variable changes or all
7019 event handlers are removed. The variable need not exist
7020 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7021 returns immediately.
7022 </p>
7023 </dd>
7024 <dt class="hdlist1">
7025 <code><strong>update ?idletasks?</strong></code>
7026 </dt>
7027 <dd>
7029 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7030 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7031 not file events.
7032 Returns once handlers have been run for all expired events.
7033 </p>
7034 </dd>
7035 </dl></div>
7036 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7037 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7038 If the <code>bgerror</code> commands does not exist, it is printed to stderr instead.</p></div>
7039 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7040 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7041 <div class="dlist"><dl>
7042 <dt class="hdlist1">
7043 <code><strong>bgerror</strong> <em>error</em></code>
7044 </dt>
7045 <dd>
7047 Called when an event handler script generates an error.
7048 </p>
7049 </dd>
7050 </dl></div>
7051 </div>
7052 <div class="sect2">
7053 <h3 id="_socket">socket</h3>
7054 <div class="paragraph"><p>Various socket types may be created.</p></div>
7055 <div class="dlist"><dl>
7056 <dt class="hdlist1">
7057 <code><strong>socket unix</strong> <em>path</em></code>
7058 </dt>
7059 <dd>
7061 A unix domain socket client.
7062 </p>
7063 </dd>
7064 <dt class="hdlist1">
7065 <code><strong>socket unix.server</strong> <em>path</em></code>
7066 </dt>
7067 <dd>
7069 A unix domain socket server.
7070 </p>
7071 </dd>
7072 <dt class="hdlist1">
7073 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7074 </dt>
7075 <dd>
7077 A TCP socket client.
7078 </p>
7079 </dd>
7080 <dt class="hdlist1">
7081 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7082 </dt>
7083 <dd>
7085 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7086 </p>
7087 </dd>
7088 <dt class="hdlist1">
7089 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7090 </dt>
7091 <dd>
7093 A UDP socket client. If the address is not specified,
7094 the client socket will be unbound and <em>sendto</em> must be used
7095 to indicated the destination.
7096 </p>
7097 </dd>
7098 <dt class="hdlist1">
7099 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7100 </dt>
7101 <dd>
7103 A UDP socket server.
7104 </p>
7105 </dd>
7106 <dt class="hdlist1">
7107 <code><strong>socket pipe</strong></code>
7108 </dt>
7109 <dd>
7111 A pipe. Note that unlike all other socket types, this command returns
7112 a list of two channels: {read write}
7113 </p>
7114 </dd>
7115 </dl></div>
7116 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7117 address.</p></div>
7118 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7119 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7120 <div class="literalblock">
7121 <div class="content">
7122 <pre><code>set f [socket stream www.google.com:80]
7123 aio.sockstream1
7124 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7125 $f gets
7126 HTTP/1.0 302 Found
7127 $f close</code></pre>
7128 </div></div>
7129 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7130 the EVENTLOOP API.</p></div>
7131 <div class="literalblock">
7132 <div class="content">
7133 <pre><code>set f [socket stream.server 80]
7134 $f readable {
7135 set client [$f accept]
7136 $client gets $buf
7138 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7139 $client close
7141 vwait done</code></pre>
7142 </div></div>
7143 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7144 <div class="olist arabic"><ol class="arabic">
7145 <li>
7147 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7148 </p>
7149 </li>
7150 <li>
7152 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7153 </p>
7154 </li>
7155 <li>
7157 A hostname
7158 </p>
7159 </li>
7160 </ol></div>
7161 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7162 also accept requests via IPv4.</p></div>
7163 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7164 which matches the socket type is used.</p></div>
7165 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7166 <div class="literalblock">
7167 <div class="content">
7168 <pre><code>lassign [socket pipe] r w</code></pre>
7169 </div></div>
7170 <div class="literalblock">
7171 <div class="content">
7172 <pre><code># Must close $w after exec
7173 exec ps &gt;@$w &amp;
7174 $w close</code></pre>
7175 </div></div>
7176 <div class="literalblock">
7177 <div class="content">
7178 <pre><code>$r readable ...</code></pre>
7179 </div></div>
7180 </div>
7181 <div class="sect2">
7182 <h3 id="_syslog">syslog</h3>
7183 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7184 <div class="paragraph"><p>This command sends message to system syslog facility with given
7185 priority. Valid priorities are:</p></div>
7186 <div class="literalblock">
7187 <div class="content">
7188 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7189 </div></div>
7190 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7191 priority of info is used.</p></div>
7192 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7193 argv0 is used as ident string. However, any of the following options
7194 may be specified before priority to control these parameters:</p></div>
7195 <div class="dlist"><dl>
7196 <dt class="hdlist1">
7197 <code><strong>-facility</strong> <em>value</em></code>
7198 </dt>
7199 <dd>
7201 Use specified facility instead of user. The following
7202 values for facility are recognized:
7203 </p>
7204 <div class="literalblock">
7205 <div class="content">
7206 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7207 uucp, local0-local7</code></pre>
7208 </div></div>
7209 </dd>
7210 <dt class="hdlist1">
7211 <code><strong>-ident</strong> <em>string</em></code>
7212 </dt>
7213 <dd>
7215 Use given string instead of argv0 variable for ident string.
7216 </p>
7217 </dd>
7218 <dt class="hdlist1">
7219 <code><strong>-options</strong> <em>integer</em></code>
7220 </dt>
7221 <dd>
7223 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7224 use numeric values of those from your system syslog.h file,
7225 because I haven&#8217;t got time to implement yet another hash
7226 table.
7227 </p>
7228 </dd>
7229 </dl></div>
7230 </div>
7231 <div class="sect2">
7232 <h3 id="cmd_3">pack: pack, unpack</h3>
7233 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7234 <div class="dlist"><dl>
7235 <dt class="hdlist1">
7236 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7237 </dt>
7238 <dd>
7240 Packs the binary representation of <code><em>value</em></code> into the variable
7241 <code><em>varName</em></code>. The value is packed according to the given type
7242 (integer/string, big-endian/little-endian), width and bit offset.
7243 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7244 Ihe variable is expanded if necessary.
7245 </p>
7246 </dd>
7247 <dt class="hdlist1">
7248 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-str</strong> <em>bitpos bitwidth</em></code>
7249 </dt>
7250 <dd>
7252 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7253 Interprets the value according to the type (integer/string, big-endian/little-endian
7254 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7255 may be up to the size of a Jim Tcl integer (typically 64 bits). For the string type,
7256 both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7257 access outside the length of the value will return 0 for integer types or the empty string
7258 for the string type.
7259 </p>
7260 </dd>
7261 </dl></div>
7262 </div>
7263 <div class="sect2">
7264 <h3 id="_binary">binary</h3>
7265 <div class="paragraph"><p>The optional, pure-Tcl <em>binary</em> extension provides the Tcl-compatible <a href="#_binary"><strong><code>binary</code></strong></a> <code>scan</code> and <a href="#_binary"><strong><code>binary</code></strong></a> <code>format</code>
7266 commands based on the low-level <a href="#cmd_3"><strong><code>pack</code></strong></a> and <a href="#cmd_3"><strong><code>unpack</code></strong></a> commands.</p></div>
7267 <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>
7268 <div class="paragraph"><p>Note that packing and unpacking of floating point values is not supported.</p></div>
7269 </div>
7270 <div class="sect2">
7271 <h3 id="cmd_4">oo: class, super</h3>
7272 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7273 <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>
7274 <div class="dlist"><dl>
7275 <dt class="hdlist1">
7276 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7277 </dt>
7278 <dd>
7280 Create a new class, <code><em>classname</em></code>, with the given dictionary
7281 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7282 which all newly created objects of this class are initialised with.
7283 If a list of baseclasses is given, methods and instance variables
7284 are inherited.
7285 </p>
7286 </dd>
7287 <dt class="hdlist1">
7288 <code><strong>super</strong> <em>method ?args ...?</em></code>
7289 </dt>
7290 <dd>
7292 From within a method, invokes the given method on the base class.
7293 Note that this will only call the last baseclass given.
7294 </p>
7295 </dd>
7296 </dl></div>
7297 </div>
7298 <div class="sect2">
7299 <h3 id="_tree">tree</h3>
7300 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7301 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>
7302 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7303 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7304 <div class="dlist"><dl>
7305 <dt class="hdlist1">
7306 <code><strong>tree</strong></code>
7307 </dt>
7308 <dd>
7310 Creates and returns a new tree object with a single node named "root".
7311 All operations on the tree are invoked through this object.
7312 </p>
7313 </dd>
7314 <dt class="hdlist1">
7315 <code>$tree <strong>destroy</strong></code>
7316 </dt>
7317 <dd>
7319 Destroy the tree and all it&#8217;s nodes. (Note that the the tree will also
7320 be automatically garbage collected once it goes out of scope).
7321 </p>
7322 </dd>
7323 <dt class="hdlist1">
7324 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7325 </dt>
7326 <dd>
7328 Set the value for the given attribute key.
7329 </p>
7330 </dd>
7331 <dt class="hdlist1">
7332 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7333 </dt>
7334 <dd>
7336 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7337 </p>
7338 </dd>
7339 <dt class="hdlist1">
7340 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7341 </dt>
7342 <dd>
7344 Returns 1 if the given attribute key exists.
7345 </p>
7346 </dd>
7347 <dt class="hdlist1">
7348 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7349 </dt>
7350 <dd>
7352 Returns the value associated with the given attribute key.
7353 </p>
7354 </dd>
7355 <dt class="hdlist1">
7356 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7357 </dt>
7358 <dd>
7360 Returns the entire attribute dictionary associated with the given key.
7361 </p>
7362 </dd>
7363 <dt class="hdlist1">
7364 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7365 </dt>
7366 <dd>
7368 Returns the depth of the given node. The depth of "root" is 0.
7369 </p>
7370 </dd>
7371 <dt class="hdlist1">
7372 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7373 </dt>
7374 <dd>
7376 Returns the node name of the parent node, or "" for the root node.
7377 </p>
7378 </dd>
7379 <dt class="hdlist1">
7380 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7381 </dt>
7382 <dd>
7384 Returns the number of child nodes.
7385 </p>
7386 </dd>
7387 <dt class="hdlist1">
7388 <code>$tree <strong>children</strong> <em>nodename</em></code>
7389 </dt>
7390 <dd>
7392 Returns a list of the child nodes.
7393 </p>
7394 </dd>
7395 <dt class="hdlist1">
7396 <code>$tree <strong>next</strong> <em>nodename</em></code>
7397 </dt>
7398 <dd>
7400 Returns the next sibling node, or "" if none.
7401 </p>
7402 </dd>
7403 <dt class="hdlist1">
7404 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7405 </dt>
7406 <dd>
7408 Add a new child node to the given node. The index is a list index
7409 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7410 Returns the name of the newly added node.
7411 </p>
7412 </dd>
7413 <dt class="hdlist1">
7414 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7415 </dt>
7416 <dd>
7418 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7419 depth first (<code>dfs</code>).
7420 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7421 The name of each node is stored in <code><em>nodevar</em></code>.
7422 The script is evaluated twice for each node, on entry and exit.
7423 </p>
7424 </dd>
7425 <dt class="hdlist1">
7426 <code>$tree <strong>dump</strong></code>
7427 </dt>
7428 <dd>
7430 Dumps the tree contents to stdout
7431 </p>
7432 </dd>
7433 </dl></div>
7434 </div>
7435 <div class="sect2">
7436 <h3 id="_tcl_prefix">tcl::prefix</h3>
7437 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7438 (<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
7439 of possible values (typically commands or options).</p></div>
7440 <div class="dlist"><dl>
7441 <dt class="hdlist1">
7442 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7443 </dt>
7444 <dd>
7446 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7447 </p>
7448 </dd>
7449 <dt class="hdlist1">
7450 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7451 </dt>
7452 <dd>
7454 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7455 </p>
7456 </dd>
7457 <dt class="hdlist1">
7458 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7459 </dt>
7460 <dd>
7462 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7463 exactly one element, the matched element is returned. If not, the
7464 result depends on the <code>-error</code> option.
7465 </p>
7466 <div class="ulist"><ul>
7467 <li>
7469 <code><strong>-exact</strong></code> Accept only exact matches.
7470 </p>
7471 </li>
7472 <li>
7474 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
7475 </p>
7476 </li>
7477 <li>
7479 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7480 empty, no error is generated and an empty string is returned.
7481 Otherwise the options are used as return options when
7482 generating the error message. The default corresponds to
7483 setting <code>-level 0</code>.
7484 </p>
7485 </li>
7486 </ul></div>
7487 </dd>
7488 </dl></div>
7489 </div>
7490 <div class="sect2">
7491 <h3 id="_history">history</h3>
7492 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
7493 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7494 Note: if line editing support is not available, <a href="#_history"><strong><code>history</code></strong></a> <code>getline</code> acts like <a href="#_gets"><strong><code>gets</code></strong></a> and
7495 the remaining subcommands do nothing.</p></div>
7496 <div class="dlist"><dl>
7497 <dt class="hdlist1">
7498 <code><strong>history load</strong> <em>filename</em></code>
7499 </dt>
7500 <dd>
7502 Load history from a (text) file. If the file does not exist or is not readable,
7503 it is ignored.
7504 </p>
7505 </dd>
7506 <dt class="hdlist1">
7507 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7508 </dt>
7509 <dd>
7511 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
7512 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7513 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7514 </p>
7515 </dd>
7516 <dt class="hdlist1">
7517 <code><strong>history add</strong> <em>line</em></code>
7518 </dt>
7519 <dd>
7521 Adds the given line to the history buffer.
7522 </p>
7523 </dd>
7524 <dt class="hdlist1">
7525 <code><strong>history save</strong> <em>filename</em></code>
7526 </dt>
7527 <dd>
7529 Saves the current history buffer to the given file.
7530 </p>
7531 </dd>
7532 <dt class="hdlist1">
7533 <code><strong>history show</strong></code>
7534 </dt>
7535 <dd>
7537 Displays the current history buffer to standard output.
7538 </p>
7539 </dd>
7540 </dl></div>
7541 </div>
7542 <div class="sect2">
7543 <h3 id="_namespace">namespace</h3>
7544 <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>
7545 <div class="dlist"><dl>
7546 <dt class="hdlist1">
7547 <code><strong>namespace code</strong> <em>script</em></code>
7548 </dt>
7549 <dd>
7551 Captures the current namespace context for later execution of
7552 the script <code><em>script</em></code>. It returns a new script in which script has
7553 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7554 </p>
7555 </dd>
7556 <dt class="hdlist1">
7557 <code><strong>namespace current</strong></code>
7558 </dt>
7559 <dd>
7561 Returns the fully-qualified name for the current namespace.
7562 </p>
7563 </dd>
7564 <dt class="hdlist1">
7565 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
7566 </dt>
7567 <dd>
7569 Deletes all commands and variables with the given namespace prefixes.
7570 </p>
7571 </dd>
7572 <dt class="hdlist1">
7573 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
7574 </dt>
7575 <dd>
7577 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7578 </p>
7579 </dd>
7580 <dt class="hdlist1">
7581 <code><strong>namespace origin</strong> <em>command</em></code>
7582 </dt>
7583 <dd>
7585 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7586 </p>
7587 </dd>
7588 <dt class="hdlist1">
7589 <code><strong>namespace parent</strong> ?namespace?</code>
7590 </dt>
7591 <dd>
7593 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7594 for the current namespace.
7595 </p>
7596 </dd>
7597 <dt class="hdlist1">
7598 <code><strong>namespace qualifiers</strong> <em>string</em></code>
7599 </dt>
7600 <dd>
7602 Returns any leading namespace qualifiers for <code><em>string</em></code>
7603 </p>
7604 </dd>
7605 <dt class="hdlist1">
7606 <code><strong>namespace tail</strong> <em>string</em></code>
7607 </dt>
7608 <dd>
7610 Returns the simple name at the end of a qualified string.
7611 </p>
7612 </dd>
7613 <dt class="hdlist1">
7614 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
7615 </dt>
7616 <dd>
7618 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
7619 </p>
7620 </dd>
7621 <dt class="hdlist1">
7622 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
7623 </dt>
7624 <dd>
7626 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
7627 </p>
7628 </dd>
7629 </dl></div>
7630 </div>
7631 </div>
7632 </div>
7633 <div class="sect1">
7634 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
7635 <div class="sectionbody">
7636 <div class="paragraph"><p>The following global variables are created automatically
7637 by the Tcl library.</p></div>
7638 <div class="dlist"><dl>
7639 <dt class="hdlist1">
7640 <code><strong>env</strong></code>
7641 </dt>
7642 <dd>
7644 This variable is set by Jim as an array
7645 whose elements are the environment variables for the process.
7646 Reading an element will return the value of the corresponding
7647 environment variable.
7648 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
7649 It may be modified and will affect the environment passed to
7650 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
7651 </p>
7652 </dd>
7653 <dt class="hdlist1">
7654 <code><strong>platform_tcl</strong></code>
7655 </dt>
7656 <dd>
7658 This variable is set by Jim as an array containing information
7659 about the platform on which Jim was built. Currently this includes
7660 <em>os</em> and <em>platform</em>.
7661 </p>
7662 </dd>
7663 <dt class="hdlist1">
7664 <code><strong>auto_path</strong></code>
7665 </dt>
7666 <dd>
7668 This variable contains a list of paths to search for packages.
7669 It defaults to a location based on where jim is installed
7670 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
7671 or the embedding application. Note that <code>jimsh</code> will consider
7672 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
7673 list of paths to add to <code><strong>auto_path</strong></code>.
7674 </p>
7675 </dd>
7676 <dt class="hdlist1">
7677 <code><strong>errorCode</strong></code>
7678 </dt>
7679 <dd>
7681 This variable holds the value of the -errorcode return
7682 option set by the most recent error that occurred in this
7683 interpreter. This list value represents additional information
7684 about the error in a form that is easy to process with
7685 programs. The first element of the list identifies a general
7686 class of errors, and determines the format of the rest of
7687 the list. The following formats for -errorcode return options
7688 are used by the Tcl core; individual applications may define
7689 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
7690 Otherwise it will be <code>NONE</code>.
7691 </p>
7692 </dd>
7693 </dl></div>
7694 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
7695 <div class="dlist"><dl>
7696 <dt class="hdlist1">
7697 <code><strong>tcl_interactive</strong></code>
7698 </dt>
7699 <dd>
7701 This variable is set to 1 if jimsh is started in interactive mode
7702 or 0 otherwise.
7703 </p>
7704 </dd>
7705 <dt class="hdlist1">
7706 <code><strong>tcl_platform</strong></code>
7707 </dt>
7708 <dd>
7710 This variable is set by Jim as an array containing information
7711 about the platform upon which Jim was built. The following is an
7712 example of the contents of this array.
7713 </p>
7714 <div class="literalblock">
7715 <div class="content">
7716 <pre><code>tcl_platform(byteOrder) = littleEndian
7717 tcl_platform(os) = Darwin
7718 tcl_platform(platform) = unix
7719 tcl_platform(pointerSize) = 8
7720 tcl_platform(threaded) = 0
7721 tcl_platform(wordSize) = 8
7722 tcl_platform(pathSeparator) = :</code></pre>
7723 </div></div>
7724 </dd>
7725 <dt class="hdlist1">
7726 <code><strong>argv0</strong></code>
7727 </dt>
7728 <dd>
7730 If jimsh is invoked to run a script, this variable contains the name
7731 of the script.
7732 </p>
7733 </dd>
7734 <dt class="hdlist1">
7735 <code><strong>argv</strong></code>
7736 </dt>
7737 <dd>
7739 If jimsh is invoked to run a script, this variable contains a list
7740 of any arguments supplied to the script.
7741 </p>
7742 </dd>
7743 <dt class="hdlist1">
7744 <code><strong>argc</strong></code>
7745 </dt>
7746 <dd>
7748 If jimsh is invoked to run a script, this variable contains the number
7749 of arguments supplied to the script.
7750 </p>
7751 </dd>
7752 <dt class="hdlist1">
7753 <code><strong>jim_argv0</strong></code>
7754 </dt>
7755 <dd>
7757 The value of argv[0] when jimsh was invoked.
7758 </p>
7759 </dd>
7760 </dl></div>
7761 </div>
7762 </div>
7763 <div class="sect1">
7764 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
7765 <div class="sectionbody">
7766 <div class="sect2">
7767 <h3 id="_in_v0_70">In v0.70</h3>
7768 <div class="olist arabic"><ol class="arabic">
7769 <li>
7771 <code>platform_tcl()</code> settings are now automatically determined
7772 </p>
7773 </li>
7774 <li>
7776 Add aio <code>$handle filename</code>
7777 </p>
7778 </li>
7779 <li>
7781 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
7782 </p>
7783 </li>
7784 <li>
7786 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
7787 </p>
7788 </li>
7789 <li>
7791 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
7792 </p>
7793 </li>
7794 <li>
7796 Add the pure-Tcl <em>oo</em> extension
7797 </p>
7798 </li>
7799 <li>
7801 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
7802 </p>
7803 </li>
7804 <li>
7806 Unit test framework is less verbose and more Tcl-compatible
7807 </p>
7808 </li>
7809 <li>
7811 Optional UTF-8 support
7812 </p>
7813 </li>
7814 <li>
7816 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
7817 </p>
7818 </li>
7819 <li>
7821 Command line editing in interactive mode, e.g. <em>jimsh</em>
7822 </p>
7823 </li>
7824 </ol></div>
7825 </div>
7826 <div class="sect2">
7827 <h3 id="_in_v0_63">In v0.63</h3>
7828 <div class="olist arabic"><ol class="arabic">
7829 <li>
7831 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
7832 </p>
7833 </li>
7834 <li>
7836 <em>info complete</em> now uses the real parser and so is 100% accurate
7837 </p>
7838 </li>
7839 <li>
7841 Better access to live stack frames with <em>info frame</em>, <a href="#_stacktrace"><strong><code>stacktrace</code></strong></a> and <a href="#_stackdump"><strong><code>stackdump</code></strong></a>
7842 </p>
7843 </li>
7844 <li>
7846 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
7847 </p>
7848 </li>
7849 <li>
7851 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
7852 </p>
7853 </li>
7854 <li>
7856 <a href="#_lambda"><strong><code>lambda</code></strong></a>, <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a> are implemented via <a href="#_tailcall"><strong><code>tailcall</code></strong></a> for efficiency
7857 </p>
7858 </li>
7859 <li>
7861 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
7862 </p>
7863 </li>
7864 <li>
7866 udp sockets are now supported for both clients and servers.
7867 </p>
7868 </li>
7869 <li>
7871 vfork-based exec is now working correctly
7872 </p>
7873 </li>
7874 <li>
7876 Add <em>file tempfile</em>
7877 </p>
7878 </li>
7879 <li>
7881 Add <em>socket pipe</em>
7882 </p>
7883 </li>
7884 <li>
7886 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
7887 </p>
7888 </li>
7889 <li>
7891 It is now possible to <a href="#_return"><strong><code>return</code></strong></a> from within <a href="#_try"><strong><code>try</code></strong></a>
7892 </p>
7893 </li>
7894 <li>
7896 IPv6 support is now included
7897 </p>
7898 </li>
7899 <li>
7901 Add <em>string is</em>
7902 </p>
7903 </li>
7904 <li>
7906 Event handlers works better if an error occurs. eof handler has been removed.
7907 </p>
7908 </li>
7909 <li>
7911 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
7912 </p>
7913 </li>
7914 <li>
7916 Command pipelines via open "|&#8230;" are now supported
7917 </p>
7918 </li>
7919 <li>
7921 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
7922 </p>
7923 </li>
7924 <li>
7926 Add <em>info references</em>
7927 </p>
7928 </li>
7929 <li>
7931 Add support for <em>after <code>'ms</em></code><em>, 'after idle</em>, <em>after info</em>, <a href="#cmd_2"><strong><code>update</code></strong></a>
7932 </p>
7933 </li>
7934 <li>
7936 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
7937 </p>
7938 </li>
7939 <li>
7941 Add <em>dict keys</em>
7942 </p>
7943 </li>
7944 <li>
7946 Add support for <em>lsort -index</em>
7947 </p>
7948 </li>
7949 </ol></div>
7950 </div>
7951 <div class="sect2">
7952 <h3 id="_in_v0_62">In v0.62</h3>
7953 <div class="olist arabic"><ol class="arabic">
7954 <li>
7956 Add support to <a href="#_exec"><strong><code>exec</code></strong></a> for <em>&gt;&amp;</em>, <em>&gt;&gt;&amp;</em>, <em>|&amp;</em>, <em>2&gt;@1</em>
7957 </p>
7958 </li>
7959 <li>
7961 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
7962 </p>
7963 </li>
7964 <li>
7966 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
7967 </p>
7968 </li>
7969 <li>
7971 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
7972 </p>
7973 </li>
7974 <li>
7976 Add support for <a href="#_return"><strong><code>return</code></strong></a>, <a href="#_break"><strong><code>break</code></strong></a>, <a href="#_continue"><strong><code>continue</code></strong></a> in subst
7977 </p>
7978 </li>
7979 <li>
7981 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
7982 </p>
7983 </li>
7984 <li>
7986 Add support for functions in <a href="#_expr"><strong><code>expr</code></strong></a> (e.g. int(), abs()), and also <em>in</em>, <em>ni</em> list operations
7987 </p>
7988 </li>
7989 <li>
7991 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
7992 </p>
7993 </li>
7994 <li>
7996 Add support for <em>unset -nocomplain</em>
7997 </p>
7998 </li>
7999 <li>
8001 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8002 </p>
8003 </li>
8004 <li>
8006 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8007 </p>
8008 </li>
8009 <li>
8011 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8012 </p>
8013 </li>
8014 <li>
8016 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8017 </p>
8018 </li>
8019 <li>
8021 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8022 </p>
8023 </li>
8024 <li>
8026 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8027 </p>
8028 </li>
8029 <li>
8031 Add <em>file copy</em>
8032 </p>
8033 </li>
8034 <li>
8036 Add <em>try &#8230; finally</em> command
8037 </p>
8038 </li>
8039 </ol></div>
8040 </div>
8041 </div>
8042 </div>
8043 <div class="sect1">
8044 <h2 id="_licence">LICENCE</h2>
8045 <div class="sectionbody">
8046 <div class="literalblock">
8047 <div class="content">
8048 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8049 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8050 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8051 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8052 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8053 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8054 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8055 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8056 </div></div>
8057 <div class="literalblock">
8058 <div class="content">
8059 <pre><code>Redistribution and use in source and binary forms, with or without
8060 modification, are permitted provided that the following conditions
8061 are met:
8062 1. Redistributions of source code must retain the above copyright
8063 notice, this list of conditions and the following disclaimer.
8064 2. Redistributions in binary form must reproduce the above
8065 copyright notice, this list of conditions and the following
8066 disclaimer in the documentation and/or other materials
8067 provided with the distribution.</code></pre>
8068 </div></div>
8069 <div class="literalblock">
8070 <div class="content">
8071 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8072 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8073 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8074 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8075 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8076 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8077 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8078 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8079 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8080 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8081 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8082 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8083 </div></div>
8084 <div class="literalblock">
8085 <div class="content">
8086 <pre><code>The views and conclusions contained in the software and documentation
8087 are those of the authors and should not be interpreted as representing
8088 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8089 </div></div>
8090 </div>
8091 </div>
8092 </div>
8093 <div id="footnotes"><hr /></div>
8094 <div id="footer">
8095 <div id="footer-text">
8096 Last updated 2013-07-22 11:07:02 EST
8097 </div>
8098 </div>
8099 </body>
8100 </html>