Update autosetup to latest version
[jimtcl.git] / Tcl_shipped.html
blob71bbbf5eb21da7e8344984f987ca9af513518763
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.9" />
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;
97 pre {
98 white-space: pre-wrap;
101 #author {
102 color: #527bbd;
103 font-weight: bold;
104 font-size: 1.1em;
106 #email {
108 #revnumber, #revdate, #revremark {
111 #footer {
112 font-size: small;
113 border-top: 2px solid silver;
114 padding-top: 0.5em;
115 margin-top: 4.0em;
117 #footer-text {
118 float: left;
119 padding-bottom: 0.5em;
121 #footer-badges {
122 float: right;
123 padding-bottom: 0.5em;
126 #preamble {
127 margin-top: 1.5em;
128 margin-bottom: 1.5em;
130 div.imageblock, div.exampleblock, div.verseblock,
131 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
132 div.admonitionblock {
133 margin-top: 1.0em;
134 margin-bottom: 1.5em;
136 div.admonitionblock {
137 margin-top: 2.0em;
138 margin-bottom: 2.0em;
139 margin-right: 10%;
140 color: #606060;
143 div.content { /* Block element content. */
144 padding: 0;
147 /* Block element titles. */
148 div.title, caption.title {
149 color: #527bbd;
150 font-weight: bold;
151 text-align: left;
152 margin-top: 1.0em;
153 margin-bottom: 0.5em;
155 div.title + * {
156 margin-top: 0;
159 td div.title:first-child {
160 margin-top: 0.0em;
162 div.content div.title:first-child {
163 margin-top: 0.0em;
165 div.content + div.title {
166 margin-top: 0.0em;
169 div.sidebarblock > div.content {
170 background: #ffffee;
171 border: 1px solid #dddddd;
172 border-left: 4px solid #f0f0f0;
173 padding: 0.5em;
176 div.listingblock > div.content {
177 border: 1px solid #dddddd;
178 border-left: 5px solid #f0f0f0;
179 background: #f8f8f8;
180 padding: 0.5em;
183 div.quoteblock, div.verseblock {
184 padding-left: 1.0em;
185 margin-left: 1.0em;
186 margin-right: 10%;
187 border-left: 5px solid #f0f0f0;
188 color: #888;
191 div.quoteblock > div.attribution {
192 padding-top: 0.5em;
193 text-align: right;
196 div.verseblock > pre.content {
197 font-family: inherit;
198 font-size: inherit;
200 div.verseblock > div.attribution {
201 padding-top: 0.75em;
202 text-align: left;
204 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
205 div.verseblock + div.attribution {
206 text-align: left;
209 div.admonitionblock .icon {
210 vertical-align: top;
211 font-size: 1.1em;
212 font-weight: bold;
213 text-decoration: underline;
214 color: #527bbd;
215 padding-right: 0.5em;
217 div.admonitionblock td.content {
218 padding-left: 0.5em;
219 border-left: 3px solid #dddddd;
222 div.exampleblock > div.content {
223 border-left: 3px solid #dddddd;
224 padding-left: 0.5em;
227 div.imageblock div.content { padding-left: 0; }
228 span.image img { border-style: none; vertical-align: text-bottom; }
229 a.image:visited { color: white; }
231 dl {
232 margin-top: 0.8em;
233 margin-bottom: 0.8em;
235 dt {
236 margin-top: 0.5em;
237 margin-bottom: 0;
238 font-style: normal;
239 color: navy;
241 dd > *:first-child {
242 margin-top: 0.1em;
245 ul, ol {
246 list-style-position: outside;
248 ol.arabic {
249 list-style-type: decimal;
251 ol.loweralpha {
252 list-style-type: lower-alpha;
254 ol.upperalpha {
255 list-style-type: upper-alpha;
257 ol.lowerroman {
258 list-style-type: lower-roman;
260 ol.upperroman {
261 list-style-type: upper-roman;
264 div.compact ul, div.compact ol,
265 div.compact p, div.compact p,
266 div.compact div, div.compact div {
267 margin-top: 0.1em;
268 margin-bottom: 0.1em;
271 tfoot {
272 font-weight: bold;
274 td > div.verse {
275 white-space: pre;
278 div.hdlist {
279 margin-top: 0.8em;
280 margin-bottom: 0.8em;
282 div.hdlist tr {
283 padding-bottom: 15px;
285 dt.hdlist1.strong, td.hdlist1.strong {
286 font-weight: bold;
288 td.hdlist1 {
289 vertical-align: top;
290 font-style: normal;
291 padding-right: 0.8em;
292 color: navy;
294 td.hdlist2 {
295 vertical-align: top;
297 div.hdlist.compact tr {
298 margin: 0;
299 padding-bottom: 0;
302 .comment {
303 background: yellow;
306 .footnote, .footnoteref {
307 font-size: 0.8em;
310 span.footnote, span.footnoteref {
311 vertical-align: super;
314 #footnotes {
315 margin: 20px 0 20px 0;
316 padding: 7px 0 0 0;
319 #footnotes div.footnote {
320 margin: 0 0 5px 0;
323 #footnotes hr {
324 border: none;
325 border-top: 1px solid silver;
326 height: 1px;
327 text-align: left;
328 margin-left: 0;
329 width: 20%;
330 min-width: 100px;
333 div.colist td {
334 padding-right: 0.5em;
335 padding-bottom: 0.3em;
336 vertical-align: top;
338 div.colist td img {
339 margin-top: 0.3em;
342 @media print {
343 #footer-badges { display: none; }
346 #toc {
347 margin-bottom: 2.5em;
350 #toctitle {
351 color: #527bbd;
352 font-size: 1.1em;
353 font-weight: bold;
354 margin-top: 1.0em;
355 margin-bottom: 0.1em;
358 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
359 margin-top: 0;
360 margin-bottom: 0;
362 div.toclevel2 {
363 margin-left: 2em;
364 font-size: 0.9em;
366 div.toclevel3 {
367 margin-left: 4em;
368 font-size: 0.9em;
370 div.toclevel4 {
371 margin-left: 6em;
372 font-size: 0.9em;
375 span.aqua { color: aqua; }
376 span.black { color: black; }
377 span.blue { color: blue; }
378 span.fuchsia { color: fuchsia; }
379 span.gray { color: gray; }
380 span.green { color: green; }
381 span.lime { color: lime; }
382 span.maroon { color: maroon; }
383 span.navy { color: navy; }
384 span.olive { color: olive; }
385 span.purple { color: purple; }
386 span.red { color: red; }
387 span.silver { color: silver; }
388 span.teal { color: teal; }
389 span.white { color: white; }
390 span.yellow { color: yellow; }
392 span.aqua-background { background: aqua; }
393 span.black-background { background: black; }
394 span.blue-background { background: blue; }
395 span.fuchsia-background { background: fuchsia; }
396 span.gray-background { background: gray; }
397 span.green-background { background: green; }
398 span.lime-background { background: lime; }
399 span.maroon-background { background: maroon; }
400 span.navy-background { background: navy; }
401 span.olive-background { background: olive; }
402 span.purple-background { background: purple; }
403 span.red-background { background: red; }
404 span.silver-background { background: silver; }
405 span.teal-background { background: teal; }
406 span.white-background { background: white; }
407 span.yellow-background { background: yellow; }
409 span.big { font-size: 2em; }
410 span.small { font-size: 0.6em; }
412 span.underline { text-decoration: underline; }
413 span.overline { text-decoration: overline; }
414 span.line-through { text-decoration: line-through; }
416 div.unbreakable { page-break-inside: avoid; }
420 * xhtml11 specific
422 * */
424 div.tableblock {
425 margin-top: 1.0em;
426 margin-bottom: 1.5em;
428 div.tableblock > table {
429 border: 3px solid #527bbd;
431 thead, p.table.header {
432 font-weight: bold;
433 color: #527bbd;
435 p.table {
436 margin-top: 0;
438 /* Because the table frame attribute is overriden by CSS in most browsers. */
439 div.tableblock > table[frame="void"] {
440 border-style: none;
442 div.tableblock > table[frame="hsides"] {
443 border-left-style: none;
444 border-right-style: none;
446 div.tableblock > table[frame="vsides"] {
447 border-top-style: none;
448 border-bottom-style: none;
453 * html5 specific
455 * */
457 table.tableblock {
458 margin-top: 1.0em;
459 margin-bottom: 1.5em;
461 thead, p.tableblock.header {
462 font-weight: bold;
463 color: #527bbd;
465 p.tableblock {
466 margin-top: 0;
468 table.tableblock {
469 border-width: 3px;
470 border-spacing: 0px;
471 border-style: solid;
472 border-color: #527bbd;
473 border-collapse: collapse;
475 th.tableblock, td.tableblock {
476 border-width: 1px;
477 padding: 4px;
478 border-style: solid;
479 border-color: #527bbd;
482 table.tableblock.frame-topbot {
483 border-left-style: hidden;
484 border-right-style: hidden;
486 table.tableblock.frame-sides {
487 border-top-style: hidden;
488 border-bottom-style: hidden;
490 table.tableblock.frame-none {
491 border-style: hidden;
494 th.tableblock.halign-left, td.tableblock.halign-left {
495 text-align: left;
497 th.tableblock.halign-center, td.tableblock.halign-center {
498 text-align: center;
500 th.tableblock.halign-right, td.tableblock.halign-right {
501 text-align: right;
504 th.tableblock.valign-top, td.tableblock.valign-top {
505 vertical-align: top;
507 th.tableblock.valign-middle, td.tableblock.valign-middle {
508 vertical-align: middle;
510 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
511 vertical-align: bottom;
516 * manpage specific
518 * */
520 body.manpage h1 {
521 padding-top: 0.5em;
522 padding-bottom: 0.5em;
523 border-top: 2px solid silver;
524 border-bottom: 2px solid silver;
526 body.manpage h2 {
527 border-style: none;
529 body.manpage div.sectionbody {
530 margin-left: 3em;
533 @media print {
534 body.manpage div#toc { display: none; }
538 </style>
539 <script type="text/javascript">
540 /*<![CDATA[*/
541 var asciidoc = { // Namespace.
543 /////////////////////////////////////////////////////////////////////
544 // Table Of Contents generator
545 /////////////////////////////////////////////////////////////////////
547 /* Author: Mihai Bazon, September 2002
548 * http://students.infoiasi.ro/~mishoo
550 * Table Of Content generator
551 * Version: 0.4
553 * Feel free to use this script under the terms of the GNU General Public
554 * License, as long as you do not remove or alter this notice.
557 /* modified by Troy D. Hanson, September 2006. License: GPL */
558 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
560 // toclevels = 1..4.
561 toc: function (toclevels) {
563 function getText(el) {
564 var text = "";
565 for (var i = el.firstChild; i != null; i = i.nextSibling) {
566 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
567 text += i.data;
568 else if (i.firstChild != null)
569 text += getText(i);
571 return text;
574 function TocEntry(el, text, toclevel) {
575 this.element = el;
576 this.text = text;
577 this.toclevel = toclevel;
580 function tocEntries(el, toclevels) {
581 var result = new Array;
582 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
583 // Function that scans the DOM tree for header elements (the DOM2
584 // nodeIterator API would be a better technique but not supported by all
585 // browsers).
586 var iterate = function (el) {
587 for (var i = el.firstChild; i != null; i = i.nextSibling) {
588 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
589 var mo = re.exec(i.tagName);
590 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
591 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
593 iterate(i);
597 iterate(el);
598 return result;
601 var toc = document.getElementById("toc");
602 if (!toc) {
603 return;
606 // Delete existing TOC entries in case we're reloading the TOC.
607 var tocEntriesToRemove = [];
608 var i;
609 for (i = 0; i < toc.childNodes.length; i++) {
610 var entry = toc.childNodes[i];
611 if (entry.nodeName.toLowerCase() == 'div'
612 && entry.getAttribute("class")
613 && entry.getAttribute("class").match(/^toclevel/))
614 tocEntriesToRemove.push(entry);
616 for (i = 0; i < tocEntriesToRemove.length; i++) {
617 toc.removeChild(tocEntriesToRemove[i]);
620 // Rebuild TOC entries.
621 var entries = tocEntries(document.getElementById("content"), toclevels);
622 for (var i = 0; i < entries.length; ++i) {
623 var entry = entries[i];
624 if (entry.element.id == "")
625 entry.element.id = "_toc_" + i;
626 var a = document.createElement("a");
627 a.href = "#" + entry.element.id;
628 a.appendChild(document.createTextNode(entry.text));
629 var div = document.createElement("div");
630 div.appendChild(a);
631 div.className = "toclevel" + entry.toclevel;
632 toc.appendChild(div);
634 if (entries.length == 0)
635 toc.parentNode.removeChild(toc);
639 /////////////////////////////////////////////////////////////////////
640 // Footnotes generator
641 /////////////////////////////////////////////////////////////////////
643 /* Based on footnote generation code from:
644 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
647 footnotes: function () {
648 // Delete existing footnote entries in case we're reloading the footnodes.
649 var i;
650 var noteholder = document.getElementById("footnotes");
651 if (!noteholder) {
652 return;
654 var entriesToRemove = [];
655 for (i = 0; i < noteholder.childNodes.length; i++) {
656 var entry = noteholder.childNodes[i];
657 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
658 entriesToRemove.push(entry);
660 for (i = 0; i < entriesToRemove.length; i++) {
661 noteholder.removeChild(entriesToRemove[i]);
664 // Rebuild footnote entries.
665 var cont = document.getElementById("content");
666 var spans = cont.getElementsByTagName("span");
667 var refs = {};
668 var n = 0;
669 for (i=0; i<spans.length; i++) {
670 if (spans[i].className == "footnote") {
671 n++;
672 var note = spans[i].getAttribute("data-note");
673 if (!note) {
674 // Use [\s\S] in place of . so multi-line matches work.
675 // Because JavaScript has no s (dotall) regex flag.
676 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
677 spans[i].innerHTML =
678 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
679 "' title='View footnote' class='footnote'>" + n + "</a>]";
680 spans[i].setAttribute("data-note", note);
682 noteholder.innerHTML +=
683 "<div class='footnote' id='_footnote_" + n + "'>" +
684 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
685 n + "</a>. " + note + "</div>";
686 var id =spans[i].getAttribute("id");
687 if (id != null) refs["#"+id] = n;
690 if (n == 0)
691 noteholder.parentNode.removeChild(noteholder);
692 else {
693 // Process footnoterefs.
694 for (i=0; i<spans.length; i++) {
695 if (spans[i].className == "footnoteref") {
696 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
697 href = href.match(/#.*/)[0]; // Because IE return full URL.
698 n = refs[href];
699 spans[i].innerHTML =
700 "[<a href='#_footnote_" + n +
701 "' title='View footnote' class='footnote'>" + n + "</a>]";
707 install: function(toclevels) {
708 var timerId;
710 function reinstall() {
711 asciidoc.footnotes();
712 if (toclevels) {
713 asciidoc.toc(toclevels);
717 function reinstallAndRemoveTimer() {
718 clearInterval(timerId);
719 reinstall();
722 timerId = setInterval(reinstall, 500);
723 if (document.addEventListener)
724 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
725 else
726 window.onload = reinstallAndRemoveTimer;
730 asciidoc.install();
731 /*]]>*/
732 </script>
733 </head>
734 <body class="manpage">
735 <div id="header">
736 <h1>
737 Jim Tcl(n) Manual Page
738 </h1>
739 <h2>NAME</h2>
740 <div class="sectionbody">
741 <p>Jim Tcl v0.76+ -
742 reference manual for the Jim Tcl scripting language
743 </p>
744 </div>
745 </div>
746 <div id="content">
747 <div class="sect1">
748 <h2 id="_synopsis">SYNOPSIS</h2>
749 <div class="sectionbody">
750 <div class="literalblock">
751 <div class="content">
752 <pre><code>cc &lt;source&gt; -ljim</code></pre>
753 </div></div>
754 <div class="paragraph"><p>or</p></div>
755 <div class="literalblock">
756 <div class="content">
757 <pre><code>jimsh [&lt;scriptfile&gt;]
758 jimsh -e '&lt;immediate-script&gt;'
759 jimsh --version</code></pre>
760 </div></div>
761 <div class="ulist"><div class="title">Quick Index</div><ul>
762 <li>
764 <a href="#CommandIndex">Command Reference</a>
765 </p>
766 </li>
767 <li>
769 <a href="#OperatorPrecedence">Operator Precedence</a>
770 </p>
771 </li>
772 <li>
774 <a href="#BuiltinVariables">Builtin Variables</a>
775 </p>
776 </li>
777 <li>
779 <a href="#BackslashSequences">Backslash Sequences</a>
780 </p>
781 </li>
782 </ul></div>
783 </div>
784 </div>
785 <div class="sect1">
786 <h2 id="_introduction">INTRODUCTION</h2>
787 <div class="sectionbody">
788 <div class="paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
789 The core language engine is compatible with Tcl 8.5+, while implementing
790 a significant subset of the Tcl 8.6 command set, plus additional features
791 available only in Jim Tcl.</p></div>
792 <div class="paragraph"><p>Some notable differences with Tcl 8.5/8.6 are:</p></div>
793 <div class="olist arabic"><ol class="arabic">
794 <li>
796 Object-based I/O (aio), but with a Tcl-compatibility layer
797 </p>
798 </li>
799 <li>
801 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
802 </p>
803 </li>
804 <li>
806 Integers are 64bit
807 </p>
808 </li>
809 <li>
811 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
812 </p>
813 </li>
814 <li>
816 Builtin dictionary type (<a href="#_dict"><strong><code>dict</code></strong></a>) with some limitations compared to Tcl 8.6
817 </p>
818 </li>
819 <li>
821 <a href="#_env"><strong><code>env</code></strong></a> command to access environment variables
822 </p>
823 </li>
824 <li>
826 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>
827 </p>
828 </li>
829 <li>
831 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>
832 </p>
833 </li>
834 <li>
836 Support for "static" variables in procedures
837 </p>
838 </li>
839 <li>
841 Threads and coroutines are not supported
842 </p>
843 </li>
844 <li>
846 Command and variable traces are not supported
847 </p>
848 </li>
849 <li>
851 Built-in command line editing
852 </p>
853 </li>
854 <li>
856 Expression shorthand syntax: <code>$(&#8230;)</code>
857 </p>
858 </li>
859 <li>
861 Modular build allows many features to be omitted or built as dynamic, loadable modules
862 </p>
863 </li>
864 <li>
866 Highly suitable for use in an embedded environment
867 </p>
868 </li>
869 <li>
871 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
872 </p>
873 </li>
874 </ol></div>
875 </div>
876 </div>
877 <div class="sect1">
878 <h2 id="_recent_changes">RECENT CHANGES</h2>
879 <div class="sectionbody">
880 <div class="sect2">
881 <h3 id="_changes_between_0_76_and_0_77">Changes between 0.76 and 0.77</h3>
882 <div class="olist arabic"><ol class="arabic">
883 <li>
885 Add support for <a href="#_aio"><strong><code>aio</code></strong></a> <code>sync</code>
886 </p>
887 </li>
888 </ol></div>
889 </div>
890 <div class="sect2">
891 <h3 id="_changes_between_0_75_and_0_76">Changes between 0.75 and 0.76</h3>
892 <div class="olist arabic"><ol class="arabic">
893 <li>
895 Add support for <a href="#_file"><strong><code>file</code></strong></a> <code>link</code>
896 </p>
897 </li>
898 <li>
900 <a href="#_glob"><strong><code>glob</code></strong></a> now supports the <em>--tails</em> option
901 </p>
902 </li>
903 <li>
905 Add support for <a href="#_string"><strong><code>string</code></strong></a> <code>cat</code>
906 </p>
907 </li>
908 <li>
910 Allow <a href="#_info"><strong><code>info</code></strong></a> <code>source</code> to add source info
911 </p>
912 </li>
913 </ol></div>
914 </div>
915 <div class="sect2">
916 <h3 id="_changes_between_0_74_and_0_75">Changes between 0.74 and 0.75</h3>
917 <div class="olist arabic"><ol class="arabic">
918 <li>
920 <a href="#_binary"><strong><code>binary</code></strong></a>, <a href="#cmd_3"><strong><code>pack</code></strong></a> and <a href="#cmd_3"><strong><code>unpack</code></strong></a> now support floating point
921 </p>
922 </li>
923 <li>
925 <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code> <em>-force</em> handles source and target as the same file
926 </p>
927 </li>
928 <li>
930 <a href="#_format"><strong><code>format</code></strong></a> now supports <code>%b</code> for binary conversion
931 </p>
932 </li>
933 <li>
935 <a href="#_lsort"><strong><code>lsort</code></strong></a> now supports <em>-unique</em> and <em>-real</em>
936 </p>
937 </li>
938 <li>
940 Add support for half-close with <a href="#_aio"><strong><code>aio</code></strong></a> <code>close</code> ?r|w?
941 </p>
942 </li>
943 <li>
945 Add <a href="#_socket"><strong><code>socket</code></strong></a> <code>pair</code> for a bidirectional pipe
946 </p>
947 </li>
948 <li>
950 Add <em>--random-hash</em> to randomise hash tables for greater security
951 </p>
952 </li>
953 <li>
955 <a href="#_dict"><strong><code>dict</code></strong></a> now supports <em>for</em>, <em>values</em>, <em>incr</em>, <em>append</em>, <em>lappend</em>, <em>update</em>, <em>info</em> and <em>replace</em>
956 </p>
957 </li>
958 <li>
960 <a href="#_file"><strong><code>file</code></strong></a> <code>stat</code> no longer requires the variable name
961 </p>
962 </li>
963 </ol></div>
964 </div>
965 <div class="sect2">
966 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
967 <div class="olist arabic"><ol class="arabic">
968 <li>
970 Numbers with leading zeros are treated as decimal, not octal
971 </p>
972 </li>
973 <li>
975 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
976 </p>
977 </li>
978 <li>
980 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>
981 </p>
982 </li>
983 <li>
985 <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>
986 </p>
987 </li>
988 <li>
990 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
991 </p>
992 </li>
993 </ol></div>
994 </div>
995 <div class="sect2">
996 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
997 <div class="olist arabic"><ol class="arabic">
998 <li>
1000 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
1001 </p>
1002 </li>
1003 <li>
1005 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
1006 </p>
1007 </li>
1008 <li>
1010 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
1011 </p>
1012 </li>
1013 <li>
1015 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
1016 </p>
1017 </li>
1018 <li>
1020 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
1021 </p>
1022 </li>
1023 <li>
1025 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
1026 </p>
1027 </li>
1028 <li>
1030 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
1031 </p>
1032 </li>
1033 <li>
1035 UTF-8 encoding past the basic multilingual plane (BMP) is supported
1036 </p>
1037 </li>
1038 <li>
1040 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
1041 </p>
1042 </li>
1043 <li>
1045 Add <a href="#_history"><strong><code>history</code></strong></a>
1046 </p>
1047 </li>
1048 <li>
1050 Most extensions are now enabled by default
1051 </p>
1052 </li>
1053 <li>
1055 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
1056 </p>
1057 </li>
1058 <li>
1060 Add <a href="#_apply"><strong><code>apply</code></strong></a>
1061 </p>
1062 </li>
1063 </ol></div>
1064 </div>
1065 <div class="sect2">
1066 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
1067 <div class="olist arabic"><ol class="arabic">
1068 <li>
1070 procs now allow <em>args</em> and optional parameters in any position
1071 </p>
1072 </li>
1073 <li>
1075 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
1076 </p>
1077 </li>
1078 <li>
1080 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
1081 </p>
1082 </li>
1083 <li>
1085 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
1086 </p>
1087 </li>
1088 <li>
1090 New <code>tcl_platform(pathSeparator)</code>
1091 </p>
1092 </li>
1093 <li>
1095 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1096 </p>
1097 </li>
1098 <li>
1100 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1101 </p>
1102 </li>
1103 <li>
1105 <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
1106 </p>
1107 </li>
1108 <li>
1110 Line editing is now supported for the win32 console (mingw32)
1111 </p>
1112 </li>
1113 <li>
1115 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1116 </p>
1117 </li>
1118 </ol></div>
1119 </div>
1120 <div class="sect2">
1121 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1122 <div class="olist arabic"><ol class="arabic">
1123 <li>
1125 Allow <em>args</em> to be renamed in procs
1126 </p>
1127 </li>
1128 <li>
1130 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1131 </p>
1132 </li>
1133 <li>
1135 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1136 </p>
1137 </li>
1138 <li>
1140 Support <code>jimsh --version</code>
1141 </p>
1142 </li>
1143 <li>
1145 Additional variables in <code>tcl_platform()</code>
1146 </p>
1147 </li>
1148 <li>
1150 <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
1151 </p>
1152 </li>
1153 <li>
1155 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1156 </p>
1157 </li>
1158 <li>
1160 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1161 </p>
1162 </li>
1163 <li>
1165 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1166 </p>
1167 </li>
1168 <li>
1170 <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
1171 </p>
1172 </li>
1173 <li>
1175 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1176 </p>
1177 </li>
1178 <li>
1180 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1181 </p>
1182 </li>
1183 </ol></div>
1184 </div>
1185 </div>
1186 </div>
1187 <div class="sect1">
1188 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1189 <div class="sectionbody">
1190 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced
1191 <em><a href="http://www.oxforddictionaries.com/definition/american_english/tickle">tickle</a></em>.
1192 It is actually two things: a language and a library.</p></div>
1193 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1194 issuing commands to interactive programs such as text editors,
1195 debuggers, illustrators, and shells. It has a simple syntax and is also
1196 programmable, so Tcl users can write command procedures to provide more
1197 powerful commands than those in the built-in set.</p></div>
1198 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1199 programs. The Tcl library consists of a parser for the Tcl language,
1200 routines to implement the Tcl built-in commands, and procedures that
1201 allow each application to extend Tcl with additional commands specific
1202 to that application. The application program generates Tcl commands and
1203 passes them to the Tcl parser for execution. Commands may be generated
1204 by reading characters from an input source, or by associating command
1205 strings with elements of the application&#8217;s user interface, such as menu
1206 entries, buttons, or keystrokes.</p></div>
1207 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1208 fields and executes built-in commands directly. For commands implemented
1209 by the application, Tcl calls back to the application to execute the
1210 commands. In many cases commands will invoke recursive invocations of the
1211 Tcl interpreter by passing in additional strings to execute (procedures,
1212 looping commands, and conditional commands all work in this way).</p></div>
1213 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1214 language. First, Tcl provides a standard syntax: once users know Tcl,
1215 they will be able to issue commands easily to any Tcl-based application.
1216 Second, Tcl provides programmability. All a Tcl application needs
1217 to do is to implement a few application-specific low-level commands.
1218 Tcl provides many utility commands plus a general programming interface
1219 for building up complex command procedures. By using Tcl, applications
1220 need not re-implement these features.</p></div>
1221 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1222 applications. Inter-application communication is not built into the
1223 Tcl core described here, but various add-on libraries, such as the Tk
1224 toolkit, allow applications to issue commands to each other. This makes
1225 it possible for applications to work together in much more powerful ways
1226 than was previously possible.</p></div>
1227 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1228 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1229 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1230 the language syntax and the built-in commands that will be available
1231 in any application based on Tcl. The individual library procedures are
1232 described in more detail in separate manual pages, one per procedure.</p></div>
1233 </div>
1234 </div>
1235 <div class="sect1">
1236 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1237 <div class="sectionbody">
1238 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1239 It may be invoked in interactive mode as:</p></div>
1240 <div class="literalblock">
1241 <div class="content">
1242 <pre><code>jimsh</code></pre>
1243 </div></div>
1244 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1245 <div class="literalblock">
1246 <div class="content">
1247 <pre><code>jimsh filename</code></pre>
1248 </div></div>
1249 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1250 <div class="literalblock">
1251 <div class="content">
1252 <pre><code>jimsh -e "script"</code></pre>
1253 </div></div>
1254 <div class="sect2">
1255 <h3 id="_interactive_mode">Interactive Mode</h3>
1256 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1257 those commands and prints the results.</p></div>
1258 <div class="literalblock">
1259 <div class="content">
1260 <pre><code>$ jimsh
1261 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1262 . info version
1263 0.73
1264 . lsort [info commands p*]
1265 package parray pid popen proc puts pwd
1266 . foreach i {a b c} {
1267 {&gt; puts $i
1268 {&gt; }
1272 . bad
1273 invalid command name "bad"
1274 [error] . exit
1275 $</code></pre>
1276 </div></div>
1277 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1278 terminal is detected, Emacs-style line editing commands are available, including:
1279 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1280 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1281 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1282 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1283 if it exists.</p></div>
1284 </div>
1285 </div>
1286 </div>
1287 <div class="sect1">
1288 <h2 id="_interpreters">INTERPRETERS</h2>
1289 <div class="sectionbody">
1290 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1291 An interpreter consists of a set of command bindings, a set of variable
1292 values, and a few other miscellaneous pieces of state. Each Tcl command
1293 is interpreted in the context of a particular interpreter.</p></div>
1294 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1295 simultaneously, each associated with a different widget or portion of
1296 the application. Interpreters are relatively lightweight structures.
1297 They can be created and deleted quickly, so application programmers should
1298 feel free to use multiple interpreters if that simplifies the application.</p></div>
1299 </div>
1300 </div>
1301 <div class="sect1">
1302 <h2 id="_data_types">DATA TYPES</h2>
1303 <div class="sectionbody">
1304 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1305 to commands, all command results, and all variable values are strings.</p></div>
1306 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1307 the arguments and results are passed as strings. Many commands expect
1308 their string arguments to have certain formats, but this interpretation
1309 is up to the individual commands. For example, arguments often contain
1310 Tcl command strings, which may get executed as part of the commands.
1311 The easiest way to understand the Tcl interpreter is to remember that
1312 everything is just an operation on a string. In many cases Tcl constructs
1313 will look similar to more structured constructs from other languages.
1314 However, the Tcl constructs are not structured at all; they are just
1315 strings of characters, and this gives them a different behaviour than
1316 the structures they may look like.</p></div>
1317 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1318 the interpretation, there are three common forms that strings take:
1319 commands, expressions, and lists. The major sections below discuss
1320 these three forms in more detail.</p></div>
1321 </div>
1322 </div>
1323 <div class="sect1">
1324 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1325 <div class="sectionbody">
1326 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1327 and Lisp. However, the interpretation of commands is different
1328 in Tcl than in either of those other two systems.
1329 A Tcl command string consists of one or more commands separated
1330 by newline characters or semi-colons.
1331 Each command consists of a collection of fields separated by
1332 white space (spaces or tabs).
1333 The first field must be the name of a command, and the
1334 additional fields, if any, are arguments that will be passed to
1335 that command. For example, the command:</p></div>
1336 <div class="literalblock">
1337 <div class="content">
1338 <pre><code>set a 22</code></pre>
1339 </div></div>
1340 <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
1341 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1342 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1343 Tcl command, an application-specific command bound in with the library
1344 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1345 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1346 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1347 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1348 for example, will treat its first argument as the name of a variable
1349 and its second argument as a string value to assign to that variable.
1350 For other commands arguments may be interpreted as integers, lists,
1351 file names, or Tcl commands.</p></div>
1352 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1353 However, if the Tcl interpreter cannot locate a command it invokes a
1354 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1355 command.</p></div>
1356 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1357 directories for the desired command and create it as a Tcl procedure if
1358 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1359 of abbreviated commands, but usually only for commands that were typed
1360 interactively.</p></div>
1361 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1362 other forms that will be re-used over time: changes to the command set
1363 may cause abbreviations to become ambiguous, resulting in scripts that
1364 no longer work.</p></div>
1365 </div>
1366 </div>
1367 <div class="sect1">
1368 <h2 id="_comments">COMMENTS</h2>
1369 <div class="sectionbody">
1370 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1371 from the <code>#</code> up through the next newline character is treated as
1372 a comment and ignored. When comments are embedded inside nested
1373 commands (e.g. fields enclosed in braces) they must have properly-matched
1374 braces (this is necessary because when Tcl parses the top-level command
1375 it doesn&#8217;t yet know that the nested field will be used as a command so
1376 it cannot process the nested comment character as a comment).</p></div>
1377 </div>
1378 </div>
1379 <div class="sect1">
1380 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1381 <div class="sectionbody">
1382 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1383 double-quotes may be used to create arguments with embedded space.</p></div>
1384 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1385 terminated by white space (including newlines) or a semi-colon (see below
1386 for information on semi-colons); instead it ends at the next double-quote
1387 character. The double-quotes are not included in the resulting argument.
1388 For example, the command</p></div>
1389 <div class="literalblock">
1390 <div class="content">
1391 <pre><code>set a "This is a single argument"</code></pre>
1392 </div></div>
1393 <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>
1394 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1395 and backslash substitutions still occur, as described below. If the
1396 first character of a command field is not a quote, then quotes receive
1397 no special interpretation in the parsing of that field.</p></div>
1398 </div>
1399 </div>
1400 <div class="sect1">
1401 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1402 <div class="sectionbody">
1403 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1404 to quotes except for two differences. First, they nest; this makes them
1405 easier to use for complicated arguments like nested Tcl command strings.
1406 Second, the substitutions described below for commands, variables, and
1407 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1408 can be used to prevent substitutions where they are undesirable.</p></div>
1409 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1410 at the matching right brace. Tcl will strip off the outermost layer
1411 of braces and pass the information between the braces to the command
1412 without any further modification. For example, in the command</p></div>
1413 <div class="literalblock">
1414 <div class="content">
1415 <pre><code>set a {xyz a {b c d}}</code></pre>
1416 </div></div>
1417 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1418 and <em>xyz a {b c d}</em>.</p></div>
1419 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1420 not be on the same line as the starting quote or brace; in this case
1421 the newline will be included in the argument field along with any other
1422 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1423 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1424 the Tcl interpreter to execute the command string. The command</p></div>
1425 <div class="literalblock">
1426 <div class="content">
1427 <pre><code>eval {
1428 set a 22
1429 set b 33
1430 }</code></pre>
1431 </div></div>
1432 <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>
1433 <div class="paragraph"><p>If the first character of a command field is not a left
1434 brace, then neither left nor right
1435 braces in the field will be treated specially (except as part of
1436 variable substitution; see below).</p></div>
1437 </div>
1438 </div>
1439 <div class="sect1">
1440 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1441 <div class="sectionbody">
1442 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1443 substitution occurs (except for fields enclosed in braces). All of the
1444 text up to the matching close bracket is treated as a Tcl command and
1445 executed immediately. Then the result of that command is substituted
1446 for the bracketed text. For example, consider the command</p></div>
1447 <div class="literalblock">
1448 <div class="content">
1449 <pre><code>set a [set b]</code></pre>
1450 </div></div>
1451 <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
1452 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1453 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1454 to the command</p></div>
1455 <div class="literalblock">
1456 <div class="content">
1457 <pre><code>set a foo</code></pre>
1458 </div></div>
1459 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1460 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1461 then the command</p></div>
1462 <div class="literalblock">
1463 <div class="content">
1464 <pre><code>set a xyz[set b].[set c]</code></pre>
1465 </div></div>
1466 <div class="paragraph"><p>is equivalent to the command</p></div>
1467 <div class="literalblock">
1468 <div class="content">
1469 <pre><code>set a xyzfoo.gorp</code></pre>
1470 </div></div>
1471 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1472 or semi-colons in the usual fashion. In this case the value of the last
1473 command is used for substitution. For example, the command</p></div>
1474 <div class="literalblock">
1475 <div class="content">
1476 <pre><code>set a x[set b 22
1477 expr $b+2]x</code></pre>
1478 </div></div>
1479 <div class="paragraph"><p>is equivalent to the command</p></div>
1480 <div class="literalblock">
1481 <div class="content">
1482 <pre><code>set a x24x</code></pre>
1483 </div></div>
1484 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1485 between them are not interpreted specially; they are passed through to
1486 the argument verbatim.</p></div>
1487 </div>
1488 </div>
1489 <div class="sect1">
1490 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1491 <div class="sectionbody">
1492 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1493 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1494 enclosed in braces then variable substitution will occur. The characters
1495 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1496 or underscore, are taken as a variable name and the string value of that
1497 variable is substituted for the name.</p></div>
1498 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1499 <div class="literalblock">
1500 <div class="content">
1501 <pre><code>set a $foo.c</code></pre>
1502 </div></div>
1503 <div class="paragraph"><p>is equivalent to the command</p></div>
1504 <div class="literalblock">
1505 <div class="content">
1506 <pre><code>set a test.c</code></pre>
1507 </div></div>
1508 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1509 character after the name of the variable is an open parenthesis, then
1510 the variable is assumed to be an array name, and all of the characters
1511 between the open parenthesis and the next close parenthesis are taken as
1512 an index into the array. Command substitutions and variable substitutions
1513 are performed on the information between the parentheses before it is
1514 used as an index.</p></div>
1515 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1516 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1517 then the command</p></div>
1518 <div class="literalblock">
1519 <div class="content">
1520 <pre><code>set a xyz$x(first)zyx</code></pre>
1521 </div></div>
1522 <div class="paragraph"><p>is equivalent to the command</p></div>
1523 <div class="literalblock">
1524 <div class="content">
1525 <pre><code>set a xyz87zyx</code></pre>
1526 </div></div>
1527 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1528 <div class="literalblock">
1529 <div class="content">
1530 <pre><code>set a xyz$x($index)zyx</code></pre>
1531 </div></div>
1532 <div class="paragraph"><p>is equivalent to the command</p></div>
1533 <div class="literalblock">
1534 <div class="content">
1535 <pre><code>set a xyzmorezyx</code></pre>
1536 </div></div>
1537 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1538 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1539 followed by an open curly brace. In this case the variable name consists
1540 of all the characters up to the next curly brace.</p></div>
1541 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1542 is assumed to refer to a scalar variable. For example, if variable
1543 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1544 <div class="literalblock">
1545 <div class="content">
1546 <pre><code>set a abc${foo}bar</code></pre>
1547 </div></div>
1548 <div class="paragraph"><p>is equivalent to the command</p></div>
1549 <div class="literalblock">
1550 <div class="content">
1551 <pre><code>set a abctestbar</code></pre>
1552 </div></div>
1553 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1554 braces: the dollar sign and variable name are passed through to the
1555 argument verbatim.</p></div>
1556 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1557 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1558 to reduce typing.</p></div>
1559 </div>
1560 </div>
1561 <div class="sect1">
1562 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1563 <div class="sectionbody">
1564 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1565 newline character). However, semi-colon (<code>;</code>) is treated as a command
1566 separator character; multiple commands may be placed on one line by
1567 separating them with a semi-colon. Semi-colons are not treated as
1568 command separators if they appear within curly braces or double-quotes.</p></div>
1569 </div>
1570 </div>
1571 <div class="sect1">
1572 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1573 <div class="sectionbody">
1574 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1575 fields and also to insert special characters like braces and brackets
1576 into fields without them being interpreted specially as described above.</p></div>
1577 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1578 listed below. In each case, the backslash
1579 sequence is replaced by the given character:</p></div>
1580 <div class="dlist" id="BackslashSequences"><dl>
1581 <dt class="hdlist1">
1582 <code>\b</code>
1583 </dt>
1584 <dd>
1586 Backspace (0x8)
1587 </p>
1588 </dd>
1589 <dt class="hdlist1">
1590 <code>\f</code>
1591 </dt>
1592 <dd>
1594 Form feed (0xc)
1595 </p>
1596 </dd>
1597 <dt class="hdlist1">
1598 <code>\n</code>
1599 </dt>
1600 <dd>
1602 Newline (0xa)
1603 </p>
1604 </dd>
1605 <dt class="hdlist1">
1606 <code>\r</code>
1607 </dt>
1608 <dd>
1610 Carriage-return (0xd).
1611 </p>
1612 </dd>
1613 <dt class="hdlist1">
1614 <code>\t</code>
1615 </dt>
1616 <dd>
1618 Tab (0x9).
1619 </p>
1620 </dd>
1621 <dt class="hdlist1">
1622 <code>\v</code>
1623 </dt>
1624 <dd>
1626 Vertical tab (0xb).
1627 </p>
1628 </dd>
1629 <dt class="hdlist1">
1630 <code>\{</code>
1631 </dt>
1632 <dd>
1634 Left brace ({).
1635 </p>
1636 </dd>
1637 <dt class="hdlist1">
1638 <code>\}</code>
1639 </dt>
1640 <dd>
1642 Right brace (}).
1643 </p>
1644 </dd>
1645 <dt class="hdlist1">
1646 <code>\[</code>
1647 </dt>
1648 <dd>
1650 Open bracket ([).
1651 </p>
1652 </dd>
1653 <dt class="hdlist1">
1654 <code>\]</code>
1655 </dt>
1656 <dd>
1658 Close bracket (]).
1659 </p>
1660 </dd>
1661 <dt class="hdlist1">
1662 <code>\$</code>
1663 </dt>
1664 <dd>
1666 Dollar sign ($).
1667 </p>
1668 </dd>
1669 <dt class="hdlist1">
1670 <code>\&lt;space&gt;</code>
1671 </dt>
1672 <dd>
1674 Space ( ): doesn&#8217;t terminate argument.
1675 </p>
1676 </dd>
1677 <dt class="hdlist1">
1678 <code>\;</code>
1679 </dt>
1680 <dd>
1682 Semi-colon: doesn&#8217;t terminate command.
1683 </p>
1684 </dd>
1685 <dt class="hdlist1">
1686 <code>\"</code>
1687 </dt>
1688 <dd>
1690 Double-quote.
1691 </p>
1692 </dd>
1693 <dt class="hdlist1">
1694 <code>\&lt;newline&gt;</code>
1695 </dt>
1696 <dd>
1698 Nothing: this joins two lines together
1699 into a single line. This backslash feature is unique in that
1700 it will be applied even when the sequence occurs within braces.
1701 </p>
1702 </dd>
1703 <dt class="hdlist1">
1704 <code>\\</code>
1705 </dt>
1706 <dd>
1708 Backslash (<em>\</em>).
1709 </p>
1710 </dd>
1711 <dt class="hdlist1">
1712 <code>\ddd</code>
1713 </dt>
1714 <dd>
1716 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1717 the character. Note that Jim supports null characters in strings.
1718 </p>
1719 </dd>
1720 <dt class="hdlist1">
1721 <code>\unnnn</code>
1722 </dt>
1723 <dt class="hdlist1">
1724 <code>\u{nnn}</code>
1725 </dt>
1726 <dt class="hdlist1">
1727 <code>\Unnnnnnnn</code>
1728 </dt>
1729 <dd>
1731 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1732 The <em>u</em> form allows for one to four hex digits.
1733 The <em>U</em> form allows for one to eight hex digits.
1734 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1735 characters UTF-8 characters which are followed by a hex digit.
1736 </p>
1737 </dd>
1738 </dl></div>
1739 <div class="paragraph"><p>For example, in the command</p></div>
1740 <div class="literalblock">
1741 <div class="content">
1742 <pre><code>set a \{x\[\ yz\141</code></pre>
1743 </div></div>
1744 <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>
1745 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1746 described above, then the backslash is transmitted to the argument
1747 field without any special processing, and the Tcl scanner continues
1748 normal processing with the next character. For example, in the
1749 command</p></div>
1750 <div class="literalblock">
1751 <div class="content">
1752 <pre><code>set \*a \\\{foo</code></pre>
1753 </div></div>
1754 <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
1755 argument will be <code>\{foo</code>.</p></div>
1756 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1757 the argument are parsed but no substitution occurs (except for
1758 backslash-newline): the backslash
1759 sequence is passed through to the argument as is, without making
1760 any special interpretation of the characters in the backslash sequence.
1761 In particular, backslashed braces are not counted in locating the
1762 matching right brace that terminates the argument.
1763 For example, in the
1764 command</p></div>
1765 <div class="literalblock">
1766 <div class="content">
1767 <pre><code>set a {\{abc}</code></pre>
1768 </div></div>
1769 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1770 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1771 any argument structure; it only covers the
1772 most common cases. To produce particularly complicated arguments
1773 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1774 command substitution.</p></div>
1775 </div>
1776 </div>
1777 <div class="sect1">
1778 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1779 <div class="sectionbody">
1780 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1781 specify a position in the string relative to the start or end of the string/list.</p></div>
1782 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1783 <div class="dlist"><dl>
1784 <dt class="hdlist1">
1785 <code>integer</code>
1786 </dt>
1787 <dd>
1789 A simple integer, where <em>0</em> refers to the first element of the string
1790 or list.
1791 </p>
1792 </dd>
1793 <dt class="hdlist1">
1794 <code>integer+integer</code> or
1795 </dt>
1796 <dt class="hdlist1">
1797 <code>integer-integer</code>
1798 </dt>
1799 <dd>
1801 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1802 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1803 <code>[expr {$i+1}]</code>
1804 </p>
1805 </dd>
1806 <dt class="hdlist1">
1807 <code>end</code>
1808 </dt>
1809 <dd>
1811 The last element of the string or list.
1812 </p>
1813 </dd>
1814 <dt class="hdlist1">
1815 <code>end-integer</code>
1816 </dt>
1817 <dd>
1819 The <em>nth-from-last</em> element of the string or list.
1820 </p>
1821 </dd>
1822 </dl></div>
1823 </div>
1824 </div>
1825 <div class="sect1">
1826 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1827 <div class="sectionbody">
1828 <div class="olist arabic"><ol class="arabic">
1829 <li>
1831 A command is just a string.
1832 </p>
1833 </li>
1834 <li>
1836 Within a string commands are separated by newlines or semi-colons
1837 (unless the newline or semi-colon is within braces or brackets
1838 or is backslashed).
1839 </p>
1840 </li>
1841 <li>
1843 A command consists of fields. The first field is the name of the command.
1844 The other fields are strings that are passed to that command as arguments.
1845 </p>
1846 </li>
1847 <li>
1849 Fields are normally separated by white space.
1850 </p>
1851 </li>
1852 <li>
1854 Double-quotes allow white space and semi-colons to appear within
1855 a single argument.
1856 Command substitution, variable substitution, and backslash substitution
1857 still occur inside quotes.
1858 </p>
1859 </li>
1860 <li>
1862 Braces defer interpretation of special characters.
1863 If a field begins with a left brace, then it consists of everything
1864 between the left brace and the matching right brace. The
1865 braces themselves are not included in the argument.
1866 No further processing is done on the information between the braces
1867 except that backslash-newline sequences are eliminated.
1868 </p>
1869 </li>
1870 <li>
1872 If a field doesn&#8217;t begin with a brace then backslash,
1873 variable, and command substitution are done on the field. Only a
1874 single level of processing is done: the results of one substitution
1875 are not scanned again for further substitutions or any other
1876 special treatment. Substitution can
1877 occur on any field of a command, including the command name
1878 as well as the arguments.
1879 </p>
1880 </li>
1881 <li>
1883 If the first non-blank character of a command is a <code>#</code>, everything
1884 from the <code>#</code> up through the next newline is treated as a comment
1885 and ignored.
1886 </p>
1887 </li>
1888 </ol></div>
1889 </div>
1890 </div>
1891 <div class="sect1">
1892 <h2 id="_expressions">EXPRESSIONS</h2>
1893 <div class="sectionbody">
1894 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1895 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
1896 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
1897 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1898 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1899 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1900 the operators permitted in C expressions, and they have the
1901 same meaning and precedence as the corresponding C operators.
1902 Expressions almost always yield numeric results
1903 (integer or floating-point values).
1904 For example, the expression</p></div>
1905 <div class="literalblock">
1906 <div class="content">
1907 <pre><code>8.2 + 6</code></pre>
1908 </div></div>
1909 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1910 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1911 operands are specified, and in that Tcl expressions support
1912 non-numeric operands and string comparisons.</p></div>
1913 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1914 and parentheses.</p></div>
1915 <div class="paragraph"><p>White space may be used between the operands and operators and
1916 parentheses; it is ignored by the expression processor.
1917 Where possible, operands are interpreted as integer values.</p></div>
1918 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
1919 hexadecimal (if the first two characters of the operand are <em>0x</em>).
1920 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
1921 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1922 above, then it is treated as a floating-point number if that is
1923 possible. Floating-point numbers may be specified in any of the
1924 ways accepted by an ANSI-compliant C compiler (except that the
1925 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1926 most installations). For example, all of the
1927 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1928 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1929 as a string (and only a limited set of operators may be applied to
1930 it).</p></div>
1931 <div class="olist arabic"><ol class="arabic">
1932 <li>
1934 Operands may be specified in any of the following ways:
1935 </p>
1936 </li>
1937 <li>
1939 As a numeric value, either integer or floating-point.
1940 </p>
1941 </li>
1942 <li>
1944 As a Tcl variable, using standard <em>$</em> notation.
1945 The variable&#8217;s value will be used as the operand.
1946 </p>
1947 </li>
1948 <li>
1950 As a string enclosed in double-quotes.
1951 The expression parser will perform backslash, variable, and
1952 command substitutions on the information between the quotes,
1953 and use the resulting value as the operand
1954 </p>
1955 </li>
1956 <li>
1958 As a string enclosed in braces.
1959 The characters between the open brace and matching close brace
1960 will be used as the operand without any substitutions.
1961 </p>
1962 </li>
1963 <li>
1965 As a Tcl command enclosed in brackets.
1966 The command will be executed and its result will be used as
1967 the operand.
1968 </p>
1969 </li>
1970 </ol></div>
1971 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1972 are performed by the expression processor.
1973 However, an additional layer of substitution may already have
1974 been performed by the command parser before the expression
1975 processor was called.</p></div>
1976 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1977 in braces to prevent the command parser from performing substitutions
1978 on the contents.</p></div>
1979 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1980 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1981 on the left side of each of the lines below will evaluate to the value
1982 on the right side of the line:</p></div>
1983 <div class="literalblock">
1984 <div class="content">
1985 <pre><code>$a + 3.1 6.1
1986 2 + "$a.$b" 5.6
1987 4*[llength "6 2"] 8
1988 {word one} &lt; "word $a" 0</code></pre>
1989 </div></div>
1990 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1991 of precedence:</p></div>
1992 <div class="dlist" id="OperatorPrecedence"><dl>
1993 <dt class="hdlist1">
1994 <code>int() double() round() abs(), rand(), srand()</code>
1995 </dt>
1996 <dd>
1998 Unary functions (except rand() which takes no arguments)
1999 </p>
2000 <div class="ulist"><ul>
2001 <li>
2003 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
2004 </p>
2005 </li>
2006 <li>
2008 <code><em>double()</em></code> converts the numeric argument to floating point.
2009 </p>
2010 </li>
2011 <li>
2013 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
2014 </p>
2015 </li>
2016 <li>
2018 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
2019 </p>
2020 </li>
2021 <li>
2023 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
2024 </p>
2025 </li>
2026 <li>
2028 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2029 </p>
2030 </li>
2031 </ul></div>
2032 </dd>
2033 <dt class="hdlist1">
2034 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
2035 </dt>
2036 <dd>
2038 Unary math functions.
2039 If Jim is compiled with math support, these functions are available.
2040 </p>
2041 </dd>
2042 <dt class="hdlist1">
2043 <code>- + ~ !</code>
2044 </dt>
2045 <dd>
2047 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2048 may be applied to string operands, and bit-wise NOT may be
2049 applied only to integers.
2050 </p>
2051 </dd>
2052 <dt class="hdlist1">
2053 <code>** pow(x,y)</code>
2054 </dt>
2055 <dd>
2057 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2058 integers. Otherwise supports integers only. (Note that the math-function form
2059 has the same highest precedence)
2060 </p>
2061 </dd>
2062 <dt class="hdlist1">
2063 <code>* / %</code>
2064 </dt>
2065 <dd>
2067 Multiply, divide, remainder. None of these operands may be
2068 applied to string operands, and remainder may be applied only
2069 to integers.
2070 </p>
2071 </dd>
2072 <dt class="hdlist1">
2073 <code>+ -</code>
2074 </dt>
2075 <dd>
2077 Add and subtract. Valid for any numeric operands.
2078 </p>
2079 </dd>
2080 <dt class="hdlist1">
2081 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
2082 </dt>
2083 <dd>
2085 Left and right shift, left and right rotate. Valid for integer operands only.
2086 </p>
2087 </dd>
2088 <dt class="hdlist1">
2089 <code>&lt; &gt; &lt;= &gt;=</code>
2090 </dt>
2091 <dd>
2093 Boolean less, greater, less than or equal, and greater than or equal.
2094 Each operator produces 1 if the condition is true, 0 otherwise.
2095 These operators may be applied to strings as well as numeric operands,
2096 in which case string comparison is used.
2097 </p>
2098 </dd>
2099 <dt class="hdlist1">
2100 <code>== !=</code>
2101 </dt>
2102 <dd>
2104 Boolean equal and not equal. Each operator produces a zero/one result.
2105 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2106 if possible, then floating point types, and finally strings will be compared.
2107 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2108 </p>
2109 </dd>
2110 <dt class="hdlist1">
2111 <code>eq ne</code>
2112 </dt>
2113 <dd>
2115 String equal and not equal. Uses the string value directly without
2116 attempting to convert to a number first.
2117 </p>
2118 </dd>
2119 <dt class="hdlist1">
2120 <code>in ni</code>
2121 </dt>
2122 <dd>
2124 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2125 is contained in the right operand (as a list), or 0 otherwise. The result for
2126 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2127 </p>
2128 </dd>
2129 <dt class="hdlist1">
2130 <code>&amp;</code>
2131 </dt>
2132 <dd>
2134 Bit-wise AND. Valid for integer operands only.
2135 </p>
2136 </dd>
2137 <dt class="hdlist1">
2138 <code>|</code>
2139 </dt>
2140 <dd>
2142 Bit-wise OR. Valid for integer operands only.
2143 </p>
2144 </dd>
2145 <dt class="hdlist1">
2146 <code>^</code>
2147 </dt>
2148 <dd>
2150 Bit-wise exclusive OR. Valid for integer operands only.
2151 </p>
2152 </dd>
2153 <dt class="hdlist1">
2154 <code>&amp;&amp;</code>
2155 </dt>
2156 <dd>
2158 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2159 Valid for numeric operands only (integers or floating-point).
2160 </p>
2161 </dd>
2162 <dt class="hdlist1">
2163 <code>||</code>
2164 </dt>
2165 <dd>
2167 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2168 Valid for numeric operands only (integers or floating-point).
2169 </p>
2170 </dd>
2171 <dt class="hdlist1">
2172 <code>x ? y : z</code>
2173 </dt>
2174 <dd>
2176 If-then-else, as in C. If <code><em>x</em></code>
2177 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2178 Otherwise the result is the value of <code><em>z</em></code>.
2179 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
2180 be of any type.
2181 </p>
2182 </dd>
2183 </dl></div>
2184 <div class="paragraph"><p>See the C manual for more details on the results
2185 produced by each operator.
2186 All of the binary operators group left-to-right within the same
2187 precedence level. For example, the expression</p></div>
2188 <div class="literalblock">
2189 <div class="content">
2190 <pre><code>4*2 &lt; 7</code></pre>
2191 </div></div>
2192 <div class="paragraph"><p>evaluates to 0.</p></div>
2193 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2194 in C, which means that operands are not evaluated if they are not
2195 needed to determine the outcome. For example, in</p></div>
2196 <div class="literalblock">
2197 <div class="content">
2198 <pre><code>$v ? [a] : [b]</code></pre>
2199 </div></div>
2200 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2201 depending on the value of <code>$v</code>.</p></div>
2202 <div class="paragraph"><p>All internal computations involving integers are done with the C
2203 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2204 computations involving floating-point are done with the C type
2205 <em>double</em>.</p></div>
2206 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2207 detected and results in a Tcl error.
2208 For conversion to integer from string, detection of overflow depends
2209 on the behaviour of some routines in the local C library, so it should
2210 be regarded as unreliable.
2211 In any case, overflow and underflow are generally not detected
2212 reliably for intermediate results.</p></div>
2213 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2214 and string operands is done automatically as needed.
2215 For arithmetic computations, integers are used until some
2216 floating-point number is introduced, after which floating-point is used.
2217 For example,</p></div>
2218 <div class="literalblock">
2219 <div class="content">
2220 <pre><code>5 / 4</code></pre>
2221 </div></div>
2222 <div class="paragraph"><p>yields the result 1, while</p></div>
2223 <div class="literalblock">
2224 <div class="content">
2225 <pre><code>5 / 4.0
2226 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2227 </div></div>
2228 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2229 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2230 although the expression evaluator tries to do comparisons as integer
2231 or floating-point when it can.
2232 If one of the operands of a comparison is a string and the other
2233 has a numeric value, the numeric operand is converted back to
2234 a string using the C <em>sprintf</em> format specifier
2235 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2236 For example, the expressions</p></div>
2237 <div class="literalblock">
2238 <div class="content">
2239 <pre><code>"0x03" &gt; "2"
2240 "0y" &lt; "0x12"</code></pre>
2241 </div></div>
2242 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2243 comparison, and the second is done using string comparison after
2244 the second operand is converted to the string <em>18</em>.</p></div>
2245 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2246 entering it in a command: otherwise, if the expression contains
2247 any white space then the Tcl interpreter will split it
2248 among several arguments. For example, the command</p></div>
2249 <div class="literalblock">
2250 <div class="content">
2251 <pre><code>expr $a + $b</code></pre>
2252 </div></div>
2253 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2254 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2255 then the Tcl interpreter will perform variable and command substitution
2256 immediately (it will happen in the command parser rather than in
2257 the expression parser). In many cases the expression is being
2258 passed to a command that will evaluate the expression later (or
2259 even many times if, for example, the expression is to be used to
2260 decide when to exit a loop). Usually the desired goal is to re-do
2261 the variable or command substitutions each time the expression is
2262 evaluated, rather than once and for all at the beginning. For example,
2263 the command</p></div>
2264 <div class="literalblock">
2265 <div class="content">
2266 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2267 </div></div>
2268 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2269 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2270 its second argument to the expression evaluator to see whether or not
2271 to continue processing. Unfortunately, in this case the value of <code>i</code>
2272 in the second argument will be substituted once and for all when the
2273 <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>
2274 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2275 which will always evaluate to 1, even though <code>i</code> eventually
2276 becomes greater than 10. In the above case the loop will never
2277 terminate. Instead, the expression should be placed in braces:</p></div>
2278 <div class="literalblock">
2279 <div class="content">
2280 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2281 </div></div>
2282 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2283 to be delayed; it will be re-done each time the expression is
2284 evaluated, which is the desired result.</p></div>
2285 </div>
2286 </div>
2287 <div class="sect1">
2288 <h2 id="_lists">LISTS</h2>
2289 <div class="sectionbody">
2290 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2291 A list is just a string with a list-like structure
2292 consisting of fields separated by white space. For example, the
2293 string</p></div>
2294 <div class="literalblock">
2295 <div class="content">
2296 <pre><code>Al Sue Anne John</code></pre>
2297 </div></div>
2298 <div class="paragraph"><p>is a list with four elements or fields.
2299 Lists have the same basic structure as command strings, except
2300 that a newline character in a list is treated as a field separator
2301 just like space or tab. Conventions for braces and quotes
2302 and backslashes are the same for lists as for commands. For example,
2303 the string</p></div>
2304 <div class="literalblock">
2305 <div class="content">
2306 <pre><code>a b\ c {d e {f g h}}</code></pre>
2307 </div></div>
2308 <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>
2309 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2310 braces and quotes and backslashes are applied as for commands. Thus in
2311 the example above when the third element is extracted from the list,
2312 the result is</p></div>
2313 <div class="literalblock">
2314 <div class="content">
2315 <pre><code>d e {f g h}</code></pre>
2316 </div></div>
2317 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2318 the outermost layer of braces). Command substitution and
2319 variable substitution are never
2320 made on a list (at least, not by the list-processing commands; the
2321 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2322 <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>,
2323 <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
2324 you to build lists, extract elements from them, search them, and perform
2325 other list-related functions.</p></div>
2326 <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>
2327 </div>
2328 </div>
2329 <div class="sect1">
2330 <h2 id="_list_expansion">LIST EXPANSION</h2>
2331 <div class="sectionbody">
2332 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2333 arguments. Support for this feature is also available in Jim.</p></div>
2334 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2335 <div class="literalblock">
2336 <div class="content">
2337 <pre><code>set cmd {ls -l}
2338 exec $cmd</code></pre>
2339 </div></div>
2340 <div class="paragraph"><p>This will attempt to exec a command named "ls -l", which will clearly not
2341 work. Typically eval and concat are required to solve this problem, however
2342 it can be solved much more easily with <code>{*}</code>.</p></div>
2343 <div class="literalblock">
2344 <div class="content">
2345 <pre><code>exec {*}$cmd</code></pre>
2346 </div></div>
2347 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2348 the resulting command.</p></div>
2349 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2350 for backward compatibility with experimental versions of this feature.</p></div>
2351 </div>
2352 </div>
2353 <div class="sect1">
2354 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2355 <div class="sectionbody">
2356 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2357 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
2358 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2359 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2360 POSIX regular expression support, or using the built-in regular expression engine.
2361 The differences between these are described below.</p></div>
2362 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2363 <div class="sect2">
2364 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2365 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2366 this support will be used by default. The type of regular expressions supported are
2367 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2368 See REG_EXTENDED in the documentation.</p></div>
2369 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2370 make for the smallest code size, but some features such as UTF-8
2371 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported, and null characters
2372 in strings are not supported.</p></div>
2373 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2374 </div>
2375 <div class="sect2">
2376 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2377 <div class="paragraph"><p>The Jim built-in regular expression engine may be selected with <code>./configure --with-jim-regexp</code>
2378 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2379 <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
2380 and POSIX are highlighted below.</p></div>
2381 <div class="olist arabic"><ol class="arabic">
2382 <li>
2384 UTF-8 strings and patterns are both supported
2385 </p>
2386 </li>
2387 <li>
2389 Supported character classes: <code>[:alnum:]</code>, <code>[:digit:]</code> and <code>[:space:]</code>
2390 </p>
2391 </li>
2392 <li>
2394 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>
2395 </p>
2396 </li>
2397 <li>
2399 Character classes apply to ASCII characters only
2400 </p>
2401 </li>
2402 <li>
2404 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2405 </p>
2406 </li>
2407 <li>
2409 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2410 </p>
2411 </li>
2412 <li>
2414 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2415 </p>
2416 </li>
2417 <li>
2419 Support for non-capturing parentheses <code>(?:&#8230;)</code>
2420 </p>
2421 </li>
2422 <li>
2424 Jim Tcl considers that both patterns and strings end at a null character (<code>\x00</code>)
2425 </p>
2426 </li>
2427 </ol></div>
2428 </div>
2429 </div>
2430 </div>
2431 <div class="sect1">
2432 <h2 id="_command_results">COMMAND RESULTS</h2>
2433 <div class="sectionbody">
2434 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2435 code indicates whether the command completed successfully or not,
2436 and the string gives additional information. The valid codes are
2437 defined in jim.h, and are:</p></div>
2438 <div class="dlist"><dl>
2439 <dt class="hdlist1">
2440 <code>JIM_OK(0)</code>
2441 </dt>
2442 <dd>
2444 This is the normal return code, and indicates that the command completed
2445 successfully. The string gives the command&#8217;s return value.
2446 </p>
2447 </dd>
2448 <dt class="hdlist1">
2449 <code>JIM_ERR(1)</code>
2450 </dt>
2451 <dd>
2453 Indicates that an error occurred; the string gives a message describing
2454 the error.
2455 </p>
2456 </dd>
2457 <dt class="hdlist1">
2458 <code>JIM_RETURN(2)</code>
2459 </dt>
2460 <dd>
2462 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2463 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2464 should return immediately. The
2465 string gives the return value for the procedure or command.
2466 </p>
2467 </dd>
2468 <dt class="hdlist1">
2469 <code>JIM_BREAK(3)</code>
2470 </dt>
2471 <dd>
2473 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2474 innermost loop should abort immediately. The string should always
2475 be empty.
2476 </p>
2477 </dd>
2478 <dt class="hdlist1">
2479 <code>JIM_CONTINUE(4)</code>
2480 </dt>
2481 <dd>
2483 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2484 innermost loop should go on to the next iteration. The string
2485 should always be empty.
2486 </p>
2487 </dd>
2488 <dt class="hdlist1">
2489 <code>JIM_SIGNAL(5)</code>
2490 </dt>
2491 <dd>
2493 Indicates that a signal was caught while executing a commands.
2494 The string contains the name of the signal caught.
2495 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2496 </p>
2497 </dd>
2498 <dt class="hdlist1">
2499 <code>JIM_EXIT(6)</code>
2500 </dt>
2501 <dd>
2503 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2504 The string contains the exit code.
2505 </p>
2506 </dd>
2507 </dl></div>
2508 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2509 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2510 by a command, then the Tcl interpreter immediately stops processing
2511 commands and returns to its caller. If there are several nested
2512 invocations of the Tcl interpreter in progress, then each nested
2513 command will usually return the error to its caller, until eventually
2514 the error is reported to the top-level application code. The
2515 application will then display the error message for the user.</p></div>
2516 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2517 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2518 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2519 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2520 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2521 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2522 command allows Tcl programs to catch errors and handle them without
2523 aborting command interpretation any further.</p></div>
2524 <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
2525 return codes and names.</p></div>
2526 </div>
2527 </div>
2528 <div class="sect1">
2529 <h2 id="_procedures">PROCEDURES</h2>
2530 <div class="sectionbody">
2531 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2532 procedures. A Tcl procedure can be invoked just like any other Tcl
2533 command (it has a name and it receives one or more arguments).
2534 The only difference is that its body isn&#8217;t a piece of C code linked
2535 into the program; it is a string containing one or more other
2536 Tcl commands.</p></div>
2537 <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>
2538 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2539 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2540 there may have been by that name. Whenever the new command is
2541 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2542 interpreter.</p></div>
2543 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2544 It consists of a list, possibly empty, of the following
2545 argument specifiers:</p></div>
2546 <div class="dlist"><dl>
2547 <dt class="hdlist1">
2548 <code>name</code>
2549 </dt>
2550 <dd>
2552 Required Argument - A simple argument name.
2553 </p>
2554 </dd>
2555 <dt class="hdlist1">
2556 <code>name default</code>
2557 </dt>
2558 <dd>
2560 Optional Argument - A two-element list consisting of the
2561 argument name, followed by the default value, which will
2562 be used if the corresponding argument is not supplied.
2563 </p>
2564 </dd>
2565 <dt class="hdlist1">
2566 <code>&amp;name</code>
2567 </dt>
2568 <dd>
2570 Reference Argument - The caller is expected to pass the name of
2571 an existing variable. An implicit <a href="#_upvar"><strong><code>upvar</code></strong></a> <code>1 'origname' 'name'</code> is done
2572 to make the variable available in the proc scope.
2573 </p>
2574 </dd>
2575 <dt class="hdlist1">
2576 <code><strong>args</strong></code>
2577 </dt>
2578 <dd>
2580 Variable Argument - The special name <code><em>args</em></code>, which is
2581 assigned all remaining arguments (including none) as a list. The
2582 variable argument may only be specified once. Note that
2583 the syntax <code>args newname</code> may be used to retain the special
2584 behaviour of <code><em>args</em></code> with a different local name. In this case,
2585 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2586 </p>
2587 </dd>
2588 </dl></div>
2589 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2590 the formal arguments to the procedure; its value will be the value
2591 of corresponding argument in the invoking command or the argument&#8217;s
2592 default value.</p></div>
2593 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2594 invocation. However, there must be enough actual arguments for all
2595 required arguments, and there must not be any extra actual arguments
2596 (unless the Variable Argument is specified).</p></div>
2597 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2598 order with the following precedence.</p></div>
2599 <div class="olist arabic"><ol class="arabic">
2600 <li>
2602 Required Arguments (including Reference Arguments)
2603 </p>
2604 </li>
2605 <li>
2607 Optional Arguments
2608 </p>
2609 </li>
2610 <li>
2612 Variable Argument
2613 </p>
2614 </li>
2615 </ol></div>
2616 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2617 <div class="literalblock">
2618 <div class="content">
2619 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2620 </div></div>
2621 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2622 The following table shows how various numbers of arguments are assigned.
2623 Values marked as <code>-</code> are assigned the default value.</p></div>
2624 <div class="tableblock">
2625 <table rules="all"
2626 width="40%"
2627 frame="hsides"
2628 cellspacing="0" cellpadding="4">
2629 <col width="16%" />
2630 <col width="16%" />
2631 <col width="16%" />
2632 <col width="16%" />
2633 <col width="16%" />
2634 <col width="16%" />
2635 <thead>
2636 <tr>
2637 <th align="left" valign="top">Number of arguments</th>
2638 <th align="left" valign="top">a</th>
2639 <th align="left" valign="top">args</th>
2640 <th align="left" valign="top">b</th>
2641 <th align="left" valign="top">c</th>
2642 <th align="left" valign="top">d</th>
2643 </tr>
2644 </thead>
2645 <tbody>
2646 <tr>
2647 <td align="left" valign="top"><p class="table">2</p></td>
2648 <td align="left" valign="top"><p class="table">-</p></td>
2649 <td align="left" valign="top"><p class="table">-</p></td>
2650 <td align="left" valign="top"><p class="table">1</p></td>
2651 <td align="left" valign="top"><p class="table">-</p></td>
2652 <td align="left" valign="top"><p class="table">2</p></td>
2653 </tr>
2654 <tr>
2655 <td align="left" valign="top"><p class="table">3</p></td>
2656 <td align="left" valign="top"><p class="table">1</p></td>
2657 <td align="left" valign="top"><p class="table">-</p></td>
2658 <td align="left" valign="top"><p class="table">2</p></td>
2659 <td align="left" valign="top"><p class="table">-</p></td>
2660 <td align="left" valign="top"><p class="table">3</p></td>
2661 </tr>
2662 <tr>
2663 <td align="left" valign="top"><p class="table">4</p></td>
2664 <td align="left" valign="top"><p class="table">1</p></td>
2665 <td align="left" valign="top"><p class="table">-</p></td>
2666 <td align="left" valign="top"><p class="table">2</p></td>
2667 <td align="left" valign="top"><p class="table">3</p></td>
2668 <td align="left" valign="top"><p class="table">4</p></td>
2669 </tr>
2670 <tr>
2671 <td align="left" valign="top"><p class="table">5</p></td>
2672 <td align="left" valign="top"><p class="table">1</p></td>
2673 <td align="left" valign="top"><p class="table">2</p></td>
2674 <td align="left" valign="top"><p class="table">3</p></td>
2675 <td align="left" valign="top"><p class="table">4</p></td>
2676 <td align="left" valign="top"><p class="table">5</p></td>
2677 </tr>
2678 <tr>
2679 <td align="left" valign="top"><p class="table">6</p></td>
2680 <td align="left" valign="top"><p class="table">1</p></td>
2681 <td align="left" valign="top"><p class="table">2,3</p></td>
2682 <td align="left" valign="top"><p class="table">4</p></td>
2683 <td align="left" valign="top"><p class="table">5</p></td>
2684 <td align="left" valign="top"><p class="table">6</p></td>
2685 </tr>
2686 </tbody>
2687 </table>
2688 </div>
2689 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2690 variables, which are created automatically when referenced and deleted
2691 when the procedure returns. One local variable is automatically created
2692 for each of the procedure&#8217;s arguments. Global variables can be
2693 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2694 <div class="sect2">
2695 <h3 id="_new_in_jim">New in Jim</h3>
2696 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2697 These variables scoped to the procedure and initialised at procedure definition.
2698 Either from the static variable definition, or from the enclosing scope.</p></div>
2699 <div class="paragraph"><p>Consider the following example:</p></div>
2700 <div class="literalblock">
2701 <div class="content">
2702 <pre><code>jim&gt; set a 1
2703 jim&gt; proc a {} {a {b 2}} {
2704 set c 1
2705 puts "$a $b $c"
2706 incr a
2707 incr b
2708 incr c
2710 jim&gt; a
2711 1 2 1
2712 jim&gt; a
2713 2 3 1</code></pre>
2714 </div></div>
2715 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2716 the enclosing scope with the value 1. (Note that it is an error if there
2717 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2718 has an initialiser, so it is initialised to 2.</p></div>
2719 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2720 invocations of the procedure.</p></div>
2721 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2722 and what happens when they are invoked. See also NAMESPACES.</p></div>
2723 </div>
2724 </div>
2725 </div>
2726 <div class="sect1">
2727 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2728 <div class="sectionbody">
2729 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2730 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2731 command, or a few other mechanisms.</p></div>
2732 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2733 be created each time a new variable name is used.</p></div>
2734 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2735 A scalar variable has a single value, whereas an array variable
2736 can have any number of elements, each with a name (called
2737 its <em>index</em>) and a value.</p></div>
2738 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2739 Parentheses are used refer to array elements in Tcl commands.
2740 For example, the command</p></div>
2741 <div class="literalblock">
2742 <div class="content">
2743 <pre><code>set x(first) 44</code></pre>
2744 </div></div>
2745 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2746 so that its new value is <em>44</em>.</p></div>
2747 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2748 that contain multiple concatenated values.
2749 For example, the commands</p></div>
2750 <div class="literalblock">
2751 <div class="content">
2752 <pre><code>set a(2,3) 1
2753 set a(3,6) 2</code></pre>
2754 </div></div>
2755 <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>
2756 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2757 variables may be used.</p></div>
2758 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2759 not be a scalar variable with the same name.</p></div>
2760 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2761 name then it is not possible to make array references to the
2762 variable.</p></div>
2763 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2764 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2765 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2766 with arrays, such as querying the names of all the elements of
2767 the array and converting between an array and a list.</p></div>
2768 <div class="paragraph"><p>Variables may be either global or local. If a variable
2769 name is used when a procedure isn&#8217;t being executed, then it
2770 automatically refers to a global variable. Variable names used
2771 within a procedure normally refer to local variables associated with that
2772 invocation of the procedure. Local variables are deleted whenever
2773 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2774 that a name refer to a global variable for the duration of the current
2775 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2776 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2777 <div class="literalblock">
2778 <div class="content">
2779 <pre><code>set a 1
2780 set b 2
2781 proc p {} {
2782 set c 3
2783 global a</code></pre>
2784 </div></div>
2785 <div class="literalblock">
2786 <div class="content">
2787 <pre><code> puts "$a $::b $c"
2789 p</code></pre>
2790 </div></div>
2791 <div class="paragraph"><p>will output:</p></div>
2792 <div class="literalblock">
2793 <div class="content">
2794 <pre><code>1 2 3</code></pre>
2795 </div></div>
2796 </div>
2797 </div>
2798 <div class="sect1">
2799 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2800 <div class="sectionbody">
2801 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2802 number of elements) and an array value. This is similar to the way Tcl
2803 can convert between a string and a list.</p></div>
2804 <div class="paragraph"><p>For example:</p></div>
2805 <div class="literalblock">
2806 <div class="content">
2807 <pre><code>set a {1 one 2 two}
2808 puts $a(2)</code></pre>
2809 </div></div>
2810 <div class="paragraph"><p>will output:</p></div>
2811 <div class="literalblock">
2812 <div class="content">
2813 <pre><code>two</code></pre>
2814 </div></div>
2815 <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
2816 exist or is empty.</p></div>
2817 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2818 a list.</p></div>
2819 <div class="literalblock">
2820 <div class="content">
2821 <pre><code>set a(1) one; set a(2) two
2822 puts $a</code></pre>
2823 </div></div>
2824 <div class="paragraph"><p>will output:</p></div>
2825 <div class="literalblock">
2826 <div class="content">
2827 <pre><code>1 one 2 two</code></pre>
2828 </div></div>
2829 </div>
2830 </div>
2831 <div class="sect1">
2832 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2833 <div class="sectionbody">
2834 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2835 of this command. Dictionaries provide efficient access to key-value
2836 pairs, just like arrays, but dictionaries are pure values. This
2837 means that you can pass them to a procedure just as a list or a
2838 string. Tcl dictionaries are therefore much more like Tcl lists,
2839 except that they represent a mapping from keys to values, rather
2840 than an ordered sequence.</p></div>
2841 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2842 consists of another dictionary. That way you can elegantly build
2843 complicated data structures, such as hierarchical databases. You
2844 can also combine dictionaries with other Tcl data structures. For
2845 instance, you can build a list of dictionaries that themselves
2846 contain lists.</p></div>
2847 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2848 mapping from arbitrary keys to arbitrary values. Each key in the
2849 dictionary maps to a single value. They have a textual format that
2850 is exactly that of any list with an even number of elements, with
2851 each mapping in the dictionary being represented as two items in
2852 the list. When a command takes a dictionary and produces a new
2853 dictionary based on it (either returning it or writing it back into
2854 the variable that the starting dictionary was read from) the new
2855 dictionary will have the same order of keys, modulo any deleted
2856 keys and with new keys added on to the end. When a string is
2857 interpreted as a dictionary and it would otherwise have duplicate
2858 keys, only the last value for a particular key is used; the others
2859 are ignored, meaning that, "apple banana" and "apple carrot apple
2860 banana" are equivalent dictionaries (with different string
2861 representations).</p></div>
2862 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2863 Thus automatic conversion between lists and dictionaries applies
2864 as it does for arrays.</p></div>
2865 <div class="literalblock">
2866 <div class="content">
2867 <pre><code>jim&gt; dict set a 1 one
2868 1 one
2869 jim&gt; dict set a 2 two
2870 1 one 2 two
2871 jim&gt; puts $a
2872 1 one 2 two
2873 jim&gt; puts $a(2)
2875 jim&gt; dict set a 3 T three
2876 1 one 2 two 3 {T three}</code></pre>
2877 </div></div>
2878 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2879 </div>
2880 </div>
2881 <div class="sect1">
2882 <h2 id="_namespaces">NAMESPACES</h2>
2883 <div class="sectionbody">
2884 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
2885 including a number of 3rd party components. While there is less need for namespaces
2886 in Jim Tcl (which does not strive to support large applications), it is convenient to
2887 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
2888 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
2889 purposes. This feature is currently experimental. See README.namespaces for more information
2890 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
2891 </div>
2892 </div>
2893 <div class="sect1">
2894 <h2 id="_garbage_collection_references_lambda_function">GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION</h2>
2895 <div class="sectionbody">
2896 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2897 These are described briefly below.</p></div>
2898 <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>
2899 <div class="sect2">
2900 <h3 id="_references">References</h3>
2901 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2902 where the value may be garbage collected when unreferenced.
2903 Consider the following example:</p></div>
2904 <div class="literalblock">
2905 <div class="content">
2906 <pre><code>jim&gt; set r [ref "One String" test]
2907 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2908 jim&gt; getref $r
2909 One String</code></pre>
2910 </div></div>
2911 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
2912 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2913 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
2914 stored in the reference.</p></div>
2915 <div class="literalblock">
2916 <div class="content">
2917 <pre><code>jim&gt; setref $r "New String"
2918 New String
2919 jim&gt; getref $r
2920 New String</code></pre>
2921 </div></div>
2922 <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
2923 is no longer accessible by any reference, it will eventually be automatically be garbage
2924 collected.</p></div>
2925 </div>
2926 <div class="sect2">
2927 <h3 id="_garbage_collection">Garbage Collection</h3>
2928 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2929 automatically as necessary.</p></div>
2930 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2931 transcend their scope. To support this, case, the Jim system will periodically identify
2932 and discard objects which are no longer accessible by any reference.</p></div>
2933 <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
2934 with a finalizer:</p></div>
2935 <div class="literalblock">
2936 <div class="content">
2937 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2938 jim&gt; set r [ref "One String" test f]
2939 &lt;reference.&lt;test___&gt;.00000000000
2940 jim&gt; collect
2942 jim&gt; set r ""
2943 jim&gt; collect
2944 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2945 1</code></pre>
2946 </div></div>
2947 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2948 contained a reference to the value, the garbage collector discarded
2949 the value (after calling the finalizer).</p></div>
2950 <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>
2951 <div class="literalblock">
2952 <div class="content">
2953 <pre><code>jim&gt; finalize $r
2955 jim&gt; finalize $r newf
2956 newf</code></pre>
2957 </div></div>
2958 </div>
2959 <div class="sect2">
2960 <h3 id="_lambda_function">Lambda Function</h3>
2961 <div class="paragraph"><p>Jim provides a garbage collected <a href="#_lambda"><strong><code>lambda</code></strong></a> function. This is a procedure
2962 which is able to create an anonymous procedure. Consider:</p></div>
2963 <div class="literalblock">
2964 <div class="content">
2965 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2966 jim&gt; $f 1
2968 jim&gt; $f 2
2970 jim&gt; set f ""</code></pre>
2971 </div></div>
2972 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2973 which is incremented by the supplied value and the result returned.</p></div>
2974 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2975 when the garbage collector runs.</p></div>
2976 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2977 <div class="literalblock">
2978 <div class="content">
2979 <pre><code>jim&gt; rename $f ""</code></pre>
2980 </div></div>
2981 </div>
2982 </div>
2983 </div>
2984 <div class="sect1">
2985 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2986 <div class="sectionbody">
2987 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2988 then most string-related commands become UTF-8 aware. These include,
2989 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
2990 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
2991 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2992 characters can take a variable number of bytes. Thus the addition of
2993 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
2994 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
2995 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2996 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>
2997 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
2998 is still available to embed UTF-8 sequences.</p></div>
2999 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
3000 <div class="sect2">
3001 <h3 id="_string_matching">String Matching</h3>
3002 <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
3003 pattern matching rules. These commands support UTF-8. For example:</p></div>
3004 <div class="literalblock">
3005 <div class="content">
3006 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
3007 </div></div>
3008 </div>
3009 <div class="sect2">
3010 <h3 id="_format_and_scan">format and scan</h3>
3011 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
3012 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
3013 <div class="literalblock">
3014 <div class="content">
3015 <pre><code>format %c 0xb5</code></pre>
3016 </div></div>
3017 <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
3018 return a string with three characters, not three bytes.</p></div>
3019 <div class="literalblock">
3020 <div class="content">
3021 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
3022 </div></div>
3023 <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
3024 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
3025 <div class="literalblock">
3026 <div class="content">
3027 <pre><code>scan \u00b5A %c%c a b</code></pre>
3028 </div></div>
3029 <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>
3030 </div>
3031 <div class="sect2">
3032 <h3 id="_string_classes">String Classes</h3>
3033 <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
3034 will return 0, even though the string may be considered to be alphabetic.</p></div>
3035 <div class="literalblock">
3036 <div class="content">
3037 <pre><code>string is alpha \ub5Test</code></pre>
3038 </div></div>
3039 <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>
3040 </div>
3041 <div class="sect2">
3042 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
3043 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3044 and comparison will not increase or decrease the number of characters in a string.
3045 (Although it may change the number of bytes).</p></div>
3046 <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.
3047 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3048 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>
3049 <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>
3050 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
3051 </div>
3052 <div class="sect2">
3053 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
3054 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3055 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3056 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3057 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
3058 the following returns 2.</p></div>
3059 <div class="literalblock">
3060 <div class="content">
3061 <pre><code>string bytelength \xff\xff</code></pre>
3062 </div></div>
3063 </div>
3064 <div class="sect2">
3065 <h3 id="_regular_expressions_2">Regular Expressions</h3>
3066 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3067 selected which supports UTF-8 strings and patterns.</p></div>
3068 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
3069 </div>
3070 </div>
3071 </div>
3072 <div class="sect1">
3073 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
3074 <div class="sectionbody">
3075 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
3076 be available in any application using Tcl. In addition to these
3077 built-in commands, there may be additional commands defined by each
3078 application, plus commands defined as Tcl procedures.</p></div>
3079 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3080 literals that you type verbatim to Tcl.</p></div>
3081 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3082 a range of values that you can type.</p></div>
3083 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
3084 in <code>?question-marks?</code>.</p></div>
3085 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
3086 arguments or groups of arguments may appear, in the same format
3087 as the preceding argument(s).</p></div>
3088 <div class="sect2">
3089 <h3 id="CommandIndex">Command Index</h3>
3090 <div class="tableblock">
3091 <table rules="none"
3092 width="100%"
3093 frame="void"
3094 cellspacing="0" cellpadding="4">
3095 <col width="12%" />
3096 <col width="12%" />
3097 <col width="12%" />
3098 <col width="12%" />
3099 <col width="12%" />
3100 <col width="12%" />
3101 <col width="12%" />
3102 <col width="12%" />
3103 <tbody>
3104 <tr>
3105 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3106 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3107 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3108 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3109 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3110 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3111 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3112 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3113 </tr>
3114 <tr>
3115 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3116 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3117 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3118 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3119 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3120 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3121 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3122 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3123 </tr>
3124 <tr>
3125 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3126 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3127 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3128 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3129 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3130 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3131 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3132 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3133 </tr>
3134 <tr>
3135 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3136 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3137 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3138 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3139 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3140 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3141 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3142 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3143 </tr>
3144 <tr>
3145 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3146 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3147 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3148 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3149 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3150 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3151 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3152 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3153 </tr>
3154 <tr>
3155 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3156 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3157 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3158 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3159 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3160 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3161 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3162 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3163 </tr>
3164 <tr>
3165 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3166 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3167 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3168 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3169 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3170 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3171 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3172 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3173 </tr>
3174 <tr>
3175 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3176 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3177 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3178 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3179 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3180 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3181 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3182 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3183 </tr>
3184 <tr>
3185 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3186 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3187 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3188 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3189 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3190 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3191 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3192 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.wait</code></strong></a></p></td>
3193 </tr>
3194 <tr>
3195 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3196 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3197 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3198 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3199 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3200 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3201 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3202 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3203 </tr>
3204 <tr>
3205 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3206 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3207 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3208 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3209 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3210 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3211 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3212 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3213 </tr>
3214 <tr>
3215 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3216 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3217 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3218 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3219 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3220 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3221 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3222 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3223 </tr>
3224 <tr>
3225 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3226 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3227 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3228 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3229 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3230 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3231 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3232 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3233 </tr>
3234 <tr>
3235 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3236 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3237 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3238 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3239 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3240 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3241 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3242 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3243 </tr>
3244 <tr>
3245 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3246 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3247 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3248 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3249 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3250 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3251 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3252 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3253 </tr>
3254 </tbody>
3255 </table>
3256 </div>
3257 </div>
3258 <div class="sect2">
3259 <h3 id="_alarm">alarm</h3>
3260 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3261 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3262 number of seconds. If the platform supports <em>ualarm(3)</em> then
3263 the argument may be a floating point value. Otherwise it must
3264 be an integer.</p></div>
3265 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3266 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3267 </div>
3268 <div class="sect2">
3269 <h3 id="_alias">alias</h3>
3270 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3271 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3272 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3273 <div class="literalblock">
3274 <div class="content">
3275 <pre><code>alias e info exists
3276 if {[e var]} {
3278 }</code></pre>
3279 </div></div>
3280 <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>
3281 <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>
3282 </div>
3283 <div class="sect2">
3284 <h3 id="_append">append</h3>
3285 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3286 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3287 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3288 it is given a value equal to the concatenation of all the
3289 <code><em>value</em></code> arguments.</p></div>
3290 <div class="paragraph"><p>This command provides an efficient way to build up long
3291 variables incrementally.
3292 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3293 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3294 </div>
3295 <div class="sect2">
3296 <h3 id="_apply">apply</h3>
3297 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3298 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3299 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3300 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3301 or a three element list <code>{args body namespace}</code>. The first element
3302 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>
3303 </div>
3304 <div class="sect2">
3305 <h3 id="_array">array</h3>
3306 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3307 <div class="paragraph"><p>This command performs one of several operations on the
3308 variable given by <code><em>arrayName</em></code>.</p></div>
3309 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3310 as though the array exists but is empty.</p></div>
3311 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3312 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3313 <div class="dlist"><dl>
3314 <dt class="hdlist1">
3315 <code><strong>array exists</strong> <em>arrayName</em></code>
3316 </dt>
3317 <dd>
3319 Returns 1 if arrayName is an array variable, 0 if there is
3320 no variable by that name. This command is essentially
3321 identical to <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>
3322 </p>
3323 </dd>
3324 <dt class="hdlist1">
3325 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3326 </dt>
3327 <dd>
3329 Returns a list containing pairs of elements. The first
3330 element in each pair is the name of an element in arrayName
3331 and the second element of each pair is the value of the
3332 array element. The order of the pairs is undefined. If
3333 pattern is not specified, then all of the elements of the
3334 array are included in the result. If pattern is specified,
3335 then only those elements whose names match pattern (using
3336 the matching rules of string match) are included. If arrayName
3337 isn&#8217;t the name of an array variable, or if the array contains
3338 no elements, then an empty list is returned.
3339 </p>
3340 </dd>
3341 <dt class="hdlist1">
3342 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3343 </dt>
3344 <dd>
3346 Returns a list containing the names of all of the elements
3347 in the array that match pattern. If pattern is omitted then
3348 the command returns all of the element names in the array.
3349 If pattern is specified, then only those elements whose
3350 names match pattern (using the matching rules of string
3351 match) are included. If there are no (matching) elements
3352 in the array, or if arrayName isn&#8217;t the name of an array
3353 variable, then an empty string is returned.
3354 </p>
3355 </dd>
3356 <dt class="hdlist1">
3357 <code><strong>array set</strong> <em>arrayName list</em></code>
3358 </dt>
3359 <dd>
3361 Sets the values of one or more elements in arrayName. list
3362 must have a form like that returned by array get, consisting
3363 of an even number of elements. Each odd-numbered element
3364 in list is treated as an element name within arrayName, and
3365 the following element in list is used as a new value for
3366 that array element. If the variable arrayName does not
3367 already exist and list is empty, arrayName is created with
3368 an empty array value.
3369 </p>
3370 </dd>
3371 <dt class="hdlist1">
3372 <code><strong>array size</strong> <em>arrayName</em></code>
3373 </dt>
3374 <dd>
3376 Returns the number of elements in the array. If arrayName
3377 isn&#8217;t the name of an array then 0 is returned.
3378 </p>
3379 </dd>
3380 <dt class="hdlist1">
3381 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3382 </dt>
3383 <dd>
3385 Unsets all of the elements in the array that match pattern
3386 (using the matching rules of string match). If arrayName
3387 isn&#8217;t the name of an array variable or there are no matching
3388 elements in the array, no error will be raised. If pattern
3389 is omitted and arrayName is an array variable, then the
3390 command unsets the entire array. The command always returns
3391 an empty string.
3392 </p>
3393 </dd>
3394 </dl></div>
3395 </div>
3396 <div class="sect2">
3397 <h3 id="_break">break</h3>
3398 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3399 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3400 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
3401 to signal the innermost containing loop command to return immediately.</p></div>
3402 </div>
3403 <div class="sect2">
3404 <h3 id="_case">case</h3>
3405 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3406 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3407 <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
3408 with Tcl 6.x is desired.</p></div>
3409 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3410 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3411 by passing it recursively to the Tcl interpreter, and return the result
3412 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3413 pattern or list of patterns. Each pattern may contain any of the wild-cards
3414 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3415 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3416 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3417 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3418 an empty string.</p></div>
3419 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3420 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3421 this form is convenient if substitutions are desired on some of the
3422 patterns or commands.</p></div>
3423 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3424 a single argument; the argument must have proper list structure, with
3425 the elements of the list being the patterns and commands.</p></div>
3426 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3427 since the braces around the whole list make it unnecessary to include a
3428 backslash at the end of each line.</p></div>
3429 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3430 no command or variable substitutions are performed on them; this makes
3431 the behaviour of the second form different than the first form in some
3432 cases.</p></div>
3433 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3434 <div class="literalblock">
3435 <div class="content">
3436 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3437 </div></div>
3438 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3439 <div class="literalblock">
3440 <div class="content">
3441 <pre><code>case a in {
3442 {a b} {format 1}
3443 default {format 2}
3444 a* {format 3}
3445 }</code></pre>
3446 </div></div>
3447 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3448 <div class="literalblock">
3449 <div class="content">
3450 <pre><code>case xyz {
3451 {a b}
3452 {format 1}
3453 default
3454 {format 2}
3456 {format 3}
3457 }</code></pre>
3458 </div></div>
3459 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3460 </div>
3461 <div class="sect2">
3462 <h3 id="_catch">catch</h3>
3463 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3464 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3465 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3466 <code>JIM_OK</code> code, regardless of any errors that might occur while
3467 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3468 see below).</p></div>
3469 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3470 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3471 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3472 it will have a non-zero value corresponding to one of the exceptional
3473 return codes (see jim.h for the definitions of code values, or the
3474 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3475 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3476 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3477 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3478 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3479 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3480 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3481 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3482 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3483 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3484 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3485 the value of the key <code>-errorcode</code> will contain the
3486 same value as the global variable $::errorCode, and the value of
3487 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3488 This can be useful to rethrow an error:</p></div>
3489 <div class="literalblock">
3490 <div class="content">
3491 <pre><code>if {[catch {...} msg opts]} {
3492 ...maybe do something with the error...
3493 incr opts(-level)
3494 return {*}$opts $msg
3495 }</code></pre>
3496 </div></div>
3497 <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>.
3498 The set of codes which will be caught may be modified by specifying the one more codes before
3499 <code><em>command</em></code>.</p></div>
3500 <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>
3501 <div class="literalblock">
3502 <div class="content">
3503 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3504 </div></div>
3505 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3506 <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
3507 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3508 </div>
3509 <div class="sect2">
3510 <h3 id="_cd">cd</h3>
3511 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3512 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3513 <div class="paragraph"><p>Returns an empty string.</p></div>
3514 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3515 be removed in some applications.</p></div>
3516 </div>
3517 <div class="sect2">
3518 <h3 id="_clock">clock</h3>
3519 <div class="dlist"><dl>
3520 <dt class="hdlist1">
3521 <code><strong>clock seconds</strong></code>
3522 </dt>
3523 <dd>
3525 Returns the current time as seconds since the epoch.
3526 </p>
3527 </dd>
3528 <dt class="hdlist1">
3529 <code><strong>clock clicks</strong></code>
3530 </dt>
3531 <dd>
3533 Returns the current time in &#8216;clicks&#8217;.
3534 </p>
3535 </dd>
3536 <dt class="hdlist1">
3537 <code><strong>clock microseconds</strong></code>
3538 </dt>
3539 <dd>
3541 Returns the current time in microseconds.
3542 </p>
3543 </dd>
3544 <dt class="hdlist1">
3545 <code><strong>clock milliseconds</strong></code>
3546 </dt>
3547 <dd>
3549 Returns the current time in milliseconds.
3550 </p>
3551 </dd>
3552 <dt class="hdlist1">
3553 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3554 </dt>
3555 <dd>
3557 Format the given time (seconds since the epoch) according to the given
3558 format. See strftime(3) for supported formats.
3559 If no format is supplied, "%c" is used.
3560 </p>
3561 </dd>
3562 <dt class="hdlist1">
3563 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3564 </dt>
3565 <dd>
3567 Scan the given time string using the given format string.
3568 See strptime(3) for supported formats.
3569 </p>
3570 </dd>
3571 </dl></div>
3572 </div>
3573 <div class="sect2">
3574 <h3 id="_close">close</h3>
3575 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3576 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3577 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3578 <code><em>fileId</em></code> must be the return value from a previous invocation
3579 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3580 used anymore.</p></div>
3581 </div>
3582 <div class="sect2">
3583 <h3 id="_collect">collect</h3>
3584 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3585 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3586 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3587 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
3588 </div>
3589 <div class="sect2">
3590 <h3 id="_concat">concat</h3>
3591 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3592 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3593 into a single list. It permits any number of arguments. For example,
3594 the command</p></div>
3595 <div class="literalblock">
3596 <div class="content">
3597 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3598 </div></div>
3599 <div class="paragraph"><p>will return</p></div>
3600 <div class="literalblock">
3601 <div class="content">
3602 <pre><code>a b c d e f {g h}</code></pre>
3603 </div></div>
3604 <div class="paragraph"><p>as its result.</p></div>
3605 </div>
3606 <div class="sect2">
3607 <h3 id="_continue">continue</h3>
3608 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3609 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3610 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
3611 signal the innermost containing loop command to skip the remainder of
3612 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3613 </div>
3614 <div class="sect2">
3615 <h3 id="_curry">curry</h3>
3616 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3617 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3618 a named procedure.</p></div>
3619 <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>
3620 <div class="literalblock">
3621 <div class="content">
3622 <pre><code>set e [local curry info exists]
3623 if {[$e var]} {
3625 }</code></pre>
3626 </div></div>
3627 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3628 <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>
3629 </div>
3630 <div class="sect2">
3631 <h3 id="_dict">dict</h3>
3632 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3633 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3634 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3635 command. The legal <code><em>options</em></code> are:</p></div>
3636 <div class="dlist"><dl>
3637 <dt class="hdlist1">
3638 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3639 </dt>
3640 <dd>
3642 Create and return a new dictionary value that contains each of
3643 the key/value mappings listed as arguments (keys and values
3644 alternating, with each key being followed by its associated
3645 value.)
3646 </p>
3647 </dd>
3648 <dt class="hdlist1">
3649 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3650 </dt>
3651 <dd>
3653 Returns a boolean value indicating whether the given key (or path
3654 of keys through a set of nested dictionaries) exists in the given
3655 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3656 on that path will succeed.
3657 </p>
3658 </dd>
3659 <dt class="hdlist1">
3660 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3661 </dt>
3662 <dd>
3664 Given a dictionary value (first argument) and a key (second argument),
3665 this will retrieve the value for that key. Where several keys are
3666 supplied, the behaviour of the command shall be as if the result
3667 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3668 dict get with the remaining arguments as second (and possibly
3669 subsequent) arguments. This facilitates lookups in nested dictionaries.
3670 If no keys are provided, dict would return a list containing pairs
3671 of elements in a manner similar to array get. That is, the first
3672 element of each pair would be the key and the second element would
3673 be the value for that key. It is an error to attempt to retrieve
3674 a value for a key that is not present in the dictionary.
3675 </p>
3676 </dd>
3677 <dt class="hdlist1">
3678 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3679 </dt>
3680 <dd>
3682 Returns a list of the keys in the dictionary.
3683 If pattern is specified, then only those keys whose
3684 names match <code><em>pattern</em></code> (using the matching rules of string
3685 match) are included.
3686 </p>
3687 </dd>
3688 <dt class="hdlist1">
3689 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3690 </dt>
3691 <dd>
3693 Return a dictionary that contains the contents of each of the
3694 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3695 contain a mapping for the same key, the resulting dictionary
3696 maps that key to the value according to the last dictionary on
3697 the command line containing a mapping for that key.
3698 </p>
3699 </dd>
3700 <dt class="hdlist1">
3701 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3702 </dt>
3703 <dd>
3705 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3706 value and places an updated dictionary value in that variable
3707 containing a mapping from the given key to the given value. When
3708 multiple keys are present, this operation creates or updates a chain
3709 of nested dictionaries.
3710 </p>
3711 </dd>
3712 <dt class="hdlist1">
3713 <code><strong>dict size</strong> <em>dictionary</em></code>
3714 </dt>
3715 <dd>
3717 Return the number of key/value mappings in the given dictionary value.
3718 </p>
3719 </dd>
3720 <dt class="hdlist1">
3721 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3722 </dt>
3723 <dd>
3725 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3726 variable containing a dictionary value and places an updated
3727 dictionary value in that variable that does not contain a mapping
3728 for the given key. Where multiple keys are present, this describes
3729 a path through nested dictionaries to the mapping to remove. At
3730 least one key must be specified, but the last key on the key-path
3731 need not exist. All other components on the path must exist.
3732 </p>
3733 </dd>
3734 <dt class="hdlist1">
3735 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3736 </dt>
3737 <dd>
3739 Execute the Tcl script in <code><em>script</em></code> with the value for each
3740 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3741 name. Where one or more keys are given, these indicate a chain
3742 of nested dictionaries, with the innermost dictionary being the
3743 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3744 unreadable will make the updates to the dictionary be discarded,
3745 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3746 adjusted so that the chain of dictionaries no longer exists.
3747 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3748 the result of the evaluation of body.
3749 </p>
3750 </dd>
3751 <dt class="hdlist1">
3753 </dt>
3754 <dd>
3756 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3757 it is recommended that this command only be used in a local
3758 scope (procedure). Because of this, the variables set by
3759 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3760 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3761 only happen when <code><em>script</em></code> terminates.
3762 </p>
3763 </dd>
3764 </dl></div>
3765 <div class="paragraph"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented&#8230;</p></div>
3766 </div>
3767 <div class="sect2">
3768 <h3 id="_env">env</h3>
3769 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3770 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3771 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3772 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3773 that value is returned instead.</p></div>
3774 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3775 and their values as <code>{name value ...}</code></p></div>
3776 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3777 </div>
3778 <div class="sect2">
3779 <h3 id="_eof">eof</h3>
3780 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3781 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3782 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3783 0 otherwise.</p></div>
3784 <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>,
3785 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3786 standard I/O channels.</p></div>
3787 </div>
3788 <div class="sect2">
3789 <h3 id="_error">error</h3>
3790 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3791 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3792 unwound. <code><em>message</em></code> is a string that is returned to the application
3793 to indicate what went wrong.</p></div>
3794 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3795 it is used to initialize the stacktrace.</p></div>
3796 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3797 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3798 to return a stack trace reflecting the original point of occurrence
3799 of the error:</p></div>
3800 <div class="literalblock">
3801 <div class="content">
3802 <pre><code>catch {...} errMsg
3804 error $errMsg [info stacktrace]</code></pre>
3805 </div></div>
3806 <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>
3807 </div>
3808 <div class="sect2">
3809 <h3 id="_errorinfo">errorInfo</h3>
3810 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3811 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3812 Typical usage is:</p></div>
3813 <div class="literalblock">
3814 <div class="content">
3815 <pre><code>if {[catch {...} error]} {
3816 puts stderr [errorInfo $error [info stacktrace]]
3817 exit 1
3818 }</code></pre>
3819 </div></div>
3820 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3821 </div>
3822 <div class="sect2">
3823 <h3 id="_eval">eval</h3>
3824 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3825 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3826 command (or collection of Tcl commands separated by newlines in the
3827 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3828 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3829 Tcl interpreter recursively, and returns the result of that
3830 evaluation (or any error generated by it).</p></div>
3831 </div>
3832 <div class="sect2">
3833 <h3 id="_exec">exec</h3>
3834 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3835 <div class="paragraph"><p>This command treats its arguments as the specification
3836 of one or more UNIX commands to execute as subprocesses.
3837 The commands take the form of a standard shell pipeline;
3838 <code>|</code> arguments separate commands in the
3839 pipeline and cause standard output of the preceding command
3840 to be piped into standard input of the next command (or <code>|&amp;</code> for
3841 both standard output and standard error).</p></div>
3842 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3843 consists of the standard output produced by the last command
3844 in the pipeline followed by the standard error output.</p></div>
3845 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3846 then this will be included in the result after the standard output
3847 of the last command.</p></div>
3848 <div class="paragraph"><p>Note that unlike Tcl, data written to standard error does not cause
3849 <a href="#_exec"><strong><code>exec</code></strong></a> to return an error.</p></div>
3850 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3851 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error.
3852 If no standard error output was produced, or is redirected,
3853 the error message will include the normal result, as above,
3854 followed by error messages describing the abnormal terminations.</p></div>
3855 <div class="paragraph"><p>If any standard error output was produced, these abnormal termination
3856 messages are suppressed.</p></div>
3857 <div class="paragraph"><p>If the last character of the result or error message
3858 is a newline then that character is deleted from the result
3859 or error message for consistency with normal
3860 Tcl return values.</p></div>
3861 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3862 <div class="dlist"><dl>
3863 <dt class="hdlist1">
3864 <code>&gt;filename</code>
3865 </dt>
3866 <dd>
3868 The standard output of the last command in the pipeline
3869 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3870 will normally return an empty string.
3871 </p>
3872 </dd>
3873 <dt class="hdlist1">
3874 <code>&gt;&gt;filename</code>
3875 </dt>
3876 <dd>
3878 As above, but append to the file.
3879 </p>
3880 </dd>
3881 <dt class="hdlist1">
3882 <code>&gt;@fileId</code>
3883 </dt>
3884 <dd>
3886 The standard output of the last command in the pipeline is
3887 redirected to the given (writable) file descriptor (e.g. stdout,
3888 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>
3889 will normally return an empty string.
3890 </p>
3891 </dd>
3892 <dt class="hdlist1">
3893 <code>2&gt;filename</code>
3894 </dt>
3895 <dd>
3897 The standard error of the last command in the pipeline
3898 is redirected to the file.
3899 </p>
3900 </dd>
3901 <dt class="hdlist1">
3902 <code>2&gt;&gt;filename</code>
3903 </dt>
3904 <dd>
3906 As above, but append to the file.
3907 </p>
3908 </dd>
3909 <dt class="hdlist1">
3910 <code>2&gt;@fileId</code>
3911 </dt>
3912 <dd>
3914 The standard error of the last command in the pipeline is
3915 redirected to the given (writable) file descriptor.
3916 </p>
3917 </dd>
3918 <dt class="hdlist1">
3919 <code>2&gt;@1</code>
3920 </dt>
3921 <dd>
3923 The standard error of the last command in the pipeline is
3924 redirected to the same file descriptor as the standard output.
3925 </p>
3926 </dd>
3927 <dt class="hdlist1">
3928 <code>&gt;&amp;filename</code>
3929 </dt>
3930 <dd>
3932 Both the standard output and standard error of the last command
3933 in the pipeline is redirected to the file.
3934 </p>
3935 </dd>
3936 <dt class="hdlist1">
3937 <code>&gt;&gt;&amp;filename</code>
3938 </dt>
3939 <dd>
3941 As above, but append to the file.
3942 </p>
3943 </dd>
3944 <dt class="hdlist1">
3945 <code>&lt;filename</code>
3946 </dt>
3947 <dd>
3949 The standard input of the first command in the pipeline
3950 is taken from the file.
3951 </p>
3952 </dd>
3953 <dt class="hdlist1">
3954 <code>&lt;&lt;string</code>
3955 </dt>
3956 <dd>
3958 The standard input of the first command is taken as the
3959 given immediate value.
3960 </p>
3961 </dd>
3962 <dt class="hdlist1">
3963 <code>&lt;@fileId</code>
3964 </dt>
3965 <dd>
3967 The standard input of the first command in the pipeline
3968 is taken from the given (readable) file descriptor.
3969 </p>
3970 </dd>
3971 </dl></div>
3972 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3973 or standard output, these are connected to the corresponding
3974 input or output of the application.</p></div>
3975 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
3976 executed in background.
3977 In this case the standard output from the last command
3978 in the pipeline will
3979 go to the application&#8217;s standard output unless
3980 redirected in the command, and error output from all
3981 the commands in the pipeline will go to the application&#8217;s
3982 standard error file. The return value of exec in this case
3983 is a list of process ids (pids) in the pipeline.</p></div>
3984 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
3985 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
3986 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
3987 <div class="paragraph"><p>The first word in each command is taken as the command name;
3988 the directories in the PATH environment variable are searched for
3989 an executable by the given name.</p></div>
3990 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
3991 are performed on the arguments to commands.</p></div>
3992 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3993 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
3994 <div class="dlist"><dl>
3995 <dt class="hdlist1">
3996 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
3997 </dt>
3998 <dd>
4000 This format is used when a child process has been killed
4001 because of a signal. The pid element will be the process&#8217;s
4002 identifier (in decimal). The sigName element will be the
4003 symbolic name of the signal that caused the process to
4004 terminate; it will be one of the names from the include
4005 file signal.h, such as SIGPIPE. The msg element will be a
4006 short human-readable message describing the signal, such
4007 as "write on pipe with no readers" for SIGPIPE.
4008 </p>
4009 </dd>
4010 <dt class="hdlist1">
4011 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
4012 </dt>
4013 <dd>
4015 This format is used when a child process has been suspended
4016 because of a signal. The pid element will be the process&#8217;s
4017 identifier, in decimal. The sigName element will be the
4018 symbolic name of the signal that caused the process to
4019 suspend; this will be one of the names from the include
4020 file signal.h, such as SIGTTIN. The msg element will be a
4021 short human-readable message describing the signal, such
4022 as "background tty read" for SIGTTIN.
4023 </p>
4024 </dd>
4025 <dt class="hdlist1">
4026 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
4027 </dt>
4028 <dd>
4030 This format is used when a child process has exited with a
4031 non-zero exit status. The pid element will be the process&#8217;s
4032 identifier (in decimal) and the code element will be the
4033 exit code returned by the process (also in decimal).
4034 </p>
4035 </dd>
4036 </dl></div>
4037 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
4038 this variable is unset, in which case the original environment is used).</p></div>
4039 </div>
4040 <div class="sect2">
4041 <h3 id="_exists">exists</h3>
4042 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
4043 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
4044 or alias respectively and returns 1 if it exists or 0 if not. This command
4045 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
4046 <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>
4047 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
4048 </div>
4049 <div class="sect2">
4050 <h3 id="_exit">exit</h3>
4051 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
4052 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
4053 parent as the exit status.</p></div>
4054 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
4055 to 0.</p></div>
4056 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
4057 </div>
4058 <div class="sect2">
4059 <h3 id="_expr">expr</h3>
4060 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
4061 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
4062 the result as a string. See the section EXPRESSIONS above.</p></div>
4063 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
4064 The following two are identical.</p></div>
4065 <div class="literalblock">
4066 <div class="content">
4067 <pre><code>set x [expr {3 * 2 + 1}]
4068 set x $(3 * 2 + 1)</code></pre>
4069 </div></div>
4070 </div>
4071 <div class="sect2">
4072 <h3 id="_file">file</h3>
4073 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
4074 <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>
4075 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
4076 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
4077 <div class="dlist"><dl>
4078 <dt class="hdlist1">
4079 <code><strong>file atime</strong> <em>name</em></code>
4080 </dt>
4081 <dd>
4083 Return a decimal string giving the time at which file <code><em>name</em></code>
4084 was last accessed. The time is measured in the standard UNIX
4085 fashion as seconds from a fixed starting time (often January 1, 1970).
4086 If the file doesn&#8217;t exist or its access time cannot be queried then an
4087 error is generated.
4088 </p>
4089 </dd>
4090 <dt class="hdlist1">
4091 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
4092 </dt>
4093 <dd>
4095 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4096 The target file must not exist, unless <code>-force</code> is specified.
4097 </p>
4098 </dd>
4099 <dt class="hdlist1">
4100 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4101 </dt>
4102 <dd>
4104 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
4105 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
4106 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4107 if the file/directory can&#8217;t be deleted. Use <code><em>--</em></code> if there is any possibility of
4108 the first name being <code><em>-force</em></code>.
4109 </p>
4110 </dd>
4111 <dt class="hdlist1">
4112 <code><strong>file dirname</strong> <em>name</em></code>
4113 </dt>
4114 <dd>
4116 Return all of the characters in <code><em>name</em></code> up to but not including
4117 the last slash character. If there are no slashes in <code><em>name</em></code>
4118 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4119 character, then return <code>/</code>.
4120 </p>
4121 </dd>
4122 <dt class="hdlist1">
4123 <code><strong>file executable</strong> <em>name</em></code>
4124 </dt>
4125 <dd>
4127 Return <em>1</em> if file <code><em>name</em></code> is executable by
4128 the current user, <em>0</em> otherwise.
4129 </p>
4130 </dd>
4131 <dt class="hdlist1">
4132 <code><strong>file exists</strong> <em>name</em></code>
4133 </dt>
4134 <dd>
4136 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4137 search privileges for the directories leading to it, <em>0</em> otherwise.
4138 </p>
4139 </dd>
4140 <dt class="hdlist1">
4141 <code><strong>file extension</strong> <em>name</em></code>
4142 </dt>
4143 <dd>
4145 Return all of the characters in <code><em>name</em></code> after and including the
4146 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4147 the empty string.
4148 </p>
4149 </dd>
4150 <dt class="hdlist1">
4151 <code><strong>file isdirectory</strong> <em>name</em></code>
4152 </dt>
4153 <dd>
4155 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4156 <em>0</em> otherwise.
4157 </p>
4158 </dd>
4159 <dt class="hdlist1">
4160 <code><strong>file isfile</strong> <em>name</em></code>
4161 </dt>
4162 <dd>
4164 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4165 <em>0</em> otherwise.
4166 </p>
4167 </dd>
4168 <dt class="hdlist1">
4169 <code><strong>file join</strong> <em>arg...</em></code>
4170 </dt>
4171 <dd>
4173 Joins multiple path components. Note that if any components is
4174 an absolute path, the preceding components are ignored.
4175 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4176 </p>
4177 </dd>
4178 <dt class="hdlist1">
4179 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4180 </dt>
4181 <dd>
4183 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4184 Note that the sense of this command is the opposite of <a href="#_file"><strong><code>file</code></strong></a> <code>rename</code> and <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code>
4185 and also of <code>ln</code>, but this is compatible with Tcl.
4186 An error is returned if <code><em>target</em></code> doesn&#8217;t exist or <code><em>newname</em></code> already exists.
4187 </p>
4188 </dd>
4189 <dt class="hdlist1">
4190 <code><strong>file lstat</strong> <em>name varName</em></code>
4191 </dt>
4192 <dd>
4194 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4195 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4196 refers to a symbolic link the information returned in <code><em>varName</em></code>
4197 is for the link rather than the file it refers to. On systems that
4198 don&#8217;t support symbolic links this option behaves exactly the same
4199 as the <em>stat</em> option.
4200 </p>
4201 </dd>
4202 <dt class="hdlist1">
4203 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4204 </dt>
4205 <dd>
4207 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4208 this command will create all non-existing parent directories
4209 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4210 then no action is taken and no error is returned. Trying to
4211 overwrite an existing file with a directory will result in an
4212 error. Arguments are processed in the order specified, halting
4213 at the first error, if any.
4214 </p>
4215 </dd>
4216 <dt class="hdlist1">
4217 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4218 </dt>
4219 <dd>
4221 Return a decimal string giving the time at which file <code><em>name</em></code>
4222 was last modified. The time is measured in the standard UNIX
4223 fashion as seconds from a fixed starting time (often January 1, 1970).
4224 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4225 error is generated. If <code><em>time</em></code> is given, sets the modification time
4226 of the file to the given value.
4227 </p>
4228 </dd>
4229 <dt class="hdlist1">
4230 <code><strong>file normalize</strong> <em>name</em></code>
4231 </dt>
4232 <dd>
4234 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4235 </p>
4236 </dd>
4237 <dt class="hdlist1">
4238 <code><strong>file owned</strong> <em>name</em></code>
4239 </dt>
4240 <dd>
4242 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4243 <em>0</em> otherwise.
4244 </p>
4245 </dd>
4246 <dt class="hdlist1">
4247 <code><strong>file readable</strong> <em>name</em></code>
4248 </dt>
4249 <dd>
4251 Return <em>1</em> if file <code><em>name</em></code> is readable by
4252 the current user, <em>0</em> otherwise.
4253 </p>
4254 </dd>
4255 <dt class="hdlist1">
4256 <code><strong>file readlink</strong> <em>name</em></code>
4257 </dt>
4258 <dd>
4260 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4261 name of the file it points to). If
4262 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4263 an error is returned. On systems that don&#8217;t support symbolic links
4264 this option is undefined.
4265 </p>
4266 </dd>
4267 <dt class="hdlist1">
4268 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4269 </dt>
4270 <dd>
4272 Renames the file from the old name to the new name.
4273 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4274 specified.
4275 </p>
4276 </dd>
4277 <dt class="hdlist1">
4278 <code><strong>file rootname</strong> <em>name</em></code>
4279 </dt>
4280 <dd>
4282 Return all of the characters in <code><em>name</em></code> up to but not including
4283 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4284 a dot, then return <code><em>name</em></code>.
4285 </p>
4286 </dd>
4287 <dt class="hdlist1">
4288 <code><strong>file size</strong> <em>name</em></code>
4289 </dt>
4290 <dd>
4292 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4293 If the file doesn&#8217;t exist or its size cannot be queried then an
4294 error is generated.
4295 </p>
4296 </dd>
4297 <dt class="hdlist1">
4298 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4299 </dt>
4300 <dd>
4302 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4303 as a dictionary with the following keys: <em>atime</em>,
4304 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4305 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4306 Each element except <em>type</em> is a decimal string with the value of
4307 the corresponding field from the <em>stat</em> return structure; see the
4308 manual entry for <em>stat</em> for details on the meanings of the values.
4309 The <em>type</em> element gives the type of the file in the same form
4310 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4311 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4312 variable and the values are also stored into the array.
4313 </p>
4314 </dd>
4315 <dt class="hdlist1">
4316 <code><strong>file tail</strong> <em>name</em></code>
4317 </dt>
4318 <dd>
4320 Return all of the characters in <code><em>name</em></code> after the last slash.
4321 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4322 </p>
4323 </dd>
4324 <dt class="hdlist1">
4325 <code><strong>file tempfile</strong> <em>?template?</em></code>
4326 </dt>
4327 <dd>
4329 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4330 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4331 the format of the template and security concerns.
4332 </p>
4333 </dd>
4334 <dt class="hdlist1">
4335 <code><strong>file type</strong> <em>name</em></code>
4336 </dt>
4337 <dd>
4339 Returns a string giving the type of file <code><em>name</em></code>, which will be
4340 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4341 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4342 </p>
4343 </dd>
4344 <dt class="hdlist1">
4345 <code><strong>file writable</strong> <em>name</em></code>
4346 </dt>
4347 <dd>
4349 Return <em>1</em> if file <code><em>name</em></code> is writable by
4350 the current user, <em>0</em> otherwise.
4351 </p>
4352 </dd>
4353 </dl></div>
4354 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4355 conditional or looping commands, for example:</p></div>
4356 <div class="literalblock">
4357 <div class="content">
4358 <pre><code>if {![file exists foo]} {
4359 error {bad file name}
4360 } else {
4362 }</code></pre>
4363 </div></div>
4364 </div>
4365 <div class="sect2">
4366 <h3 id="_finalize">finalize</h3>
4367 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4368 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4369 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4370 the empty string to remove the current finalizer.</p></div>
4371 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4372 command.</p></div>
4373 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4374 </div>
4375 <div class="sect2">
4376 <h3 id="_flush">flush</h3>
4377 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4378 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4379 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4380 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4381 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4382 refer to a file that was opened for writing. This command returns an
4383 empty string.</p></div>
4384 </div>
4385 <div class="sect2">
4386 <h3 id="_for">for</h3>
4387 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4388 <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.
4389 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4390 and <code><em>test</em></code> is an expression string.</p></div>
4391 <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>.
4392 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4393 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4394 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4395 when <code><em>test</em></code> evaluates to 0.</p></div>
4396 <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
4397 commands in the current execution of <code><em>body</em></code> are skipped; processing
4398 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4399 <code><em>test</em></code>, and so on.</p></div>
4400 <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>
4401 command will return immediately.</p></div>
4402 <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
4403 statements in C.</p></div>
4404 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4405 </div>
4406 <div class="sect2">
4407 <h3 id="_foreach">foreach</h3>
4408 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4409 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4410 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4411 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4412 collection of Tcl commands.</p></div>
4413 <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
4414 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4415 had been used to extract the field), then calls the Tcl interpreter to
4416 execute <code><em>body</em></code>.</p></div>
4417 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4418 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4419 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4420 the list, the loop will be executed three times.</p></div>
4421 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4422 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4423 of the loop are undefined.</p></div>
4424 <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>,
4425 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4426 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4427 </div>
4428 <div class="sect2">
4429 <h3 id="_format">format</h3>
4430 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4431 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4432 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4433 implementation). <code><em>formatString</em></code> indicates how to format
4434 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4435 arguments, if any, provide values to be substituted into the result.</p></div>
4436 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4437 man page for details. Each <code><em>arg</em></code> must match the expected type
4438 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4439 converts each argument to the correct type (floating, integer, etc.)
4440 before passing it to <em>sprintf</em> for formatting.</p></div>
4441 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4442 must be a decimal string, which will then be converted to the corresponding
4443 ASCII (or UTF-8) character value.</p></div>
4444 <div class="paragraph"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4445 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4446 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4447 correctly even if the argument is in braces.</p></div>
4448 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4449 </div>
4450 <div class="sect2">
4451 <h3 id="_getref">getref</h3>
4452 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4453 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4454 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4455 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4456 </div>
4457 <div class="sect2">
4458 <h3 id="_gets">gets</h3>
4459 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4460 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4461 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4462 the terminating newline character.</p></div>
4463 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4464 by that name and the return value is a count of the number of characters
4465 read (not including the newline).</p></div>
4466 <div class="paragraph"><p>If the end of the file is reached before reading
4467 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4468 empty string.</p></div>
4469 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4470 the line (minus the newline character) or an empty string if
4471 the end of the file is reached before reading any characters.</p></div>
4472 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4473 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4474 what really happened.</p></div>
4475 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4476 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4477 at the end of the file.</p></div>
4478 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4479 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4480 for reading.</p></div>
4481 </div>
4482 <div class="sect2">
4483 <h3 id="_glob">glob</h3>
4484 <div class="paragraph"><p><code><strong>glob</strong> ?<strong>-nocomplain</strong>? ?<strong>-directory</strong> <em>dir</em>? ?<strong>-tails</strong>? ?<strong>--</strong>? <em>pattern ?pattern ...?</em></code></p></div>
4485 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4486 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4487 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4488 list may be returned; otherwise an error is returned if the expanded
4489 list is empty. The <code>-nocomplain</code> argument must be provided
4490 exactly: an abbreviation will not be accepted.</p></div>
4491 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4492 directory name to search in. This allows globbing inside directories
4493 whose names may contain glob-sensitive characters. The returned names
4494 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4495 <div class="paragraph"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4496 are relative to the given directory.</p></div>
4497 </div>
4498 <div class="sect2">
4499 <h3 id="_global">global</h3>
4500 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4501 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4502 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4503 rather than a local one. For the duration of the current procedure
4504 (and only while executing in the current procedure), any reference to
4505 <code><em>varName</em></code> will be bound to a global variable instead
4506 of a local one.</p></div>
4507 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4508 to explicitly name a variable in the global scope.</p></div>
4509 </div>
4510 <div class="sect2">
4511 <h3 id="_if">if</h3>
4512 <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>
4513 <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
4514 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4515 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4516 the Tcl interpreter.</p></div>
4517 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4518 then <code><em>body2</em></code> is executed, and so on.</p></div>
4519 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4520 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4521 command easier to read.</p></div>
4522 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4523 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4524 <div class="paragraph"><p>The return value from the command is the result of the body script that
4525 was executed, or an empty string if none of the expressions was non-zero
4526 and there was no <code><em>bodyN</em></code>.</p></div>
4527 </div>
4528 <div class="sect2">
4529 <h3 id="_incr">incr</h3>
4530 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4531 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4532 The value of the variable must be integral.</p></div>
4533 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4534 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4535 1 is added to <code><em>varName</em></code>.</p></div>
4536 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4537 and also returned as result.</p></div>
4538 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4539 and set to <code>0</code> first.</p></div>
4540 </div>
4541 <div class="sect2">
4542 <h3 id="_info">info</h3>
4543 <div class="dlist"><dl>
4544 <dt class="hdlist1">
4545 <code><strong>info</strong> <em>option ?arg...?</em></code>
4546 </dt>
4547 <dd>
4549 Provide information about various internals to the Tcl interpreter.
4550 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4551 </p>
4552 </dd>
4553 <dt class="hdlist1">
4554 <code><strong>info args</strong> <em>procname</em></code>
4555 </dt>
4556 <dd>
4558 Returns a list containing the names of the arguments to procedure
4559 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4560 Tcl command procedure.
4561 </p>
4562 </dd>
4563 <dt class="hdlist1">
4564 <code><strong>info alias</strong> <em>command</em></code>
4565 </dt>
4566 <dd>
4568 <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
4569 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>
4570 </p>
4571 </dd>
4572 <dt class="hdlist1">
4573 <code><strong>info body</strong> <em>procname</em></code>
4574 </dt>
4575 <dd>
4577 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4578 the name of a Tcl command procedure.
4579 </p>
4580 </dd>
4581 <dt class="hdlist1">
4582 <code><strong>info channels</strong></code>
4583 </dt>
4584 <dd>
4586 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>
4587 </p>
4588 </dd>
4589 <dt class="hdlist1">
4590 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4591 </dt>
4592 <dd>
4594 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4595 Tcl commands, including both the built-in commands written in C and
4596 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4597 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4598 are returned. Matching is determined using the same rules as for
4599 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4600 </p>
4601 </dd>
4602 <dt class="hdlist1">
4603 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4604 </dt>
4605 <dd>
4607 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4608 having no unclosed quotes, braces, brackets or array element names,
4609 If the command doesn&#8217;t appear to be complete then 0 is returned.
4610 This command is typically used in line-oriented input environments
4611 to allow users to type in commands that span multiple lines; if the
4612 command isn&#8217;t complete, the script can delay evaluating it until additional
4613 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4614 missing character is stored in the variable with that name.
4615 </p>
4616 </dd>
4617 <dt class="hdlist1">
4618 <code><strong>info exists</strong> <em>varName</em></code>
4619 </dt>
4620 <dd>
4622 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4623 current context (either as a global or local variable), returns <em>0</em>
4624 otherwise.
4625 </p>
4626 </dd>
4627 <dt class="hdlist1">
4628 <code><strong>info frame</strong> ?<em>number</em>?</code>
4629 </dt>
4630 <dd>
4632 If <code><em>number</em></code> is not specified, this command returns a number
4633 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4634 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4635 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4636 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4637 to the top-most active procedure, 2 to the procedure it called, and
4638 so on); otherwise it gives a level relative to the current level
4639 (0 refers to the current procedure, -1 to its caller, and so on).
4640 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4641 </p>
4642 </dd>
4643 <dt class="hdlist1">
4644 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4645 </dt>
4646 <dd>
4648 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4649 of currently-defined global variables.
4650 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4651 are returned. Matching is determined using the same rules as for
4652 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4653 </p>
4654 </dd>
4655 <dt class="hdlist1">
4656 <code><strong>info hostname</strong></code>
4657 </dt>
4658 <dd>
4660 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4661 </p>
4662 </dd>
4663 <dt class="hdlist1">
4664 <code><strong>info level</strong> ?<em>number</em>?</code>
4665 </dt>
4666 <dd>
4668 If <code><em>number</em></code> is not specified, this command returns a number
4669 giving the stack level of the invoking procedure, or 0 if the
4670 command is invoked at top-level. If <code><em>number</em></code> is specified,
4671 then the result is a list consisting of the name and arguments for the
4672 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4673 is positive then it selects a particular stack level (1 refers
4674 to the top-most active procedure, 2 to the procedure it called, and
4675 so on); otherwise it gives a level relative to the current level
4676 (0 refers to the current procedure, -1 to its caller, and so on).
4677 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4678 levels mean.
4679 </p>
4680 </dd>
4681 <dt class="hdlist1">
4682 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4683 </dt>
4684 <dd>
4686 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4687 of currently-defined local variables, including arguments to the
4688 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4689 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4690 specified, only those names matching <code><em>pattern</em></code> are returned.
4691 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4692 </p>
4693 </dd>
4694 <dt class="hdlist1">
4695 <code><strong>info nameofexecutable</strong></code>
4696 </dt>
4697 <dd>
4699 Returns the name of the binary file from which the application
4700 was invoked. A full path will be returned, unless the path
4701 can&#8217;t be determined, in which case the empty string will be returned.
4702 </p>
4703 </dd>
4704 <dt class="hdlist1">
4705 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4706 </dt>
4707 <dd>
4709 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4710 names of Tcl command procedures.
4711 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4712 are returned. Matching is determined using the same rules as for
4713 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4714 </p>
4715 </dd>
4716 <dt class="hdlist1">
4717 <code><strong>info references</strong></code>
4718 </dt>
4719 <dd>
4721 Returns a list of all references which have not yet been garbage
4722 collected.
4723 </p>
4724 </dd>
4725 <dt class="hdlist1">
4726 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4727 </dt>
4728 <dd>
4730 Returns a list representing the mapping of standard return codes
4731 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4732 instead returns the name for the given code.
4733 </p>
4734 </dd>
4735 <dt class="hdlist1">
4736 <code><strong>info script</strong></code>
4737 </dt>
4738 <dd>
4740 If a Tcl script file is currently being evaluated (i.e. there is a
4741 call to <em>Jim_EvalFile</em> active or there is an active invocation
4742 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4743 of the innermost file being processed. Otherwise the command returns an
4744 empty string.
4745 </p>
4746 </dd>
4747 <dt class="hdlist1">
4748 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4749 </dt>
4750 <dd>
4752 With a single argument, returns the original source location of the given script as a list of
4753 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4754 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4755 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4756 useful messages from <a href="#_eval"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4757 </p>
4758 </dd>
4759 <dt class="hdlist1">
4760 <code><strong>info stacktrace</strong></code>
4761 </dt>
4762 <dd>
4764 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4765 of <code>{procedure filename line ...}</code>.
4766 </p>
4767 </dd>
4768 <dt class="hdlist1">
4769 <code><strong>info statics</strong> <em>procname</em></code>
4770 </dt>
4771 <dd>
4773 Returns a dictionary of the static variables of procedure
4774 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4775 procedure. An empty dictionary is returned if the procedure has
4776 no static variables.
4777 </p>
4778 </dd>
4779 <dt class="hdlist1">
4780 <code><strong>info version</strong></code>
4781 </dt>
4782 <dd>
4784 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4785 </p>
4786 </dd>
4787 <dt class="hdlist1">
4788 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4789 </dt>
4790 <dd>
4792 If <code><em>pattern</em></code> isn&#8217;t specified,
4793 returns a list of all the names of currently-visible variables, including
4794 both locals and currently-visible globals.
4795 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4796 are returned. Matching is determined using the same rules as for
4797 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4798 </p>
4799 </dd>
4800 </dl></div>
4801 </div>
4802 <div class="sect2">
4803 <h3 id="_join">join</h3>
4804 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4805 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4806 string formed by joining all of the elements of <code><em>list</em></code> together with
4807 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4808 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4809 </div>
4810 <div class="sect2">
4811 <h3 id="_kill">kill</h3>
4812 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4813 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4814 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4815 <div class="ulist"><ul>
4816 <li>
4818 <code>TERM</code>
4819 </p>
4820 </li>
4821 <li>
4823 <code>SIGTERM</code>
4824 </p>
4825 </li>
4826 <li>
4828 <code>-TERM</code>
4829 </p>
4830 </li>
4831 <li>
4833 <code>15</code>
4834 </p>
4835 </li>
4836 <li>
4838 <code>-15</code>
4839 </p>
4840 </li>
4841 </ul></div>
4842 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4843 <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>
4844 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4845 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4846 </div>
4847 <div class="sect2">
4848 <h3 id="_lambda">lambda</h3>
4849 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4850 <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
4851 creating a named procedure, it creates an anonymous procedure and returns
4852 the name of the procedure.</p></div>
4853 <div class="paragraph"><p>See <a href="#_proc"><strong><code>proc</code></strong></a> and GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4854 </div>
4855 <div class="sect2">
4856 <h3 id="_lappend">lappend</h3>
4857 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4858 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4859 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4860 between elements.</p></div>
4861 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4862 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
4863 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4864 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4865 For example,</p></div>
4866 <div class="literalblock">
4867 <div class="content">
4868 <pre><code>lappend a $b</code></pre>
4869 </div></div>
4870 <div class="paragraph"><p>is much more efficient than</p></div>
4871 <div class="literalblock">
4872 <div class="content">
4873 <pre><code>set a [concat $a [list $b]]</code></pre>
4874 </div></div>
4875 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
4876 </div>
4877 <div class="sect2">
4878 <h3 id="_lassign">lassign</h3>
4879 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
4880 <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
4881 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
4882 list elements, the remaining variables are set to the empty string. If there are more list elements
4883 than variables, a list of unassigned elements is returned.</p></div>
4884 <div class="literalblock">
4885 <div class="content">
4886 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4888 a=1,b=2</code></pre>
4889 </div></div>
4890 </div>
4891 <div class="sect2">
4892 <h3 id="_local">local</h3>
4893 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
4894 <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
4895 be the name of an existing command, which is marked as having local scope.
4896 This means that when the current procedure exits, the specified
4897 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
4898 to automatically close a filehandle.</p></div>
4899 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4900 the existing command will be kept rather than deleted, and may be called
4901 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
4902 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
4903 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4904 continues to have global scope while it is active.</p></div>
4905 <div class="literalblock">
4906 <div class="content">
4907 <pre><code>proc outer {} {
4908 # proc ... returns "inner" which is marked local
4909 local proc inner {} {
4910 # will be deleted when 'outer' exits
4911 }</code></pre>
4912 </div></div>
4913 <div class="literalblock">
4914 <div class="content">
4915 <pre><code> inner
4917 }</code></pre>
4918 </div></div>
4919 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4920 than waiting until garbage collection.</p></div>
4921 <div class="literalblock">
4922 <div class="content">
4923 <pre><code>proc outer {} {
4924 set x [lambda inner {args} {
4925 # will be deleted when 'outer' exits
4927 # Use 'function' here which simply returns $x
4928 local function $x</code></pre>
4929 </div></div>
4930 <div class="literalblock">
4931 <div class="content">
4932 <pre><code> $x ...
4934 }</code></pre>
4935 </div></div>
4936 </div>
4937 <div class="sect2">
4938 <h3 id="_loop">loop</h3>
4939 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
4940 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
4941 With a positive increment, equivalent to:</p></div>
4942 <div class="literalblock">
4943 <div class="content">
4944 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
4945 </div></div>
4946 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
4947 Note that setting the loop variable inside the loop does not
4948 affect the loop count.</p></div>
4949 </div>
4950 <div class="sect2">
4951 <h3 id="_lindex">lindex</h3>
4952 <div class="paragraph"><p><code><strong>lindex</strong> <em>list ?index &#8230;?</em></code></p></div>
4953 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
4954 (0 refers to the first element of the list).
4955 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4956 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
4957 braces and quotes and backslashes as the Tcl command interpreter; however,
4958 variable substitution and command substitution do not occur.</p></div>
4959 <div class="paragraph"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
4960 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
4961 in <code><em>list</em></code>, then an empty string is returned.</p></div>
4962 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4963 used in turn to select an element from the previous indexing
4964 operation, allowing the script to select elements from sublists.</p></div>
4965 </div>
4966 <div class="sect2">
4967 <h3 id="_linsert">linsert</h3>
4968 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
4969 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
4970 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
4971 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
4972 a separate element of the new list. If <code><em>index</em></code> is less than
4973 or equal to zero, then the new elements are inserted at the
4974 beginning of the list. If <code><em>index</em></code> is greater than or equal
4975 to the number of elements in the list, then the new elements are
4976 appended to the list.</p></div>
4977 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
4978 </div>
4979 <div class="sect2">
4980 <h3 id="_list">list</h3>
4981 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
4982 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
4983 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4984 may be used on the result to re-extract the original arguments, and also
4985 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
4986 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
4987 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
4988 <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
4989 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
4990 For example, the command</p></div>
4991 <div class="literalblock">
4992 <div class="content">
4993 <pre><code>list a b {c d e} {f {g h}}</code></pre>
4994 </div></div>
4995 <div class="paragraph"><p>will return</p></div>
4996 <div class="literalblock">
4997 <div class="content">
4998 <pre><code>a b {c d e} {f {g h}}</code></pre>
4999 </div></div>
5000 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
5001 <div class="literalblock">
5002 <div class="content">
5003 <pre><code>a b c d e f {g h}</code></pre>
5004 </div></div>
5005 </div>
5006 <div class="sect2">
5007 <h3 id="_llength">llength</h3>
5008 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
5009 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
5010 the number of elements in it.</p></div>
5011 </div>
5012 <div class="sect2">
5013 <h3 id="_lset">lset</h3>
5014 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
5015 <div class="paragraph"><p>Sets an element in a list.</p></div>
5016 <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
5017 as the name of a variable containing a Tcl list. It also accepts
5018 zero or more indices into the list. Finally, it accepts a new value
5019 for an element of varName. If no indices are presented, the command
5020 takes the form:</p></div>
5021 <div class="literalblock">
5022 <div class="content">
5023 <pre><code>lset varName newValue</code></pre>
5024 </div></div>
5025 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
5026 varName.</p></div>
5027 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
5028 treats the content of the varName variable as a Tcl list. It addresses
5029 the index&#8217;th element in it (0 refers to the first element of the
5030 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
5031 concerning braces and quotes and backslashes as the Tcl command
5032 interpreter; however, variable substitution and command substitution
5033 do not occur. The command constructs a new list in which the
5034 designated element is replaced with newValue. This new list is
5035 stored in the variable varName, and is also the return value from
5036 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
5037 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
5038 elements in $varName, then an error occurs.</p></div>
5039 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5040 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5041 used in turn to address an element within a sublist designated by
5042 the previous indexing operation, allowing the script to alter
5043 elements in sublists. The command,</p></div>
5044 <div class="literalblock">
5045 <div class="content">
5046 <pre><code>lset a 1 2 newValue</code></pre>
5047 </div></div>
5048 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
5049 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
5050 or equal to zero. The integer appearing in each index argument must
5051 be strictly less than the length of the corresponding list. In other
5052 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
5053 index is outside the permitted range, an error is reported.</p></div>
5054 </div>
5055 <div class="sect2">
5056 <h3 id="_lmap">lmap</h3>
5057 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
5058 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
5059 <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>
5060 <div class="paragraph"><p>For example:</p></div>
5061 <div class="literalblock">
5062 <div class="content">
5063 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
5064 1 4 9 16 25
5065 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
5066 {1 A} {2 B} {3 C}</code></pre>
5067 </div></div>
5068 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
5069 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
5070 </div>
5071 <div class="sect2">
5072 <h3 id="_load">load</h3>
5073 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
5074 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
5075 the extension <code>.so</code>. The initialisation function for the module must be based
5076 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
5077 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
5078 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>
5079 </div>
5080 <div class="sect2">
5081 <h3 id="_lrange">lrange</h3>
5082 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
5083 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
5084 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
5085 <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>
5086 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
5087 in the list, then it is treated as if it were <code>end</code>.</p></div>
5088 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5089 is returned.</p></div>
5090 <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
5091 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
5092 for simple fields that aren&#8217;t enclosed in braces); it does, however,
5093 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>
5094 </div>
5095 <div class="sect2">
5096 <h3 id="_lreplace">lreplace</h3>
5097 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5098 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
5099 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5100 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5101 to be replaced.</p></div>
5102 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5103 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5104 must exist in the list.</p></div>
5105 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5106 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5107 <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>
5108 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5109 be added to the list in place of those that were deleted.</p></div>
5110 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
5111 the list.</p></div>
5112 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5113 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5114 </div>
5115 <div class="sect2">
5116 <h3 id="_lrepeat">lrepeat</h3>
5117 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5118 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5119 a positive integer).</p></div>
5120 <div class="literalblock">
5121 <div class="content">
5122 <pre><code>jim&gt; lrepeat 3 a b
5123 a b a b a b</code></pre>
5124 </div></div>
5125 </div>
5126 <div class="sect2">
5127 <h3 id="_lreverse">lreverse</h3>
5128 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5129 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
5130 <div class="literalblock">
5131 <div class="content">
5132 <pre><code>jim&gt; lreverse {1 2 3}
5133 3 2 1</code></pre>
5134 </div></div>
5135 </div>
5136 <div class="sect2">
5137 <h3 id="_lsearch">lsearch</h3>
5138 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5139 <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
5140 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5141 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5142 the list are to be matched against pattern and must have one of the values below:</p></div>
5143 <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>
5144 <div class="dlist"><dl>
5145 <dt class="hdlist1">
5146 <code><strong>-exact</strong></code>
5147 </dt>
5148 <dd>
5150 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5151 This is the default.
5152 </p>
5153 </dd>
5154 <dt class="hdlist1">
5155 <code><strong>-glob</strong></code>
5156 </dt>
5157 <dd>
5159 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5160 rules as the string match command.
5161 </p>
5162 </dd>
5163 <dt class="hdlist1">
5164 <code><strong>-regexp</strong></code>
5165 </dt>
5166 <dd>
5168 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5169 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5170 </p>
5171 </dd>
5172 <dt class="hdlist1">
5173 <code><strong>-command</strong> <em>cmdname</em></code>
5174 </dt>
5175 <dd>
5177 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5178 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5179 for a match, or 0 for no match.
5180 </p>
5181 </dd>
5182 <dt class="hdlist1">
5183 <code><strong>-all</strong></code>
5184 </dt>
5185 <dd>
5187 Changes the result to be the list of all matching indices (or all matching values if
5188 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5189 order. If values are returned, the order of the values will be the order of those values
5190 within the input list.
5191 </p>
5192 </dd>
5193 <dt class="hdlist1">
5194 <code><strong>-inline</strong></code>
5195 </dt>
5196 <dd>
5198 The matching value is returned instead of its index (or an empty string if no value
5199 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5200 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5201 </p>
5202 </dd>
5203 <dt class="hdlist1">
5204 <code><strong>-bool</strong></code>
5205 </dt>
5206 <dd>
5208 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5209 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5210 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5211 </p>
5212 </dd>
5213 <dt class="hdlist1">
5214 <code><strong>-not</strong></code>
5215 </dt>
5216 <dd>
5218 This negates the sense of the match, returning the index (or value
5219 if <code>-inline</code> is specified) of the first non-matching value in the
5220 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5221 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5222 non-matches will be returned rather than matches.
5223 </p>
5224 </dd>
5225 <dt class="hdlist1">
5226 <code><strong>-nocase</strong></code>
5227 </dt>
5228 <dd>
5230 Causes comparisons to be handled in a case-insensitive manner.
5231 </p>
5232 </dd>
5233 </dl></div>
5234 </div>
5235 <div class="sect2">
5236 <h3 id="_lsort">lsort</h3>
5237 <div class="paragraph"><p><code><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-nocase|-integer|-real|-command</strong> <em>cmdname</em>? ?<strong>-unique</strong>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></code></p></div>
5238 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5239 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5240 <div class="paragraph"><p>If <code>-nocase</code> is specified, comparisons are case-insensitive.</p></div>
5241 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5242 <div class="paragraph"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5243 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5244 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5245 should compare the values and return an integer less than, equal
5246 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5247 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5248 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5249 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5250 <div class="paragraph"><p>If <code>-unique</code> is specified, then only the last set of duplicate elements found in the list will be retained.
5251 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5252 <code>{1 a}</code> and <code>{1 b}</code> would be considered duplicates and only the second element, <code>{1 b}</code>, would be retained.</p></div>
5253 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5254 the given index is extracted from the list for comparison. The list index may
5255 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5256 </div>
5257 <div class="sect2">
5258 <h3 id="_open">open</h3>
5259 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5260 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5261 <div class="paragraph"><p>Opens a file and returns an identifier
5262 that may be used in future invocations
5263 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>.
5264 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5265 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5266 It may have any of the following values:</p></div>
5267 <div class="dlist"><dl>
5268 <dt class="hdlist1">
5269 <code>r</code>
5270 </dt>
5271 <dd>
5273 Open the file for reading only; the file must already exist.
5274 </p>
5275 </dd>
5276 <dt class="hdlist1">
5277 <code>r</code>+
5278 </dt>
5279 <dd>
5281 Open the file for both reading and writing; the file must
5282 already exist.
5283 </p>
5284 </dd>
5285 <dt class="hdlist1">
5286 <code>w</code>
5287 </dt>
5288 <dd>
5290 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5291 exist, create a new file.
5292 </p>
5293 </dd>
5294 <dt class="hdlist1">
5295 <code>w</code>+
5296 </dt>
5297 <dd>
5299 Open the file for reading and writing. Truncate it if it exists.
5300 If it doesn&#8217;t exist, create a new file.
5301 </p>
5302 </dd>
5303 <dt class="hdlist1">
5304 <code>a</code>
5305 </dt>
5306 <dd>
5308 Open the file for writing only. The file must already exist, and the file
5309 is positioned so that new data is appended to the file.
5310 </p>
5311 </dd>
5312 <dt class="hdlist1">
5313 <code>a</code>+
5314 </dt>
5315 <dd>
5317 Open the file for reading and writing. If the file doesn&#8217;t
5318 exist, create a new empty file. Set the initial access position
5319 to the end of the file.
5320 </p>
5321 </dd>
5322 </dl></div>
5323 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5324 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5325 must be invoked between a read and a write, or vice versa.</p></div>
5326 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5327 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5328 describe a command pipeline to invoke, in the same style as the
5329 arguments for exec. In this case, the channel identifier returned
5330 by open may be used to write to the command&#8217;s input pipe or read
5331 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5332 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5333 pipeline is directed to the current standard output unless overridden
5334 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5335 standard input for the pipeline is taken from the current standard
5336 input unless overridden by the command.</p></div>
5337 <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
5338 forming the command pipeline.</p></div>
5339 <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>
5340 </div>
5341 <div class="sect2">
5342 <h3 id="_package">package</h3>
5343 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5344 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5345 If no version is specified, <em>1.0</em> is used.</p></div>
5346 <div class="paragraph"><p>Any script which provides a package may include this statement
5347 as the first statement, although it is not required.</p></div>
5348 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5349 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5350 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5351 or <em>$path/$name.tcl</em> as a script package.</p></div>
5352 <div class="paragraph"><p>The first such file which is found is considered to provide the package.
5353 (The version number is ignored).</p></div>
5354 <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,
5355 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5356 <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.
5357 No further attempt will be made to locate the file.</p></div>
5358 </div>
5359 <div class="sect2">
5360 <h3 id="_pid">pid</h3>
5361 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5362 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5363 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5364 <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
5365 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5366 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5367 the empty string is returned instead.</p></div>
5368 <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>
5369 </div>
5370 <div class="sect2">
5371 <h3 id="_proc">proc</h3>
5372 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5373 <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>.
5374 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5375 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5376 If specified, <code><em>static</em></code>, declares static variables which are bound to the
5377 procedure.</p></div>
5378 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5379 <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>
5380 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5381 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5382 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5383 of the last command executed in the procedure&#8217;s body.</p></div>
5384 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5385 procedure-as-a-whole will return that same error.</p></div>
5386 </div>
5387 <div class="sect2">
5388 <h3 id="_puts">puts</h3>
5389 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5390 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5391 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5392 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5393 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5394 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5395 channels; it must refer to a file that was opened for
5396 writing.</p></div>
5397 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5398 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5399 but this feature may be suppressed by specifying the <code>-nonewline</code>
5400 switch.</p></div>
5401 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5402 command may be used to force buffered characters to be output.</p></div>
5403 </div>
5404 <div class="sect2">
5405 <h3 id="_pwd">pwd</h3>
5406 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5407 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5408 </div>
5409 <div class="sect2">
5410 <h3 id="_rand">rand</h3>
5411 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5412 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5413 (defaults to the maximum integer).</p></div>
5414 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5415 </div>
5416 <div class="sect2">
5417 <h3 id="_range">range</h3>
5418 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5419 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5420 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>
5421 <div class="literalblock">
5422 <div class="content">
5423 <pre><code>jim&gt; range 5
5424 0 1 2 3 4
5425 jim&gt; range 2 5
5426 2 3 4
5427 jim&gt; range 2 10 4
5429 jim&gt; range 7 4 -2
5430 7 5</code></pre>
5431 </div></div>
5432 </div>
5433 <div class="sect2">
5434 <h3 id="_read">read</h3>
5435 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5436 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5437 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5438 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5439 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5440 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5441 If the <code>-nonewline</code> switch is specified then the last
5442 character of the file is discarded if it is a newline.</p></div>
5443 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5444 exactly this many bytes will be read and returned, unless there are fewer than
5445 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5446 bytes are returned.</p></div>
5447 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5448 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5449 </div>
5450 <div class="sect2">
5451 <h3 id="_regexp">regexp</h3>
5452 <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>
5453 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5454 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5455 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5456 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5457 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5458 are treated as the names of variables to use to return
5459 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5460 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5461 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5462 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5463 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5464 contain the characters that matched the next parenthesized
5465 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5466 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5467 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5468 <code>-inline</code> below.</p></div>
5469 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5470 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5471 match the string (e.g. because it was in a portion of the expression
5472 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5473 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5474 string otherwise.</p></div>
5475 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5476 <div class="dlist"><dl>
5477 <dt class="hdlist1">
5478 <code><strong>-nocase</strong></code>
5479 </dt>
5480 <dd>
5482 Causes upper-case and lower-case characters to be treated as
5483 identical during the matching process.
5484 </p>
5485 </dd>
5486 <dt class="hdlist1">
5487 <code><strong>-line</strong></code>
5488 </dt>
5489 <dd>
5491 Use newline-sensitive matching. By default, newline
5492 is a completely ordinary character with no special meaning in
5493 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5494 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5495 string after any newline in the string in addition to its normal
5496 function, and the <code>$</code> anchor matches the null string before any
5497 newline in the string in addition to its normal function.
5498 </p>
5499 </dd>
5500 <dt class="hdlist1">
5501 <code><strong>-indices</strong></code>
5502 </dt>
5503 <dd>
5505 Changes what is stored in the subMatchVars. Instead of
5506 storing the matching characters from string, each variable
5507 will contain a list of two decimal strings giving the indices
5508 in string of the first and last characters in the matching
5509 range of characters.
5510 </p>
5511 </dd>
5512 <dt class="hdlist1">
5513 <code><strong>-start</strong> <em>offset</em></code>
5514 </dt>
5515 <dd>
5517 Specifies a character index offset into the string at which to start
5518 matching the regular expression. If <code>-indices</code> is
5519 specified, the indices will be indexed starting from the
5520 absolute beginning of the input string. <code><em>offset</em></code> will be
5521 constrained to the bounds of the input string.
5522 </p>
5523 </dd>
5524 <dt class="hdlist1">
5525 <code><strong>-all</strong></code>
5526 </dt>
5527 <dd>
5529 Causes the regular expression to be matched as many times as possible
5530 in the string, returning the total number of matches found. If this
5531 is specified with match variables, they will contain information
5532 for the last match only.
5533 </p>
5534 </dd>
5535 <dt class="hdlist1">
5536 <code><strong>-inline</strong></code>
5537 </dt>
5538 <dd>
5540 Causes the command to return, as a list, the data that would otherwise
5541 be placed in match variables. When using <code>-inline</code>, match variables
5542 may not be specified. If used with <code>-all</code>, the list will be concatenated
5543 at each iteration, such that a flat list is always returned. For
5544 each match iteration, the command will append the overall match
5545 data, plus one element for each subexpression in the regular
5546 expression.
5547 </p>
5548 </dd>
5549 <dt class="hdlist1">
5550 <code><strong>--</strong></code>
5551 </dt>
5552 <dd>
5554 Marks the end of switches. The argument following this one will be
5555 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5556 </p>
5557 </dd>
5558 </dl></div>
5559 </div>
5560 <div class="sect2">
5561 <h3 id="_regsub">regsub</h3>
5562 <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>
5563 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5564 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5565 above.</p></div>
5566 <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>
5567 with the substitutions detailed below, and returns the number of
5568 substitutions made (normally 1 unless <code>-all</code> is specified).
5569 This is 0 if there were no matches.</p></div>
5570 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5571 instead.</p></div>
5572 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5573 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5574 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5575 in the substitution with the portion of <code><em>string</em></code> that
5576 matched <code><em>exp</em></code>.</p></div>
5577 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5578 between 1 and 9, then it is replaced in the substitution with
5579 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5580 parenthesized subexpression of <code><em>exp</em></code>.
5581 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5582 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5583 backslash.</p></div>
5584 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5585 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5586 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5587 backslashes.</p></div>
5588 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5589 <div class="dlist"><dl>
5590 <dt class="hdlist1">
5591 <code><strong>-nocase</strong></code>
5592 </dt>
5593 <dd>
5595 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5596 before matching against <code><em>exp</em></code>; however, substitutions
5597 specified by <code><em>subSpec</em></code> use the original unconverted form
5598 of <code><em>string</em></code>.
5599 </p>
5600 </dd>
5601 <dt class="hdlist1">
5602 <code><strong>-all</strong></code>
5603 </dt>
5604 <dd>
5606 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5607 is performed for each of these ranges, rather than only the
5608 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5609 each substitution using the information from the corresponding
5610 match.
5611 </p>
5612 </dd>
5613 <dt class="hdlist1">
5614 <code><strong>-line</strong></code>
5615 </dt>
5616 <dd>
5618 Use newline-sensitive matching. By default, newline
5619 is a completely ordinary character with no special meaning in
5620 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5621 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5622 string after any newline in the string in addition to its normal
5623 function, and the <code>$</code> anchor matches the null string before any
5624 newline in the string in addition to its normal function.
5625 </p>
5626 </dd>
5627 <dt class="hdlist1">
5628 <code><strong>-start</strong> <em>offset</em></code>
5629 </dt>
5630 <dd>
5632 Specifies a character index offset into the string at which to
5633 start matching the regular expression. <code><em>offset</em></code> will be
5634 constrained to the bounds of the input string.
5635 </p>
5636 </dd>
5637 <dt class="hdlist1">
5638 <code><strong>--</strong></code>
5639 </dt>
5640 <dd>
5642 Marks the end of switches. The argument following this one will be
5643 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5644 </p>
5645 </dd>
5646 </dl></div>
5647 </div>
5648 <div class="sect2">
5649 <h3 id="_ref">ref</h3>
5650 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5651 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5652 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5653 when the a garbage collection cycle runs and this reference is
5654 no longer accessible.</p></div>
5655 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5656 <div class="literalblock">
5657 <div class="content">
5658 <pre><code>finalizer reference string</code></pre>
5659 </div></div>
5660 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5661 </div>
5662 <div class="sect2">
5663 <h3 id="_rename">rename</h3>
5664 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5665 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5666 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5667 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5668 returns an empty string as result.</p></div>
5669 </div>
5670 <div class="sect2">
5671 <h3 id="_return">return</h3>
5672 <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>
5673 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5674 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>
5675 is not specified, an empty string will be returned as result.</p></div>
5676 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5677 continue, signal, return or exit), this code will be used instead
5678 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5679 commands.</p></div>
5680 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5681 the new return code from <code>-code</code>. This is useful when rethrowing an error
5682 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5683 an example of how this is done.</p></div>
5684 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5685 <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>)
5686 it is used to initialize the stacktrace.</p></div>
5687 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5688 </div>
5689 <div class="sect2">
5690 <h3 id="_scan">scan</h3>
5691 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5692 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5693 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5694 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5695 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5696 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5697 when a field is scanned from <code><em>string</em></code>, the result is converted back
5698 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5699 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5700 character value is converted to a decimal string, which is then
5701 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5702 specified for this conversion.</p></div>
5703 </div>
5704 <div class="sect2">
5705 <h3 id="_seek">seek</h3>
5706 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5707 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5708 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5709 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5710 which the next read or write will occur for <code><em>fileId</em></code>.
5711 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5712 must be one of the following:</p></div>
5713 <div class="dlist"><dl>
5714 <dt class="hdlist1">
5715 <code><strong>start</strong></code>
5716 </dt>
5717 <dd>
5719 The new access position will be <code><em>offset</em></code> bytes from the start
5720 of the file.
5721 </p>
5722 </dd>
5723 <dt class="hdlist1">
5724 <code><strong>current</strong></code>
5725 </dt>
5726 <dd>
5728 The new access position will be <code><em>offset</em></code> bytes from the current
5729 access position; a negative <code><em>offset</em></code> moves the access position
5730 backwards in the file.
5731 </p>
5732 </dd>
5733 <dt class="hdlist1">
5734 <code><strong>end</strong></code>
5735 </dt>
5736 <dd>
5738 The new access position will be <code><em>offset</em></code> bytes from the end of
5739 the file. A negative <code><em>offset</em></code> places the access position before
5740 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5741 after the end-of-file.
5742 </p>
5743 </dd>
5744 </dl></div>
5745 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5746 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5747 <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
5748 of the standard I/O channels.</p></div>
5749 <div class="paragraph"><p>This command returns an empty string.</p></div>
5750 </div>
5751 <div class="sect2">
5752 <h3 id="_set">set</h3>
5753 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5754 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5755 <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>,
5756 creating a new variable if one doesn&#8217;t already exist, and return
5757 its value.</p></div>
5758 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5759 close parenthesis, then it refers to an array element: the characters
5760 before the open parenthesis are the name of the array, and the characters
5761 between the parentheses are the index within the array.
5762 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5763 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5764 variable.</p></div>
5765 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5766 or local variable of the procedure, unless the <code><em>global</em></code> command
5767 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5768 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5769 in the global scope.</p></div>
5770 </div>
5771 <div class="sect2">
5772 <h3 id="_setref">setref</h3>
5773 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5774 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5775 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5776 command.</p></div>
5777 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5778 </div>
5779 <div class="sect2">
5780 <h3 id="_signal">signal</h3>
5781 <div class="paragraph"><p>Command for signal handling.</p></div>
5782 <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>
5783 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5784 "<code>SIGINT SIGTERM</code>".</p></div>
5785 <div class="dlist"><dl>
5786 <dt class="hdlist1">
5787 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5788 </dt>
5789 <dd>
5791 If no signals are given, returns a list of all signals which are currently
5792 being handled.
5793 If signals are specified, these are added to the list of signals currently
5794 being handled.
5795 </p>
5796 </dd>
5797 <dt class="hdlist1">
5798 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5799 </dt>
5800 <dd>
5802 If no signals are given, returns a lists all signals which are currently
5803 being ignored.
5804 If signals are specified, these are added to the list of signals
5805 currently being ignored. These signals are still delivered, but
5806 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
5807 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5808 been ignored.
5809 </p>
5810 </dd>
5811 <dt class="hdlist1">
5812 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5813 </dt>
5814 <dd>
5816 If no signals are given, returns a lists all signals which are currently have
5817 the default behaviour.
5818 If signals are specified, these are added to the list of signals which have
5819 the default behaviour.
5820 </p>
5821 </dd>
5822 <dt class="hdlist1">
5823 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5824 </dt>
5825 <dd>
5827 Returns a list of signals which have been delivered to the process
5828 but are <em>ignored</em>. If signals are specified, only that set of signals will
5829 be checked, otherwise all signals will be checked.
5830 If <code>-clear</code> is specified, any signals returned are removed and will not be
5831 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5832 </p>
5833 </dd>
5834 <dt class="hdlist1">
5835 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5836 </dt>
5837 <dd>
5839 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5840 The behaviour is identical to:
5841 </p>
5842 <div class="literalblock">
5843 <div class="content">
5844 <pre><code>kill signal [pid]</code></pre>
5845 </div></div>
5846 </dd>
5847 </dl></div>
5848 <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
5849 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>
5850 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5851 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5852 two examples below.</p></div>
5853 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5854 <div class="literalblock">
5855 <div class="content">
5856 <pre><code>signal handle SIGALRM
5857 alarm 20
5858 try -signal {
5859 .. possibly long running process ..
5860 alarm 0
5861 } on signal {sig} {
5862 puts stderr "Process took too long"
5863 }</code></pre>
5864 </div></div>
5865 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5866 <div class="literalblock">
5867 <div class="content">
5868 <pre><code>signal ignore SIGHUP
5869 while {1} {
5870 ... handle configuration/reconfiguration ...
5871 while {[signal check -clear SIGHUP] eq ""} {
5872 ... do processing ..
5874 # Received SIGHUP, so reconfigure
5875 }</code></pre>
5876 </div></div>
5877 </div>
5878 <div class="sect2">
5879 <h3 id="_sleep">sleep</h3>
5880 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
5881 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5882 point value less than one to sleep for less than a second, or an
5883 integer to sleep for one or more seconds.</p></div>
5884 </div>
5885 <div class="sect2">
5886 <h3 id="_source">source</h3>
5887 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
5888 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
5889 as a sequence of commands to execute in the normal fashion. The return
5890 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
5891 from the file. If an error occurs in executing the contents of the
5892 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
5893 <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
5894 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
5895 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
5896 </div>
5897 <div class="sect2">
5898 <h3 id="_split">split</h3>
5899 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
5900 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
5901 that is in the <code><em>splitChars</em></code> argument.</p></div>
5902 <div class="paragraph"><p>Each element of the result list will consist of the
5903 characters from <code><em>string</em></code> between instances of the
5904 characters in <code><em>splitChars</em></code>.</p></div>
5905 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
5906 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
5907 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
5908 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
5909 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
5910 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
5911 For example,</p></div>
5912 <div class="literalblock">
5913 <div class="content">
5914 <pre><code>split "comp.unix.misc" .</code></pre>
5915 </div></div>
5916 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
5917 <div class="literalblock">
5918 <div class="content">
5919 <pre><code>split "Hello world" {}</code></pre>
5920 </div></div>
5921 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
5922 </div>
5923 <div class="sect2">
5924 <h3 id="_stackdump">stackdump</h3>
5925 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
5926 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5927 </div>
5928 <div class="sect2">
5929 <h3 id="_stacktrace">stacktrace</h3>
5930 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
5931 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
5932 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
5933 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>
5934 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
5935 </div>
5936 <div class="sect2">
5937 <h3 id="_string">string</h3>
5938 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
5939 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
5940 The legal options (which may be abbreviated) are:</p></div>
5941 <div class="dlist"><dl>
5942 <dt class="hdlist1">
5943 <code><strong>string bytelength</strong> <em>string</em></code>
5944 </dt>
5945 <dd>
5947 Returns the length of the string in bytes. This will return
5948 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
5949 or if the string is composed entirely of ASCII characters.
5950 See UTF-8 AND UNICODE.
5951 </p>
5952 </dd>
5953 <dt class="hdlist1">
5954 <code><strong>string byterange</strong> <em>string first last</em></code>
5955 </dt>
5956 <dd>
5958 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
5959 These commands are identical if UTF-8 support is not enabled.
5960 </p>
5961 </dd>
5962 <dt class="hdlist1">
5963 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
5964 </dt>
5965 <dd>
5967 Concatenates the given strings into a single string.
5968 </p>
5969 </dd>
5970 <dt class="hdlist1">
5971 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
5972 </dt>
5973 <dd>
5975 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
5976 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
5977 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
5978 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
5979 is specified, then only the first <code><em>len</em></code> characters are used
5980 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5981 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5982 </p>
5983 </dd>
5984 <dt class="hdlist1">
5985 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
5986 </dt>
5987 <dd>
5989 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
5990 is specified, then only the first <code><em>len</em></code> characters are used
5991 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
5992 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
5993 </p>
5994 </dd>
5995 <dt class="hdlist1">
5996 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
5997 </dt>
5998 <dd>
6000 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6001 the characters in <code><em>string1</em></code>. If found, return the index of the
6002 first character in the first such match within <code><em>string2</em></code>. If not
6003 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
6004 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
6005 </p>
6006 </dd>
6007 <dt class="hdlist1">
6009 </dt>
6010 <dd>
6012 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
6013 </p>
6014 </dd>
6015 <dt class="hdlist1">
6016 <code><strong>string index</strong> <em>string charIndex</em></code>
6017 </dt>
6018 <dd>
6020 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
6021 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
6022 character of the string.
6023 If <code><em>charIndex</em></code> is less than 0 or greater than
6024 or equal to the length of the string then an empty string is
6025 returned.
6026 </p>
6027 </dd>
6028 <dt class="hdlist1">
6030 </dt>
6031 <dd>
6033 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
6034 </p>
6035 </dd>
6036 <dt class="hdlist1">
6037 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
6038 </dt>
6039 <dd>
6041 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
6042 class, otherwise returns 0. If <code>-strict</code> is specified, then an
6043 empty string returns 0, otherwise an empty string will return 1
6044 on any class. The following character classes are recognized
6045 (the class name can be abbreviated):
6046 </p>
6047 </dd>
6048 <dt class="hdlist1">
6050 </dt>
6051 <dd>
6052 <div class="dlist"><dl>
6053 <dt class="hdlist1">
6054 <code>alnum</code>
6055 </dt>
6056 <dd>
6058 Any alphabet or digit character.
6059 </p>
6060 </dd>
6061 <dt class="hdlist1">
6062 <code>alpha</code>
6063 </dt>
6064 <dd>
6066 Any alphabet character.
6067 </p>
6068 </dd>
6069 <dt class="hdlist1">
6070 <code>ascii</code>
6071 </dt>
6072 <dd>
6074 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6075 </p>
6076 </dd>
6077 <dt class="hdlist1">
6078 <code>control</code>
6079 </dt>
6080 <dd>
6082 Any control character.
6083 </p>
6084 </dd>
6085 <dt class="hdlist1">
6086 <code>digit</code>
6087 </dt>
6088 <dd>
6090 Any digit character.
6091 </p>
6092 </dd>
6093 <dt class="hdlist1">
6094 <code>double</code>
6095 </dt>
6096 <dd>
6098 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6099 In case of under/overflow in the value, 0 is returned.
6100 </p>
6101 </dd>
6102 <dt class="hdlist1">
6103 <code>graph</code>
6104 </dt>
6105 <dd>
6107 Any printing character, except space.
6108 </p>
6109 </dd>
6110 <dt class="hdlist1">
6111 <code>integer</code>
6112 </dt>
6113 <dd>
6115 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6116 </p>
6117 </dd>
6118 <dt class="hdlist1">
6119 <code>lower</code>
6120 </dt>
6121 <dd>
6123 Any lower case alphabet character.
6124 </p>
6125 </dd>
6126 <dt class="hdlist1">
6127 <code>print</code>
6128 </dt>
6129 <dd>
6131 Any printing character, including space.
6132 </p>
6133 </dd>
6134 <dt class="hdlist1">
6135 <code>punct</code>
6136 </dt>
6137 <dd>
6139 Any punctuation character.
6140 </p>
6141 </dd>
6142 <dt class="hdlist1">
6143 <code>space</code>
6144 </dt>
6145 <dd>
6147 Any space character.
6148 </p>
6149 </dd>
6150 <dt class="hdlist1">
6151 <code>upper</code>
6152 </dt>
6153 <dd>
6155 Any upper case alphabet character.
6156 </p>
6157 </dd>
6158 <dt class="hdlist1">
6159 <code>xdigit</code>
6160 </dt>
6161 <dd>
6163 Any hexadecimal digit character ([0-9A-Fa-f]).
6164 </p>
6165 </dd>
6166 </dl></div>
6167 </dd>
6168 <dt class="hdlist1">
6170 </dt>
6171 <dd>
6173 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6174 </p>
6175 </dd>
6176 <dt class="hdlist1">
6177 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6178 </dt>
6179 <dd>
6181 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6182 the characters in <code><em>string1</em></code>. If found, return the index of the
6183 first character in the last such match within <code><em>string2</em></code>. If there
6184 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6185 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6186 </p>
6187 </dd>
6188 <dt class="hdlist1">
6190 </dt>
6191 <dd>
6193 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6194 </p>
6195 </dd>
6196 <dt class="hdlist1">
6197 <code><strong>string length</strong> <em>string</em></code>
6198 </dt>
6199 <dd>
6201 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6202 If UTF-8 support is enabled, this may be different than the number of bytes.
6203 See UTF-8 AND UNICODE
6204 </p>
6205 </dd>
6206 <dt class="hdlist1">
6207 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6208 </dt>
6209 <dd>
6211 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6212 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6213 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6214 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6215 matching is done without regard to case differences. Both key and value may
6216 be multiple characters. Replacement is done in an ordered manner, so the
6217 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6218 only iterated over once, so earlier key replacements will have no affect for
6219 later key matches. For example,
6220 </p>
6221 <div class="literalblock">
6222 <div class="content">
6223 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6224 </div></div>
6225 </dd>
6226 <dt class="hdlist1">
6228 </dt>
6229 <dd>
6231 will return the string <code>01321221</code>.
6232 </p>
6233 </dd>
6234 <dt class="hdlist1">
6236 </dt>
6237 <dd>
6239 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6240 one. So if the previous example is reordered like this,
6241 </p>
6242 <div class="literalblock">
6243 <div class="content">
6244 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6245 </div></div>
6246 </dd>
6247 <dt class="hdlist1">
6249 </dt>
6250 <dd>
6252 it will return the string <code>02c322c222c</code>.
6253 </p>
6254 </dd>
6255 <dt class="hdlist1">
6256 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6257 </dt>
6258 <dd>
6260 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6261 if it doesn&#8217;t. Matching is done in a fashion similar to that
6262 used by the C-shell. For the two strings to match, their contents
6263 must be identical except that the following special sequences
6264 may appear in <code><em>pattern</em></code>:
6265 </p>
6266 <div class="dlist"><dl>
6267 <dt class="hdlist1">
6268 <code>*</code>
6269 </dt>
6270 <dd>
6272 Matches any sequence of characters in <code><em>string</em></code>,
6273 including a null string.
6274 </p>
6275 </dd>
6276 <dt class="hdlist1">
6277 <code>?</code>
6278 </dt>
6279 <dd>
6281 Matches any single character in <code><em>string</em></code>.
6282 </p>
6283 </dd>
6284 <dt class="hdlist1">
6285 <code>[<em>chars</em>]</code>
6286 </dt>
6287 <dd>
6289 Matches any character in the set given by <code><em>chars</em></code>.
6290 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6291 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6292 will match.
6293 </p>
6294 </dd>
6295 <dt class="hdlist1">
6296 <code>\x</code>
6297 </dt>
6298 <dd>
6300 Matches the single character <code><em>x</em></code>. This provides a way of
6301 avoiding the special interpretation of the characters <code>\*?[]</code>
6302 in <code><em>pattern</em></code>.
6303 </p>
6304 </dd>
6305 </dl></div>
6306 </dd>
6307 <dt class="hdlist1">
6309 </dt>
6310 <dd>
6312 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6313 </p>
6314 </dd>
6315 <dt class="hdlist1">
6316 <code><strong>string range</strong> <em>string first last</em></code>
6317 </dt>
6318 <dd>
6320 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6321 with the character whose index is <code><em>first</em></code> and ending with the
6322 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6323 first character of the string.
6324 </p>
6325 </dd>
6326 <dt class="hdlist1">
6328 </dt>
6329 <dd>
6331 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6332 </p>
6333 </dd>
6334 <dt class="hdlist1">
6336 </dt>
6337 <dd>
6339 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6340 if <code><em>last</em></code> is greater than or equal to the length of the string then
6341 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6342 <code><em>last</em></code> then an empty string is returned.
6343 </p>
6344 </dd>
6345 <dt class="hdlist1">
6346 <code><strong>string repeat</strong> <em>string count</em></code>
6347 </dt>
6348 <dd>
6350 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6351 </p>
6352 </dd>
6353 <dt class="hdlist1">
6354 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6355 </dt>
6356 <dd>
6358 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6359 with the character whose index is <code><em>first</em></code> and ending with the
6360 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6361 then it is placed in the removed character range. If <code><em>first</em></code> is
6362 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6363 is greater than or equal to the length of the string then it is
6364 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6365 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6366 then the initial string is returned untouched.
6367 </p>
6368 </dd>
6369 <dt class="hdlist1">
6370 <code><strong>string reverse</strong> <em>string</em></code>
6371 </dt>
6372 <dd>
6374 Returns a string that is the same length as <code><em>string</em></code> but
6375 with its characters in the reverse order.
6376 </p>
6377 </dd>
6378 <dt class="hdlist1">
6379 <code><strong>string tolower</strong> <em>string</em></code>
6380 </dt>
6381 <dd>
6383 Returns a value equal to <code><em>string</em></code> except that all upper case
6384 letters have been converted to lower case.
6385 </p>
6386 </dd>
6387 <dt class="hdlist1">
6388 <code><strong>string totitle</strong> <em>string</em></code>
6389 </dt>
6390 <dd>
6392 Returns a value equal to <code><em>string</em></code> except that the first character
6393 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6394 and all remaining characters have been converted to lower case.
6395 </p>
6396 </dd>
6397 <dt class="hdlist1">
6398 <code><strong>string toupper</strong> <em>string</em></code>
6399 </dt>
6400 <dd>
6402 Returns a value equal to <code><em>string</em></code> except that all lower case
6403 letters have been converted to upper case.
6404 </p>
6405 </dd>
6406 <dt class="hdlist1">
6407 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6408 </dt>
6409 <dd>
6411 Returns a value equal to <code><em>string</em></code> except that any leading
6412 or trailing characters from the set given by <code><em>chars</em></code> are
6413 removed.
6414 If <code><em>chars</em></code> is not specified then white space is removed
6415 (spaces, tabs, newlines, and carriage returns).
6416 </p>
6417 </dd>
6418 <dt class="hdlist1">
6419 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6420 </dt>
6421 <dd>
6423 Returns a value equal to <code><em>string</em></code> except that any
6424 leading characters from the set given by <code><em>chars</em></code> are
6425 removed.
6426 If <code><em>chars</em></code> is not specified then white space is removed
6427 (spaces, tabs, newlines, and carriage returns).
6428 </p>
6429 </dd>
6430 <dt class="hdlist1">
6431 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6432 </dt>
6433 <dd>
6435 Returns a value equal to <code><em>string</em></code> except that any
6436 trailing characters from the set given by <code><em>chars</em></code> are
6437 removed.
6438 If <code><em>chars</em></code> is not specified then white space is removed
6439 (spaces, tabs, newlines, and carriage returns).
6440 Null characters are always removed.
6441 </p>
6442 </dd>
6443 </dl></div>
6444 </div>
6445 <div class="sect2">
6446 <h3 id="_subst">subst</h3>
6447 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6448 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6449 and backslash substitutions on its string argument and returns the
6450 fully-substituted result. The substitutions are performed in exactly
6451 the same way as for Tcl commands. As a result, the string argument
6452 is actually substituted twice, once by the Tcl parser in the usual
6453 fashion for Tcl commands, and again by the subst command.</p></div>
6454 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6455 specified, then the corresponding substitutions are not performed.
6456 For example, if <code>-nocommands</code> is specified, no command substitution
6457 is performed: open and close brackets are treated as ordinary
6458 characters with no special interpretation.</p></div>
6459 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6460 special treatment to double quotes or curly braces. For example,
6461 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6462 <div class="literalblock">
6463 <div class="content">
6464 <pre><code>set a 44
6465 subst {xyz {$a}}</code></pre>
6466 </div></div>
6467 </div>
6468 <div class="sect2">
6469 <h3 id="_switch">switch</h3>
6470 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6471 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6472 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6473 the pattern arguments in order. As soon as it finds a pattern that
6474 matches string it evaluates the following body and returns the
6475 result of that evaluation. If the last pattern argument is default
6476 then it matches anything. If no pattern argument matches string and
6477 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6478 If the initial arguments to switch start with - then they are treated
6479 as options. The following options are currently supported:</p></div>
6480 <div class="dlist"><dl>
6481 <dt class="hdlist1">
6482 <code>-exact</code>
6483 </dt>
6484 <dd>
6486 Use exact matching when comparing string to a
6487 pattern. This is the default.
6488 </p>
6489 </dd>
6490 <dt class="hdlist1">
6491 <code>-glob</code>
6492 </dt>
6493 <dd>
6495 When matching string to the patterns, use glob-style
6496 matching (i.e. the same as implemented by the string
6497 match command).
6498 </p>
6499 </dd>
6500 <dt class="hdlist1">
6501 <code>-regexp</code>
6502 </dt>
6503 <dd>
6505 When matching string to the patterns, use regular
6506 expression matching (i.e. the same as implemented
6507 by the regexp command).
6508 </p>
6509 </dd>
6510 <dt class="hdlist1">
6511 <code>-command <em>commandname</em></code>
6512 </dt>
6513 <dd>
6515 When matching string to the patterns, use the given command, which
6516 must be a single word. The command is invoked as
6517 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6518 and must return 1 if matched, or 0 if not.
6519 </p>
6520 </dd>
6521 <dt class="hdlist1">
6522 <code>--</code>
6523 </dt>
6524 <dd>
6526 Marks the end of options. The argument following
6527 this one will be treated as string even if it starts
6528 with a <code>-</code>.
6529 </p>
6530 </dd>
6531 </dl></div>
6532 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6533 first uses a separate argument for each of the patterns and commands;
6534 this form is convenient if substitutions are desired on some of the
6535 patterns or commands. The second form places all of the patterns
6536 and commands together into a single argument; the argument must
6537 have proper list structure, with the elements of the list being the
6538 patterns and commands. The second form makes it easy to construct
6539 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6540 make it unnecessary to include a backslash at the end of each line.
6541 Since the pattern arguments are in braces in the second form, no
6542 command or variable substitutions are performed on them; this makes
6543 the behaviour of the second form different than the first form in
6544 some cases.</p></div>
6545 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6546 pattern should also be used as the body for this pattern (if the
6547 next pattern also has a body of <code>-</code> then the body after that is
6548 used, and so on). This feature makes it possible to share a single
6549 body among several patterns.</p></div>
6550 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6551 <div class="literalblock">
6552 <div class="content">
6553 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6554 </div></div>
6555 <div class="paragraph"><p>will return 2,</p></div>
6556 <div class="literalblock">
6557 <div class="content">
6558 <pre><code>switch -regexp aaab {
6559 ^a.*b$ -
6560 b {format 1}
6561 a* {format 2}
6562 default {format 3}
6563 }</code></pre>
6564 </div></div>
6565 <div class="paragraph"><p>will return 1, and</p></div>
6566 <div class="literalblock">
6567 <div class="content">
6568 <pre><code>switch xyz {
6570 b {format 1}
6571 a* {format 2}
6572 default {format 3}
6573 }</code></pre>
6574 </div></div>
6575 <div class="paragraph"><p>will return 3.</p></div>
6576 </div>
6577 <div class="sect2">
6578 <h3 id="_tailcall">tailcall</h3>
6579 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6580 <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
6581 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6582 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6583 <div class="literalblock">
6584 <div class="content">
6585 <pre><code>tailcall a b c</code></pre>
6586 </div></div>
6587 <div class="literalblock">
6588 <div class="content">
6589 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6590 </div></div>
6591 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6592 <div class="literalblock">
6593 <div class="content">
6594 <pre><code>proc a {cmd args} {
6595 tailcall sub_$cmd {*}$args
6597 proc sub_cmd1 ...
6598 proc sub_cmd2 ...</code></pre>
6599 </div></div>
6600 </div>
6601 <div class="sect2">
6602 <h3 id="_tell">tell</h3>
6603 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6604 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6605 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6606 <code><em>fileId</em></code>.</p></div>
6607 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6608 <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
6609 of the standard I/O channels.</p></div>
6610 </div>
6611 <div class="sect2">
6612 <h3 id="_throw">throw</h3>
6613 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6614 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6615 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6616 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6617 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>
6618 </div>
6619 <div class="sect2">
6620 <h3 id="_time">time</h3>
6621 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6622 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6623 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6624 specified). It will then return a string of the form</p></div>
6625 <div class="literalblock">
6626 <div class="content">
6627 <pre><code>503 microseconds per iteration</code></pre>
6628 </div></div>
6629 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6630 in microseconds.</p></div>
6631 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6632 </div>
6633 <div class="sect2">
6634 <h3 id="_try">try</h3>
6635 <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>
6636 <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>
6637 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6638 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6639 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6640 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6641 section. For example a normal <code>JIM_ERR</code> error will be matched by
6642 an <em>on error</em> handler.</p></div>
6643 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6644 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6645 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6646 in which case the result is this new exception.</p></div>
6647 <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.)
6648 or as integers.</p></div>
6649 <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
6650 the matching handler.</p></div>
6651 <div class="paragraph"><p>For example:</p></div>
6652 <div class="literalblock">
6653 <div class="content">
6654 <pre><code>set f [open input]
6655 try -signal {
6656 process $f
6657 } on {continue break} {} {
6658 error "Unexpected break/continue"
6659 } on error {msg opts} {
6660 puts "Dealing with error"
6661 return {*}$opts $msg
6662 } on signal sig {
6663 puts "Got signal: $sig"
6664 } finally {
6665 $f close
6666 }</code></pre>
6667 </div></div>
6668 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6669 handler.</p></div>
6670 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6671 <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>
6672 </div>
6673 <div class="sect2">
6674 <h3 id="_unknown">unknown</h3>
6675 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6676 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6677 invoke it if it does exist.</p></div>
6678 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6679 is not a defined command, then Tcl checks for the existence of
6680 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6681 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6682 error.</p></div>
6683 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6684 arguments consisting of the fully-substituted name and arguments
6685 for the original non-existent command.</p></div>
6686 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6687 through library directories for a command procedure with the name
6688 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6689 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6690 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6691 change the original command slightly and then (re-)execute it.
6692 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6693 the original non-existent command.</p></div>
6694 </div>
6695 <div class="sect2">
6696 <h3 id="_unset">unset</h3>
6697 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6698 <div class="paragraph"><p>Remove variables.
6699 Each <code><em>name</em></code> is a variable name, specified in any of the
6700 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6701 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6702 element is removed without affecting the rest of the array.</p></div>
6703 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6704 index, then the entire array is deleted.</p></div>
6705 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6706 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6707 is specified. The <em>--</em> argument may be specified to stop option processing
6708 in case the variable name may be <em>-nocomplain</em>.</p></div>
6709 </div>
6710 <div class="sect2">
6711 <h3 id="_upcall">upcall</h3>
6712 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6713 <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
6714 the previous, hidden version of the same command.</p></div>
6715 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6716 </div>
6717 <div class="sect2">
6718 <h3 id="_uplevel">uplevel</h3>
6719 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6720 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6721 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6722 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6723 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6724 it gives a distance (up the procedure calling stack) to move before
6725 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6726 a number then the number gives an absolute level number. If <code><em>level</em></code>
6727 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6728 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6729 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6730 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6731 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6732 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6733 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6734 then the command will be executed in the variable context of <em>a</em>.</p></div>
6735 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6736 at top-level (only global variables will be visible).
6737 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6738 from the procedure calling stack while the command is being executed.
6739 In the above example, suppose <em>c</em> invokes the command</p></div>
6740 <div class="literalblock">
6741 <div class="content">
6742 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6743 </div></div>
6744 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6745 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6746 at level 3, as if called from <em>b</em>. If it in turn executes
6747 the command</p></div>
6748 <div class="literalblock">
6749 <div class="content">
6750 <pre><code>uplevel {set x 42}</code></pre>
6751 </div></div>
6752 <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
6753 context: the procedure 'c</em> does not appear to be on the call stack
6754 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6755 be used to obtain the level of the current procedure.</p></div>
6756 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6757 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6758 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6759 </div>
6760 <div class="sect2">
6761 <h3 id="_upvar">upvar</h3>
6762 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6763 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6764 procedure to refer to variables in an enclosing procedure call or
6765 to global variables.</p></div>
6766 <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>
6767 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6768 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6769 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6770 by that name in the procedure frame given by <code><em>level</em></code> (or at
6771 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6772 in the current procedure by the name given in the corresponding
6773 <code><em>myVar</em></code> argument.</p></div>
6774 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6775 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6776 an ordinary variable.</p></div>
6777 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6778 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6779 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6780 procedure calling and also makes it easier to build new control constructs
6781 as Tcl procedures.
6782 For example, consider the following procedure:</p></div>
6783 <div class="literalblock">
6784 <div class="content">
6785 <pre><code>proc add2 name {
6786 upvar $name x
6787 set x [expr $x+2]
6788 }</code></pre>
6789 </div></div>
6790 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6791 and it adds two to the value of that variable.
6792 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6793 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>
6794 to access the variable in the caller&#8217;s procedure frame.</p></div>
6795 </div>
6796 <div class="sect2">
6797 <h3 id="_while">while</h3>
6798 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6799 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6800 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6801 The value of the expression must be numeric; if it is non-zero
6802 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6803 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6804 again, and the process repeats until eventually <code><em>test</em></code>
6805 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6806 commands may be executed inside <code><em>body</em></code> to terminate the current
6807 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6808 commands may be executed inside <code><em>body</em></code> to cause immediate
6809 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6810 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6811 </div>
6812 </div>
6813 </div>
6814 <div class="sect1">
6815 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6816 <div class="sectionbody">
6817 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6818 what options were selected when Jim Tcl was built.</p></div>
6819 <div class="sect2">
6820 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6821 <div class="dlist"><dl>
6822 <dt class="hdlist1">
6823 <code><strong>os.fork</strong></code>
6824 </dt>
6825 <dd>
6827 Invokes <em>fork(2)</em> and returns the result.
6828 </p>
6829 </dd>
6830 <dt class="hdlist1">
6831 <code><strong>os.wait -nohang</strong> <em>pid</em></code>
6832 </dt>
6833 <dd>
6835 Invokes waitpid(2), with WNOHANG if <code>-nohang</code> is specified.
6836 Returns a list of 3 elements.
6837 </p>
6838 <div class="literalblock">
6839 <div class="content">
6840 <pre><code>{0 none 0} if -nohang is specified, and the process is still alive.</code></pre>
6841 </div></div>
6842 <div class="literalblock">
6843 <div class="content">
6844 <pre><code>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</code></pre>
6845 </div></div>
6846 <div class="literalblock">
6847 <div class="content">
6848 <pre><code>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</code></pre>
6849 </div></div>
6850 <div class="literalblock">
6851 <div class="content">
6852 <pre><code>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</code></pre>
6853 </div></div>
6854 <div class="literalblock">
6855 <div class="content">
6856 <pre><code>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</code></pre>
6857 </div></div>
6858 </dd>
6859 <dt class="hdlist1">
6860 <code><strong>os.gethostname</strong></code>
6861 </dt>
6862 <dd>
6864 Invokes <em>gethostname(3)</em> and returns the result.
6865 </p>
6866 </dd>
6867 <dt class="hdlist1">
6868 <code><strong>os.getids</strong></code>
6869 </dt>
6870 <dd>
6872 Returns the various user/group ids for the current process.
6873 </p>
6874 <div class="literalblock">
6875 <div class="content">
6876 <pre><code>jim&gt; os.getids
6877 uid 1000 euid 1000 gid 100 egid 100</code></pre>
6878 </div></div>
6879 </dd>
6880 <dt class="hdlist1">
6881 <code><strong>os.uptime</strong></code>
6882 </dt>
6883 <dd>
6885 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6886 </p>
6887 </dd>
6888 </dl></div>
6889 </div>
6890 </div>
6891 </div>
6892 <div class="sect1">
6893 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6894 <div class="sectionbody">
6895 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6896 <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>
6897 <div class="sect2">
6898 <h3 id="_aio">aio</h3>
6899 <div class="dlist"><dl>
6900 <dt class="hdlist1">
6901 <code>$handle <strong>accept</strong> ?addrvar?</code>
6902 </dt>
6903 <dd>
6905 Server socket only: Accept a connection and return stream.
6906 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
6907 in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
6908 </p>
6909 </dd>
6910 <dt class="hdlist1">
6911 <code>$handle <strong>buffering none|line|full</strong></code>
6912 </dt>
6913 <dd>
6915 Sets the buffering mode of the stream.
6916 </p>
6917 </dd>
6918 <dt class="hdlist1">
6919 <code>$handle <strong>close</strong> ?r(ead)|w(rite)?</code>
6920 </dt>
6921 <dd>
6923 Closes the stream.
6924 The two-argument form is a "half-close" on a socket. See the <code>shutdown(2)</code> man page.
6925 </p>
6926 </dd>
6927 <dt class="hdlist1">
6928 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
6929 </dt>
6930 <dd>
6932 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
6933 that many bytes will be copied. Otherwise copying continues until the end
6934 of the input file. Returns the number of bytes actually copied.
6935 </p>
6936 </dd>
6937 <dt class="hdlist1">
6938 <code>$handle <strong>eof</strong></code>
6939 </dt>
6940 <dd>
6942 Returns 1 if stream is at eof
6943 </p>
6944 </dd>
6945 <dt class="hdlist1">
6946 <code>$handle <strong>filename</strong></code>
6947 </dt>
6948 <dd>
6950 Returns the original filename associated with the handle.
6951 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
6952 </p>
6953 </dd>
6954 <dt class="hdlist1">
6955 <code>$handle <strong>flush</strong></code>
6956 </dt>
6957 <dd>
6959 Flush the stream
6960 </p>
6961 </dd>
6962 <dt class="hdlist1">
6963 <code>$handle <strong>gets</strong> <em>?var?</em></code>
6964 </dt>
6965 <dd>
6967 Read one line and return it or store it in the var
6968 </p>
6969 </dd>
6970 <dt class="hdlist1">
6971 <code>$handle <strong>isatty</strong></code>
6972 </dt>
6973 <dd>
6975 Returns 1 if the stream is a tty device.
6976 </p>
6977 </dd>
6978 <dt class="hdlist1">
6979 <code>$handle <strong>ndelay ?0|1?</strong></code>
6980 </dt>
6981 <dd>
6983 Set O_NDELAY (if arg). Returns current/new setting.
6984 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6985 Use with care.
6986 </p>
6987 </dd>
6988 <dt class="hdlist1">
6989 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
6990 </dt>
6991 <dd>
6993 Write the string, with newline unless -nonewline
6994 </p>
6995 </dd>
6996 <dt class="hdlist1">
6997 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
6998 </dt>
6999 <dd>
7001 Read and return bytes from the stream. To eof if no len.
7002 </p>
7003 </dd>
7004 <dt class="hdlist1">
7005 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
7006 </dt>
7007 <dd>
7009 Receives a message from the handle via recvfrom(2) and returns it.
7010 At most <code><em>maxlen</em></code> bytes are read.
7011 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
7012 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
7013 </p>
7014 </dd>
7015 <dt class="hdlist1">
7016 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
7017 </dt>
7018 <dd>
7020 Seeks in the stream (default <em>current</em>)
7021 </p>
7022 </dd>
7023 <dt class="hdlist1">
7024 <code>$handle <strong>sendto</strong> <em>str ?addr:?port</em></code>
7025 </dt>
7026 <dd>
7028 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
7029 This is intended for udp/dgram sockets and may give an error or behave in unintended
7030 ways for other handle types.
7031 Returns the number of bytes written.
7032 </p>
7033 </dd>
7034 <dt class="hdlist1">
7035 <code>$handle <strong>sync</strong></code>
7036 </dt>
7037 <dd>
7039 Flush the stream, then fsync(2) to commit any changes to storage.
7040 Only available on platforms that support fsync(2).
7041 </p>
7042 </dd>
7043 <dt class="hdlist1">
7044 <code>$handle <strong>tell</strong></code>
7045 </dt>
7046 <dd>
7048 Returns the current seek position
7049 </p>
7050 </dd>
7051 </dl></div>
7052 </div>
7053 <div class="sect2">
7054 <h3 id="_fconfigure">fconfigure</h3>
7055 <div class="dlist"><dl>
7056 <dt class="hdlist1">
7057 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7058 </dt>
7059 <dd>
7061 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
7062 command is supported.
7063 </p>
7064 <div class="ulist"><ul>
7065 <li>
7067 <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>
7068 </p>
7069 </li>
7070 <li>
7072 <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>
7073 </p>
7074 </li>
7075 <li>
7077 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7078 </p>
7079 </li>
7080 </ul></div>
7081 </dd>
7082 </dl></div>
7083 </div>
7084 <div class="sect2">
7085 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
7086 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
7087 If no script is given, returns the current script. If the given script is the empty, the
7088 handler is removed.</p></div>
7089 <div class="dlist"><dl>
7090 <dt class="hdlist1">
7091 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7092 </dt>
7093 <dd>
7095 Sets or returns the script for when the socket is readable.
7096 </p>
7097 </dd>
7098 <dt class="hdlist1">
7099 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7100 </dt>
7101 <dd>
7103 Sets or returns the script for when the socket is writable.
7104 </p>
7105 </dd>
7106 <dt class="hdlist1">
7107 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7108 </dt>
7109 <dd>
7111 Sets or returns the script for when oob data received.
7112 </p>
7113 </dd>
7114 </dl></div>
7115 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7116 <div class="dlist"><dl>
7117 <dt class="hdlist1">
7119 </dt>
7120 <dd>
7122 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7123 </p>
7124 </dd>
7125 </dl></div>
7126 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
7127 <div class="dlist"><dl>
7128 <dt class="hdlist1">
7129 <code><strong>after</strong> <em>ms</em></code>
7130 </dt>
7131 <dd>
7133 Sleeps for the given number of milliseconds. No events are
7134 processed during this time.
7135 </p>
7136 </dd>
7137 <dt class="hdlist1">
7138 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> <em>script ?script ...?</em></code>
7139 </dt>
7140 <dd>
7142 The scripts are concatenated and executed after the given
7143 number of milliseconds have elapsed. If <em>idle</em> is specified,
7144 the script will run the next time the event loop is processed
7145 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
7146 then removed. Returns an event id.
7147 </p>
7148 </dd>
7149 <dt class="hdlist1">
7150 <code><strong>after cancel</strong> <em>id|command</em></code>
7151 </dt>
7152 <dd>
7154 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
7155 command (script). Returns the number of milliseconds
7156 remaining until the event would have fired. Returns the
7157 empty string if no matching event is found.
7158 </p>
7159 </dd>
7160 <dt class="hdlist1">
7161 <code><strong>after info</strong> <em>?id?</em></code>
7162 </dt>
7163 <dd>
7165 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7166 events. If <code><em>id</em></code> is given, returns a list containing the
7167 associated script and either <em>timer</em> or <em>idle</em> to indicated
7168 the type of the event. An error occurs if <code><em>id</em></code> does not
7169 match an event.
7170 </p>
7171 </dd>
7172 <dt class="hdlist1">
7173 <code><strong>vwait</strong> <em>variable</em></code>
7174 </dt>
7175 <dd>
7177 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
7178 events until the named (global) variable changes or all
7179 event handlers are removed. The variable need not exist
7180 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7181 returns immediately.
7182 </p>
7183 </dd>
7184 <dt class="hdlist1">
7185 <code><strong>update ?idletasks?</strong></code>
7186 </dt>
7187 <dd>
7189 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7190 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7191 not file events.
7192 Returns once handlers have been run for all expired events.
7193 </p>
7194 </dd>
7195 </dl></div>
7196 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7197 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7198 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7199 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7200 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7201 <div class="dlist"><dl>
7202 <dt class="hdlist1">
7203 <code><strong>bgerror</strong> <em>msg</em></code>
7204 </dt>
7205 <dd>
7207 Called when an event handler script generates an error. Note that the normal command resolution
7208 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7209 global scope.
7210 </p>
7211 </dd>
7212 </dl></div>
7213 </div>
7214 <div class="sect2">
7215 <h3 id="_socket">socket</h3>
7216 <div class="paragraph"><p>Various socket types may be created.</p></div>
7217 <div class="dlist"><dl>
7218 <dt class="hdlist1">
7219 <code><strong>socket unix</strong> <em>path</em></code>
7220 </dt>
7221 <dd>
7223 A unix domain socket client.
7224 </p>
7225 </dd>
7226 <dt class="hdlist1">
7227 <code><strong>socket unix.server</strong> <em>path</em></code>
7228 </dt>
7229 <dd>
7231 A unix domain socket server.
7232 </p>
7233 </dd>
7234 <dt class="hdlist1">
7235 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7236 </dt>
7237 <dd>
7239 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7240 </p>
7241 </dd>
7242 <dt class="hdlist1">
7243 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7244 </dt>
7245 <dd>
7247 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7248 </p>
7249 </dd>
7250 <dt class="hdlist1">
7251 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7252 </dt>
7253 <dd>
7255 A UDP socket client. If the address is not specified,
7256 the client socket will be unbound and <em>sendto</em> must be used
7257 to indicated the destination.
7258 </p>
7259 </dd>
7260 <dt class="hdlist1">
7261 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7262 </dt>
7263 <dd>
7265 A UDP socket server.
7266 </p>
7267 </dd>
7268 <dt class="hdlist1">
7269 <code><strong>socket pipe</strong></code>
7270 </dt>
7271 <dd>
7273 A pipe. Note that unlike all other socket types, this command returns
7274 a list of two channels: {read write}
7275 </p>
7276 </dd>
7277 <dt class="hdlist1">
7278 <code><strong>socket pair</strong></code>
7279 </dt>
7280 <dd>
7282 A socketpair (see socketpair(2)). Like <a href="#_socket"><strong><code>socket</code></strong></a> <code>pipe</code>, this command returns
7283 a list of two channels: {s1 s2}. These channels are both readable and writable.
7284 </p>
7285 </dd>
7286 </dl></div>
7287 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7288 address.</p></div>
7289 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7290 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7291 <div class="literalblock">
7292 <div class="content">
7293 <pre><code>set f [socket stream www.google.com:80]
7294 aio.sockstream1
7295 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7296 $f gets
7297 HTTP/1.0 302 Found
7298 $f close</code></pre>
7299 </div></div>
7300 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7301 the EVENTLOOP API.</p></div>
7302 <div class="literalblock">
7303 <div class="content">
7304 <pre><code>set f [socket stream.server 80]
7305 $f readable {
7306 set client [$f accept]
7307 $client gets $buf
7309 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7310 $client close
7312 vwait done</code></pre>
7313 </div></div>
7314 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7315 <div class="olist arabic"><ol class="arabic">
7316 <li>
7318 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7319 </p>
7320 </li>
7321 <li>
7323 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7324 </p>
7325 </li>
7326 <li>
7328 A hostname
7329 </p>
7330 </li>
7331 </ol></div>
7332 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7333 also accept requests via IPv4.</p></div>
7334 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7335 which matches the socket type is used.</p></div>
7336 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7337 <div class="literalblock">
7338 <div class="content">
7339 <pre><code>lassign [socket pipe] r w</code></pre>
7340 </div></div>
7341 <div class="literalblock">
7342 <div class="content">
7343 <pre><code># Must close $w after exec
7344 exec ps &gt;@$w &amp;
7345 $w close</code></pre>
7346 </div></div>
7347 <div class="literalblock">
7348 <div class="content">
7349 <pre><code>$r readable ...</code></pre>
7350 </div></div>
7351 </div>
7352 <div class="sect2">
7353 <h3 id="_syslog">syslog</h3>
7354 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7355 <div class="paragraph"><p>This command sends message to system syslog facility with given
7356 priority. Valid priorities are:</p></div>
7357 <div class="literalblock">
7358 <div class="content">
7359 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7360 </div></div>
7361 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7362 priority of info is used.</p></div>
7363 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7364 argv0 is used as ident string. However, any of the following options
7365 may be specified before priority to control these parameters:</p></div>
7366 <div class="dlist"><dl>
7367 <dt class="hdlist1">
7368 <code><strong>-facility</strong> <em>value</em></code>
7369 </dt>
7370 <dd>
7372 Use specified facility instead of user. The following
7373 values for facility are recognized:
7374 </p>
7375 <div class="literalblock">
7376 <div class="content">
7377 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7378 uucp, local0-local7</code></pre>
7379 </div></div>
7380 </dd>
7381 <dt class="hdlist1">
7382 <code><strong>-ident</strong> <em>string</em></code>
7383 </dt>
7384 <dd>
7386 Use given string instead of argv0 variable for ident string.
7387 </p>
7388 </dd>
7389 <dt class="hdlist1">
7390 <code><strong>-options</strong> <em>integer</em></code>
7391 </dt>
7392 <dd>
7394 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7395 use numeric values of those from your system syslog.h file,
7396 because I haven&#8217;t got time to implement yet another hash
7397 table.
7398 </p>
7399 </dd>
7400 </dl></div>
7401 </div>
7402 <div class="sect2">
7403 <h3 id="cmd_3">pack: pack, unpack</h3>
7404 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7405 <div class="dlist"><dl>
7406 <dt class="hdlist1">
7407 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7408 </dt>
7409 <dd>
7411 Packs the binary representation of <code><em>value</em></code> into the variable
7412 <code><em>varName</em></code>. The value is packed according to the given type
7413 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7414 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7415 The variable is expanded if necessary.
7416 </p>
7417 </dd>
7418 <dt class="hdlist1">
7419 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7420 </dt>
7421 <dd>
7423 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7424 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7425 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7426 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7427 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7428 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7429 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7430 or the empty string for the string type.
7431 </p>
7432 </dd>
7433 </dl></div>
7434 </div>
7435 <div class="sect2">
7436 <h3 id="_binary">binary</h3>
7437 <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>
7438 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>
7439 <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>
7440 <div class="paragraph"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7441 in case of overflow.</p></div>
7442 </div>
7443 <div class="sect2">
7444 <h3 id="cmd_4">oo: class, super</h3>
7445 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7446 <div class="paragraph"><p>See the online documentation (<a href="http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/">http://jim.tcl.tk/index.html/doc/www/www/documentation/oo/</a>) for more details.</p></div>
7447 <div class="dlist"><dl>
7448 <dt class="hdlist1">
7449 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7450 </dt>
7451 <dd>
7453 Create a new class, <code><em>classname</em></code>, with the given dictionary
7454 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7455 which all newly created objects of this class are initialised with.
7456 If a list of baseclasses is given, methods and instance variables
7457 are inherited.
7458 </p>
7459 </dd>
7460 <dt class="hdlist1">
7461 <code><strong>super</strong> <em>method ?args ...?</em></code>
7462 </dt>
7463 <dd>
7465 From within a method, invokes the given method on the base class.
7466 Note that this will only call the last baseclass given.
7467 </p>
7468 </dd>
7469 </dl></div>
7470 </div>
7471 <div class="sect2">
7472 <h3 id="_tree">tree</h3>
7473 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7474 similar to that provided by tcllib ::struct::tree (<a href="http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html">http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/struct_tree.html</a>)</p></div>
7475 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7476 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7477 <div class="dlist"><dl>
7478 <dt class="hdlist1">
7479 <code><strong>tree</strong></code>
7480 </dt>
7481 <dd>
7483 Creates and returns a new tree object with a single node named "root".
7484 All operations on the tree are invoked through this object.
7485 </p>
7486 </dd>
7487 <dt class="hdlist1">
7488 <code>$tree <strong>destroy</strong></code>
7489 </dt>
7490 <dd>
7492 Destroy the tree and all it&#8217;s nodes. (Note that the tree will also
7493 be automatically garbage collected once it goes out of scope).
7494 </p>
7495 </dd>
7496 <dt class="hdlist1">
7497 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7498 </dt>
7499 <dd>
7501 Set the value for the given attribute key.
7502 </p>
7503 </dd>
7504 <dt class="hdlist1">
7505 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7506 </dt>
7507 <dd>
7509 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7510 </p>
7511 </dd>
7512 <dt class="hdlist1">
7513 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7514 </dt>
7515 <dd>
7517 Returns 1 if the given attribute key exists.
7518 </p>
7519 </dd>
7520 <dt class="hdlist1">
7521 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7522 </dt>
7523 <dd>
7525 Returns the value associated with the given attribute key.
7526 </p>
7527 </dd>
7528 <dt class="hdlist1">
7529 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7530 </dt>
7531 <dd>
7533 Returns the entire attribute dictionary associated with the given key.
7534 </p>
7535 </dd>
7536 <dt class="hdlist1">
7537 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7538 </dt>
7539 <dd>
7541 Returns the depth of the given node. The depth of "root" is 0.
7542 </p>
7543 </dd>
7544 <dt class="hdlist1">
7545 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7546 </dt>
7547 <dd>
7549 Returns the node name of the parent node, or "" for the root node.
7550 </p>
7551 </dd>
7552 <dt class="hdlist1">
7553 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7554 </dt>
7555 <dd>
7557 Returns the number of child nodes.
7558 </p>
7559 </dd>
7560 <dt class="hdlist1">
7561 <code>$tree <strong>children</strong> <em>nodename</em></code>
7562 </dt>
7563 <dd>
7565 Returns a list of the child nodes.
7566 </p>
7567 </dd>
7568 <dt class="hdlist1">
7569 <code>$tree <strong>next</strong> <em>nodename</em></code>
7570 </dt>
7571 <dd>
7573 Returns the next sibling node, or "" if none.
7574 </p>
7575 </dd>
7576 <dt class="hdlist1">
7577 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7578 </dt>
7579 <dd>
7581 Add a new child node to the given node. The index is a list index
7582 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7583 Returns the name of the newly added node.
7584 </p>
7585 </dd>
7586 <dt class="hdlist1">
7587 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7588 </dt>
7589 <dd>
7591 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7592 depth first (<code>dfs</code>).
7593 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7594 The name of each node is stored in <code><em>nodevar</em></code>.
7595 The script is evaluated twice for each node, on entry and exit.
7596 </p>
7597 </dd>
7598 <dt class="hdlist1">
7599 <code>$tree <strong>dump</strong></code>
7600 </dt>
7601 <dd>
7603 Dumps the tree contents to stdout
7604 </p>
7605 </dd>
7606 </dl></div>
7607 </div>
7608 <div class="sect2">
7609 <h3 id="_tcl_prefix">tcl::prefix</h3>
7610 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <em>tcl::prefix</em> command
7611 (<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
7612 of possible values (typically commands or options).</p></div>
7613 <div class="dlist"><dl>
7614 <dt class="hdlist1">
7615 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7616 </dt>
7617 <dd>
7619 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7620 </p>
7621 </dd>
7622 <dt class="hdlist1">
7623 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7624 </dt>
7625 <dd>
7627 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7628 </p>
7629 </dd>
7630 <dt class="hdlist1">
7631 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7632 </dt>
7633 <dd>
7635 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
7636 exactly one element, the matched element is returned. If not, the
7637 result depends on the <code>-error</code> option.
7638 </p>
7639 <div class="ulist"><ul>
7640 <li>
7642 <code><strong>-exact</strong></code> Accept only exact matches.
7643 </p>
7644 </li>
7645 <li>
7647 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
7648 </p>
7649 </li>
7650 <li>
7652 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
7653 empty, no error is generated and an empty string is returned.
7654 Otherwise the options are used as return options when
7655 generating the error message. The default corresponds to
7656 setting <code>-level 0</code>.
7657 </p>
7658 </li>
7659 </ul></div>
7660 </dd>
7661 </dl></div>
7662 </div>
7663 <div class="sect2">
7664 <h3 id="_history">history</h3>
7665 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
7666 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
7667 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
7668 the remaining subcommands do nothing.</p></div>
7669 <div class="dlist"><dl>
7670 <dt class="hdlist1">
7671 <code><strong>history load</strong> <em>filename</em></code>
7672 </dt>
7673 <dd>
7675 Load history from a (text) file. If the file does not exist or is not readable,
7676 it is ignored.
7677 </p>
7678 </dd>
7679 <dt class="hdlist1">
7680 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
7681 </dt>
7682 <dd>
7684 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
7685 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
7686 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
7687 </p>
7688 </dd>
7689 <dt class="hdlist1">
7690 <code><strong>history add</strong> <em>line</em></code>
7691 </dt>
7692 <dd>
7694 Adds the given line to the history buffer.
7695 </p>
7696 </dd>
7697 <dt class="hdlist1">
7698 <code><strong>history save</strong> <em>filename</em></code>
7699 </dt>
7700 <dd>
7702 Saves the current history buffer to the given file.
7703 </p>
7704 </dd>
7705 <dt class="hdlist1">
7706 <code><strong>history show</strong></code>
7707 </dt>
7708 <dd>
7710 Displays the current history buffer to standard output.
7711 </p>
7712 </dd>
7713 </dl></div>
7714 </div>
7715 <div class="sect2">
7716 <h3 id="_namespace">namespace</h3>
7717 <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>
7718 <div class="dlist"><dl>
7719 <dt class="hdlist1">
7720 <code><strong>namespace code</strong> <em>script</em></code>
7721 </dt>
7722 <dd>
7724 Captures the current namespace context for later execution of
7725 the script <code><em>script</em></code>. It returns a new script in which script has
7726 been wrapped in a <code><strong>namespace inscope</strong></code> command.
7727 </p>
7728 </dd>
7729 <dt class="hdlist1">
7730 <code><strong>namespace current</strong></code>
7731 </dt>
7732 <dd>
7734 Returns the fully-qualified name for the current namespace.
7735 </p>
7736 </dd>
7737 <dt class="hdlist1">
7738 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
7739 </dt>
7740 <dd>
7742 Deletes all commands and variables with the given namespace prefixes.
7743 </p>
7744 </dd>
7745 <dt class="hdlist1">
7746 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
7747 </dt>
7748 <dd>
7750 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
7751 </p>
7752 </dd>
7753 <dt class="hdlist1">
7754 <code><strong>namespace origin</strong> <em>command</em></code>
7755 </dt>
7756 <dd>
7758 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
7759 </p>
7760 </dd>
7761 <dt class="hdlist1">
7762 <code><strong>namespace parent</strong> ?namespace?</code>
7763 </dt>
7764 <dd>
7766 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
7767 for the current namespace.
7768 </p>
7769 </dd>
7770 <dt class="hdlist1">
7771 <code><strong>namespace qualifiers</strong> <em>string</em></code>
7772 </dt>
7773 <dd>
7775 Returns any leading namespace qualifiers for <code><em>string</em></code>
7776 </p>
7777 </dd>
7778 <dt class="hdlist1">
7779 <code><strong>namespace tail</strong> <em>string</em></code>
7780 </dt>
7781 <dd>
7783 Returns the simple name at the end of a qualified string.
7784 </p>
7785 </dd>
7786 <dt class="hdlist1">
7787 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
7788 </dt>
7789 <dd>
7791 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
7792 </p>
7793 </dd>
7794 <dt class="hdlist1">
7795 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
7796 </dt>
7797 <dd>
7799 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
7800 </p>
7801 </dd>
7802 </dl></div>
7803 </div>
7804 </div>
7805 </div>
7806 <div class="sect1">
7807 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
7808 <div class="sectionbody">
7809 <div class="paragraph"><p>The following global variables are created automatically
7810 by the Tcl library.</p></div>
7811 <div class="dlist"><dl>
7812 <dt class="hdlist1">
7813 <code><strong>env</strong></code>
7814 </dt>
7815 <dd>
7817 This variable is set by Jim as an array
7818 whose elements are the environment variables for the process.
7819 Reading an element will return the value of the corresponding
7820 environment variable.
7821 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
7822 It may be modified and will affect the environment passed to
7823 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
7824 </p>
7825 </dd>
7826 <dt class="hdlist1">
7827 <code><strong>platform_tcl</strong></code>
7828 </dt>
7829 <dd>
7831 This variable is set by Jim as an array containing information
7832 about the platform on which Jim was built. Currently this includes
7833 <em>os</em> and <em>platform</em>.
7834 </p>
7835 </dd>
7836 <dt class="hdlist1">
7837 <code><strong>auto_path</strong></code>
7838 </dt>
7839 <dd>
7841 This variable contains a list of paths to search for packages.
7842 It defaults to a location based on where jim is installed
7843 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
7844 or the embedding application. Note that <code>jimsh</code> will consider
7845 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
7846 list of paths to add to <code><strong>auto_path</strong></code>.
7847 </p>
7848 </dd>
7849 <dt class="hdlist1">
7850 <code><strong>errorCode</strong></code>
7851 </dt>
7852 <dd>
7854 This variable holds the value of the -errorcode return
7855 option set by the most recent error that occurred in this
7856 interpreter. This list value represents additional information
7857 about the error in a form that is easy to process with
7858 programs. The first element of the list identifies a general
7859 class of errors, and determines the format of the rest of
7860 the list. The following formats for -errorcode return options
7861 are used by the Tcl core; individual applications may define
7862 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
7863 Otherwise it will be <code>NONE</code>.
7864 </p>
7865 </dd>
7866 </dl></div>
7867 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
7868 <div class="dlist"><dl>
7869 <dt class="hdlist1">
7870 <code><strong>tcl_interactive</strong></code>
7871 </dt>
7872 <dd>
7874 This variable is set to 1 if jimsh is started in interactive mode
7875 or 0 otherwise.
7876 </p>
7877 </dd>
7878 <dt class="hdlist1">
7879 <code><strong>tcl_platform</strong></code>
7880 </dt>
7881 <dd>
7883 This variable is set by Jim as an array containing information
7884 about the platform upon which Jim was built. The following is an
7885 example of the contents of this array.
7886 </p>
7887 <div class="literalblock">
7888 <div class="content">
7889 <pre><code>tcl_platform(byteOrder) = littleEndian
7890 tcl_platform(os) = Darwin
7891 tcl_platform(platform) = unix
7892 tcl_platform(pointerSize) = 8
7893 tcl_platform(threaded) = 0
7894 tcl_platform(wordSize) = 8
7895 tcl_platform(pathSeparator) = :</code></pre>
7896 </div></div>
7897 </dd>
7898 <dt class="hdlist1">
7899 <code><strong>argv0</strong></code>
7900 </dt>
7901 <dd>
7903 If jimsh is invoked to run a script, this variable contains the name
7904 of the script.
7905 </p>
7906 </dd>
7907 <dt class="hdlist1">
7908 <code><strong>argv</strong></code>
7909 </dt>
7910 <dd>
7912 If jimsh is invoked to run a script, this variable contains a list
7913 of any arguments supplied to the script.
7914 </p>
7915 </dd>
7916 <dt class="hdlist1">
7917 <code><strong>argc</strong></code>
7918 </dt>
7919 <dd>
7921 If jimsh is invoked to run a script, this variable contains the number
7922 of arguments supplied to the script.
7923 </p>
7924 </dd>
7925 <dt class="hdlist1">
7926 <code><strong>jim::argv0</strong></code>
7927 </dt>
7928 <dd>
7930 The value of argv[0] when jimsh was invoked.
7931 </p>
7932 </dd>
7933 </dl></div>
7934 </div>
7935 </div>
7936 <div class="sect1">
7937 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
7938 <div class="sectionbody">
7939 <div class="sect2">
7940 <h3 id="_in_v0_70">In v0.70</h3>
7941 <div class="olist arabic"><ol class="arabic">
7942 <li>
7944 <code>platform_tcl()</code> settings are now automatically determined
7945 </p>
7946 </li>
7947 <li>
7949 Add aio <code>$handle filename</code>
7950 </p>
7951 </li>
7952 <li>
7954 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
7955 </p>
7956 </li>
7957 <li>
7959 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
7960 </p>
7961 </li>
7962 <li>
7964 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
7965 </p>
7966 </li>
7967 <li>
7969 Add the pure-Tcl <em>oo</em> extension
7970 </p>
7971 </li>
7972 <li>
7974 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
7975 </p>
7976 </li>
7977 <li>
7979 Unit test framework is less verbose and more Tcl-compatible
7980 </p>
7981 </li>
7982 <li>
7984 Optional UTF-8 support
7985 </p>
7986 </li>
7987 <li>
7989 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
7990 </p>
7991 </li>
7992 <li>
7994 Command line editing in interactive mode, e.g. <em>jimsh</em>
7995 </p>
7996 </li>
7997 </ol></div>
7998 </div>
7999 <div class="sect2">
8000 <h3 id="_in_v0_63">In v0.63</h3>
8001 <div class="olist arabic"><ol class="arabic">
8002 <li>
8004 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
8005 </p>
8006 </li>
8007 <li>
8009 <em>info complete</em> now uses the real parser and so is 100% accurate
8010 </p>
8011 </li>
8012 <li>
8014 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>
8015 </p>
8016 </li>
8017 <li>
8019 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
8020 </p>
8021 </li>
8022 <li>
8024 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
8025 </p>
8026 </li>
8027 <li>
8029 <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
8030 </p>
8031 </li>
8032 <li>
8034 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
8035 </p>
8036 </li>
8037 <li>
8039 udp sockets are now supported for both clients and servers.
8040 </p>
8041 </li>
8042 <li>
8044 vfork-based exec is now working correctly
8045 </p>
8046 </li>
8047 <li>
8049 Add <em>file tempfile</em>
8050 </p>
8051 </li>
8052 <li>
8054 Add <em>socket pipe</em>
8055 </p>
8056 </li>
8057 <li>
8059 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
8060 </p>
8061 </li>
8062 <li>
8064 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>
8065 </p>
8066 </li>
8067 <li>
8069 IPv6 support is now included
8070 </p>
8071 </li>
8072 <li>
8074 Add <em>string is</em>
8075 </p>
8076 </li>
8077 <li>
8079 Event handlers works better if an error occurs. eof handler has been removed.
8080 </p>
8081 </li>
8082 <li>
8084 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8085 </p>
8086 </li>
8087 <li>
8089 Command pipelines via open "|&#8230;" are now supported
8090 </p>
8091 </li>
8092 <li>
8094 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8095 </p>
8096 </li>
8097 <li>
8099 Add <em>info references</em>
8100 </p>
8101 </li>
8102 <li>
8104 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>
8105 </p>
8106 </li>
8107 <li>
8109 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
8110 </p>
8111 </li>
8112 <li>
8114 Add <em>dict keys</em>
8115 </p>
8116 </li>
8117 <li>
8119 Add support for <em>lsort -index</em>
8120 </p>
8121 </li>
8122 </ol></div>
8123 </div>
8124 <div class="sect2">
8125 <h3 id="_in_v0_62">In v0.62</h3>
8126 <div class="olist arabic"><ol class="arabic">
8127 <li>
8129 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>
8130 </p>
8131 </li>
8132 <li>
8134 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
8135 </p>
8136 </li>
8137 <li>
8139 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
8140 </p>
8141 </li>
8142 <li>
8144 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
8145 </p>
8146 </li>
8147 <li>
8149 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
8150 </p>
8151 </li>
8152 <li>
8154 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
8155 </p>
8156 </li>
8157 <li>
8159 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
8160 </p>
8161 </li>
8162 <li>
8164 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
8165 </p>
8166 </li>
8167 <li>
8169 Add support for <em>unset -nocomplain</em>
8170 </p>
8171 </li>
8172 <li>
8174 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8175 </p>
8176 </li>
8177 <li>
8179 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8180 </p>
8181 </li>
8182 <li>
8184 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8185 </p>
8186 </li>
8187 <li>
8189 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8190 </p>
8191 </li>
8192 <li>
8194 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8195 </p>
8196 </li>
8197 <li>
8199 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8200 </p>
8201 </li>
8202 <li>
8204 Add <em>file copy</em>
8205 </p>
8206 </li>
8207 <li>
8209 Add <em>try &#8230; finally</em> command
8210 </p>
8211 </li>
8212 </ol></div>
8213 </div>
8214 </div>
8215 </div>
8216 <div class="sect1">
8217 <h2 id="_licence">LICENCE</h2>
8218 <div class="sectionbody">
8219 <div class="literalblock">
8220 <div class="content">
8221 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8222 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8223 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8224 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8225 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8226 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8227 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8228 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8229 </div></div>
8230 <div class="literalblock">
8231 <div class="content">
8232 <pre><code>Redistribution and use in source and binary forms, with or without
8233 modification, are permitted provided that the following conditions
8234 are met:
8235 1. Redistributions of source code must retain the above copyright
8236 notice, this list of conditions and the following disclaimer.
8237 2. Redistributions in binary form must reproduce the above
8238 copyright notice, this list of conditions and the following
8239 disclaimer in the documentation and/or other materials
8240 provided with the distribution.</code></pre>
8241 </div></div>
8242 <div class="literalblock">
8243 <div class="content">
8244 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8245 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8246 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8247 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8248 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8249 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8250 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8251 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8252 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8253 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8254 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8255 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8256 </div></div>
8257 <div class="literalblock">
8258 <div class="content">
8259 <pre><code>The views and conclusions contained in the software and documentation
8260 are those of the authors and should not be interpreted as representing
8261 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8262 </div></div>
8263 </div>
8264 </div>
8265 </div>
8266 <div id="footnotes"><hr /></div>
8267 <div id="footer">
8268 <div id="footer-text">
8269 Last updated 2015-07-09 08:26:33 EEST
8270 </div>
8271 </div>
8272 </body>
8273 </html>