file: Better support for trailing slashes in pathnames
[jimtcl.git] / Tcl_shipped.html
blob55824a8a4e333b02d4bf4311f084c28b3c4c8607
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.78 -
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
760 jimsh --help</code></pre>
761 </div></div>
762 <div class="ulist"><div class="title">Quick Index</div><ul>
763 <li>
765 <a href="#CommandIndex">Command Reference</a>
766 </p>
767 </li>
768 <li>
770 <a href="#OperatorPrecedence">Operator Precedence</a>
771 </p>
772 </li>
773 <li>
775 <a href="#BuiltinVariables">Builtin Variables</a>
776 </p>
777 </li>
778 <li>
780 <a href="#BackslashSequences">Backslash Sequences</a>
781 </p>
782 </li>
783 </ul></div>
784 </div>
785 </div>
786 <div class="sect1">
787 <h2 id="_introduction">INTRODUCTION</h2>
788 <div class="sectionbody">
789 <div class="paragraph"><p>Jim Tcl is a small footprint reimplementation of the Tcl scripting language.
790 The core language engine is compatible with Tcl 8.5+, while implementing
791 a significant subset of the Tcl 8.6 command set, plus additional features
792 available only in Jim Tcl.</p></div>
793 <div class="paragraph"><p>Some notable differences with Tcl 8.5/8.6 are:</p></div>
794 <div class="olist arabic"><ol class="arabic">
795 <li>
797 Object-based I/O (aio), but with a Tcl-compatibility layer
798 </p>
799 </li>
800 <li>
802 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
803 </p>
804 </li>
805 <li>
807 Integers are 64bit
808 </p>
809 </li>
810 <li>
812 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
813 </p>
814 </li>
815 <li>
817 Builtin dictionary type (<a href="#_dict"><strong><code>dict</code></strong></a>) with some limitations compared to Tcl 8.6
818 </p>
819 </li>
820 <li>
822 <a href="#_env"><strong><code>env</code></strong></a> command to access environment variables
823 </p>
824 </li>
825 <li>
827 Operating system features: <a href="#cmd_1"><strong><code>os.fork</code></strong></a>, <a href="#cmd_1"><strong><code>os.uptime</code></strong></a>, <a href="#_wait"><strong><code>wait</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>
828 </p>
829 </li>
830 <li>
832 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>
833 </p>
834 </li>
835 <li>
837 Support for "static" variables in procedures
838 </p>
839 </li>
840 <li>
842 Threads and coroutines are not supported
843 </p>
844 </li>
845 <li>
847 Command and variable traces are not supported
848 </p>
849 </li>
850 <li>
852 Built-in command line editing
853 </p>
854 </li>
855 <li>
857 Expression shorthand syntax: <code>$(&#8230;)</code>
858 </p>
859 </li>
860 <li>
862 Modular build allows many features to be omitted or built as dynamic, loadable modules
863 </p>
864 </li>
865 <li>
867 Highly suitable for use in an embedded environment
868 </p>
869 </li>
870 <li>
872 Support for UDP, IPv6, Unix-Domain sockets in addition to TCP sockets
873 </p>
874 </li>
875 </ol></div>
876 </div>
877 </div>
878 <div class="sect1">
879 <h2 id="_recent_changes">RECENT CHANGES</h2>
880 <div class="sectionbody">
881 <div class="sect2">
882 <h3 id="_changes_between_0_77_and_0_78">Changes between 0.77 and 0.78</h3>
883 <div class="olist arabic"><ol class="arabic">
884 <li>
886 Add serial/tty support with <a href="#_aio"><strong><code>aio</code></strong></a> <code>tty</code>
887 </p>
888 </li>
889 <li>
891 Add support for <em>jimsh -</em>
892 </p>
893 </li>
894 <li>
896 Add hidden <em>-commands</em> option to many commands
897 </p>
898 </li>
899 <li>
901 Add scriptable autocompletion support in interactive mode with <a href="#_tcl_autocomplete"><strong><code>tcl::autocomplete</code></strong></a>
902 </p>
903 </li>
904 <li>
906 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>sockopt</code>
907 </p>
908 </li>
909 <li>
911 Add scriptable autocompletion support with <a href="#_history"><strong><code>history</code></strong></a> <code>completion</code>
912 </p>
913 </li>
914 <li>
916 Add support for <a href="#_tree"><strong><code>tree</code></strong></a> <code>delete</code>
917 </p>
918 </li>
919 <li>
921 Add support for <a href="#_defer"><strong><code>defer</code></strong></a> and <em>$jim::defer</em>
922 </p>
923 </li>
924 <li>
926 Renamed <code>os.wait</code> to <a href="#_wait"><strong><code>wait</code></strong></a>, now more Tcl-compatible and compatible with <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>
927 </p>
928 </li>
929 <li>
931 <a href="#_pipe"><strong><code>pipe</code></strong></a> is now a synonym for <a href="#_socket"><strong><code>socket</code></strong></a> <code>pipe</code>
932 </p>
933 </li>
934 <li>
936 Closing a pipe open with <a href="#_open"><strong><code>open</code></strong></a> <code>|...</code> now returns Tcl-like status
937 </p>
938 </li>
939 <li>
941 It is now possible to used <a href="#_exec"><strong><code>exec</code></strong></a> redirection with a pipe opened with <a href="#_open"><strong><code>open</code></strong></a> <code>|...</code>
942 </p>
943 </li>
944 <li>
946 Interactive line editing now supports multiline mode if $::history::multiline is set
947 </p>
948 </li>
949 </ol></div>
950 </div>
951 <div class="sect2">
952 <h3 id="_changes_between_0_76_and_0_77">Changes between 0.76 and 0.77</h3>
953 <div class="olist arabic"><ol class="arabic">
954 <li>
956 Add support for <a href="#_aio"><strong><code>aio</code></strong></a> <code>sync</code>
957 </p>
958 </li>
959 <li>
961 Add SSL and TLS support in aio
962 </p>
963 </li>
964 <li>
966 Added <a href="#_zlib"><strong><code>zlib</code></strong></a>
967 </p>
968 </li>
969 <li>
971 Added support for boolean constants in <a href="#_expr"><strong><code>expr</code></strong></a>
972 </p>
973 </li>
974 <li>
976 <a href="#_string"><strong><code>string</code></strong></a> <code>is</code> now supports <em>boolean</em> class
977 </p>
978 </li>
979 <li>
981 Add support for <a href="#_aio"><strong><code>aio</code></strong></a> <code>lock</code> and <a href="#_aio"><strong><code>aio</code></strong></a> <code>unlock</code>
982 </p>
983 </li>
984 <li>
986 Add new <a href="#_interp"><strong><code>interp</code></strong></a> command
987 </p>
988 </li>
989 </ol></div>
990 </div>
991 <div class="sect2">
992 <h3 id="_changes_between_0_75_and_0_76">Changes between 0.75 and 0.76</h3>
993 <div class="olist arabic"><ol class="arabic">
994 <li>
996 <a href="#_glob"><strong><code>glob</code></strong></a> now supports the <code>-tails</code> option
997 </p>
998 </li>
999 <li>
1001 Add support for <a href="#_string"><strong><code>string</code></strong></a> <code>cat</code>
1002 </p>
1003 </li>
1004 <li>
1006 Allow <a href="#_info"><strong><code>info</code></strong></a> <code>source</code> to add source info
1007 </p>
1008 </li>
1009 </ol></div>
1010 </div>
1011 <div class="sect2">
1012 <h3 id="_changes_between_0_74_and_0_75">Changes between 0.74 and 0.75</h3>
1013 <div class="olist arabic"><ol class="arabic">
1014 <li>
1016 <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
1017 </p>
1018 </li>
1019 <li>
1021 <a href="#_file"><strong><code>file</code></strong></a> <code>copy</code> <code>-force</code> handles source and target as the same file
1022 </p>
1023 </li>
1024 <li>
1026 <a href="#_format"><strong><code>format</code></strong></a> now supports <code>%b</code> for binary conversion
1027 </p>
1028 </li>
1029 <li>
1031 <a href="#_lsort"><strong><code>lsort</code></strong></a> now supports <code>-unique</code> and <code>-real</code>
1032 </p>
1033 </li>
1034 <li>
1036 Add support for half-close with <a href="#_aio"><strong><code>aio</code></strong></a> <code>close</code> <code>?r|w?</code>
1037 </p>
1038 </li>
1039 <li>
1041 Add <a href="#_socket"><strong><code>socket</code></strong></a> <code>pair</code> for a bidirectional pipe
1042 </p>
1043 </li>
1044 <li>
1046 Add <em>--random-hash</em> to randomise hash tables for greater security
1047 </p>
1048 </li>
1049 <li>
1051 <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>
1052 </p>
1053 </li>
1054 <li>
1056 <a href="#_file"><strong><code>file</code></strong></a> <code>stat</code> no longer requires the variable name
1057 </p>
1058 </li>
1059 <li>
1061 Add support for <a href="#_file"><strong><code>file</code></strong></a> <code>link</code>
1062 </p>
1063 </li>
1064 </ol></div>
1065 </div>
1066 <div class="sect2">
1067 <h3 id="_changes_between_0_73_and_0_74">Changes between 0.73 and 0.74</h3>
1068 <div class="olist arabic"><ol class="arabic">
1069 <li>
1071 Numbers with leading zeros are treated as decimal, not octal
1072 </p>
1073 </li>
1074 <li>
1076 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>isatty</code>
1077 </p>
1078 </li>
1079 <li>
1081 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>
1082 </p>
1083 </li>
1084 <li>
1086 <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>
1087 </p>
1088 </li>
1089 <li>
1091 <a href="#_glob"><strong><code>glob</code></strong></a> now supports <em>-directory</em>
1092 </p>
1093 </li>
1094 </ol></div>
1095 </div>
1096 <div class="sect2">
1097 <h3 id="_changes_between_0_72_and_0_73">Changes between 0.72 and 0.73</h3>
1098 <div class="olist arabic"><ol class="arabic">
1099 <li>
1101 Built-in regexp now support non-capturing parentheses: (?:&#8230;)
1102 </p>
1103 </li>
1104 <li>
1106 Add <a href="#_string"><strong><code>string</code></strong></a> <code>replace</code>
1107 </p>
1108 </li>
1109 <li>
1111 Add <a href="#_string"><strong><code>string</code></strong></a> <code>totitle</code>
1112 </p>
1113 </li>
1114 <li>
1116 Add <a href="#_info"><strong><code>info</code></strong></a> <code>statics</code>
1117 </p>
1118 </li>
1119 <li>
1121 Add <code>build-jim-ext</code> for easy separate building of loadable modules (extensions)
1122 </p>
1123 </li>
1124 <li>
1126 <a href="#_local"><strong><code>local</code></strong></a> now works with any command, not just procs
1127 </p>
1128 </li>
1129 <li>
1131 Add <a href="#_info"><strong><code>info</code></strong></a> <code>alias</code> to access the target of an alias
1132 </p>
1133 </li>
1134 <li>
1136 UTF-8 encoding past the basic multilingual plane (BMP) is supported
1137 </p>
1138 </li>
1139 <li>
1141 Add <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a>
1142 </p>
1143 </li>
1144 <li>
1146 Add <a href="#_history"><strong><code>history</code></strong></a>
1147 </p>
1148 </li>
1149 <li>
1151 Most extensions are now enabled by default
1152 </p>
1153 </li>
1154 <li>
1156 Add support for namespaces and the <a href="#_namespace"><strong><code>namespace</code></strong></a> command
1157 </p>
1158 </li>
1159 <li>
1161 Add <a href="#_apply"><strong><code>apply</code></strong></a>
1162 </p>
1163 </li>
1164 </ol></div>
1165 </div>
1166 <div class="sect2">
1167 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
1168 <div class="olist arabic"><ol class="arabic">
1169 <li>
1171 procs now allow <em>args</em> and optional parameters in any position
1172 </p>
1173 </li>
1174 <li>
1176 Add Tcl-compatible expr functions, <code>rand()</code>, <code>srand()</code> and <code>pow()</code>
1177 </p>
1178 </li>
1179 <li>
1181 Add support for the <em>-force</em> option to <a href="#_file"><strong><code>file</code></strong></a> <code>delete</code>
1182 </p>
1183 </li>
1184 <li>
1186 Better diagnostics when <a href="#_source"><strong><code>source</code></strong></a> fails to load a script with a missing quote or bracket
1187 </p>
1188 </li>
1189 <li>
1191 New <code>tcl_platform(pathSeparator)</code>
1192 </p>
1193 </li>
1194 <li>
1196 Add support settings the modification time with <a href="#_file"><strong><code>file</code></strong></a> <code>mtime</code>
1197 </p>
1198 </li>
1199 <li>
1201 <a href="#_exec"><strong><code>exec</code></strong></a> is now fully supported on win32 (mingw32)
1202 </p>
1203 </li>
1204 <li>
1206 <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
1207 </p>
1208 </li>
1209 <li>
1211 Line editing is now supported for the win32 console (mingw32)
1212 </p>
1213 </li>
1214 <li>
1216 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>listen</code> command
1217 </p>
1218 </li>
1219 </ol></div>
1220 </div>
1221 <div class="sect2">
1222 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
1223 <div class="olist arabic"><ol class="arabic">
1224 <li>
1226 Allow <em>args</em> to be renamed in procs
1227 </p>
1228 </li>
1229 <li>
1231 Add <code>$(&#8230;)</code> shorthand syntax for expressions
1232 </p>
1233 </li>
1234 <li>
1236 Add automatic reference variables in procs with <code>&amp;var</code> syntax
1237 </p>
1238 </li>
1239 <li>
1241 Support <code>jimsh --version</code>
1242 </p>
1243 </li>
1244 <li>
1246 Additional variables in <code>tcl_platform()</code>
1247 </p>
1248 </li>
1249 <li>
1251 <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
1252 </p>
1253 </li>
1254 <li>
1256 Add <a href="#_loop"><strong><code>loop</code></strong></a> command (TclX compatible)
1257 </p>
1258 </li>
1259 <li>
1261 Add <a href="#_aio"><strong><code>aio</code></strong></a> <code>buffering</code> command
1262 </p>
1263 </li>
1264 <li>
1266 <a href="#_info"><strong><code>info</code></strong></a> <code>complete</code> can now return the missing character
1267 </p>
1268 </li>
1269 <li>
1271 <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
1272 </p>
1273 </li>
1274 <li>
1276 Add <a href="#_string"><strong><code>string</code></strong></a> <code>byterange</code>
1277 </p>
1278 </li>
1279 <li>
1281 Built-in regexp now support non-greedy repetition (*?, +?, ??)
1282 </p>
1283 </li>
1284 </ol></div>
1285 </div>
1286 </div>
1287 </div>
1288 <div class="sect1">
1289 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
1290 <div class="sectionbody">
1291 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced
1292 <em><a href="http://www.oxforddictionaries.com/definition/american_english/tickle">tickle</a></em>.
1293 It is actually two things: a language and a library.</p></div>
1294 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
1295 issuing commands to interactive programs such as text editors,
1296 debuggers, illustrators, and shells. It has a simple syntax and is also
1297 programmable, so Tcl users can write command procedures to provide more
1298 powerful commands than those in the built-in set.</p></div>
1299 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
1300 programs. The Tcl library consists of a parser for the Tcl language,
1301 routines to implement the Tcl built-in commands, and procedures that
1302 allow each application to extend Tcl with additional commands specific
1303 to that application. The application program generates Tcl commands and
1304 passes them to the Tcl parser for execution. Commands may be generated
1305 by reading characters from an input source, or by associating command
1306 strings with elements of the application&#8217;s user interface, such as menu
1307 entries, buttons, or keystrokes.</p></div>
1308 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
1309 fields and executes built-in commands directly. For commands implemented
1310 by the application, Tcl calls back to the application to execute the
1311 commands. In many cases commands will invoke recursive invocations of the
1312 Tcl interpreter by passing in additional strings to execute (procedures,
1313 looping commands, and conditional commands all work in this way).</p></div>
1314 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
1315 language. First, Tcl provides a standard syntax: once users know Tcl,
1316 they will be able to issue commands easily to any Tcl-based application.
1317 Second, Tcl provides programmability. All a Tcl application needs
1318 to do is to implement a few application-specific low-level commands.
1319 Tcl provides many utility commands plus a general programming interface
1320 for building up complex command procedures. By using Tcl, applications
1321 need not re-implement these features.</p></div>
1322 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
1323 applications. Inter-application communication is not built into the
1324 Tcl core described here, but various add-on libraries, such as the Tk
1325 toolkit, allow applications to issue commands to each other. This makes
1326 it possible for applications to work together in much more powerful ways
1327 than was previously possible.</p></div>
1328 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <code>jimsh</code>, which can be
1329 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
1330 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
1331 the language syntax and the built-in commands that will be available
1332 in any application based on Tcl. The individual library procedures are
1333 described in more detail in separate manual pages, one per procedure.</p></div>
1334 </div>
1335 </div>
1336 <div class="sect1">
1337 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
1338 <div class="sectionbody">
1339 <div class="paragraph"><p>A simple, but powerful command processor, <code>jimsh</code>, is part of Jim Tcl.
1340 It may be invoked in interactive mode as:</p></div>
1341 <div class="literalblock">
1342 <div class="content">
1343 <pre><code>jimsh</code></pre>
1344 </div></div>
1345 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
1346 <div class="literalblock">
1347 <div class="content">
1348 <pre><code>jimsh filename</code></pre>
1349 </div></div>
1350 <div class="paragraph"><p>or to process the Tcl script from standard input:</p></div>
1351 <div class="literalblock">
1352 <div class="content">
1353 <pre><code>jimsh -</code></pre>
1354 </div></div>
1355 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
1356 <div class="literalblock">
1357 <div class="content">
1358 <pre><code>jimsh -e "script"</code></pre>
1359 </div></div>
1360 <div class="sect2">
1361 <h3 id="_interactive_mode">Interactive Mode</h3>
1362 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
1363 those commands and prints the results.</p></div>
1364 <div class="literalblock">
1365 <div class="content">
1366 <pre><code>$ jimsh
1367 Welcome to Jim version 0.73, Copyright (c) 2005-8 Salvatore Sanfilippo
1368 . info version
1369 0.73
1370 . lsort [info commands p*]
1371 package parray pid popen proc puts pwd
1372 . foreach i {a b c} {
1373 {&gt; puts $i
1374 {&gt; }
1378 . bad
1379 invalid command name "bad"
1380 [error] . exit
1381 $</code></pre>
1382 </div></div>
1383 <div class="paragraph"><p>If <code>jimsh</code> is configured with line editing (it is by default) and a VT-100-compatible
1384 terminal is detected, Emacs-style line editing commands are available, including:
1385 arrow keys, <code>^W</code> to erase a word, <code>^U</code> to erase the line, <code>^R</code> for reverse incremental search
1386 in history. Additionally, the <code>h</code> command may be used to display the command history.</p></div>
1387 <div class="paragraph"><p>Command line history is automatically saved and loaded from <code>~/.jim_history</code></p></div>
1388 <div class="paragraph"><p>In interactive mode, <code>jimsh</code> automatically runs the script <code>~/.jimrc</code> at startup
1389 if it exists.</p></div>
1390 </div>
1391 </div>
1392 </div>
1393 <div class="sect1">
1394 <h2 id="_interpreters">INTERPRETERS</h2>
1395 <div class="sectionbody">
1396 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
1397 An interpreter consists of a set of command bindings, a set of variable
1398 values, and a few other miscellaneous pieces of state. Each Tcl command
1399 is interpreted in the context of a particular interpreter.</p></div>
1400 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
1401 simultaneously, each associated with a different widget or portion of
1402 the application. Interpreters are relatively lightweight structures.
1403 They can be created and deleted quickly, so application programmers should
1404 feel free to use multiple interpreters if that simplifies the application.</p></div>
1405 </div>
1406 </div>
1407 <div class="sect1">
1408 <h2 id="_data_types">DATA TYPES</h2>
1409 <div class="sectionbody">
1410 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
1411 to commands, all command results, and all variable values are strings.</p></div>
1412 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
1413 the arguments and results are passed as strings. Many commands expect
1414 their string arguments to have certain formats, but this interpretation
1415 is up to the individual commands. For example, arguments often contain
1416 Tcl command strings, which may get executed as part of the commands.
1417 The easiest way to understand the Tcl interpreter is to remember that
1418 everything is just an operation on a string. In many cases Tcl constructs
1419 will look similar to more structured constructs from other languages.
1420 However, the Tcl constructs are not structured at all; they are just
1421 strings of characters, and this gives them a different behaviour than
1422 the structures they may look like.</p></div>
1423 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
1424 the interpretation, there are three common forms that strings take:
1425 commands, expressions, and lists. The major sections below discuss
1426 these three forms in more detail.</p></div>
1427 </div>
1428 </div>
1429 <div class="sect1">
1430 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
1431 <div class="sectionbody">
1432 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
1433 and Lisp. However, the interpretation of commands is different
1434 in Tcl than in either of those other two systems.
1435 A Tcl command string consists of one or more commands separated
1436 by newline characters or semi-colons.
1437 Each command consists of a collection of fields separated by
1438 white space (spaces or tabs).
1439 The first field must be the name of a command, and the
1440 additional fields, if any, are arguments that will be passed to
1441 that command. For example, the command:</p></div>
1442 <div class="literalblock">
1443 <div class="content">
1444 <pre><code>set a 22</code></pre>
1445 </div></div>
1446 <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
1447 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
1448 the <a href="#_set"><strong><code>set</code></strong></a> command. The command name may refer either to a built-in
1449 Tcl command, an application-specific command bound in with the library
1450 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
1451 <a href="#_proc"><strong><code>proc</code></strong></a> built-in command.</p></div>
1452 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1453 interpret those strings in any fashion they wish. The <a href="#_set"><strong><code>set</code></strong></a> command,
1454 for example, will treat its first argument as the name of a variable
1455 and its second argument as a string value to assign to that variable.
1456 For other commands arguments may be interpreted as integers, lists,
1457 file names, or Tcl commands.</p></div>
1458 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1459 However, if the Tcl interpreter cannot locate a command it invokes a
1460 special command named <a href="#_unknown"><strong><code>unknown</code></strong></a> which attempts to find or create the
1461 command.</p></div>
1462 <div class="paragraph"><p>For example, at many sites <a href="#_unknown"><strong><code>unknown</code></strong></a> will search through library
1463 directories for the desired command and create it as a Tcl procedure if
1464 it is found. The <a href="#_unknown"><strong><code>unknown</code></strong></a> command often provides automatic completion
1465 of abbreviated commands, but usually only for commands that were typed
1466 interactively.</p></div>
1467 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1468 other forms that will be re-used over time: changes to the command set
1469 may cause abbreviations to become ambiguous, resulting in scripts that
1470 no longer work.</p></div>
1471 </div>
1472 </div>
1473 <div class="sect1">
1474 <h2 id="_comments">COMMENTS</h2>
1475 <div class="sectionbody">
1476 <div class="paragraph"><p>If the first non-blank character in a command is <code>#</code>, then everything
1477 from the <code>#</code> up through the next newline character is treated as
1478 a comment and ignored. When comments are embedded inside nested
1479 commands (e.g. fields enclosed in braces) they must have properly-matched
1480 braces (this is necessary because when Tcl parses the top-level command
1481 it doesn&#8217;t yet know that the nested field will be used as a command so
1482 it cannot process the nested comment character as a comment).</p></div>
1483 </div>
1484 </div>
1485 <div class="sect1">
1486 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1487 <div class="sectionbody">
1488 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1489 double-quotes may be used to create arguments with embedded space.</p></div>
1490 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1491 terminated by white space (including newlines) or a semi-colon (see below
1492 for information on semi-colons); instead it ends at the next double-quote
1493 character. The double-quotes are not included in the resulting argument.
1494 For example, the command</p></div>
1495 <div class="literalblock">
1496 <div class="content">
1497 <pre><code>set a "This is a single argument"</code></pre>
1498 </div></div>
1499 <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>
1500 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1501 and backslash substitutions still occur, as described below. If the
1502 first character of a command field is not a quote, then quotes receive
1503 no special interpretation in the parsing of that field.</p></div>
1504 </div>
1505 </div>
1506 <div class="sect1">
1507 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1508 <div class="sectionbody">
1509 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1510 to quotes except for two differences. First, they nest; this makes them
1511 easier to use for complicated arguments like nested Tcl command strings.
1512 Second, the substitutions described below for commands, variables, and
1513 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1514 can be used to prevent substitutions where they are undesirable.</p></div>
1515 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1516 at the matching right brace. Tcl will strip off the outermost layer
1517 of braces and pass the information between the braces to the command
1518 without any further modification. For example, in the command</p></div>
1519 <div class="literalblock">
1520 <div class="content">
1521 <pre><code>set a {xyz a {b c d}}</code></pre>
1522 </div></div>
1523 <div class="paragraph"><p>the <a href="#_set"><strong><code>set</code></strong></a> command will receive two arguments: <em>a</em>
1524 and <em>xyz a {b c d}</em>.</p></div>
1525 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1526 not be on the same line as the starting quote or brace; in this case
1527 the newline will be included in the argument field along with any other
1528 characters up to the matching brace or quote. For example, the <a href="#_eval"><strong><code>eval</code></strong></a>
1529 command takes one argument, which is a command string; <a href="#_eval"><strong><code>eval</code></strong></a> invokes
1530 the Tcl interpreter to execute the command string. The command</p></div>
1531 <div class="literalblock">
1532 <div class="content">
1533 <pre><code>eval {
1534 set a 22
1535 set b 33
1536 }</code></pre>
1537 </div></div>
1538 <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>
1539 <div class="paragraph"><p>If the first character of a command field is not a left
1540 brace, then neither left nor right
1541 braces in the field will be treated specially (except as part of
1542 variable substitution; see below).</p></div>
1543 </div>
1544 </div>
1545 <div class="sect1">
1546 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1547 <div class="sectionbody">
1548 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1549 substitution occurs (except for fields enclosed in braces). All of the
1550 text up to the matching close bracket is treated as a Tcl command and
1551 executed immediately. Then the result of that command is substituted
1552 for the bracketed text. For example, consider the command</p></div>
1553 <div class="literalblock">
1554 <div class="content">
1555 <pre><code>set a [set b]</code></pre>
1556 </div></div>
1557 <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
1558 variable and <a href="#_set"><strong><code>set</code></strong></a> returns the contents of that variable. In this case,
1559 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1560 to the command</p></div>
1561 <div class="literalblock">
1562 <div class="content">
1563 <pre><code>set a foo</code></pre>
1564 </div></div>
1565 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1566 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1567 then the command</p></div>
1568 <div class="literalblock">
1569 <div class="content">
1570 <pre><code>set a xyz[set b].[set c]</code></pre>
1571 </div></div>
1572 <div class="paragraph"><p>is equivalent to the command</p></div>
1573 <div class="literalblock">
1574 <div class="content">
1575 <pre><code>set a xyzfoo.gorp</code></pre>
1576 </div></div>
1577 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1578 or semi-colons in the usual fashion. In this case the value of the last
1579 command is used for substitution. For example, the command</p></div>
1580 <div class="literalblock">
1581 <div class="content">
1582 <pre><code>set a x[set b 22
1583 expr $b+2]x</code></pre>
1584 </div></div>
1585 <div class="paragraph"><p>is equivalent to the command</p></div>
1586 <div class="literalblock">
1587 <div class="content">
1588 <pre><code>set a x24x</code></pre>
1589 </div></div>
1590 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1591 between them are not interpreted specially; they are passed through to
1592 the argument verbatim.</p></div>
1593 </div>
1594 </div>
1595 <div class="sect1">
1596 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1597 <div class="sectionbody">
1598 <div class="paragraph"><p>The dollar sign (<code>$</code>) may be used as a special shorthand form for
1599 substituting variable values. If <code>$</code> appears in an argument that isn&#8217;t
1600 enclosed in braces then variable substitution will occur. The characters
1601 after the <code>$</code>, up to the first character that isn&#8217;t a number, letter,
1602 or underscore, are taken as a variable name and the string value of that
1603 variable is substituted for the name.</p></div>
1604 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1605 <div class="literalblock">
1606 <div class="content">
1607 <pre><code>set a $foo.c</code></pre>
1608 </div></div>
1609 <div class="paragraph"><p>is equivalent to the command</p></div>
1610 <div class="literalblock">
1611 <div class="content">
1612 <pre><code>set a test.c</code></pre>
1613 </div></div>
1614 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1615 character after the name of the variable is an open parenthesis, then
1616 the variable is assumed to be an array name, and all of the characters
1617 between the open parenthesis and the next close parenthesis are taken as
1618 an index into the array. Command substitutions and variable substitutions
1619 are performed on the information between the parentheses before it is
1620 used as an index.</p></div>
1621 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1622 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1623 then the command</p></div>
1624 <div class="literalblock">
1625 <div class="content">
1626 <pre><code>set a xyz$x(first)zyx</code></pre>
1627 </div></div>
1628 <div class="paragraph"><p>is equivalent to the command</p></div>
1629 <div class="literalblock">
1630 <div class="content">
1631 <pre><code>set a xyz87zyx</code></pre>
1632 </div></div>
1633 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1634 <div class="literalblock">
1635 <div class="content">
1636 <pre><code>set a xyz$x($index)zyx</code></pre>
1637 </div></div>
1638 <div class="paragraph"><p>is equivalent to the command</p></div>
1639 <div class="literalblock">
1640 <div class="content">
1641 <pre><code>set a xyzmorezyx</code></pre>
1642 </div></div>
1643 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1644 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1645 followed by an open curly brace. In this case the variable name consists
1646 of all the characters up to the next curly brace.</p></div>
1647 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1648 is assumed to refer to a scalar variable. For example, if variable
1649 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1650 <div class="literalblock">
1651 <div class="content">
1652 <pre><code>set a abc${foo}bar</code></pre>
1653 </div></div>
1654 <div class="paragraph"><p>is equivalent to the command</p></div>
1655 <div class="literalblock">
1656 <div class="content">
1657 <pre><code>set a abctestbar</code></pre>
1658 </div></div>
1659 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1660 braces: the dollar sign and variable name are passed through to the
1661 argument verbatim.</p></div>
1662 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <code>$a</code> is
1663 completely equivalent to <code>[set a]</code>; it is provided as a convenience
1664 to reduce typing.</p></div>
1665 </div>
1666 </div>
1667 <div class="sect1">
1668 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1669 <div class="sectionbody">
1670 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1671 newline character). However, semi-colon (<code>;</code>) is treated as a command
1672 separator character; multiple commands may be placed on one line by
1673 separating them with a semi-colon. Semi-colons are not treated as
1674 command separators if they appear within curly braces or double-quotes.</p></div>
1675 </div>
1676 </div>
1677 <div class="sect1">
1678 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1679 <div class="sectionbody">
1680 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1681 fields and also to insert special characters like braces and brackets
1682 into fields without them being interpreted specially as described above.</p></div>
1683 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1684 listed below. In each case, the backslash
1685 sequence is replaced by the given character:</p></div>
1686 <div class="dlist" id="BackslashSequences"><dl>
1687 <dt class="hdlist1">
1688 <code>\b</code>
1689 </dt>
1690 <dd>
1692 Backspace (0x8)
1693 </p>
1694 </dd>
1695 <dt class="hdlist1">
1696 <code>\f</code>
1697 </dt>
1698 <dd>
1700 Form feed (0xc)
1701 </p>
1702 </dd>
1703 <dt class="hdlist1">
1704 <code>\n</code>
1705 </dt>
1706 <dd>
1708 Newline (0xa)
1709 </p>
1710 </dd>
1711 <dt class="hdlist1">
1712 <code>\r</code>
1713 </dt>
1714 <dd>
1716 Carriage-return (0xd).
1717 </p>
1718 </dd>
1719 <dt class="hdlist1">
1720 <code>\t</code>
1721 </dt>
1722 <dd>
1724 Tab (0x9).
1725 </p>
1726 </dd>
1727 <dt class="hdlist1">
1728 <code>\v</code>
1729 </dt>
1730 <dd>
1732 Vertical tab (0xb).
1733 </p>
1734 </dd>
1735 <dt class="hdlist1">
1736 <code>\{</code>
1737 </dt>
1738 <dd>
1740 Left brace ({).
1741 </p>
1742 </dd>
1743 <dt class="hdlist1">
1744 <code>\}</code>
1745 </dt>
1746 <dd>
1748 Right brace (}).
1749 </p>
1750 </dd>
1751 <dt class="hdlist1">
1752 <code>\[</code>
1753 </dt>
1754 <dd>
1756 Open bracket ([).
1757 </p>
1758 </dd>
1759 <dt class="hdlist1">
1760 <code>\]</code>
1761 </dt>
1762 <dd>
1764 Close bracket (]).
1765 </p>
1766 </dd>
1767 <dt class="hdlist1">
1768 <code>\$</code>
1769 </dt>
1770 <dd>
1772 Dollar sign ($).
1773 </p>
1774 </dd>
1775 <dt class="hdlist1">
1776 <code>\&lt;space&gt;</code>
1777 </dt>
1778 <dd>
1780 Space ( ): doesn&#8217;t terminate argument.
1781 </p>
1782 </dd>
1783 <dt class="hdlist1">
1784 <code>\;</code>
1785 </dt>
1786 <dd>
1788 Semi-colon: doesn&#8217;t terminate command.
1789 </p>
1790 </dd>
1791 <dt class="hdlist1">
1792 <code>\"</code>
1793 </dt>
1794 <dd>
1796 Double-quote.
1797 </p>
1798 </dd>
1799 <dt class="hdlist1">
1800 <code>\&lt;newline&gt;</code>
1801 </dt>
1802 <dd>
1804 Nothing: this joins two lines together
1805 into a single line. This backslash feature is unique in that
1806 it will be applied even when the sequence occurs within braces.
1807 </p>
1808 </dd>
1809 <dt class="hdlist1">
1810 <code>\\</code>
1811 </dt>
1812 <dd>
1814 Backslash (<em>\</em>).
1815 </p>
1816 </dd>
1817 <dt class="hdlist1">
1818 <code>\ddd</code>
1819 </dt>
1820 <dd>
1822 The digits <code><em>ddd</em></code> (one, two, or three of them) give the octal value of
1823 the character. Note that Jim supports null characters in strings.
1824 </p>
1825 </dd>
1826 <dt class="hdlist1">
1827 <code>\unnnn</code>
1828 </dt>
1829 <dt class="hdlist1">
1830 <code>\u{nnn}</code>
1831 </dt>
1832 <dt class="hdlist1">
1833 <code>\Unnnnnnnn</code>
1834 </dt>
1835 <dd>
1837 The UTF-8 encoding of the unicode codepoint represented by the hex digits, <code><em>nnnn</em></code>, is inserted.
1838 The <em>u</em> form allows for one to four hex digits.
1839 The <em>U</em> form allows for one to eight hex digits.
1840 The <em>u{nnn}</em> form allows for one to eight hex digits, but makes it easier to insert
1841 characters UTF-8 characters which are followed by a hex digit.
1842 </p>
1843 </dd>
1844 </dl></div>
1845 <div class="paragraph"><p>For example, in the command</p></div>
1846 <div class="literalblock">
1847 <div class="content">
1848 <pre><code>set a \{x\[\ yz\141</code></pre>
1849 </div></div>
1850 <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>
1851 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1852 described above, then the backslash is transmitted to the argument
1853 field without any special processing, and the Tcl scanner continues
1854 normal processing with the next character. For example, in the
1855 command</p></div>
1856 <div class="literalblock">
1857 <div class="content">
1858 <pre><code>set \*a \\\{foo</code></pre>
1859 </div></div>
1860 <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
1861 argument will be <code>\{foo</code>.</p></div>
1862 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1863 the argument are parsed but no substitution occurs (except for
1864 backslash-newline): the backslash
1865 sequence is passed through to the argument as is, without making
1866 any special interpretation of the characters in the backslash sequence.
1867 In particular, backslashed braces are not counted in locating the
1868 matching right brace that terminates the argument.
1869 For example, in the
1870 command</p></div>
1871 <div class="literalblock">
1872 <div class="content">
1873 <pre><code>set a {\{abc}</code></pre>
1874 </div></div>
1875 <div class="paragraph"><p>the second argument to <a href="#_set"><strong><code>set</code></strong></a> will be <code>\{abc</code>.</p></div>
1876 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1877 any argument structure; it only covers the
1878 most common cases. To produce particularly complicated arguments
1879 it is probably easiest to use the <a href="#_format"><strong><code>format</code></strong></a> command along with
1880 command substitution.</p></div>
1881 </div>
1882 </div>
1883 <div class="sect1">
1884 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1885 <div class="sectionbody">
1886 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1887 specify a position in the string relative to the start or end of the string/list.</p></div>
1888 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1889 <div class="dlist"><dl>
1890 <dt class="hdlist1">
1891 <code>integer</code>
1892 </dt>
1893 <dd>
1895 A simple integer, where <em>0</em> refers to the first element of the string
1896 or list.
1897 </p>
1898 </dd>
1899 <dt class="hdlist1">
1900 <code>integer+integer</code> or
1901 </dt>
1902 <dt class="hdlist1">
1903 <code>integer-integer</code>
1904 </dt>
1905 <dd>
1907 The sum or difference of the two integers. e.g. <code>2+3</code> refers to the 5th element.
1908 This is useful when used with (e.g.) <code>$i+1</code> rather than the more verbose
1909 <code>[expr {$i+1}]</code>
1910 </p>
1911 </dd>
1912 <dt class="hdlist1">
1913 <code>end</code>
1914 </dt>
1915 <dd>
1917 The last element of the string or list.
1918 </p>
1919 </dd>
1920 <dt class="hdlist1">
1921 <code>end-integer</code>
1922 </dt>
1923 <dd>
1925 The <em>nth-from-last</em> element of the string or list.
1926 </p>
1927 </dd>
1928 </dl></div>
1929 </div>
1930 </div>
1931 <div class="sect1">
1932 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1933 <div class="sectionbody">
1934 <div class="olist arabic"><ol class="arabic">
1935 <li>
1937 A command is just a string.
1938 </p>
1939 </li>
1940 <li>
1942 Within a string commands are separated by newlines or semi-colons
1943 (unless the newline or semi-colon is within braces or brackets
1944 or is backslashed).
1945 </p>
1946 </li>
1947 <li>
1949 A command consists of fields. The first field is the name of the command.
1950 The other fields are strings that are passed to that command as arguments.
1951 </p>
1952 </li>
1953 <li>
1955 Fields are normally separated by white space.
1956 </p>
1957 </li>
1958 <li>
1960 Double-quotes allow white space and semi-colons to appear within
1961 a single argument.
1962 Command substitution, variable substitution, and backslash substitution
1963 still occur inside quotes.
1964 </p>
1965 </li>
1966 <li>
1968 Braces defer interpretation of special characters.
1969 If a field begins with a left brace, then it consists of everything
1970 between the left brace and the matching right brace. The
1971 braces themselves are not included in the argument.
1972 No further processing is done on the information between the braces
1973 except that backslash-newline sequences are eliminated.
1974 </p>
1975 </li>
1976 <li>
1978 If a field doesn&#8217;t begin with a brace then backslash,
1979 variable, and command substitution are done on the field. Only a
1980 single level of processing is done: the results of one substitution
1981 are not scanned again for further substitutions or any other
1982 special treatment. Substitution can
1983 occur on any field of a command, including the command name
1984 as well as the arguments.
1985 </p>
1986 </li>
1987 <li>
1989 If the first non-blank character of a command is a <code>#</code>, everything
1990 from the <code>#</code> up through the next newline is treated as a comment
1991 and ignored.
1992 </p>
1993 </li>
1994 </ol></div>
1995 </div>
1996 </div>
1997 <div class="sect1">
1998 <h2 id="_expressions">EXPRESSIONS</h2>
1999 <div class="sectionbody">
2000 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
2001 as expressions. Several commands, such as <a href="#_expr"><strong><code>expr</code></strong></a>, <a href="#_for"><strong><code>for</code></strong></a>,
2002 and <a href="#_if"><strong><code>if</code></strong></a>, treat one or more of their arguments as expressions
2003 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
2004 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
2005 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
2006 the operators permitted in C expressions, and they have the
2007 same meaning and precedence as the corresponding C operators.
2008 Expressions almost always yield numeric results
2009 (integer or floating-point values).
2010 For example, the expression</p></div>
2011 <div class="literalblock">
2012 <div class="content">
2013 <pre><code>8.2 + 6</code></pre>
2014 </div></div>
2015 <div class="paragraph"><p>evaluates to 14.2.</p></div>
2016 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
2017 operands are specified, and in that Tcl expressions support
2018 non-numeric operands and string comparisons.</p></div>
2019 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
2020 and parentheses.</p></div>
2021 <div class="paragraph"><p>White space may be used between the operands and operators and
2022 parentheses; it is ignored by the expression processor.
2023 Where possible, operands are interpreted as integer values.</p></div>
2024 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case) or in
2025 hexadecimal (if the first two characters of the operand are <em>0x</em>).
2026 Note that Jim Tcl does <strong>not</strong> treat numbers with leading zeros as octal.</p></div>
2027 <div class="paragraph"><p>If an operand does not have one of the integer formats given
2028 above, then it is treated as a floating-point number if that is
2029 possible. Floating-point numbers may be specified in any of the
2030 ways accepted by an ANSI-compliant C compiler (except that the
2031 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
2032 most installations). For example, all of the
2033 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
2034 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
2035 as a string (and only a limited set of operators may be applied to
2036 it).</p></div>
2037 <div class="paragraph"><p>String constants representing boolean constants
2038 (<code><em>0</em></code>, <code><em>1</em></code>, <code><em>false</em></code>, <code><em>off</em></code>, <code><em>no</em></code>, <code><em>true</em></code>, <code><em>on</em></code>, <code><em>yes</em></code>)
2039 are also recognized and can be used in logical operations.</p></div>
2040 <div class="olist arabic"><ol class="arabic">
2041 <li>
2043 Operands may be specified in any of the following ways:
2044 </p>
2045 </li>
2046 <li>
2048 As a numeric value, either integer or floating-point.
2049 </p>
2050 </li>
2051 <li>
2053 As one of valid boolean constants
2054 </p>
2055 </li>
2056 <li>
2058 As a Tcl variable, using standard <em>$</em> notation.
2059 The variable&#8217;s value will be used as the operand.
2060 </p>
2061 </li>
2062 <li>
2064 As a string enclosed in double-quotes.
2065 The expression parser will perform backslash, variable, and
2066 command substitutions on the information between the quotes,
2067 and use the resulting value as the operand
2068 </p>
2069 </li>
2070 <li>
2072 As a string enclosed in braces.
2073 The characters between the open brace and matching close brace
2074 will be used as the operand without any substitutions.
2075 </p>
2076 </li>
2077 <li>
2079 As a Tcl command enclosed in brackets.
2080 The command will be executed and its result will be used as
2081 the operand.
2082 </p>
2083 </li>
2084 </ol></div>
2085 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
2086 are performed by the expression processor.
2087 However, an additional layer of substitution may already have
2088 been performed by the command parser before the expression
2089 processor was called.</p></div>
2090 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
2091 in braces to prevent the command parser from performing substitutions
2092 on the contents.</p></div>
2093 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
2094 the value 3 and the variable <em>b</em> has the value 6. Then the expression
2095 on the left side of each of the lines below will evaluate to the value
2096 on the right side of the line:</p></div>
2097 <div class="literalblock">
2098 <div class="content">
2099 <pre><code>$a + 3.1 6.1
2100 2 + "$a.$b" 5.6
2101 4*[llength "6 2"] 8
2102 {word one} &lt; "word $a" 0</code></pre>
2103 </div></div>
2104 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
2105 of precedence:</p></div>
2106 <div class="dlist" id="OperatorPrecedence"><dl>
2107 <dt class="hdlist1">
2108 <code>int() double() round() abs(), rand(), srand()</code>
2109 </dt>
2110 <dd>
2112 Unary functions (except rand() which takes no arguments)
2113 </p>
2114 <div class="ulist"><ul>
2115 <li>
2117 <code><em>int()</em></code> converts the numeric argument to an integer by truncating down.
2118 </p>
2119 </li>
2120 <li>
2122 <code><em>double()</em></code> converts the numeric argument to floating point.
2123 </p>
2124 </li>
2125 <li>
2127 <code><em>round()</em></code> converts the numeric argument to the closest integer value.
2128 </p>
2129 </li>
2130 <li>
2132 <code><em>abs()</em></code> takes the absolute value of the numeric argument.
2133 </p>
2134 </li>
2135 <li>
2137 <code><em>rand()</em></code> returns a pseudo-random floating-point value in the range (0,1).
2138 </p>
2139 </li>
2140 <li>
2142 <code><em>srand()</em></code> takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
2143 </p>
2144 </li>
2145 </ul></div>
2146 </dd>
2147 <dt class="hdlist1">
2148 <code>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</code>
2149 </dt>
2150 <dd>
2152 Unary math functions.
2153 If Jim is compiled with math support, these functions are available.
2154 </p>
2155 </dd>
2156 <dt class="hdlist1">
2157 <code>- + ~ !</code>
2158 </dt>
2159 <dd>
2161 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
2162 may be applied to string operands, and bit-wise NOT may be
2163 applied only to integers.
2164 </p>
2165 </dd>
2166 <dt class="hdlist1">
2167 <code>** pow(x,y)</code>
2168 </dt>
2169 <dd>
2171 Power. e.g. <em>x<sup>y</sup></em>. If Jim is compiled with math support, supports doubles and
2172 integers. Otherwise supports integers only. (Note that the math-function form
2173 has the same highest precedence)
2174 </p>
2175 </dd>
2176 <dt class="hdlist1">
2177 <code>* / %</code>
2178 </dt>
2179 <dd>
2181 Multiply, divide, remainder. None of these operands may be
2182 applied to string operands, and remainder may be applied only
2183 to integers.
2184 </p>
2185 </dd>
2186 <dt class="hdlist1">
2187 <code>+ -</code>
2188 </dt>
2189 <dd>
2191 Add and subtract. Valid for any numeric operands.
2192 </p>
2193 </dd>
2194 <dt class="hdlist1">
2195 <code>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</code>
2196 </dt>
2197 <dd>
2199 Left and right shift, left and right rotate. Valid for integer operands only.
2200 </p>
2201 </dd>
2202 <dt class="hdlist1">
2203 <code>&lt; &gt; &lt;= &gt;=</code>
2204 </dt>
2205 <dd>
2207 Boolean less, greater, less than or equal, and greater than or equal.
2208 Each operator produces 1 if the condition is true, 0 otherwise.
2209 These operators may be applied to strings as well as numeric operands,
2210 in which case string comparison is used.
2211 </p>
2212 </dd>
2213 <dt class="hdlist1">
2214 <code>== !=</code>
2215 </dt>
2216 <dd>
2218 Boolean equal and not equal. Each operator produces a zero/one result.
2219 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
2220 if possible, then floating point types, and finally strings will be compared.
2221 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
2222 </p>
2223 </dd>
2224 <dt class="hdlist1">
2225 <code>eq ne</code>
2226 </dt>
2227 <dd>
2229 String equal and not equal. Uses the string value directly without
2230 attempting to convert to a number first.
2231 </p>
2232 </dd>
2233 <dt class="hdlist1">
2234 <code>in ni</code>
2235 </dt>
2236 <dd>
2238 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
2239 is contained in the right operand (as a list), or 0 otherwise. The result for
2240 <code>{$a ni $list}</code> is equivalent to <code>{!($a in $list)}</code>.
2241 </p>
2242 </dd>
2243 <dt class="hdlist1">
2244 <code>&amp;</code>
2245 </dt>
2246 <dd>
2248 Bit-wise AND. Valid for integer operands only.
2249 </p>
2250 </dd>
2251 <dt class="hdlist1">
2252 <code>|</code>
2253 </dt>
2254 <dd>
2256 Bit-wise OR. Valid for integer operands only.
2257 </p>
2258 </dd>
2259 <dt class="hdlist1">
2260 <code>^</code>
2261 </dt>
2262 <dd>
2264 Bit-wise exclusive OR. Valid for integer operands only.
2265 </p>
2266 </dd>
2267 <dt class="hdlist1">
2268 <code>&amp;&amp;</code>
2269 </dt>
2270 <dd>
2272 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
2273 Valid for numeric operands only (integers or floating-point).
2274 </p>
2275 </dd>
2276 <dt class="hdlist1">
2277 <code>||</code>
2278 </dt>
2279 <dd>
2281 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
2282 Valid for numeric operands only (integers or floating-point).
2283 </p>
2284 </dd>
2285 <dt class="hdlist1">
2286 <code>x ? y : z</code>
2287 </dt>
2288 <dd>
2290 If-then-else, as in C. If <code><em>x</em></code>
2291 evaluates to non-zero, then the result is the value of <code><em>y</em></code>.
2292 Otherwise the result is the value of <code><em>z</em></code>.
2293 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
2294 be of any type.
2295 </p>
2296 </dd>
2297 </dl></div>
2298 <div class="paragraph"><p>See the C manual for more details on the results
2299 produced by each operator.
2300 All of the binary operators group left-to-right within the same
2301 precedence level. For example, the expression</p></div>
2302 <div class="literalblock">
2303 <div class="content">
2304 <pre><code>4*2 &lt; 7</code></pre>
2305 </div></div>
2306 <div class="paragraph"><p>evaluates to 0.</p></div>
2307 <div class="paragraph"><p>The <code>&amp;&amp;</code>, <code>||</code>, and <code>?:</code> operators have <em>lazy evaluation</em>, just as
2308 in C, which means that operands are not evaluated if they are not
2309 needed to determine the outcome. For example, in</p></div>
2310 <div class="literalblock">
2311 <div class="content">
2312 <pre><code>$v ? [a] : [b]</code></pre>
2313 </div></div>
2314 <div class="paragraph"><p>only one of <code>[a]</code> or <code>[b]</code> will actually be evaluated,
2315 depending on the value of <code>$v</code>.</p></div>
2316 <div class="paragraph"><p>All internal computations involving integers are done with the C
2317 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
2318 computations involving floating-point are done with the C type
2319 <em>double</em>.</p></div>
2320 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
2321 detected and results in a Tcl error.
2322 For conversion to integer from string, detection of overflow depends
2323 on the behaviour of some routines in the local C library, so it should
2324 be regarded as unreliable.
2325 In any case, overflow and underflow are generally not detected
2326 reliably for intermediate results.</p></div>
2327 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
2328 string operands is done automatically as needed.
2329 For arithmetic computations, integers are used until some
2330 floating-point number is introduced, after which floating-point is used.
2331 For example,</p></div>
2332 <div class="literalblock">
2333 <div class="content">
2334 <pre><code>5 / 4</code></pre>
2335 </div></div>
2336 <div class="paragraph"><p>yields the result 1, while</p></div>
2337 <div class="literalblock">
2338 <div class="content">
2339 <pre><code>5 / 4.0
2340 5 / ( [string length "abcd"] + 0.0 )</code></pre>
2341 </div></div>
2342 <div class="paragraph"><p>both yield the result 1.25.</p></div>
2343 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
2344 although the expression evaluator tries to do comparisons as integer
2345 or floating-point when it can.
2346 If one of the operands of a comparison is a string and the other
2347 has a numeric value, the numeric operand is converted back to
2348 a string using the C <em>sprintf</em> format specifier
2349 <em>%d</em> for integers and <em>%g</em> for floating-point values.
2350 For example, the expressions</p></div>
2351 <div class="literalblock">
2352 <div class="content">
2353 <pre><code>"0x03" &gt; "2"
2354 "0y" &lt; "0x12"</code></pre>
2355 </div></div>
2356 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
2357 comparison, and the second is done using string comparison after
2358 the second operand is converted to the string <em>18</em>.</p></div>
2359 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
2360 entering it in a command: otherwise, if the expression contains
2361 any white space then the Tcl interpreter will split it
2362 among several arguments. For example, the command</p></div>
2363 <div class="literalblock">
2364 <div class="content">
2365 <pre><code>expr $a + $b</code></pre>
2366 </div></div>
2367 <div class="paragraph"><p>results in three arguments being passed to <a href="#_expr"><strong><code>expr</code></strong></a>: <code>$a</code>,
2368 +, and <code>$b</code>. In addition, if the expression isn&#8217;t in braces
2369 then the Tcl interpreter will perform variable and command substitution
2370 immediately (it will happen in the command parser rather than in
2371 the expression parser). In many cases the expression is being
2372 passed to a command that will evaluate the expression later (or
2373 even many times if, for example, the expression is to be used to
2374 decide when to exit a loop). Usually the desired goal is to re-do
2375 the variable or command substitutions each time the expression is
2376 evaluated, rather than once and for all at the beginning. For example,
2377 the command</p></div>
2378 <div class="literalblock">
2379 <div class="content">
2380 <pre><code>for {set i 1} $i&lt;=10 {incr i} {...} ** WRONG **</code></pre>
2381 </div></div>
2382 <div class="paragraph"><p>is probably intended to iterate over all values of <code>i</code> from 1 to 10.
2383 After each iteration of the body of the loop, <a href="#_for"><strong><code>for</code></strong></a> will pass
2384 its second argument to the expression evaluator to see whether or not
2385 to continue processing. Unfortunately, in this case the value of <code>i</code>
2386 in the second argument will be substituted once and for all when the
2387 <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>
2388 command was invoked then the second argument of <a href="#_for"><strong><code>for</code></strong></a> will be <code>0&lt;=10</code>
2389 which will always evaluate to 1, even though <code>i</code> eventually
2390 becomes greater than 10. In the above case the loop will never
2391 terminate. Instead, the expression should be placed in braces:</p></div>
2392 <div class="literalblock">
2393 <div class="content">
2394 <pre><code>for {set i 1} {$i&lt;=10} {incr i} {...} ** RIGHT **</code></pre>
2395 </div></div>
2396 <div class="paragraph"><p>This causes the substitution of <em>i</em>
2397 to be delayed; it will be re-done each time the expression is
2398 evaluated, which is the desired result.</p></div>
2399 </div>
2400 </div>
2401 <div class="sect1">
2402 <h2 id="_lists">LISTS</h2>
2403 <div class="sectionbody">
2404 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
2405 A list is just a string with a list-like structure
2406 consisting of fields separated by white space. For example, the
2407 string</p></div>
2408 <div class="literalblock">
2409 <div class="content">
2410 <pre><code>Al Sue Anne John</code></pre>
2411 </div></div>
2412 <div class="paragraph"><p>is a list with four elements or fields.
2413 Lists have the same basic structure as command strings, except
2414 that a newline character in a list is treated as a field separator
2415 just like space or tab. Conventions for braces and quotes
2416 and backslashes are the same for lists as for commands. For example,
2417 the string</p></div>
2418 <div class="literalblock">
2419 <div class="content">
2420 <pre><code>a b\ c {d e {f g h}}</code></pre>
2421 </div></div>
2422 <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>
2423 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
2424 braces and quotes and backslashes are applied as for commands. Thus in
2425 the example above when the third element is extracted from the list,
2426 the result is</p></div>
2427 <div class="literalblock">
2428 <div class="content">
2429 <pre><code>d e {f g h}</code></pre>
2430 </div></div>
2431 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
2432 the outermost layer of braces). Command substitution and
2433 variable substitution are never
2434 made on a list (at least, not by the list-processing commands; the
2435 list can always be passed to the Tcl interpreter for evaluation).</p></div>
2436 <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>,
2437 <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
2438 you to build lists, extract elements from them, search them, and perform
2439 other list-related functions.</p></div>
2440 <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>
2441 </div>
2442 </div>
2443 <div class="sect1">
2444 <h2 id="_list_expansion">LIST EXPANSION</h2>
2445 <div class="sectionbody">
2446 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
2447 arguments. Support for this feature is also available in Jim.</p></div>
2448 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
2449 <div class="literalblock">
2450 <div class="content">
2451 <pre><code>set cmd {ls -l}
2452 exec $cmd</code></pre>
2453 </div></div>
2454 <div class="paragraph"><p>This will attempt to exec a command named "ls -l", which will clearly not
2455 work. Typically eval and concat are required to solve this problem, however
2456 it can be solved much more easily with <code>{*}</code>.</p></div>
2457 <div class="literalblock">
2458 <div class="content">
2459 <pre><code>exec {*}$cmd</code></pre>
2460 </div></div>
2461 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
2462 the resulting command.</p></div>
2463 <div class="paragraph"><p>Note that the official Tcl syntax is <code>{*}</code>, however <code>{expand}</code> is retained
2464 for backward compatibility with experimental versions of this feature.</p></div>
2465 </div>
2466 </div>
2467 <div class="sect1">
2468 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
2469 <div class="sectionbody">
2470 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
2471 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
2472 <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-regexp</code>.</p></div>
2473 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
2474 POSIX regular expression support, or using the built-in regular expression engine.
2475 The differences between these are described below.</p></div>
2476 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<code>ARE</code>).</p></div>
2477 <div class="sect2">
2478 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
2479 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
2480 this support will be used by default. The type of regular expressions supported are
2481 Extended Regular Expressions (<code>ERE</code>) rather than Basic Regular Expressions (<code>BRE</code>).
2482 See REG_EXTENDED in the documentation.</p></div>
2483 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
2484 make for the smallest code size, but some features such as UTF-8
2485 and <code>\w</code>, <code>\d</code>, <code>\s</code> are not supported, and null characters
2486 in strings are not supported.</p></div>
2487 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
2488 </div>
2489 <div class="sect2">
2490 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
2491 <div class="paragraph"><p>The Jim built-in regular expression engine may be selected with <code>./configure --with-jim-regexp</code>
2492 or it will be selected automatically if UTF-8 support is enabled.</p></div>
2493 <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
2494 and POSIX are highlighted below.</p></div>
2495 <div class="olist arabic"><ol class="arabic">
2496 <li>
2498 UTF-8 strings and patterns are both supported
2499 </p>
2500 </li>
2501 <li>
2503 All Tcl character classes are supported (e.g. <code>[:alnum:]</code>, <code>[:digit:]</code>, <code>[:space:]</code>), but&#8230;
2504 </p>
2505 </li>
2506 <li>
2508 Character classes apply to ASCII characters only
2509 </p>
2510 </li>
2511 <li>
2513 Supported shorthand character classes: <code>\w</code> = <code>[:alnum:]</code>, <code>\W</code> = <code><sup>[:alnum:]</code>, <code>\d</code> = <code>[:digit:],</code> <code>\D</code> = <code></sup>[:digit:],</code> <code>\s</code> = <code>[:space:]</code>, + <code>\S</code> = <code>^[:space:]</code>
2514 </p>
2515 </li>
2516 <li>
2518 Supported constraint escapes: <code>\m</code> = <code>\&lt;</code> = start of word, <code>\M</code> = <code>\&gt;</code> = end of word
2519 </p>
2520 </li>
2521 <li>
2523 Backslash escapes may be used within regular expressions, such as <code>\n</code> = newline, <code>\uNNNN</code> = unicode
2524 </p>
2525 </li>
2526 <li>
2528 Partially supported constraint escapes: <code>\A</code> = start of string, <code>\Z</code> = end of string
2529 </p>
2530 </li>
2531 <li>
2533 Support for the <code>?</code> non-greedy quantifier. e.g. <code>*?</code>
2534 </p>
2535 </li>
2536 <li>
2538 Support for non-capturing parentheses <code>(?:&#8230;)</code>
2539 </p>
2540 </li>
2541 <li>
2543 Jim Tcl considers that both patterns and strings end at a null character (<code>\x00</code>)
2544 </p>
2545 </li>
2546 </ol></div>
2547 </div>
2548 </div>
2549 </div>
2550 <div class="sect1">
2551 <h2 id="_command_results">COMMAND RESULTS</h2>
2552 <div class="sectionbody">
2553 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2554 code indicates whether the command completed successfully or not,
2555 and the string gives additional information. The valid codes are
2556 defined in jim.h, and are:</p></div>
2557 <div class="dlist"><dl>
2558 <dt class="hdlist1">
2559 <code>JIM_OK(0)</code>
2560 </dt>
2561 <dd>
2563 This is the normal return code, and indicates that the command completed
2564 successfully. The string gives the command&#8217;s return value.
2565 </p>
2566 </dd>
2567 <dt class="hdlist1">
2568 <code>JIM_ERR(1)</code>
2569 </dt>
2570 <dd>
2572 Indicates that an error occurred; the string gives a message describing
2573 the error.
2574 </p>
2575 </dd>
2576 <dt class="hdlist1">
2577 <code>JIM_RETURN(2)</code>
2578 </dt>
2579 <dd>
2581 Indicates that the <a href="#_return"><strong><code>return</code></strong></a> command has been invoked, and that the
2582 current procedure (or top-level command or <a href="#_source"><strong><code>source</code></strong></a> command)
2583 should return immediately. The
2584 string gives the return value for the procedure or command.
2585 </p>
2586 </dd>
2587 <dt class="hdlist1">
2588 <code>JIM_BREAK(3)</code>
2589 </dt>
2590 <dd>
2592 Indicates that the <a href="#_break"><strong><code>break</code></strong></a> command has been invoked, so the
2593 innermost loop should abort immediately. The string should always
2594 be empty.
2595 </p>
2596 </dd>
2597 <dt class="hdlist1">
2598 <code>JIM_CONTINUE(4)</code>
2599 </dt>
2600 <dd>
2602 Indicates that the <a href="#_continue"><strong><code>continue</code></strong></a> command has been invoked, so the
2603 innermost loop should go on to the next iteration. The string
2604 should always be empty.
2605 </p>
2606 </dd>
2607 <dt class="hdlist1">
2608 <code>JIM_SIGNAL(5)</code>
2609 </dt>
2610 <dd>
2612 Indicates that a signal was caught while executing a commands.
2613 The string contains the name of the signal caught.
2614 See the <a href="#_signal"><strong><code>signal</code></strong></a> and <a href="#_catch"><strong><code>catch</code></strong></a> commands.
2615 </p>
2616 </dd>
2617 <dt class="hdlist1">
2618 <code>JIM_EXIT(6)</code>
2619 </dt>
2620 <dd>
2622 Indicates that the command called the <a href="#_exit"><strong><code>exit</code></strong></a> command.
2623 The string contains the exit code.
2624 </p>
2625 </dd>
2626 </dl></div>
2627 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2628 since <code>JIM_OK</code> is almost always returned. If anything else is returned
2629 by a command, then the Tcl interpreter immediately stops processing
2630 commands and returns to its caller. If there are several nested
2631 invocations of the Tcl interpreter in progress, then each nested
2632 command will usually return the error to its caller, until eventually
2633 the error is reported to the top-level application code. The
2634 application will then display the error message for the user.</p></div>
2635 <div class="paragraph"><p>In a few cases, some commands will handle certain <a href="#_error"><strong><code>error</code></strong></a> conditions
2636 themselves and not return them upwards. For example, the <a href="#_for"><strong><code>for</code></strong></a>
2637 command checks for the <code>JIM_BREAK</code> code; if it occurs, then <a href="#_for"><strong><code>for</code></strong></a>
2638 stops executing the body of the loop and returns <code>JIM_OK</code> to its
2639 caller. The <a href="#_for"><strong><code>for</code></strong></a> command also handles <code>JIM_CONTINUE</code> codes and the
2640 procedure interpreter handles <code>JIM_RETURN</code> codes. The <a href="#_catch"><strong><code>catch</code></strong></a>
2641 command allows Tcl programs to catch errors and handle them without
2642 aborting command interpretation any further.</p></div>
2643 <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
2644 return codes and names.</p></div>
2645 </div>
2646 </div>
2647 <div class="sect1">
2648 <h2 id="_procedures">PROCEDURES</h2>
2649 <div class="sectionbody">
2650 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2651 procedures. A Tcl procedure can be invoked just like any other Tcl
2652 command (it has a name and it receives one or more arguments).
2653 The only difference is that its body isn&#8217;t a piece of C code linked
2654 into the program; it is a string containing one or more other
2655 Tcl commands.</p></div>
2656 <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>
2657 <div class="paragraph"><p><code><strong>proc</strong> <em>name arglist ?statics? body</em></code></p></div>
2658 <div class="paragraph"><p>The new command is named <code><em>name</em></code>, and it replaces any existing command
2659 there may have been by that name. Whenever the new command is
2660 invoked, the contents of <code><em>body</em></code> will be executed by the Tcl
2661 interpreter.</p></div>
2662 <div class="paragraph"><p><code><em>arglist</em></code> specifies the formal arguments to the procedure.
2663 It consists of a list, possibly empty, of the following
2664 argument specifiers:</p></div>
2665 <div class="dlist"><dl>
2666 <dt class="hdlist1">
2667 <code>name</code>
2668 </dt>
2669 <dd>
2671 Required Argument - A simple argument name.
2672 </p>
2673 </dd>
2674 <dt class="hdlist1">
2675 <code>{name default}</code>
2676 </dt>
2677 <dd>
2679 Optional Argument - A two-element list consisting of the
2680 argument name, followed by the default value, which will
2681 be used if the corresponding argument is not supplied.
2682 </p>
2683 </dd>
2684 <dt class="hdlist1">
2685 <code>&amp;name</code>
2686 </dt>
2687 <dd>
2689 Reference Argument - The caller is expected to pass the name of
2690 an existing variable. An implicit <code><a href="#_upvar"><strong><code>upvar</code></strong></a> 1 origname name</code> is done
2691 to make the variable available in the proc scope.
2692 </p>
2693 </dd>
2694 <dt class="hdlist1">
2695 <code><strong>args</strong></code>
2696 </dt>
2697 <dd>
2699 Variable Argument - The special name <code><em>args</em></code>, which is
2700 assigned all remaining arguments (including none) as a list. The
2701 variable argument may only be specified once. Note that
2702 the syntax <code>{args newname}</code> may be used to retain the special
2703 behaviour of <code><em>args</em></code> with a different local name. In this case,
2704 the variable is named <code><em>newname</em></code> rather than <code><em>args</em></code>.
2705 </p>
2706 </dd>
2707 </dl></div>
2708 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2709 the formal arguments to the procedure; its value will be the value
2710 of corresponding argument in the invoking command or the argument&#8217;s
2711 default value.</p></div>
2712 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2713 invocation. However, there must be enough actual arguments for all
2714 required arguments, and there must not be any extra actual arguments
2715 (unless the Variable Argument is specified).</p></div>
2716 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2717 order with the following precedence.</p></div>
2718 <div class="olist arabic"><ol class="arabic">
2719 <li>
2721 Required Arguments (including Reference Arguments)
2722 </p>
2723 </li>
2724 <li>
2726 Optional Arguments
2727 </p>
2728 </li>
2729 <li>
2731 Variable Argument
2732 </p>
2733 </li>
2734 </ol></div>
2735 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2736 <div class="literalblock">
2737 <div class="content">
2738 <pre><code>proc p {{a A} args b {c C} d} {...}</code></pre>
2739 </div></div>
2740 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2741 The following table shows how various numbers of arguments are assigned.
2742 Values marked as <code>-</code> are assigned the default value.</p></div>
2743 <div class="tableblock">
2744 <table rules="all"
2745 width="40%"
2746 frame="hsides"
2747 cellspacing="0" cellpadding="4">
2748 <col width="16%" />
2749 <col width="16%" />
2750 <col width="16%" />
2751 <col width="16%" />
2752 <col width="16%" />
2753 <col width="16%" />
2754 <thead>
2755 <tr>
2756 <th align="left" valign="top">Number of arguments</th>
2757 <th align="left" valign="top">a</th>
2758 <th align="left" valign="top">args</th>
2759 <th align="left" valign="top">b</th>
2760 <th align="left" valign="top">c</th>
2761 <th align="left" valign="top">d</th>
2762 </tr>
2763 </thead>
2764 <tbody>
2765 <tr>
2766 <td align="left" valign="top"><p class="table">2</p></td>
2767 <td align="left" valign="top"><p class="table">-</p></td>
2768 <td align="left" valign="top"><p class="table">-</p></td>
2769 <td align="left" valign="top"><p class="table">1</p></td>
2770 <td align="left" valign="top"><p class="table">-</p></td>
2771 <td align="left" valign="top"><p class="table">2</p></td>
2772 </tr>
2773 <tr>
2774 <td align="left" valign="top"><p class="table">3</p></td>
2775 <td align="left" valign="top"><p class="table">1</p></td>
2776 <td align="left" valign="top"><p class="table">-</p></td>
2777 <td align="left" valign="top"><p class="table">2</p></td>
2778 <td align="left" valign="top"><p class="table">-</p></td>
2779 <td align="left" valign="top"><p class="table">3</p></td>
2780 </tr>
2781 <tr>
2782 <td align="left" valign="top"><p class="table">4</p></td>
2783 <td align="left" valign="top"><p class="table">1</p></td>
2784 <td align="left" valign="top"><p class="table">-</p></td>
2785 <td align="left" valign="top"><p class="table">2</p></td>
2786 <td align="left" valign="top"><p class="table">3</p></td>
2787 <td align="left" valign="top"><p class="table">4</p></td>
2788 </tr>
2789 <tr>
2790 <td align="left" valign="top"><p class="table">5</p></td>
2791 <td align="left" valign="top"><p class="table">1</p></td>
2792 <td align="left" valign="top"><p class="table">2</p></td>
2793 <td align="left" valign="top"><p class="table">3</p></td>
2794 <td align="left" valign="top"><p class="table">4</p></td>
2795 <td align="left" valign="top"><p class="table">5</p></td>
2796 </tr>
2797 <tr>
2798 <td align="left" valign="top"><p class="table">6</p></td>
2799 <td align="left" valign="top"><p class="table">1</p></td>
2800 <td align="left" valign="top"><p class="table">2,3</p></td>
2801 <td align="left" valign="top"><p class="table">4</p></td>
2802 <td align="left" valign="top"><p class="table">5</p></td>
2803 <td align="left" valign="top"><p class="table">6</p></td>
2804 </tr>
2805 </tbody>
2806 </table>
2807 </div>
2808 <div class="paragraph"><p>When <code><em>body</em></code> is being executed, variable names normally refer to local
2809 variables, which are created automatically when referenced and deleted
2810 when the procedure returns. One local variable is automatically created
2811 for each of the procedure&#8217;s arguments. Global variables can be
2812 accessed by invoking the <a href="#_global"><strong><code>global</code></strong></a> command or via the <code>::</code> prefix.</p></div>
2813 <div class="sect2">
2814 <h3 id="_new_in_jim">New in Jim</h3>
2815 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2816 These variables scoped to the procedure and initialised at procedure definition.
2817 Either from the static variable definition, or from the enclosing scope.</p></div>
2818 <div class="paragraph"><p>Consider the following example:</p></div>
2819 <div class="literalblock">
2820 <div class="content">
2821 <pre><code>jim&gt; set a 1
2822 jim&gt; proc a {} {a {b 2}} {
2823 set c 1
2824 puts "$a $b $c"
2825 incr a
2826 incr b
2827 incr c
2829 jim&gt; a
2830 1 2 1
2831 jim&gt; a
2832 2 3 1</code></pre>
2833 </div></div>
2834 <div class="paragraph"><p>The static variable <code><em>a</em></code> has no initialiser, so it is initialised from
2835 the enclosing scope with the value 1. (Note that it is an error if there
2836 is no variable with the same name in the enclosing scope). However <code><em>b</em></code>
2837 has an initialiser, so it is initialised to 2.</p></div>
2838 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2839 invocations of the procedure.</p></div>
2840 <div class="paragraph"><p>See the <a href="#_proc"><strong><code>proc</code></strong></a> command for information on how to define procedures
2841 and what happens when they are invoked. See also NAMESPACES.</p></div>
2842 </div>
2843 </div>
2844 </div>
2845 <div class="sect1">
2846 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2847 <div class="sectionbody">
2848 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2849 either through <em>$</em>-style variable substitution, the <a href="#_set"><strong><code>set</code></strong></a>
2850 command, or a few other mechanisms.</p></div>
2851 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2852 be created each time a new variable name is used.</p></div>
2853 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2854 A scalar variable has a single value, whereas an array variable
2855 can have any number of elements, each with a name (called
2856 its <em>index</em>) and a value.</p></div>
2857 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2858 Parentheses are used refer to array elements in Tcl commands.
2859 For example, the command</p></div>
2860 <div class="literalblock">
2861 <div class="content">
2862 <pre><code>set x(first) 44</code></pre>
2863 </div></div>
2864 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2865 so that its new value is <em>44</em>.</p></div>
2866 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2867 that contain multiple concatenated values.
2868 For example, the commands</p></div>
2869 <div class="literalblock">
2870 <div class="content">
2871 <pre><code>set a(2,3) 1
2872 set a(3,6) 2</code></pre>
2873 </div></div>
2874 <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>
2875 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2876 variables may be used.</p></div>
2877 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2878 not be a scalar variable with the same name.</p></div>
2879 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2880 name then it is not possible to make array references to the
2881 variable.</p></div>
2882 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2883 the existing variable with the <a href="#_unset"><strong><code>unset</code></strong></a> command.</p></div>
2884 <div class="paragraph"><p>The <a href="#_array"><strong><code>array</code></strong></a> command provides several features for dealing
2885 with arrays, such as querying the names of all the elements of
2886 the array and converting between an array and a list.</p></div>
2887 <div class="paragraph"><p>Variables may be either global or local. If a variable
2888 name is used when a procedure isn&#8217;t being executed, then it
2889 automatically refers to a global variable. Variable names used
2890 within a procedure normally refer to local variables associated with that
2891 invocation of the procedure. Local variables are deleted whenever
2892 a procedure exits. Either <a href="#_global"><strong><code>global</code></strong></a> command may be used to request
2893 that a name refer to a global variable for the duration of the current
2894 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2895 may be explicitly scoped with the <code>::</code> prefix. For example</p></div>
2896 <div class="literalblock">
2897 <div class="content">
2898 <pre><code>set a 1
2899 set b 2
2900 proc p {} {
2901 set c 3
2902 global a</code></pre>
2903 </div></div>
2904 <div class="literalblock">
2905 <div class="content">
2906 <pre><code> puts "$a $::b $c"
2908 p</code></pre>
2909 </div></div>
2910 <div class="paragraph"><p>will output:</p></div>
2911 <div class="literalblock">
2912 <div class="content">
2913 <pre><code>1 2 3</code></pre>
2914 </div></div>
2915 </div>
2916 </div>
2917 <div class="sect1">
2918 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2919 <div class="sectionbody">
2920 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2921 number of elements) and an array value. This is similar to the way Tcl
2922 can convert between a string and a list.</p></div>
2923 <div class="paragraph"><p>For example:</p></div>
2924 <div class="literalblock">
2925 <div class="content">
2926 <pre><code>set a {1 one 2 two}
2927 puts $a(2)</code></pre>
2928 </div></div>
2929 <div class="paragraph"><p>will output:</p></div>
2930 <div class="literalblock">
2931 <div class="content">
2932 <pre><code>two</code></pre>
2933 </div></div>
2934 <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
2935 exist or is empty.</p></div>
2936 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2937 a list.</p></div>
2938 <div class="literalblock">
2939 <div class="content">
2940 <pre><code>set a(1) one; set a(2) two
2941 puts $a</code></pre>
2942 </div></div>
2943 <div class="paragraph"><p>will output:</p></div>
2944 <div class="literalblock">
2945 <div class="content">
2946 <pre><code>1 one 2 two</code></pre>
2947 </div></div>
2948 </div>
2949 </div>
2950 <div class="sect1">
2951 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2952 <div class="sectionbody">
2953 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2954 of this command. Dictionaries provide efficient access to key-value
2955 pairs, just like arrays, but dictionaries are pure values. This
2956 means that you can pass them to a procedure just as a list or a
2957 string. Tcl dictionaries are therefore much more like Tcl lists,
2958 except that they represent a mapping from keys to values, rather
2959 than an ordered sequence.</p></div>
2960 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2961 consists of another dictionary. That way you can elegantly build
2962 complicated data structures, such as hierarchical databases. You
2963 can also combine dictionaries with other Tcl data structures. For
2964 instance, you can build a list of dictionaries that themselves
2965 contain lists.</p></div>
2966 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2967 mapping from arbitrary keys to arbitrary values. Each key in the
2968 dictionary maps to a single value. They have a textual format that
2969 is exactly that of any list with an even number of elements, with
2970 each mapping in the dictionary being represented as two items in
2971 the list. When a command takes a dictionary and produces a new
2972 dictionary based on it (either returning it or writing it back into
2973 the variable that the starting dictionary was read from) the new
2974 dictionary will have the same order of keys, modulo any deleted
2975 keys and with new keys added on to the end. When a string is
2976 interpreted as a dictionary and it would otherwise have duplicate
2977 keys, only the last value for a particular key is used; the others
2978 are ignored, meaning that, "apple banana" and "apple carrot apple
2979 banana" are equivalent dictionaries (with different string
2980 representations).</p></div>
2981 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2982 Thus automatic conversion between lists and dictionaries applies
2983 as it does for arrays.</p></div>
2984 <div class="literalblock">
2985 <div class="content">
2986 <pre><code>jim&gt; dict set a 1 one
2987 1 one
2988 jim&gt; dict set a 2 two
2989 1 one 2 two
2990 jim&gt; puts $a
2991 1 one 2 two
2992 jim&gt; puts $a(2)
2994 jim&gt; dict set a 3 T three
2995 1 one 2 two 3 {T three}</code></pre>
2996 </div></div>
2997 <div class="paragraph"><p>See the <a href="#_dict"><strong><code>dict</code></strong></a> command for more details.</p></div>
2998 </div>
2999 </div>
3000 <div class="sect1">
3001 <h2 id="_namespaces">NAMESPACES</h2>
3002 <div class="sectionbody">
3003 <div class="paragraph"><p>Tcl added namespaces as a mechanism avoiding name clashes, especially in applications
3004 including a number of 3rd party components. While there is less need for namespaces
3005 in Jim Tcl (which does not strive to support large applications), it is convenient to
3006 provide a subset of the support for namespaces to easy porting code from Tcl.</p></div>
3007 <div class="paragraph"><p>Jim Tcl currently supports "light-weight" namespaces which should be adequate for most
3008 purposes. This feature is currently experimental. See README.namespaces for more information
3009 and the documentation of the <a href="#_namespace"><strong><code>namespace</code></strong></a> command.</p></div>
3010 </div>
3011 </div>
3012 <div class="sect1">
3013 <h2 id="_garbage_collection_references_lambda_function">GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION</h2>
3014 <div class="sectionbody">
3015 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
3016 These are described briefly below.</p></div>
3017 <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>
3018 <div class="sect2">
3019 <h3 id="_references">References</h3>
3020 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
3021 where the value may be garbage collected when unreferenced.
3022 Consider the following example:</p></div>
3023 <div class="literalblock">
3024 <div class="content">
3025 <pre><code>jim&gt; set r [ref "One String" test]
3026 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
3027 jim&gt; getref $r
3028 One String</code></pre>
3029 </div></div>
3030 <div class="paragraph"><p>The operation <a href="#_ref"><strong><code>ref</code></strong></a> creates a references to the value specified by the
3031 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
3032 <div class="paragraph"><p>The operation <a href="#_getref"><strong><code>getref</code></strong></a> is the dereferencing operation which retrieves the value
3033 stored in the reference.</p></div>
3034 <div class="literalblock">
3035 <div class="content">
3036 <pre><code>jim&gt; setref $r "New String"
3037 New String
3038 jim&gt; getref $r
3039 New String</code></pre>
3040 </div></div>
3041 <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
3042 is no longer accessible by any reference, it will eventually be automatically be garbage
3043 collected.</p></div>
3044 </div>
3045 <div class="sect2">
3046 <h3 id="_garbage_collection">Garbage Collection</h3>
3047 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
3048 automatically as necessary.</p></div>
3049 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
3050 transcend their scope. To support this, case, the Jim system will periodically identify
3051 and discard objects which are no longer accessible by any reference.</p></div>
3052 <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
3053 with a finalizer:</p></div>
3054 <div class="literalblock">
3055 <div class="content">
3056 <pre><code>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
3057 jim&gt; set r [ref "One String" test f]
3058 &lt;reference.&lt;test___&gt;.00000000000
3059 jim&gt; collect
3061 jim&gt; set r ""
3062 jim&gt; collect
3063 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
3064 1</code></pre>
3065 </div></div>
3066 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
3067 contained a reference to the value, the garbage collector discarded
3068 the value (after calling the finalizer).</p></div>
3069 <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>
3070 <div class="literalblock">
3071 <div class="content">
3072 <pre><code>jim&gt; finalize $r
3074 jim&gt; finalize $r newf
3075 newf</code></pre>
3076 </div></div>
3077 </div>
3078 <div class="sect2">
3079 <h3 id="_lambda_function">Lambda Function</h3>
3080 <div class="paragraph"><p>Jim provides a garbage collected <a href="#_lambda"><strong><code>lambda</code></strong></a> function. This is a procedure
3081 which is able to create an anonymous procedure. Consider:</p></div>
3082 <div class="literalblock">
3083 <div class="content">
3084 <pre><code>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
3085 jim&gt; $f 1
3087 jim&gt; $f 2
3089 jim&gt; set f ""</code></pre>
3090 </div></div>
3091 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
3092 which is incremented by the supplied value and the result returned.</p></div>
3093 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
3094 when the garbage collector runs.</p></div>
3095 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
3096 <div class="literalblock">
3097 <div class="content">
3098 <pre><code>jim&gt; rename $f ""</code></pre>
3099 </div></div>
3100 </div>
3101 </div>
3102 </div>
3103 <div class="sect1">
3104 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
3105 <div class="sectionbody">
3106 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
3107 then most string-related commands become UTF-8 aware. These include,
3108 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
3109 <a href="#_format"><strong><code>format</code></strong></a>.</p></div>
3110 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
3111 characters can take a variable number of bytes. Thus the addition of
3112 <a href="#_string"><strong><code>string</code></strong></a> <code>bytelength</code> which returns the number of bytes in a string,
3113 while <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> returns the number of characters.</p></div>
3114 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
3115 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>
3116 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <code>\uNNNN</code> and related syntax
3117 is still available to embed UTF-8 sequences.</p></div>
3118 <div class="paragraph"><p>Jim Tcl supports all currently defined unicode codepoints. That is 21 bits, up to +<em>U+1FFFFF</em>.</p></div>
3119 <div class="sect2">
3120 <h3 id="_string_matching">String Matching</h3>
3121 <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
3122 pattern matching rules. These commands support UTF-8. For example:</p></div>
3123 <div class="literalblock">
3124 <div class="content">
3125 <pre><code>string match a\[\ua0-\ubf\]b "a\u00a3b"</code></pre>
3126 </div></div>
3127 </div>
3128 <div class="sect2">
3129 <h3 id="_format_and_scan">format and scan</h3>
3130 <div class="paragraph"><p><code>format %c</code> allows a unicode codepoint to be be encoded. For example, the following will return
3131 a string with two bytes and one character. The same as <code>\ub5</code></p></div>
3132 <div class="literalblock">
3133 <div class="content">
3134 <pre><code>format %c 0xb5</code></pre>
3135 </div></div>
3136 <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
3137 return a string with three characters, not three bytes.</p></div>
3138 <div class="literalblock">
3139 <div class="content">
3140 <pre><code>format %.3s \ub5\ub6\ub7\ub8</code></pre>
3141 </div></div>
3142 <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
3143 <code><em>a</em></code> to 181 (0xb5) and <code><em>b</em></code> to 65 (0x41).</p></div>
3144 <div class="literalblock">
3145 <div class="content">
3146 <pre><code>scan \u00b5A %c%c a b</code></pre>
3147 </div></div>
3148 <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>
3149 </div>
3150 <div class="sect2">
3151 <h3 id="_string_classes">String Classes</h3>
3152 <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
3153 will return 0, even though the string may be considered to be alphabetic.</p></div>
3154 <div class="literalblock">
3155 <div class="content">
3156 <pre><code>string is alpha \ub5Test</code></pre>
3157 </div></div>
3158 <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>
3159 </div>
3160 <div class="sect2">
3161 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
3162 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
3163 and comparison will not increase or decrease the number of characters in a string.
3164 (Although it may change the number of bytes).</p></div>
3165 <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.
3166 Any character which is not a letter or has no uppercase equivalent is left unchanged.
3167 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>
3168 <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>
3169 and <a href="#_lsearch"><strong><code>lsearch</code></strong></a> <code>-nocase</code> fold both strings to uppercase before comparison.</p></div>
3170 </div>
3171 <div class="sect2">
3172 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
3173 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
3174 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
3175 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
3176 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
3177 the following returns 2.</p></div>
3178 <div class="literalblock">
3179 <div class="content">
3180 <pre><code>string bytelength \xff\xff</code></pre>
3181 </div></div>
3182 </div>
3183 <div class="sect2">
3184 <h3 id="_regular_expressions_2">Regular Expressions</h3>
3185 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
3186 selected which supports UTF-8 strings and patterns.</p></div>
3187 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
3188 </div>
3189 </div>
3190 </div>
3191 <div class="sect1">
3192 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
3193 <div class="sectionbody">
3194 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
3195 be available in any application using Tcl. In addition to these
3196 built-in commands, there may be additional commands defined by each
3197 application, plus commands defined as Tcl procedures.</p></div>
3198 <div class="paragraph"><p>In the command syntax descriptions below, words in <code><strong>boldface</strong></code> are
3199 literals that you type verbatim to Tcl.</p></div>
3200 <div class="paragraph"><p>Words in <code><em>italics</em></code> are meta-symbols; they serve as names for any of
3201 a range of values that you can type.</p></div>
3202 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
3203 in <code>?question-marks?</code>.</p></div>
3204 <div class="paragraph"><p>Ellipses (<code>...</code>) indicate that any number of additional
3205 arguments or groups of arguments may appear, in the same format
3206 as the preceding argument(s).</p></div>
3207 <div class="sect2">
3208 <h3 id="CommandIndex">Command Index</h3>
3209 <div class="tableblock">
3210 <table rules="none"
3211 width="100%"
3212 frame="void"
3213 cellspacing="0" cellpadding="4">
3214 <col width="12%" />
3215 <col width="12%" />
3216 <col width="12%" />
3217 <col width="12%" />
3218 <col width="12%" />
3219 <col width="12%" />
3220 <col width="12%" />
3221 <col width="12%" />
3222 <tbody>
3223 <tr>
3224 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>after</code></strong></a></p></td>
3225 <td align="left" valign="top"><p class="table"><a href="#_aio"><strong><code>aio</code></strong></a></p></td>
3226 <td align="left" valign="top"><p class="table"><a href="#_alarm"><strong><code>alarm</code></strong></a></p></td>
3227 <td align="left" valign="top"><p class="table"><a href="#_alias"><strong><code>alias</code></strong></a></p></td>
3228 <td align="left" valign="top"><p class="table"><a href="#_append"><strong><code>append</code></strong></a></p></td>
3229 <td align="left" valign="top"><p class="table"><a href="#_apply"><strong><code>apply</code></strong></a></p></td>
3230 <td align="left" valign="top"><p class="table"><a href="#_array"><strong><code>array</code></strong></a></p></td>
3231 <td align="left" valign="top"><p class="table"><a href="#_binary"><strong><code>binary</code></strong></a></p></td>
3232 </tr>
3233 <tr>
3234 <td align="left" valign="top"><p class="table"><a href="#_break"><strong><code>break</code></strong></a></p></td>
3235 <td align="left" valign="top"><p class="table"><a href="#_case"><strong><code>case</code></strong></a></p></td>
3236 <td align="left" valign="top"><p class="table"><a href="#_catch"><strong><code>catch</code></strong></a></p></td>
3237 <td align="left" valign="top"><p class="table"><a href="#_cd"><strong><code>cd</code></strong></a></p></td>
3238 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>class</code></strong></a></p></td>
3239 <td align="left" valign="top"><p class="table"><a href="#_clock"><strong><code>clock</code></strong></a></p></td>
3240 <td align="left" valign="top"><p class="table"><a href="#_close"><strong><code>close</code></strong></a></p></td>
3241 <td align="left" valign="top"><p class="table"><a href="#_collect"><strong><code>collect</code></strong></a></p></td>
3242 </tr>
3243 <tr>
3244 <td align="left" valign="top"><p class="table"><a href="#_concat"><strong><code>concat</code></strong></a></p></td>
3245 <td align="left" valign="top"><p class="table"><a href="#_continue"><strong><code>continue</code></strong></a></p></td>
3246 <td align="left" valign="top"><p class="table"><a href="#_curry"><strong><code>curry</code></strong></a></p></td>
3247 <td align="left" valign="top"><p class="table"><a href="#_defer"><strong><code>defer</code></strong></a></p></td>
3248 <td align="left" valign="top"><p class="table"><a href="#_dict"><strong><code>dict</code></strong></a></p></td>
3249 <td align="left" valign="top"><p class="table"><a href="#_env"><strong><code>env</code></strong></a></p></td>
3250 <td align="left" valign="top"><p class="table"><a href="#_eof"><strong><code>eof</code></strong></a></p></td>
3251 <td align="left" valign="top"><p class="table"><a href="#_error"><strong><code>error</code></strong></a></p></td>
3252 </tr>
3253 <tr>
3254 <td align="left" valign="top"><p class="table"><a href="#_eval"><strong><code>eval</code></strong></a></p></td>
3255 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>eventloop</code></strong></a></p></td>
3256 <td align="left" valign="top"><p class="table"><a href="#_exec"><strong><code>exec</code></strong></a></p></td>
3257 <td align="left" valign="top"><p class="table"><a href="#_exists"><strong><code>exists</code></strong></a></p></td>
3258 <td align="left" valign="top"><p class="table"><a href="#_exit"><strong><code>exit</code></strong></a></p></td>
3259 <td align="left" valign="top"><p class="table"><a href="#_expr"><strong><code>expr</code></strong></a></p></td>
3260 <td align="left" valign="top"><p class="table"><a href="#_fconfigure"><strong><code>fconfigure</code></strong></a></p></td>
3261 <td align="left" valign="top"><p class="table"><a href="#_file"><strong><code>file</code></strong></a></p></td>
3262 </tr>
3263 <tr>
3264 <td align="left" valign="top"><p class="table"><a href="#_finalize"><strong><code>finalize</code></strong></a></p></td>
3265 <td align="left" valign="top"><p class="table"><a href="#_flush"><strong><code>flush</code></strong></a></p></td>
3266 <td align="left" valign="top"><p class="table"><a href="#_for"><strong><code>for</code></strong></a></p></td>
3267 <td align="left" valign="top"><p class="table"><a href="#_foreach"><strong><code>foreach</code></strong></a></p></td>
3268 <td align="left" valign="top"><p class="table"><a href="#_format"><strong><code>format</code></strong></a></p></td>
3269 <td align="left" valign="top"><p class="table"><a href="#_getref"><strong><code>getref</code></strong></a></p></td>
3270 <td align="left" valign="top"><p class="table"><a href="#_gets"><strong><code>gets</code></strong></a></p></td>
3271 <td align="left" valign="top"><p class="table"><a href="#_glob"><strong><code>glob</code></strong></a></p></td>
3272 </tr>
3273 <tr>
3274 <td align="left" valign="top"><p class="table"><a href="#_global"><strong><code>global</code></strong></a></p></td>
3275 <td align="left" valign="top"><p class="table"><a href="#_history"><strong><code>history</code></strong></a></p></td>
3276 <td align="left" valign="top"><p class="table"><a href="#_if"><strong><code>if</code></strong></a></p></td>
3277 <td align="left" valign="top"><p class="table"><a href="#_incr"><strong><code>incr</code></strong></a></p></td>
3278 <td align="left" valign="top"><p class="table"><a href="#_info"><strong><code>info</code></strong></a></p></td>
3279 <td align="left" valign="top"><p class="table"><a href="#_interp"><strong><code>interp</code></strong></a></p></td>
3280 <td align="left" valign="top"><p class="table"><a href="#_join"><strong><code>join</code></strong></a></p></td>
3281 <td align="left" valign="top"><p class="table"><a href="#_kill"><strong><code>kill</code></strong></a></p></td>
3282 </tr>
3283 <tr>
3284 <td align="left" valign="top"><p class="table"><a href="#_lambda"><strong><code>lambda</code></strong></a></p></td>
3285 <td align="left" valign="top"><p class="table"><a href="#_lappend"><strong><code>lappend</code></strong></a></p></td>
3286 <td align="left" valign="top"><p class="table"><a href="#_lassign"><strong><code>lassign</code></strong></a></p></td>
3287 <td align="left" valign="top"><p class="table"><a href="#_lindex"><strong><code>lindex</code></strong></a></p></td>
3288 <td align="left" valign="top"><p class="table"><a href="#_linsert"><strong><code>linsert</code></strong></a></p></td>
3289 <td align="left" valign="top"><p class="table"><a href="#_list"><strong><code>list</code></strong></a></p></td>
3290 <td align="left" valign="top"><p class="table"><a href="#_llength"><strong><code>llength</code></strong></a></p></td>
3291 <td align="left" valign="top"><p class="table"><a href="#_lmap"><strong><code>lmap</code></strong></a></p></td>
3292 </tr>
3293 <tr>
3294 <td align="left" valign="top"><p class="table"><a href="#_load"><strong><code>load</code></strong></a></p></td>
3295 <td align="left" valign="top"><p class="table"><a href="#_local"><strong><code>local</code></strong></a></p></td>
3296 <td align="left" valign="top"><p class="table"><a href="#_loop"><strong><code>loop</code></strong></a></p></td>
3297 <td align="left" valign="top"><p class="table"><a href="#_lrange"><strong><code>lrange</code></strong></a></p></td>
3298 <td align="left" valign="top"><p class="table"><a href="#_lrepeat"><strong><code>lrepeat</code></strong></a></p></td>
3299 <td align="left" valign="top"><p class="table"><a href="#_lreplace"><strong><code>lreplace</code></strong></a></p></td>
3300 <td align="left" valign="top"><p class="table"><a href="#_lreverse"><strong><code>lreverse</code></strong></a></p></td>
3301 <td align="left" valign="top"><p class="table"><a href="#_lsearch"><strong><code>lsearch</code></strong></a></p></td>
3302 </tr>
3303 <tr>
3304 <td align="left" valign="top"><p class="table"><a href="#_lset"><strong><code>lset</code></strong></a></p></td>
3305 <td align="left" valign="top"><p class="table"><a href="#_lsort"><strong><code>lsort</code></strong></a></p></td>
3306 <td align="left" valign="top"><p class="table"><a href="#_namespace"><strong><code>namespace</code></strong></a></p></td>
3307 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>oo</code></strong></a></p></td>
3308 <td align="left" valign="top"><p class="table"><a href="#_open"><strong><code>open</code></strong></a></p></td>
3309 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.fork</code></strong></a></p></td>
3310 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.gethostname</code></strong></a></p></td>
3311 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.getids</code></strong></a></p></td>
3312 </tr>
3313 <tr>
3314 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>os.uptime</code></strong></a></p></td>
3315 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3316 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>pack</code></strong></a></p></td>
3317 <td align="left" valign="top"><p class="table"><a href="#_package"><strong><code>package</code></strong></a></p></td>
3318 <td align="left" valign="top"><p class="table"><a href="#_pid"><strong><code>pid</code></strong></a></p></td>
3319 <td align="left" valign="top"><p class="table"><a href="#_pipe"><strong><code>pipe</code></strong></a></p></td>
3320 <td align="left" valign="top"><p class="table"><a href="#cmd_1"><strong><code>posix</code></strong></a></p></td>
3321 <td align="left" valign="top"><p class="table"><a href="#_proc"><strong><code>proc</code></strong></a></p></td>
3322 </tr>
3323 <tr>
3324 <td align="left" valign="top"><p class="table"><a href="#_puts"><strong><code>puts</code></strong></a></p></td>
3325 <td align="left" valign="top"><p class="table"><a href="#_pwd"><strong><code>pwd</code></strong></a></p></td>
3326 <td align="left" valign="top"><p class="table"><a href="#_rand"><strong><code>rand</code></strong></a></p></td>
3327 <td align="left" valign="top"><p class="table"><a href="#_range"><strong><code>range</code></strong></a></p></td>
3328 <td align="left" valign="top"><p class="table"><a href="#_read"><strong><code>read</code></strong></a></p></td>
3329 <td align="left" valign="top"><p class="table"><a href="#_ref"><strong><code>ref</code></strong></a></p></td>
3330 <td align="left" valign="top"><p class="table"><a href="#_regexp"><strong><code>regexp</code></strong></a></p></td>
3331 <td align="left" valign="top"><p class="table"><a href="#_regsub"><strong><code>regsub</code></strong></a></p></td>
3332 </tr>
3333 <tr>
3334 <td align="left" valign="top"><p class="table"><a href="#_rename"><strong><code>rename</code></strong></a></p></td>
3335 <td align="left" valign="top"><p class="table"><a href="#_return"><strong><code>return</code></strong></a></p></td>
3336 <td align="left" valign="top"><p class="table"><a href="#_scan"><strong><code>scan</code></strong></a></p></td>
3337 <td align="left" valign="top"><p class="table"><a href="#_seek"><strong><code>seek</code></strong></a></p></td>
3338 <td align="left" valign="top"><p class="table"><a href="#_set"><strong><code>set</code></strong></a></p></td>
3339 <td align="left" valign="top"><p class="table"><a href="#_setref"><strong><code>setref</code></strong></a></p></td>
3340 <td align="left" valign="top"><p class="table"><a href="#_signal"><strong><code>signal</code></strong></a></p></td>
3341 <td align="left" valign="top"><p class="table"><a href="#_sleep"><strong><code>sleep</code></strong></a></p></td>
3342 </tr>
3343 <tr>
3344 <td align="left" valign="top"><p class="table"><a href="#_socket"><strong><code>socket</code></strong></a></p></td>
3345 <td align="left" valign="top"><p class="table"><a href="#_source"><strong><code>source</code></strong></a></p></td>
3346 <td align="left" valign="top"><p class="table"><a href="#_split"><strong><code>split</code></strong></a></p></td>
3347 <td align="left" valign="top"><p class="table"><a href="#_stackdump"><strong><code>stackdump</code></strong></a></p></td>
3348 <td align="left" valign="top"><p class="table"><a href="#_stacktrace"><strong><code>stacktrace</code></strong></a></p></td>
3349 <td align="left" valign="top"><p class="table"><a href="#_string"><strong><code>string</code></strong></a></p></td>
3350 <td align="left" valign="top"><p class="table"><a href="#_subst"><strong><code>subst</code></strong></a></p></td>
3351 <td align="left" valign="top"><p class="table"><a href="#cmd_4"><strong><code>super</code></strong></a></p></td>
3352 </tr>
3353 <tr>
3354 <td align="left" valign="top"><p class="table"><a href="#_switch"><strong><code>switch</code></strong></a></p></td>
3355 <td align="left" valign="top"><p class="table"><a href="#_syslog"><strong><code>syslog</code></strong></a></p></td>
3356 <td align="left" valign="top"><p class="table"><a href="#_tailcall"><strong><code>tailcall</code></strong></a></p></td>
3357 <td align="left" valign="top"><p class="table"><a href="#_tcl_autocomplete"><strong><code>tcl::autocomplete</code></strong></a></p></td>
3358 <td align="left" valign="top"><p class="table"><a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a></p></td>
3359 <td align="left" valign="top"><p class="table"><a href="#_tell"><strong><code>tell</code></strong></a></p></td>
3360 <td align="left" valign="top"><p class="table"><a href="#_throw"><strong><code>throw</code></strong></a></p></td>
3361 <td align="left" valign="top"><p class="table"><a href="#_time"><strong><code>time</code></strong></a></p></td>
3362 </tr>
3363 <tr>
3364 <td align="left" valign="top"><p class="table"><a href="#_tree"><strong><code>tree</code></strong></a></p></td>
3365 <td align="left" valign="top"><p class="table"><a href="#_try"><strong><code>try</code></strong></a></p></td>
3366 <td align="left" valign="top"><p class="table"><a href="#_unknown"><strong><code>unknown</code></strong></a></p></td>
3367 <td align="left" valign="top"><p class="table"><a href="#cmd_3"><strong><code>unpack</code></strong></a></p></td>
3368 <td align="left" valign="top"><p class="table"><a href="#_unset"><strong><code>unset</code></strong></a></p></td>
3369 <td align="left" valign="top"><p class="table"><a href="#_upcall"><strong><code>upcall</code></strong></a></p></td>
3370 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>update</code></strong></a></p></td>
3371 <td align="left" valign="top"><p class="table"><a href="#_uplevel"><strong><code>uplevel</code></strong></a></p></td>
3372 </tr>
3373 <tr>
3374 <td align="left" valign="top"><p class="table"><a href="#_upvar"><strong><code>upvar</code></strong></a></p></td>
3375 <td align="left" valign="top"><p class="table"><a href="#cmd_2"><strong><code>vwait</code></strong></a></p></td>
3376 <td align="left" valign="top"><p class="table"><a href="#_wait"><strong><code>wait</code></strong></a></p></td>
3377 <td align="left" valign="top"><p class="table"><a href="#_while"><strong><code>while</code></strong></a></p></td>
3378 <td align="left" valign="top"><p class="table"><a href="#_zlib"><strong><code>zlib</code></strong></a></p></td>
3379 <td align="left" valign="top"><p class="table"></p></td>
3380 <td align="left" valign="top"><p class="table"></p></td>
3381 <td align="left" valign="top"><p class="table"></p></td>
3382 </tr>
3383 </tbody>
3384 </table>
3385 </div>
3386 </div>
3387 <div class="sect2">
3388 <h3 id="_alarm">alarm</h3>
3389 <div class="paragraph"><p><code><strong>alarm</strong> <em>seconds</em></code></p></div>
3390 <div class="paragraph"><p>Delivers the <code>SIGALRM</code> signal to the process after the given
3391 number of seconds. If the platform supports <em>ualarm(3)</em> then
3392 the argument may be a floating point value. Otherwise it must
3393 be an integer.</p></div>
3394 <div class="paragraph"><p>Note that unless a signal handler for <code>SIGALRM</code> has been installed
3395 (see <a href="#_signal"><strong><code>signal</code></strong></a>), the process will exit on this signal.</p></div>
3396 </div>
3397 <div class="sect2">
3398 <h3 id="_alias">alias</h3>
3399 <div class="paragraph"><p><code><strong>alias</strong> <em>name args...</em></code></p></div>
3400 <div class="paragraph"><p>Creates a single word alias (command) for one or more words. For example,
3401 the following creates an alias for the command <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>.</p></div>
3402 <div class="literalblock">
3403 <div class="content">
3404 <pre><code>alias e info exists
3405 if {[e var]} {
3407 }</code></pre>
3408 </div></div>
3409 <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>
3410 <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>
3411 </div>
3412 <div class="sect2">
3413 <h3 id="_append">append</h3>
3414 <div class="paragraph"><p><code><strong>append</strong> <em>varName value ?value value &#8230;?</em></code></p></div>
3415 <div class="paragraph"><p>Append all of the <code><em>value</em></code> arguments to the current value
3416 of variable <code><em>varName</em></code>. If <code><em>varName</em></code> doesn&#8217;t exist,
3417 it is given a value equal to the concatenation of all the
3418 <code><em>value</em></code> arguments.</p></div>
3419 <div class="paragraph"><p>This command provides an efficient way to build up long
3420 variables incrementally.
3421 For example, "<a href="#_append"><strong><code>append</code></strong></a> <code>a $b</code>" is much more efficient than
3422 "<a href="#_set"><strong><code>set</code></strong></a> <code>a $a$b</code>" if <code>$a</code> is long.</p></div>
3423 </div>
3424 <div class="sect2">
3425 <h3 id="_apply">apply</h3>
3426 <div class="paragraph"><p><code><strong>apply</strong> <em>lambdaExpr ?arg1 arg2 ...?</em></code></p></div>
3427 <div class="paragraph"><p>The command <a href="#_apply"><strong><code>apply</code></strong></a> provides for anonymous procedure calls,
3428 similar to <a href="#_lambda"><strong><code>lambda</code></strong></a>, but without command name being created, even temporarily.</p></div>
3429 <div class="paragraph"><p>The function <code><em>lambdaExpr</em></code> is a two element list <code>{args body}</code>
3430 or a three element list <code>{args body namespace}</code>. The first element
3431 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>
3432 </div>
3433 <div class="sect2">
3434 <h3 id="_array">array</h3>
3435 <div class="paragraph"><p><code><strong>array</strong> <em>option arrayName ?arg...?</em></code></p></div>
3436 <div class="paragraph"><p>This command performs one of several operations on the
3437 variable given by <code><em>arrayName</em></code>.</p></div>
3438 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <code><em>array</em></code> command behaves
3439 as though the array exists but is empty.</p></div>
3440 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3441 command. The legal <code><em>options</em></code> (which may be abbreviated) are:</p></div>
3442 <div class="dlist"><dl>
3443 <dt class="hdlist1">
3444 <code><strong>array exists</strong> <em>arrayName</em></code>
3445 </dt>
3446 <dd>
3448 Returns 1 if arrayName is an array variable, 0 if there is
3449 no variable by that name.
3450 </p>
3451 </dd>
3452 <dt class="hdlist1">
3453 <code><strong>array get</strong> <em>arrayName ?pattern?</em></code>
3454 </dt>
3455 <dd>
3457 Returns a list containing pairs of elements. The first
3458 element in each pair is the name of an element in arrayName
3459 and the second element of each pair is the value of the
3460 array element. The order of the pairs is undefined. If
3461 pattern is not specified, then all of the elements of the
3462 array are included in the result. If pattern is specified,
3463 then only those elements whose names match pattern (using
3464 the matching rules of string match) are included. If arrayName
3465 isn&#8217;t the name of an array variable, or if the array contains
3466 no elements, then an empty list is returned.
3467 </p>
3468 </dd>
3469 <dt class="hdlist1">
3470 <code><strong>array names</strong> <em>arrayName ?pattern?</em></code>
3471 </dt>
3472 <dd>
3474 Returns a list containing the names of all of the elements
3475 in the array that match pattern. If pattern is omitted then
3476 the command returns all of the element names in the array.
3477 If pattern is specified, then only those elements whose
3478 names match pattern (using the matching rules of string
3479 match) are included. If there are no (matching) elements
3480 in the array, or if arrayName isn&#8217;t the name of an array
3481 variable, then an empty string is returned.
3482 </p>
3483 </dd>
3484 <dt class="hdlist1">
3485 <code><strong>array set</strong> <em>arrayName list</em></code>
3486 </dt>
3487 <dd>
3489 Sets the values of one or more elements in arrayName. list
3490 must have a form like that returned by array get, consisting
3491 of an even number of elements. Each odd-numbered element
3492 in list is treated as an element name within arrayName, and
3493 the following element in list is used as a new value for
3494 that array element. If the variable arrayName does not
3495 already exist and list is empty, arrayName is created with
3496 an empty array value.
3497 </p>
3498 </dd>
3499 <dt class="hdlist1">
3500 <code><strong>array size</strong> <em>arrayName</em></code>
3501 </dt>
3502 <dd>
3504 Returns the number of elements in the array. If arrayName
3505 isn&#8217;t the name of an array then 0 is returned.
3506 </p>
3507 </dd>
3508 <dt class="hdlist1">
3509 <code><strong>array unset</strong> <em>arrayName ?pattern?</em></code>
3510 </dt>
3511 <dd>
3513 Unsets all of the elements in the array that match pattern
3514 (using the matching rules of string match). If arrayName
3515 isn&#8217;t the name of an array variable or there are no matching
3516 elements in the array, no error will be raised. If pattern
3517 is omitted and arrayName is an array variable, then the
3518 command unsets the entire array. The command always returns
3519 an empty string.
3520 </p>
3521 </dd>
3522 </dl></div>
3523 </div>
3524 <div class="sect2">
3525 <h3 id="_break">break</h3>
3526 <div class="paragraph"><p><code><strong>break</strong></code></p></div>
3527 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
3528 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
3529 to signal the innermost containing loop command to return immediately.</p></div>
3530 </div>
3531 <div class="sect2">
3532 <h3 id="_case">case</h3>
3533 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? <em>patList body ?patList body &#8230;?</em></code></p></div>
3534 <div class="paragraph"><p><code><strong>case</strong> <em>string</em> ?in? {<em>patList body ?patList body &#8230;?</em>}</code></p></div>
3535 <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
3536 with Tcl 6.x is desired.</p></div>
3537 <div class="paragraph"><p>Match <code><em>string</em></code> against each of the <code><em>patList</em></code> arguments
3538 in order. If one matches, then evaluate the following <code><em>body</em></code> argument
3539 by passing it recursively to the Tcl interpreter, and return the result
3540 of that evaluation. Each <code><em>patList</em></code> argument consists of a single
3541 pattern or list of patterns. Each pattern may contain any of the wild-cards
3542 described under <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.</p></div>
3543 <div class="paragraph"><p>If a <code><em>patList</em></code> argument is <code>default</code>, the corresponding body will be
3544 evaluated if no <code><em>patList</em></code> matches <code><em>string</em></code>. If no <code><em>patList</em></code> argument
3545 matches <code><em>string</em></code> and no default is given, then the <a href="#_case"><strong><code>case</code></strong></a> command returns
3546 an empty string.</p></div>
3547 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
3548 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
3549 this form is convenient if substitutions are desired on some of the
3550 patterns or commands.</p></div>
3551 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3552 a single argument; the argument must have proper list structure, with
3553 the elements of the list being the patterns and commands.</p></div>
3554 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3555 since the braces around the whole list make it unnecessary to include a
3556 backslash at the end of each line.</p></div>
3557 <div class="paragraph"><p>Since the <code><em>patList</em></code> arguments are in braces in the second form,
3558 no command or variable substitutions are performed on them; this makes
3559 the behaviour of the second form different than the first form in some
3560 cases.</p></div>
3561 <div class="paragraph"><p>Below are some examples of <a href="#_case"><strong><code>case</code></strong></a> commands:</p></div>
3562 <div class="literalblock">
3563 <div class="content">
3564 <pre><code>case abc in {a b} {format 1} default {format 2} a* {format 3}</code></pre>
3565 </div></div>
3566 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3567 <div class="literalblock">
3568 <div class="content">
3569 <pre><code>case a in {
3570 {a b} {format 1}
3571 default {format 2}
3572 a* {format 3}
3573 }</code></pre>
3574 </div></div>
3575 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3576 <div class="literalblock">
3577 <div class="content">
3578 <pre><code>case xyz {
3579 {a b}
3580 {format 1}
3581 default
3582 {format 2}
3584 {format 3}
3585 }</code></pre>
3586 </div></div>
3587 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3588 </div>
3589 <div class="sect2">
3590 <h3 id="_catch">catch</h3>
3591 <div class="paragraph"><p><code><strong>catch</strong> ?-?no?<em>code ...</em>? ?--? <em>command ?resultVarName? ?optionsVarName?</em></code></p></div>
3592 <div class="paragraph"><p>The <a href="#_catch"><strong><code>catch</code></strong></a> command may be used to prevent errors from aborting
3593 command interpretation. <a href="#_catch"><strong><code>catch</code></strong></a> evaluates <code><em>command</em></code>, and returns a
3594 <code>JIM_OK</code> code, regardless of any errors that might occur while
3595 executing <code><em>command</em></code> (with the possible exception of <code>JIM_SIGNAL</code> -
3596 see below).</p></div>
3597 <div class="paragraph"><p>The return value from <a href="#_catch"><strong><code>catch</code></strong></a> is a decimal string giving the code
3598 returned by the Tcl interpreter after executing <code><em>command</em></code>. This
3599 will be <em>0</em> (<code>JIM_OK</code>) if there were no errors in <code><em>command</em></code>; otherwise
3600 it will have a non-zero value corresponding to one of the exceptional
3601 return codes (see jim.h for the definitions of code values, or the
3602 <a href="#_info"><strong><code>info</code></strong></a> <code>returncodes</code> command).</p></div>
3603 <div class="paragraph"><p>If the <code><em>resultVarName</em></code> argument is given, then it gives the name
3604 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to the
3605 string returned from <code><em>command</em></code> (either a result or an error message).</p></div>
3606 <div class="paragraph"><p>If the <code><em>optionsVarName</em></code> argument is given, then it gives the name
3607 of a variable; <a href="#_catch"><strong><code>catch</code></strong></a> will set the value of the variable to a
3608 dictionary. For any return code other than <code>JIM_RETURN</code>, the value
3609 for the key <code>-code</code> will be set to the return code. For <code>JIM_RETURN</code>
3610 it will be set to the code given in <a href="#_return"><strong><code>return</code></strong></a> <code>-code</code>. Additionally,
3611 for the return code <code>JIM_ERR</code>, the value of the key <code>-errorinfo</code>
3612 will contain the current stack trace (the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>stacktrace</code>),
3613 the value of the key <code>-errorcode</code> will contain the
3614 same value as the global variable $::errorCode, and the value of
3615 the key <code>-level</code> will be the current return level (see <a href="#_return"><strong><code>return</code></strong></a> <code>-level</code>).
3616 This can be useful to rethrow an error:</p></div>
3617 <div class="literalblock">
3618 <div class="content">
3619 <pre><code>if {[catch {...} msg opts]} {
3620 ...maybe do something with the error...
3621 incr opts(-level)
3622 return {*}$opts $msg
3623 }</code></pre>
3624 </div></div>
3625 <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>.
3626 The set of codes which will be caught may be modified by specifying the one more codes before
3627 <code><em>command</em></code>.</p></div>
3628 <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>
3629 <div class="literalblock">
3630 <div class="content">
3631 <pre><code>catch -exit -nobreak -nocontinue -- { ... }</code></pre>
3632 </div></div>
3633 <div class="paragraph"><p>The use of <code>--</code> is optional. It signifies that no more return code options follow.</p></div>
3634 <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
3635 (stored in <code><em>resultVarName</em></code>) is name of the signal caught.</p></div>
3636 </div>
3637 <div class="sect2">
3638 <h3 id="_cd">cd</h3>
3639 <div class="paragraph"><p><code><strong>cd</strong> <em>dirName</em></code></p></div>
3640 <div class="paragraph"><p>Change the current working directory to <code><em>dirName</em></code>.</p></div>
3641 <div class="paragraph"><p>Returns an empty string.</p></div>
3642 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3643 be removed in some applications.</p></div>
3644 </div>
3645 <div class="sect2">
3646 <h3 id="_clock">clock</h3>
3647 <div class="dlist"><dl>
3648 <dt class="hdlist1">
3649 <code><strong>clock seconds</strong></code>
3650 </dt>
3651 <dd>
3653 Returns the current time as seconds since the epoch.
3654 </p>
3655 </dd>
3656 <dt class="hdlist1">
3657 <code><strong>clock clicks</strong></code>
3658 </dt>
3659 <dd>
3661 Returns the current time in &#8216;clicks&#8217;.
3662 </p>
3663 </dd>
3664 <dt class="hdlist1">
3665 <code><strong>clock microseconds</strong></code>
3666 </dt>
3667 <dd>
3669 Returns the current time in microseconds.
3670 </p>
3671 </dd>
3672 <dt class="hdlist1">
3673 <code><strong>clock milliseconds</strong></code>
3674 </dt>
3675 <dd>
3677 Returns the current time in milliseconds.
3678 </p>
3679 </dd>
3680 <dt class="hdlist1">
3681 <code><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></code>
3682 </dt>
3683 <dd>
3685 Format the given time (seconds since the epoch) according to the given
3686 format. See strftime(3) for supported formats.
3687 If no format is supplied, "%c" is used.
3688 </p>
3689 </dd>
3690 <dt class="hdlist1">
3691 <code><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></code>
3692 </dt>
3693 <dd>
3695 Scan the given time string using the given format string.
3696 See strptime(3) for supported formats.
3697 </p>
3698 </dd>
3699 </dl></div>
3700 </div>
3701 <div class="sect2">
3702 <h3 id="_close">close</h3>
3703 <div class="paragraph"><p><code><strong>close</strong> <em>fileId</em></code></p></div>
3704 <div class="paragraph"><p><code><em>fileId</em> <strong>close</strong></code></p></div>
3705 <div class="paragraph"><p>Closes the file given by <code><em>fileId</em></code>.
3706 <code><em>fileId</em></code> must be the return value from a previous invocation
3707 of the <a href="#_open"><strong><code>open</code></strong></a> command; after this command, it should not be
3708 used anymore.</p></div>
3709 </div>
3710 <div class="sect2">
3711 <h3 id="_collect">collect</h3>
3712 <div class="paragraph"><p><code><strong>collect</strong></code></p></div>
3713 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3714 However it may be run immediately with the <a href="#_collect"><strong><code>collect</code></strong></a> command.</p></div>
3715 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
3716 </div>
3717 <div class="sect2">
3718 <h3 id="_concat">concat</h3>
3719 <div class="paragraph"><p><code><strong>concat</strong> <em>arg ?arg ...?</em></code></p></div>
3720 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3721 into a single list. It permits any number of arguments. For example,
3722 the command</p></div>
3723 <div class="literalblock">
3724 <div class="content">
3725 <pre><code>concat a b {c d e} {f {g h}}</code></pre>
3726 </div></div>
3727 <div class="paragraph"><p>will return</p></div>
3728 <div class="literalblock">
3729 <div class="content">
3730 <pre><code>a b c d e f {g h}</code></pre>
3731 </div></div>
3732 <div class="paragraph"><p>as its result.</p></div>
3733 </div>
3734 <div class="sect2">
3735 <h3 id="_continue">continue</h3>
3736 <div class="paragraph"><p><code><strong>continue</strong></code></p></div>
3737 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3738 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
3739 signal the innermost containing loop command to skip the remainder of
3740 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3741 </div>
3742 <div class="sect2">
3743 <h3 id="_curry">curry</h3>
3744 <div class="paragraph"><p><code><strong>alias</strong> <em>args...</em></code></p></div>
3745 <div class="paragraph"><p>Similar to <a href="#_alias"><strong><code>alias</code></strong></a> except it creates an anonymous procedure (lambda) instead of
3746 a named procedure.</p></div>
3747 <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>
3748 <div class="literalblock">
3749 <div class="content">
3750 <pre><code>set e [local curry info exists]
3751 if {[$e var]} {
3753 }</code></pre>
3754 </div></div>
3755 <div class="paragraph"><p><a href="#_curry"><strong><code>curry</code></strong></a> returns the name of the procedure.</p></div>
3756 <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>
3757 </div>
3758 <div class="sect2">
3759 <h3 id="_dict">dict</h3>
3760 <div class="paragraph"><p><code><strong>dict</strong> <em>option ?arg...?</em></code></p></div>
3761 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3762 <div class="paragraph"><p>The <code><em>option</em></code> argument determines what action is carried out by the
3763 command. The legal <code><em>options</em></code> are:</p></div>
3764 <div class="dlist"><dl>
3765 <dt class="hdlist1">
3766 <code><strong>dict create</strong> <em>?key value ...?</em></code>
3767 </dt>
3768 <dd>
3770 Create and return a new dictionary value that contains each of
3771 the key/value mappings listed as arguments (keys and values
3772 alternating, with each key being followed by its associated
3773 value.)
3774 </p>
3775 </dd>
3776 <dt class="hdlist1">
3777 <code><strong>dict exists</strong> <em>dictionary key ?key ...?</em></code>
3778 </dt>
3779 <dd>
3781 Returns a boolean value indicating whether the given key (or path
3782 of keys through a set of nested dictionaries) exists in the given
3783 dictionary value. This returns a true value exactly when <a href="#_dict"><strong><code>dict</code></strong></a> <code>get</code>
3784 on that path will succeed.
3785 </p>
3786 </dd>
3787 <dt class="hdlist1">
3788 <code><strong>dict get</strong> <em>dictionary ?key ...?</em></code>
3789 </dt>
3790 <dd>
3792 Given a dictionary value (first argument) and a key (second argument),
3793 this will retrieve the value for that key. Where several keys are
3794 supplied, the behaviour of the command shall be as if the result
3795 of "<a href="#_dict"><strong><code>dict</code></strong></a> <code>get $dictVal $key</code>" was passed as the first argument to
3796 dict get with the remaining arguments as second (and possibly
3797 subsequent) arguments. This facilitates lookups in nested dictionaries.
3798 If no keys are provided, dict would return a list containing pairs
3799 of elements in a manner similar to array get. That is, the first
3800 element of each pair would be the key and the second element would
3801 be the value for that key. It is an error to attempt to retrieve
3802 a value for a key that is not present in the dictionary.
3803 </p>
3804 </dd>
3805 <dt class="hdlist1">
3806 <code><strong>dict keys</strong> <em>dictionary ?pattern?</em></code>
3807 </dt>
3808 <dd>
3810 Returns a list of the keys in the dictionary.
3811 If pattern is specified, then only those keys whose
3812 names match <code><em>pattern</em></code> (using the matching rules of string
3813 match) are included.
3814 </p>
3815 </dd>
3816 <dt class="hdlist1">
3817 <code><strong>dict merge</strong> ?<em>dictionary ...</em>?</code>
3818 </dt>
3819 <dd>
3821 Return a dictionary that contains the contents of each of the
3822 <code><em>dictionary</em></code> arguments. Where two (or more) dictionaries
3823 contain a mapping for the same key, the resulting dictionary
3824 maps that key to the value according to the last dictionary on
3825 the command line containing a mapping for that key.
3826 </p>
3827 </dd>
3828 <dt class="hdlist1">
3829 <code><strong>dict set</strong> <em>dictionaryName key ?key ...? value</em></code>
3830 </dt>
3831 <dd>
3833 This operation takes the <code><em>name</em></code> of a variable containing a dictionary
3834 value and places an updated dictionary value in that variable
3835 containing a mapping from the given key to the given value. When
3836 multiple keys are present, this operation creates or updates a chain
3837 of nested dictionaries.
3838 </p>
3839 </dd>
3840 <dt class="hdlist1">
3841 <code><strong>dict size</strong> <em>dictionary</em></code>
3842 </dt>
3843 <dd>
3845 Return the number of key/value mappings in the given dictionary value.
3846 </p>
3847 </dd>
3848 <dt class="hdlist1">
3849 <code><strong>dict unset</strong> <em>dictionaryName key ?key ...? value</em></code>
3850 </dt>
3851 <dd>
3853 This operation (the companion to <a href="#_dict"><strong><code>dict</code></strong></a> <code>set</code>) takes the name of a
3854 variable containing a dictionary value and places an updated
3855 dictionary value in that variable that does not contain a mapping
3856 for the given key. Where multiple keys are present, this describes
3857 a path through nested dictionaries to the mapping to remove. At
3858 least one key must be specified, but the last key on the key-path
3859 need not exist. All other components on the path must exist.
3860 </p>
3861 </dd>
3862 <dt class="hdlist1">
3863 <code><strong>dict with</strong> <em>dictionaryName key ?key ...? script</em></code>
3864 </dt>
3865 <dd>
3867 Execute the Tcl script in <code><em>script</em></code> with the value for each
3868 key in <code><em>dictionaryName</em></code> mapped to a variable with the same
3869 name. Where one or more keys are given, these indicate a chain
3870 of nested dictionaries, with the innermost dictionary being the
3871 one opened out for the execution of body. Making <code><em>dictionaryName</em></code>
3872 unreadable will make the updates to the dictionary be discarded,
3873 and this also happens if the contents of <code><em>dictionaryName</em></code> are
3874 adjusted so that the chain of dictionaries no longer exists.
3875 The result of <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> is (unless some kind of error occurs)
3876 the result of the evaluation of body.
3877 </p>
3878 </dd>
3879 <dt class="hdlist1">
3881 </dt>
3882 <dd>
3884 The variables are mapped in the scope enclosing the <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code>;
3885 it is recommended that this command only be used in a local
3886 scope (procedure). Because of this, the variables set by
3887 <a href="#_dict"><strong><code>dict</code></strong></a> <code>with</code> will continue to exist after the command finishes (unless
3888 explicitly unset). Note that changes to the contents of <code><em>dictionaryName</em></code>
3889 only happen when <code><em>script</em></code> terminates.
3890 </p>
3891 </dd>
3892 </dl></div>
3893 <div class="paragraph"><p><code><strong>dict for, values, incr, append, lappend, update, info, replace</strong></code> to be documented&#8230;</p></div>
3894 </div>
3895 <div class="sect2">
3896 <h3 id="_env">env</h3>
3897 <div class="paragraph"><p><code><strong>env</strong> <em>?name? ?default?</em></code></p></div>
3898 <div class="paragraph"><p>If <code><em>name</em></code> is supplied, returns the value of <code><em>name</em></code> from the initial
3899 environment (see getenv(3)). An error is returned if <code><em>name</em></code> does not
3900 exist in the environment, unless <code><em>default</em></code> is supplied - in which case
3901 that value is returned instead.</p></div>
3902 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3903 and their values as <code>{name value ...}</code></p></div>
3904 <div class="paragraph"><p>See also the global variable <code>::env</code></p></div>
3905 </div>
3906 <div class="sect2">
3907 <h3 id="_eof">eof</h3>
3908 <div class="paragraph"><p><code><strong>eof</strong> <em>fileId</em></code></p></div>
3909 <div class="paragraph"><p><code><em>fileId</em> <strong>eof</strong></code></p></div>
3910 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <code><em>fileId</em></code>,
3911 0 otherwise.</p></div>
3912 <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>,
3913 or it may be <code>stdin</code>, <code>stdout</code>, or <code>stderr</code> to refer to one of the
3914 standard I/O channels.</p></div>
3915 </div>
3916 <div class="sect2">
3917 <h3 id="_error">error</h3>
3918 <div class="paragraph"><p><code><strong>error</strong> <em>message ?stacktrace?</em></code></p></div>
3919 <div class="paragraph"><p>Returns a <code>JIM_ERR</code> code, which causes command interpretation to be
3920 unwound. <code><em>message</em></code> is a string that is returned to the application
3921 to indicate what went wrong.</p></div>
3922 <div class="paragraph"><p>If the <code><em>stacktrace</em></code> argument is provided and is non-empty,
3923 it is used to initialize the stacktrace.</p></div>
3924 <div class="paragraph"><p>This feature is most useful in conjunction with the <a href="#_catch"><strong><code>catch</code></strong></a> command:
3925 if a caught error cannot be handled successfully, <code><em>stacktrace</em></code> can be used
3926 to return a stack trace reflecting the original point of occurrence
3927 of the error:</p></div>
3928 <div class="literalblock">
3929 <div class="content">
3930 <pre><code>catch {...} errMsg
3932 error $errMsg [info stacktrace]</code></pre>
3933 </div></div>
3934 <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>
3935 </div>
3936 <div class="sect2">
3937 <h3 id="_errorinfo">errorInfo</h3>
3938 <div class="paragraph"><p><code><strong>errorInfo</strong> <em>error ?stacktrace?</em></code></p></div>
3939 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3940 Typical usage is:</p></div>
3941 <div class="literalblock">
3942 <div class="content">
3943 <pre><code>if {[catch {...} error]} {
3944 puts stderr [errorInfo $error [info stacktrace]]
3945 exit 1
3946 }</code></pre>
3947 </div></div>
3948 <div class="paragraph"><p>See also <a href="#_error"><strong><code>error</code></strong></a>.</p></div>
3949 </div>
3950 <div class="sect2">
3951 <h3 id="_eval">eval</h3>
3952 <div class="paragraph"><p><code><strong>eval</strong> <em>arg ?arg...?</em></code></p></div>
3953 <div class="paragraph"><p><a href="#_eval"><strong><code>eval</code></strong></a> takes one or more arguments, which together comprise a Tcl
3954 command (or collection of Tcl commands separated by newlines in the
3955 usual way). <a href="#_eval"><strong><code>eval</code></strong></a> concatenates all its arguments in the same
3956 fashion as the <a href="#_concat"><strong><code>concat</code></strong></a> command, passes the concatenated string to the
3957 Tcl interpreter recursively, and returns the result of that
3958 evaluation (or any error generated by it).</p></div>
3959 </div>
3960 <div class="sect2">
3961 <h3 id="_exec">exec</h3>
3962 <div class="paragraph"><p><code><strong>exec</strong> <em>arg ?arg...?</em></code></p></div>
3963 <div class="paragraph"><p>This command treats its arguments as the specification
3964 of one or more UNIX commands to execute as subprocesses.
3965 The commands take the form of a standard shell pipeline;
3966 <code>|</code> arguments separate commands in the
3967 pipeline and cause standard output of the preceding command
3968 to be piped into standard input of the next command (or <code>|&amp;</code> for
3969 both standard output and standard error).</p></div>
3970 <div class="paragraph"><p>Under normal conditions the result of the <a href="#_exec"><strong><code>exec</code></strong></a> command
3971 consists of the standard output produced by the last command
3972 in the pipeline followed by the standard error output.</p></div>
3973 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3974 then this will be included in the result after the standard output
3975 of the last command.</p></div>
3976 <div class="paragraph"><p>Note that unlike Tcl, data written to standard error does not cause
3977 <a href="#_exec"><strong><code>exec</code></strong></a> to return an error.</p></div>
3978 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3979 are killed or suspended, then <a href="#_exec"><strong><code>exec</code></strong></a> will return an error.
3980 If no standard error output was produced, or is redirected,
3981 the error message will include the normal result, as above,
3982 followed by error messages describing the abnormal terminations.</p></div>
3983 <div class="paragraph"><p>If any standard error output was produced, these abnormal termination
3984 messages are suppressed.</p></div>
3985 <div class="paragraph"><p>If the last character of the result or error message
3986 is a newline then that character is deleted from the result
3987 or error message for consistency with normal
3988 Tcl return values.</p></div>
3989 <div class="paragraph"><p>An <code><em>arg</em></code> may have one of the following special forms:</p></div>
3990 <div class="dlist"><dl>
3991 <dt class="hdlist1">
3992 <code>&gt;filename</code>
3993 </dt>
3994 <dd>
3996 The standard output of the last command in the pipeline
3997 is redirected to the file. In this situation <a href="#_exec"><strong><code>exec</code></strong></a>
3998 will normally return an empty string.
3999 </p>
4000 </dd>
4001 <dt class="hdlist1">
4002 <code>&gt;&gt;filename</code>
4003 </dt>
4004 <dd>
4006 As above, but append to the file.
4007 </p>
4008 </dd>
4009 <dt class="hdlist1">
4010 <code>&gt;@fileId</code>
4011 </dt>
4012 <dd>
4014 The standard output of the last command in the pipeline is
4015 redirected to the given (writable) file descriptor (e.g. stdout,
4016 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>
4017 will normally return an empty string.
4018 </p>
4019 </dd>
4020 <dt class="hdlist1">
4021 <code>2&gt;filename</code>
4022 </dt>
4023 <dd>
4025 The standard error of the last command in the pipeline
4026 is redirected to the file.
4027 </p>
4028 </dd>
4029 <dt class="hdlist1">
4030 <code>2&gt;&gt;filename</code>
4031 </dt>
4032 <dd>
4034 As above, but append to the file.
4035 </p>
4036 </dd>
4037 <dt class="hdlist1">
4038 <code>2&gt;@fileId</code>
4039 </dt>
4040 <dd>
4042 The standard error of the last command in the pipeline is
4043 redirected to the given (writable) file descriptor.
4044 </p>
4045 </dd>
4046 <dt class="hdlist1">
4047 <code>2&gt;@1</code>
4048 </dt>
4049 <dd>
4051 The standard error of the last command in the pipeline is
4052 redirected to the same file descriptor as the standard output.
4053 </p>
4054 </dd>
4055 <dt class="hdlist1">
4056 <code>&gt;&amp;filename</code>
4057 </dt>
4058 <dd>
4060 Both the standard output and standard error of the last command
4061 in the pipeline is redirected to the file.
4062 </p>
4063 </dd>
4064 <dt class="hdlist1">
4065 <code>&gt;&gt;&amp;filename</code>
4066 </dt>
4067 <dd>
4069 As above, but append to the file.
4070 </p>
4071 </dd>
4072 <dt class="hdlist1">
4073 <code>&lt;filename</code>
4074 </dt>
4075 <dd>
4077 The standard input of the first command in the pipeline
4078 is taken from the file.
4079 </p>
4080 </dd>
4081 <dt class="hdlist1">
4082 <code>&lt;&lt;string</code>
4083 </dt>
4084 <dd>
4086 The standard input of the first command is taken as the
4087 given immediate value.
4088 </p>
4089 </dd>
4090 <dt class="hdlist1">
4091 <code>&lt;@fileId</code>
4092 </dt>
4093 <dd>
4095 The standard input of the first command in the pipeline
4096 is taken from the given (readable) file descriptor.
4097 </p>
4098 </dd>
4099 </dl></div>
4100 <div class="paragraph"><p>If there is no redirection of standard input, standard error
4101 or standard output, these are connected to the corresponding
4102 input or output of the application.</p></div>
4103 <div class="paragraph"><p>If the last <code><em>arg</em></code> is <code>&amp;</code> then the command will be
4104 executed in background.
4105 In this case the standard output from the last command
4106 in the pipeline will
4107 go to the application&#8217;s standard output unless
4108 redirected in the command, and error output from all
4109 the commands in the pipeline will go to the application&#8217;s
4110 standard error file. The return value of exec in this case
4111 is a list of process ids (pids) in the pipeline.</p></div>
4112 <div class="paragraph"><p>Each <code><em>arg</em></code> becomes one word for a command, except for
4113 <code>|</code>, <code>&lt;</code>, <code>&lt;&lt;</code>, <code>&gt;</code>, and <code>&amp;</code> arguments, and the
4114 arguments that follow <code>&lt;</code>, <code>&lt;&lt;</code>, and <code>&gt;</code>.</p></div>
4115 <div class="paragraph"><p>The first word in each command is taken as the command name;
4116 the directories in the PATH environment variable are searched for
4117 an executable by the given name.</p></div>
4118 <div class="paragraph"><p>No <a href="#_glob"><strong><code>glob</code></strong></a> expansion or other shell-like substitutions
4119 are performed on the arguments to commands.</p></div>
4120 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
4121 option in <a href="#_catch"><strong><code>catch</code></strong></a>) will be set to a list, as follows:</p></div>
4122 <div class="dlist"><dl>
4123 <dt class="hdlist1">
4124 <code><strong>CHILDKILLED</strong> <em>pid sigName msg</em></code>
4125 </dt>
4126 <dd>
4128 This format is used when a child process has been killed
4129 because of a signal. The pid element will be the process&#8217;s
4130 identifier (in decimal). The sigName element will be the
4131 symbolic name of the signal that caused the process to
4132 terminate; it will be one of the names from the include
4133 file signal.h, such as SIGPIPE. The msg element will be a
4134 short human-readable message describing the signal, such
4135 as "write on pipe with no readers" for SIGPIPE.
4136 </p>
4137 </dd>
4138 <dt class="hdlist1">
4139 <code><strong>CHILDSUSP</strong> <em>pid sigName msg</em></code>
4140 </dt>
4141 <dd>
4143 This format is used when a child process has been suspended
4144 because of a signal. The pid element will be the process&#8217;s
4145 identifier, in decimal. The sigName element will be the
4146 symbolic name of the signal that caused the process to
4147 suspend; this will be one of the names from the include
4148 file signal.h, such as SIGTTIN. The msg element will be a
4149 short human-readable message describing the signal, such
4150 as "background tty read" for SIGTTIN.
4151 </p>
4152 </dd>
4153 <dt class="hdlist1">
4154 <code><strong>CHILDSTATUS</strong> <em>pid code</em></code>
4155 </dt>
4156 <dd>
4158 This format is used when a child process has exited with a
4159 non-zero exit status. The pid element will be the process&#8217;s
4160 identifier (in decimal) and the code element will be the
4161 exit code returned by the process (also in decimal).
4162 </p>
4163 </dd>
4164 </dl></div>
4165 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
4166 this variable is unset, in which case the original environment is used).</p></div>
4167 </div>
4168 <div class="sect2">
4169 <h3 id="_exists">exists</h3>
4170 <div class="paragraph"><p><code><strong>exists ?-var|-proc|-command|-alias?</strong> <em>name</em></code></p></div>
4171 <div class="paragraph"><p>Checks the existence of the given variable, procedure, command
4172 or alias respectively and returns 1 if it exists or 0 if not. This command
4173 provides a more simplified/convenient version of <a href="#_info"><strong><code>info</code></strong></a> <code>exists</code>,
4174 <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>
4175 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
4176 </div>
4177 <div class="sect2">
4178 <h3 id="_exit">exit</h3>
4179 <div class="paragraph"><p><code><strong>exit</strong> <em>?returnCode?</em></code></p></div>
4180 <div class="paragraph"><p>Terminate the process, returning <code><em>returnCode</em></code> to the
4181 parent as the exit status.</p></div>
4182 <div class="paragraph"><p>If <code><em>returnCode</em></code> isn&#8217;t specified then it defaults
4183 to 0.</p></div>
4184 <div class="paragraph"><p>Note that exit can be caught with <a href="#_catch"><strong><code>catch</code></strong></a>.</p></div>
4185 </div>
4186 <div class="sect2">
4187 <h3 id="_expr">expr</h3>
4188 <div class="paragraph"><p><code><strong>expr</strong> <em>arg</em></code></p></div>
4189 <div class="paragraph"><p>Calls the expression processor to evaluate <code><em>arg</em></code>, and returns
4190 the result as a string. See the section EXPRESSIONS above.</p></div>
4191 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <a href="#_expr"><strong><code>expr</code></strong></a> as <code>$(...)</code>
4192 The following two are identical.</p></div>
4193 <div class="literalblock">
4194 <div class="content">
4195 <pre><code>set x [expr {3 * 2 + 1}]
4196 set x $(3 * 2 + 1)</code></pre>
4197 </div></div>
4198 </div>
4199 <div class="sect2">
4200 <h3 id="_file">file</h3>
4201 <div class="paragraph"><p><code><strong>file</strong> <em>option name ?arg...?</em></code></p></div>
4202 <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>
4203 <div class="paragraph"><p><code><em>option</em></code> indicates what to do with the file name. Any unique
4204 abbreviation for <code><em>option</em></code> is acceptable. The valid options are:</p></div>
4205 <div class="dlist"><dl>
4206 <dt class="hdlist1">
4207 <code><strong>file atime</strong> <em>name</em></code>
4208 </dt>
4209 <dd>
4211 Return a decimal string giving the time at which file <code><em>name</em></code>
4212 was last accessed. The time is measured in the standard UNIX
4213 fashion as seconds from a fixed starting time (often January 1, 1970).
4214 If the file doesn&#8217;t exist or its access time cannot be queried then an
4215 error is generated.
4216 </p>
4217 </dd>
4218 <dt class="hdlist1">
4219 <code><strong>file copy ?-force?</strong> <em>source target</em></code>
4220 </dt>
4221 <dd>
4223 Copies file <code><em>source</em></code> to file <code><em>target</em></code>. The source file must exist.
4224 The target file must not exist, unless <code>-force</code> is specified.
4225 </p>
4226 </dd>
4227 <dt class="hdlist1">
4228 <code><strong>file delete ?-force? ?--?</strong> <em>name...</em></code>
4229 </dt>
4230 <dd>
4232 Deletes file or directory <code><em>name</em></code>. If the file or directory doesn&#8217;t exist, nothing happens.
4233 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
4234 unless the <code>-force</code> options is given. In this case no errors will be generated, even
4235 if the file/directory can&#8217;t be deleted. Use <code><em>--</em></code> if there is any possibility of
4236 the first name being <code><em>-force</em></code>.
4237 </p>
4238 </dd>
4239 <dt class="hdlist1">
4240 <code><strong>file dirname</strong> <em>name</em></code>
4241 </dt>
4242 <dd>
4244 Return all of the characters in <code><em>name</em></code> up to but not including
4245 the last slash character. If there are no slashes in <code><em>name</em></code>
4246 then return <code>.</code> (a single dot). If the last slash in <code><em>name</em></code> is its first
4247 character, then return <code>/</code>.
4248 </p>
4249 </dd>
4250 <dt class="hdlist1">
4251 <code><strong>file executable</strong> <em>name</em></code>
4252 </dt>
4253 <dd>
4255 Return <em>1</em> if file <code><em>name</em></code> is executable by
4256 the current user, <em>0</em> otherwise.
4257 </p>
4258 </dd>
4259 <dt class="hdlist1">
4260 <code><strong>file exists</strong> <em>name</em></code>
4261 </dt>
4262 <dd>
4264 Return <em>1</em> if file <code><em>name</em></code> exists and the current user has
4265 search privileges for the directories leading to it, <em>0</em> otherwise.
4266 </p>
4267 </dd>
4268 <dt class="hdlist1">
4269 <code><strong>file extension</strong> <em>name</em></code>
4270 </dt>
4271 <dd>
4273 Return all of the characters in <code><em>name</em></code> after and including the
4274 last dot in <code><em>name</em></code>. If there is no dot in <code><em>name</em></code> then return
4275 the empty string.
4276 </p>
4277 </dd>
4278 <dt class="hdlist1">
4279 <code><strong>file isdirectory</strong> <em>name</em></code>
4280 </dt>
4281 <dd>
4283 Return <em>1</em> if file <code><em>name</em></code> is a directory,
4284 <em>0</em> otherwise.
4285 </p>
4286 </dd>
4287 <dt class="hdlist1">
4288 <code><strong>file isfile</strong> <em>name</em></code>
4289 </dt>
4290 <dd>
4292 Return <em>1</em> if file <code><em>name</em></code> is a regular file,
4293 <em>0</em> otherwise.
4294 </p>
4295 </dd>
4296 <dt class="hdlist1">
4297 <code><strong>file join</strong> <em>arg...</em></code>
4298 </dt>
4299 <dd>
4301 Joins multiple path components. Note that if any components is
4302 an absolute path, the preceding components are ignored.
4303 Thus <code>"<a href="#_file"><strong><code>file</code></strong></a> join /tmp /root"</code> returns <code>"/root"</code>.
4304 </p>
4305 </dd>
4306 <dt class="hdlist1">
4307 <code><strong>file link</strong> ?<strong>-hard|-symbolic</strong>? <em>newname target</em></code>
4308 </dt>
4309 <dd>
4311 Creates a hard link (default) or symbolic link from <code><em>newname</em></code> to <code><em>target</em></code>.
4312 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>
4313 and also of <code>ln</code>, but this is compatible with Tcl.
4314 An error is returned if <code><em>target</em></code> doesn&#8217;t exist or <code><em>newname</em></code> already exists.
4315 </p>
4316 </dd>
4317 <dt class="hdlist1">
4318 <code><strong>file lstat</strong> <em>name varName</em></code>
4319 </dt>
4320 <dd>
4322 Same as <em>stat</em> option (see below) except uses the <code><em>lstat</em></code>
4323 kernel call instead of <code><em>stat</em></code>. This means that if <code><em>name</em></code>
4324 refers to a symbolic link the information returned in <code><em>varName</em></code>
4325 is for the link rather than the file it refers to. On systems that
4326 don&#8217;t support symbolic links this option behaves exactly the same
4327 as the <em>stat</em> option.
4328 </p>
4329 </dd>
4330 <dt class="hdlist1">
4331 <code><strong>file mkdir</strong> <em>dir1 ?dir2...?</em></code>
4332 </dt>
4333 <dd>
4335 Creates each directory specified. For each pathname <code><em>dir</em></code> specified,
4336 this command will create all non-existing parent directories
4337 as well as <code><em>dir</em></code> itself. If an existing directory is specified,
4338 then no action is taken and no error is returned. Trying to
4339 overwrite an existing file with a directory will result in an
4340 error. Arguments are processed in the order specified, halting
4341 at the first error, if any.
4342 </p>
4343 </dd>
4344 <dt class="hdlist1">
4345 <code><strong>file mtime</strong> <em>name ?time?</em></code>
4346 </dt>
4347 <dd>
4349 Return a decimal string giving the time at which file <code><em>name</em></code>
4350 was last modified. The time is measured in the standard UNIX
4351 fashion as seconds from a fixed starting time (often January 1, 1970).
4352 If the file doesn&#8217;t exist or its modified time cannot be queried then an
4353 error is generated. If <code><em>time</em></code> is given, sets the modification time
4354 of the file to the given value.
4355 </p>
4356 </dd>
4357 <dt class="hdlist1">
4358 <code><strong>file normalize</strong> <em>name</em></code>
4359 </dt>
4360 <dd>
4362 Return the normalized path of <code><em>name</em></code>. See <em>realpath(3)</em>.
4363 </p>
4364 </dd>
4365 <dt class="hdlist1">
4366 <code><strong>file owned</strong> <em>name</em></code>
4367 </dt>
4368 <dd>
4370 Return <em>1</em> if file <code><em>name</em></code> is owned by the current user,
4371 <em>0</em> otherwise.
4372 </p>
4373 </dd>
4374 <dt class="hdlist1">
4375 <code><strong>file readable</strong> <em>name</em></code>
4376 </dt>
4377 <dd>
4379 Return <em>1</em> if file <code><em>name</em></code> is readable by
4380 the current user, <em>0</em> otherwise.
4381 </p>
4382 </dd>
4383 <dt class="hdlist1">
4384 <code><strong>file readlink</strong> <em>name</em></code>
4385 </dt>
4386 <dd>
4388 Returns the value of the symbolic link given by <code><em>name</em></code> (i.e. the
4389 name of the file it points to). If
4390 <code><em>name</em></code> isn&#8217;t a symbolic link or its value cannot be read, then
4391 an error is returned. On systems that don&#8217;t support symbolic links
4392 this option is undefined.
4393 </p>
4394 </dd>
4395 <dt class="hdlist1">
4396 <code><strong>file rename</strong> ?<strong>-force</strong>? <em>oldname</em> <em>newname</em></code>
4397 </dt>
4398 <dd>
4400 Renames the file from the old name to the new name.
4401 If <code><em>newname</em></code> already exists, an error is returned unless <code><em>-force</em></code> is
4402 specified.
4403 </p>
4404 </dd>
4405 <dt class="hdlist1">
4406 <code><strong>file rootname</strong> <em>name</em></code>
4407 </dt>
4408 <dd>
4410 Return all of the characters in <code><em>name</em></code> up to but not including
4411 the last <em>.</em> character in the name. If <code><em>name</em></code> doesn&#8217;t contain
4412 a dot, then return <code><em>name</em></code>.
4413 </p>
4414 </dd>
4415 <dt class="hdlist1">
4416 <code><strong>file size</strong> <em>name</em></code>
4417 </dt>
4418 <dd>
4420 Return a decimal string giving the size of file <code><em>name</em></code> in bytes.
4421 If the file doesn&#8217;t exist or its size cannot be queried then an
4422 error is generated.
4423 </p>
4424 </dd>
4425 <dt class="hdlist1">
4426 <code><strong>file stat</strong> <em>name ?varName?</em></code>
4427 </dt>
4428 <dd>
4430 Invoke the <em>stat</em> kernel call on <code><em>name</em></code>, and return the result
4431 as a dictionary with the following keys: <em>atime</em>,
4432 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
4433 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
4434 Each element except <em>type</em> is a decimal string with the value of
4435 the corresponding field from the <em>stat</em> return structure; see the
4436 manual entry for <em>stat</em> for details on the meanings of the values.
4437 The <em>type</em> element gives the type of the file in the same form
4438 returned by the command <a href="#_file"><strong><code>file</code></strong></a> <code>type</code>.
4439 If <code><em>varName</em></code> is specified, it is taken to be the name of an array
4440 variable and the values are also stored into the array.
4441 </p>
4442 </dd>
4443 <dt class="hdlist1">
4444 <code><strong>file tail</strong> <em>name</em></code>
4445 </dt>
4446 <dd>
4448 Return all of the characters in <code><em>name</em></code> after the last slash.
4449 If <code><em>name</em></code> contains no slashes then return <code><em>name</em></code>.
4450 </p>
4451 </dd>
4452 <dt class="hdlist1">
4453 <code><strong>file tempfile</strong> <em>?template?</em></code>
4454 </dt>
4455 <dd>
4457 Creates and returns the name of a unique temporary file. If <code><em>template</em></code> is omitted, a
4458 default template will be used to place the file in /tmp. See <em>mkstemp(3)</em> for
4459 the format of the template and security concerns.
4460 </p>
4461 </dd>
4462 <dt class="hdlist1">
4463 <code><strong>file type</strong> <em>name</em></code>
4464 </dt>
4465 <dd>
4467 Returns a string giving the type of file <code><em>name</em></code>, which will be
4468 one of <code>file</code>, <code>directory</code>, <code>characterSpecial</code>,
4469 <code>blockSpecial</code>, <code>fifo</code>, <code>link</code>, or <code>socket</code>.
4470 </p>
4471 </dd>
4472 <dt class="hdlist1">
4473 <code><strong>file writable</strong> <em>name</em></code>
4474 </dt>
4475 <dd>
4477 Return <em>1</em> if file <code><em>name</em></code> is writable by
4478 the current user, <em>0</em> otherwise.
4479 </p>
4480 </dd>
4481 </dl></div>
4482 <div class="paragraph"><p>The <a href="#_file"><strong><code>file</code></strong></a> commands that return 0/1 results are often used in
4483 conditional or looping commands, for example:</p></div>
4484 <div class="literalblock">
4485 <div class="content">
4486 <pre><code>if {![file exists foo]} {
4487 error {bad file name}
4488 } else {
4490 }</code></pre>
4491 </div></div>
4492 </div>
4493 <div class="sect2">
4494 <h3 id="_finalize">finalize</h3>
4495 <div class="paragraph"><p><code><strong>finalize</strong> <em>reference ?command?</em></code></p></div>
4496 <div class="paragraph"><p>If <code><em>command</em></code> is omitted, returns the finalizer command for the given reference.</p></div>
4497 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <code><em>command</em></code> may be
4498 the empty string to remove the current finalizer.</p></div>
4499 <div class="paragraph"><p>The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
4500 command.</p></div>
4501 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4502 </div>
4503 <div class="sect2">
4504 <h3 id="_flush">flush</h3>
4505 <div class="paragraph"><p><code><strong>flush</strong> <em>fileId</em></code></p></div>
4506 <div class="paragraph"><p><code><em>fileId</em> <strong>flush</strong></code></p></div>
4507 <div class="paragraph"><p>Flushes any output that has been buffered for <code><em>fileId</em></code>. <code><em>fileId</em></code> must
4508 have been the return value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
4509 <code>stdout</code> or <code>stderr</code> to access one of the standard I/O streams; it must
4510 refer to a file that was opened for writing. This command returns an
4511 empty string.</p></div>
4512 </div>
4513 <div class="sect2">
4514 <h3 id="_for">for</h3>
4515 <div class="paragraph"><p><code><strong>for</strong> <em>start test next body</em></code></p></div>
4516 <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.
4517 The <code><em>start</em></code>, <code><em>next</em></code>, and <code><em>body</em></code> arguments must be Tcl command strings,
4518 and <code><em>test</em></code> is an expression string.</p></div>
4519 <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>.
4520 Then it repeatedly evaluates <code><em>test</em></code> as an expression; if the result is
4521 non-zero it invokes the Tcl interpreter on <code><em>body</em></code>, then invokes the Tcl
4522 interpreter on <code><em>next</em></code>, then repeats the loop. The command terminates
4523 when <code><em>test</em></code> evaluates to 0.</p></div>
4524 <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
4525 commands in the current execution of <code><em>body</em></code> are skipped; processing
4526 continues by invoking the Tcl interpreter on <code><em>next</em></code>, then evaluating
4527 <code><em>test</em></code>, and so on.</p></div>
4528 <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>
4529 command will return immediately.</p></div>
4530 <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
4531 statements in C.</p></div>
4532 <div class="paragraph"><p><a href="#_for"><strong><code>for</code></strong></a> returns an empty string.</p></div>
4533 </div>
4534 <div class="sect2">
4535 <h3 id="_foreach">foreach</h3>
4536 <div class="paragraph"><p><code><strong>foreach</strong> <em>varName list body</em></code></p></div>
4537 <div class="paragraph"><p><code><strong>foreach</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
4538 <div class="paragraph"><p>In this command, <code><em>varName</em></code> is the name of a variable, <code><em>list</em></code>
4539 is a list of values to assign to <code><em>varName</em></code>, and <code><em>body</em></code> is a
4540 collection of Tcl commands.</p></div>
4541 <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
4542 the contents of the field to <code><em>varName</em></code> (as if the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
4543 had been used to extract the field), then calls the Tcl interpreter to
4544 execute <code><em>body</em></code>.</p></div>
4545 <div class="paragraph"><p>If instead of being a simple name, <code><em>varList</em></code> is used, multiple assignments
4546 are made each time through the loop, one for each element of <code><em>varList</em></code>.</p></div>
4547 <div class="paragraph"><p>For example, if there are two elements in <code><em>varList</em></code> and six elements in
4548 the list, the loop will be executed three times.</p></div>
4549 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
4550 in <code><em>varList</em></code>, the value of the remaining variables in the last iteration
4551 of the loop are undefined.</p></div>
4552 <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>,
4553 with the same effect as in the <a href="#_for"><strong><code>for</code></strong></a> command.</p></div>
4554 <div class="paragraph"><p><a href="#_foreach"><strong><code>foreach</code></strong></a> returns an empty string.</p></div>
4555 </div>
4556 <div class="sect2">
4557 <h3 id="_format">format</h3>
4558 <div class="paragraph"><p><code><strong>format</strong> <em>formatString ?arg ...?</em></code></p></div>
4559 <div class="paragraph"><p>This command generates a formatted string in the same way as the
4560 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
4561 implementation). <code><em>formatString</em></code> indicates how to format
4562 the result, using <code>%</code> fields as in <em>sprintf</em>, and the additional
4563 arguments, if any, provide values to be substituted into the result.</p></div>
4564 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
4565 man page for details. Each <code><em>arg</em></code> must match the expected type
4566 from the <code>%</code> field in <code><em>formatString</em></code>; the <a href="#_format"><strong><code>format</code></strong></a> command
4567 converts each argument to the correct type (floating, integer, etc.)
4568 before passing it to <em>sprintf</em> for formatting.</p></div>
4569 <div class="paragraph"><p>The only unusual conversion is for <code>%c</code>; in this case the argument
4570 must be a decimal string, which will then be converted to the corresponding
4571 ASCII (or UTF-8) character value.</p></div>
4572 <div class="paragraph"><p>In addition, Jim Tcl provides basic support for conversion to binary with <code>%b</code>.</p></div>
4573 <div class="paragraph"><p><a href="#_format"><strong><code>format</code></strong></a> does backslash substitution on its <code><em>formatString</em></code>
4574 argument, so backslash sequences in <code><em>formatString</em></code> will be handled
4575 correctly even if the argument is in braces.</p></div>
4576 <div class="paragraph"><p>The return value from <a href="#_format"><strong><code>format</code></strong></a> is the formatted string.</p></div>
4577 </div>
4578 <div class="sect2">
4579 <h3 id="_getref">getref</h3>
4580 <div class="paragraph"><p><code><strong>getref</strong> <em>reference</em></code></p></div>
4581 <div class="paragraph"><p>Returns the string associated with <code><em>reference</em></code>. The reference must
4582 be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a> command.</p></div>
4583 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
4584 </div>
4585 <div class="sect2">
4586 <h3 id="_gets">gets</h3>
4587 <div class="paragraph"><p><code><strong>gets</strong> <em>fileId ?varName?</em></code></p></div>
4588 <div class="paragraph"><p><code><em>fileId</em> <strong>gets</strong> <em>?varName?</em></code></p></div>
4589 <div class="paragraph"><p>Reads the next line from the file given by <code><em>fileId</em></code> and discards
4590 the terminating newline character.</p></div>
4591 <div class="paragraph"><p>If <code><em>varName</em></code> is specified, then the line is placed in the variable
4592 by that name and the return value is a count of the number of characters
4593 read (not including the newline).</p></div>
4594 <div class="paragraph"><p>If the end of the file is reached before reading
4595 any characters then -1 is returned and <code><em>varName</em></code> is set to an
4596 empty string.</p></div>
4597 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified then the return value will be
4598 the line (minus the newline character) or an empty string if
4599 the end of the file is reached before reading any characters.</p></div>
4600 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
4601 except the newline, so <a href="#_eof"><strong><code>eof</code></strong></a> may have to be used to determine
4602 what really happened.</p></div>
4603 <div class="paragraph"><p>If the last character in the file is not a newline character, then
4604 <a href="#_gets"><strong><code>gets</code></strong></a> behaves as if there were an additional newline character
4605 at the end of the file.</p></div>
4606 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous
4607 call to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened
4608 for reading.</p></div>
4609 </div>
4610 <div class="sect2">
4611 <h3 id="_glob">glob</h3>
4612 <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>
4613 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
4614 value from <a href="#_glob"><strong><code>glob</code></strong></a> is the list of expanded filenames.</p></div>
4615 <div class="paragraph"><p>If <code>-nocomplain</code> is specified as the first argument then an empty
4616 list may be returned; otherwise an error is returned if the expanded
4617 list is empty. The <code>-nocomplain</code> argument must be provided
4618 exactly: an abbreviation will not be accepted.</p></div>
4619 <div class="paragraph"><p>If <code>-directory</code> is given, the <code><em>dir</em></code> is understood to contain a
4620 directory name to search in. This allows globbing inside directories
4621 whose names may contain glob-sensitive characters. The returned names
4622 include the directory name unless <code><em>-tails</em></code> is specified.</p></div>
4623 <div class="paragraph"><p>If <code><em>-tails</em></code> is specified, along with <code>-directory</code>, the returned names
4624 are relative to the given directory.</p></div>
4625 </div>
4626 <div class="sect2">
4627 <h3 id="_global">global</h3>
4628 <div class="paragraph"><p><code><strong>global</strong> <em>varName ?varName ...?</em></code></p></div>
4629 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
4630 If so, then it declares each given <code><em>varName</em></code> to be a global variable
4631 rather than a local one. For the duration of the current procedure
4632 (and only while executing in the current procedure), any reference to
4633 <code><em>varName</em></code> will be bound to a global variable instead
4634 of a local one.</p></div>
4635 <div class="paragraph"><p>An alternative to using <a href="#_global"><strong><code>global</code></strong></a> is to use the <code>::</code> prefix
4636 to explicitly name a variable in the global scope.</p></div>
4637 </div>
4638 <div class="sect2">
4639 <h3 id="_if">if</h3>
4640 <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>
4641 <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
4642 that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument). The value of the expression must
4643 be numeric; if it is non-zero then <code><em>body1</em></code> is executed by passing it to
4644 the Tcl interpreter.</p></div>
4645 <div class="paragraph"><p>Otherwise <code><em>expr2</em></code> is evaluated as an expression and if it is non-zero
4646 then <code><em>body2</em></code> is executed, and so on.</p></div>
4647 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <code><em>bodyN</em></code> is executed.</p></div>
4648 <div class="paragraph"><p>The <code>then</code> and <code>else</code> arguments are optional "noise words" to make the
4649 command easier to read.</p></div>
4650 <div class="paragraph"><p>There may be any number of <code>elseif</code> clauses, including zero. <code><em>bodyN</em></code>
4651 may also be omitted as long as <code>else</code> is omitted too.</p></div>
4652 <div class="paragraph"><p>The return value from the command is the result of the body script that
4653 was executed, or an empty string if none of the expressions was non-zero
4654 and there was no <code><em>bodyN</em></code>.</p></div>
4655 </div>
4656 <div class="sect2">
4657 <h3 id="_incr">incr</h3>
4658 <div class="paragraph"><p><code><strong>incr</strong> <em>varName ?increment?</em></code></p></div>
4659 <div class="paragraph"><p>Increment the value stored in the variable whose name is <code><em>varName</em></code>.
4660 The value of the variable must be integral.</p></div>
4661 <div class="paragraph"><p>If <code><em>increment</em></code> is supplied then its value (which must be an
4662 integer) is added to the value of variable <code><em>varName</em></code>; otherwise
4663 1 is added to <code><em>varName</em></code>.</p></div>
4664 <div class="paragraph"><p>The new value is stored as a decimal string in variable <code><em>varName</em></code>
4665 and also returned as result.</p></div>
4666 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4667 and set to <code>0</code> first.</p></div>
4668 </div>
4669 <div class="sect2">
4670 <h3 id="_info">info</h3>
4671 <div class="dlist"><dl>
4672 <dt class="hdlist1">
4673 <code><strong>info</strong> <em>option ?arg...?</em></code>
4674 </dt>
4675 <dd>
4677 Provide information about various internals to the Tcl interpreter.
4678 The legal <code><em>option</em></code>'s (which may be abbreviated) are:
4679 </p>
4680 </dd>
4681 <dt class="hdlist1">
4682 <code><strong>info args</strong> <em>procname</em></code>
4683 </dt>
4684 <dd>
4686 Returns a list containing the names of the arguments to procedure
4687 <code><em>procname</em></code>, in order. <code><em>procname</em></code> must be the name of a
4688 Tcl command procedure.
4689 </p>
4690 </dd>
4691 <dt class="hdlist1">
4692 <code><strong>info alias</strong> <em>command</em></code>
4693 </dt>
4694 <dd>
4696 <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
4697 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>
4698 </p>
4699 </dd>
4700 <dt class="hdlist1">
4701 <code><strong>info body</strong> <em>procname</em></code>
4702 </dt>
4703 <dd>
4705 Returns the body of procedure <code><em>procname</em></code>. <code><em>procname</em></code> must be
4706 the name of a Tcl command procedure.
4707 </p>
4708 </dd>
4709 <dt class="hdlist1">
4710 <code><strong>info channels</strong></code>
4711 </dt>
4712 <dd>
4714 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>
4715 </p>
4716 </dd>
4717 <dt class="hdlist1">
4718 <code><strong>info commands</strong> ?<em>pattern</em>?</code>
4719 </dt>
4720 <dd>
4722 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of names of all the
4723 Tcl commands, including both the built-in commands written in C and
4724 the command procedures defined using the <a href="#_proc"><strong><code>proc</code></strong></a> command.
4725 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4726 are returned. Matching is determined using the same rules as for
4727 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4728 </p>
4729 </dd>
4730 <dt class="hdlist1">
4731 <code><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</code>
4732 </dt>
4733 <dd>
4735 Returns 1 if <code><em>command</em></code> is a complete Tcl command in the sense of
4736 having no unclosed quotes, braces, brackets or array element names,
4737 If the command doesn&#8217;t appear to be complete then 0 is returned.
4738 This command is typically used in line-oriented input environments
4739 to allow users to type in commands that span multiple lines; if the
4740 command isn&#8217;t complete, the script can delay evaluating it until additional
4741 lines have been typed to complete the command. If <code><em>varName</em></code> is specified, the
4742 missing character is stored in the variable with that name.
4743 </p>
4744 </dd>
4745 <dt class="hdlist1">
4746 <code><strong>info exists</strong> <em>varName</em></code>
4747 </dt>
4748 <dd>
4750 Returns <em>1</em> if the variable named <code><em>varName</em></code> exists in the
4751 current context (either as a global or local variable), returns <em>0</em>
4752 otherwise.
4753 </p>
4754 </dd>
4755 <dt class="hdlist1">
4756 <code><strong>info frame</strong> ?<em>number</em>?</code>
4757 </dt>
4758 <dd>
4760 If <code><em>number</em></code> is not specified, this command returns a number
4761 which is the same result as <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> - the current stack frame level.
4762 If <code><em>number</em></code> is specified, then the result is a list consisting of the procedure,
4763 filename and line number for the procedure call at level <code><em>number</em></code> on the stack.
4764 If <code><em>number</em></code> is positive then it selects a particular stack level (1 refers
4765 to the top-most active procedure, 2 to the procedure it called, and
4766 so on); otherwise it gives a level relative to the current level
4767 (0 refers to the current procedure, -1 to its caller, and so on).
4768 The level has an identical meaning to <a href="#_info"><strong><code>info</code></strong></a> <code>level</code>.
4769 </p>
4770 </dd>
4771 <dt class="hdlist1">
4772 <code><strong>info globals</strong> ?<em>pattern</em>?</code>
4773 </dt>
4774 <dd>
4776 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4777 of currently-defined global variables.
4778 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4779 are returned. Matching is determined using the same rules as for
4780 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4781 </p>
4782 </dd>
4783 <dt class="hdlist1">
4784 <code><strong>info hostname</strong></code>
4785 </dt>
4786 <dd>
4788 An alias for <a href="#cmd_1"><strong><code>os.gethostname</code></strong></a> for compatibility with Tcl 6.x
4789 </p>
4790 </dd>
4791 <dt class="hdlist1">
4792 <code><strong>info level</strong> ?<em>number</em>?</code>
4793 </dt>
4794 <dd>
4796 If <code><em>number</em></code> is not specified, this command returns a number
4797 giving the stack level of the invoking procedure, or 0 if the
4798 command is invoked at top-level. If <code><em>number</em></code> is specified,
4799 then the result is a list consisting of the name and arguments for the
4800 procedure call at level <code><em>number</em></code> on the stack. If <code><em>number</em></code>
4801 is positive then it selects a particular stack level (1 refers
4802 to the top-most active procedure, 2 to the procedure it called, and
4803 so on); otherwise it gives a level relative to the current level
4804 (0 refers to the current procedure, -1 to its caller, and so on).
4805 See the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command for more information on what stack
4806 levels mean.
4807 </p>
4808 </dd>
4809 <dt class="hdlist1">
4810 <code><strong>info locals</strong> ?<em>pattern</em>?</code>
4811 </dt>
4812 <dd>
4814 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the names
4815 of currently-defined local variables, including arguments to the
4816 current procedure, if any. Variables defined with the <a href="#_global"><strong><code>global</code></strong></a>
4817 and <a href="#_upvar"><strong><code>upvar</code></strong></a> commands will not be returned. If <code><em>pattern</em></code> is
4818 specified, only those names matching <code><em>pattern</em></code> are returned.
4819 Matching is determined using the same rules as for <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4820 </p>
4821 </dd>
4822 <dt class="hdlist1">
4823 <code><strong>info nameofexecutable</strong></code>
4824 </dt>
4825 <dd>
4827 Returns the name of the binary file from which the application
4828 was invoked. A full path will be returned, unless the path
4829 can&#8217;t be determined, in which case the empty string will be returned.
4830 </p>
4831 </dd>
4832 <dt class="hdlist1">
4833 <code><strong>info procs</strong> ?<em>pattern</em>?</code>
4834 </dt>
4835 <dd>
4837 If <code><em>pattern</em></code> isn&#8217;t specified, returns a list of all the
4838 names of Tcl command procedures.
4839 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4840 are returned. Matching is determined using the same rules as for
4841 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4842 </p>
4843 </dd>
4844 <dt class="hdlist1">
4845 <code><strong>info references</strong></code>
4846 </dt>
4847 <dd>
4849 Returns a list of all references which have not yet been garbage
4850 collected.
4851 </p>
4852 </dd>
4853 <dt class="hdlist1">
4854 <code><strong>info returncodes</strong> ?<em>code</em>?</code>
4855 </dt>
4856 <dd>
4858 Returns a list representing the mapping of standard return codes
4859 to names. e.g. <code>{0 ok 1 error 2 return ...}</code>. If a code is given,
4860 instead returns the name for the given code.
4861 </p>
4862 </dd>
4863 <dt class="hdlist1">
4864 <code><strong>info script</strong></code>
4865 </dt>
4866 <dd>
4868 If a Tcl script file is currently being evaluated (i.e. there is a
4869 call to <em>Jim_EvalFile</em> active or there is an active invocation
4870 of the <a href="#_source"><strong><code>source</code></strong></a> command), then this command returns the name
4871 of the innermost file being processed. Otherwise the command returns an
4872 empty string.
4873 </p>
4874 </dd>
4875 <dt class="hdlist1">
4876 <code><strong>info source</strong> <em>script ?filename line?</em></code>
4877 </dt>
4878 <dd>
4880 With a single argument, returns the original source location of the given script as a list of
4881 <code>{filename linenumber}</code>. If the source location can&#8217;t be determined, the
4882 list <code>{{} 0}</code> is returned. If <code><em>filename</em></code> and <code><em>line</em></code> are given, returns a copy
4883 of <code><em>script</em></code> with the associate source information. This can be useful to produce
4884 useful messages from <a href="#_eval"><strong><code>eval</code></strong></a>, etc. if the original source information may be lost.
4885 </p>
4886 </dd>
4887 <dt class="hdlist1">
4888 <code><strong>info stacktrace</strong></code>
4889 </dt>
4890 <dd>
4892 After an error is caught with <a href="#_catch"><strong><code>catch</code></strong></a>, returns the stack trace as a list
4893 of <code>{procedure filename line ...}</code>.
4894 </p>
4895 </dd>
4896 <dt class="hdlist1">
4897 <code><strong>info statics</strong> <em>procname</em></code>
4898 </dt>
4899 <dd>
4901 Returns a dictionary of the static variables of procedure
4902 <code><em>procname</em></code>. <code><em>procname</em></code> must be the name of a Tcl command
4903 procedure. An empty dictionary is returned if the procedure has
4904 no static variables.
4905 </p>
4906 </dd>
4907 <dt class="hdlist1">
4908 <code><strong>info version</strong></code>
4909 </dt>
4910 <dd>
4912 Returns the version number for this version of Jim in the form <code><strong>x.yy</strong></code>.
4913 </p>
4914 </dd>
4915 <dt class="hdlist1">
4916 <code><strong>info vars</strong> ?<em>pattern</em>?</code>
4917 </dt>
4918 <dd>
4920 If <code><em>pattern</em></code> isn&#8217;t specified,
4921 returns a list of all the names of currently-visible variables, including
4922 both locals and currently-visible globals.
4923 If <code><em>pattern</em></code> is specified, only those names matching <code><em>pattern</em></code>
4924 are returned. Matching is determined using the same rules as for
4925 <a href="#_string"><strong><code>string</code></strong></a> <code>match</code>.
4926 </p>
4927 </dd>
4928 </dl></div>
4929 </div>
4930 <div class="sect2">
4931 <h3 id="_join">join</h3>
4932 <div class="paragraph"><p><code><strong>join</strong> <em>list ?joinString?</em></code></p></div>
4933 <div class="paragraph"><p>The <code><em>list</em></code> argument must be a valid Tcl list. This command returns the
4934 string formed by joining all of the elements of <code><em>list</em></code> together with
4935 <code><em>joinString</em></code> separating each adjacent pair of elements.</p></div>
4936 <div class="paragraph"><p>The <code><em>joinString</em></code> argument defaults to a space character.</p></div>
4937 </div>
4938 <div class="sect2">
4939 <h3 id="_kill">kill</h3>
4940 <div class="paragraph"><p><code><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></code></p></div>
4941 <div class="paragraph"><p>Sends the given signal to the process identified by <code><em>pid</em></code>.</p></div>
4942 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4943 <div class="ulist"><ul>
4944 <li>
4946 <code>TERM</code>
4947 </p>
4948 </li>
4949 <li>
4951 <code>SIGTERM</code>
4952 </p>
4953 </li>
4954 <li>
4956 <code>-TERM</code>
4957 </p>
4958 </li>
4959 <li>
4961 <code>15</code>
4962 </p>
4963 </li>
4964 <li>
4966 <code>-15</code>
4967 </p>
4968 </li>
4969 </ul></div>
4970 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4971 <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>
4972 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4973 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4974 </div>
4975 <div class="sect2">
4976 <h3 id="_lambda">lambda</h3>
4977 <div class="paragraph"><p><code><strong>lambda</strong> <em>args ?statics? body</em></code></p></div>
4978 <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
4979 creating a named procedure, it creates an anonymous procedure and returns
4980 the name of the procedure.</p></div>
4981 <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>
4982 </div>
4983 <div class="sect2">
4984 <h3 id="_lappend">lappend</h3>
4985 <div class="paragraph"><p><code><strong>lappend</strong> <em>varName value ?value value ...?</em></code></p></div>
4986 <div class="paragraph"><p>Treat the variable given by <code><em>varName</em></code> as a list and append each of
4987 the <code><em>value</em></code> arguments to that list as a separate element, with spaces
4988 between elements.</p></div>
4989 <div class="paragraph"><p>If <code><em>varName</em></code> doesn&#8217;t exist, it is created as a list with elements given
4990 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
4991 each <code><em>value</em></code> is appended as a list element rather than raw text.</p></div>
4992 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4993 For example,</p></div>
4994 <div class="literalblock">
4995 <div class="content">
4996 <pre><code>lappend a $b</code></pre>
4997 </div></div>
4998 <div class="paragraph"><p>is much more efficient than</p></div>
4999 <div class="literalblock">
5000 <div class="content">
5001 <pre><code>set a [concat $a [list $b]]</code></pre>
5002 </div></div>
5003 <div class="paragraph"><p>when <code>$a</code> is long.</p></div>
5004 </div>
5005 <div class="sect2">
5006 <h3 id="_lassign">lassign</h3>
5007 <div class="paragraph"><p><code><strong>lassign</strong> <em>list varName ?varName ...?</em></code></p></div>
5008 <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
5009 the variables given by the <code><em>varName</em></code> arguments in order. If there are more variable names than
5010 list elements, the remaining variables are set to the empty string. If there are more list elements
5011 than variables, a list of unassigned elements is returned.</p></div>
5012 <div class="literalblock">
5013 <div class="content">
5014 <pre><code>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
5016 a=1,b=2</code></pre>
5017 </div></div>
5018 </div>
5019 <div class="sect2">
5020 <h3 id="_local">local</h3>
5021 <div class="paragraph"><p><code><strong>local</strong> <em>cmd ?arg...?</em></code></p></div>
5022 <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
5023 be the name of an existing command, which is marked as having local scope.
5024 This means that when the current procedure exits, the specified
5025 command is deleted. This can be useful with <a href="#_lambda"><strong><code>lambda</code></strong></a>, local procedures or
5026 to automatically close a filehandle.</p></div>
5027 <div class="paragraph"><p>In addition, if a command already exists with the same name,
5028 the existing command will be kept rather than deleted, and may be called
5029 via <a href="#_upcall"><strong><code>upcall</code></strong></a>. The previous command will be restored when the current
5030 procedure exits. See <a href="#_upcall"><strong><code>upcall</code></strong></a> for more details.</p></div>
5031 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
5032 continues to have global scope while it is active.</p></div>
5033 <div class="literalblock">
5034 <div class="content">
5035 <pre><code>proc outer {} {
5036 # proc ... returns "inner" which is marked local
5037 local proc inner {} {
5038 # will be deleted when 'outer' exits
5039 }</code></pre>
5040 </div></div>
5041 <div class="literalblock">
5042 <div class="content">
5043 <pre><code> inner
5045 }</code></pre>
5046 </div></div>
5047 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
5048 than waiting until garbage collection.</p></div>
5049 <div class="literalblock">
5050 <div class="content">
5051 <pre><code>proc outer {} {
5052 set x [lambda inner {args} {
5053 # will be deleted when 'outer' exits
5055 # Use 'function' here which simply returns $x
5056 local function $x</code></pre>
5057 </div></div>
5058 <div class="literalblock">
5059 <div class="content">
5060 <pre><code> $x ...
5062 }</code></pre>
5063 </div></div>
5064 </div>
5065 <div class="sect2">
5066 <h3 id="_loop">loop</h3>
5067 <div class="paragraph"><p><code><strong>loop</strong> <em>var first limit ?incr? body</em></code></p></div>
5068 <div class="paragraph"><p>Similar to <a href="#_for"><strong><code>for</code></strong></a> except simpler and possibly more efficient.
5069 With a positive increment, equivalent to:</p></div>
5070 <div class="literalblock">
5071 <div class="content">
5072 <pre><code>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</code></pre>
5073 </div></div>
5074 <div class="paragraph"><p>If <code><em>incr</em></code> is not specified, 1 is used.
5075 Note that setting the loop variable inside the loop does not
5076 affect the loop count.</p></div>
5077 </div>
5078 <div class="sect2">
5079 <h3 id="_lindex">lindex</h3>
5080 <div class="paragraph"><p><code><strong>lindex</strong> <em>list ?index &#8230;?</em></code></p></div>
5081 <div class="paragraph"><p>Treats <code><em>list</em></code> as a Tcl list and returns element <code><em>index</em></code> from it
5082 (0 refers to the first element of the list).
5083 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5084 <div class="paragraph"><p>In extracting the element, <code><em>lindex</em></code> observes the same rules concerning
5085 braces and quotes and backslashes as the Tcl command interpreter; however,
5086 variable substitution and command substitution do not occur.</p></div>
5087 <div class="paragraph"><p>If no index values are given, simply returns <code><em>list</em></code></p></div>
5088 <div class="paragraph"><p>If <code><em>index</em></code> is negative or greater than or equal to the number of elements
5089 in <code><em>list</em></code>, then an empty string is returned.</p></div>
5090 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5091 used in turn to select an element from the previous indexing
5092 operation, allowing the script to select elements from sublists.</p></div>
5093 </div>
5094 <div class="sect2">
5095 <h3 id="_linsert">linsert</h3>
5096 <div class="paragraph"><p><code><strong>linsert</strong> <em>list index element ?element element ...?</em></code></p></div>
5097 <div class="paragraph"><p>This command produces a new list from <code><em>list</em></code> by inserting all
5098 of the <code><em>element</em></code> arguments just before the element <code><em>index</em></code>
5099 of <code><em>list</em></code>. Each <code><em>element</em></code> argument will become
5100 a separate element of the new list. If <code><em>index</em></code> is less than
5101 or equal to zero, then the new elements are inserted at the
5102 beginning of the list. If <code><em>index</em></code> is greater than or equal
5103 to the number of elements in the list, then the new elements are
5104 appended to the list.</p></div>
5105 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5106 </div>
5107 <div class="sect2">
5108 <h3 id="_list">list</h3>
5109 <div class="paragraph"><p><code><strong>list</strong> <em>arg ?arg ...?</em></code></p></div>
5110 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <code><em>arg</em></code>. Braces
5111 and backslashes get added as necessary, so that the <a href="#_lindex"><strong><code>lindex</code></strong></a> command
5112 may be used on the result to re-extract the original arguments, and also
5113 so that <a href="#_eval"><strong><code>eval</code></strong></a> may be used to execute the resulting list, with
5114 <code><em>arg1</em></code> comprising the command&#8217;s name and the other args comprising
5115 its arguments. <a href="#_list"><strong><code>list</code></strong></a> produces slightly different results than
5116 <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
5117 the list, while <a href="#_list"><strong><code>list</code></strong></a> works directly from the original arguments.
5118 For example, the command</p></div>
5119 <div class="literalblock">
5120 <div class="content">
5121 <pre><code>list a b {c d e} {f {g h}}</code></pre>
5122 </div></div>
5123 <div class="paragraph"><p>will return</p></div>
5124 <div class="literalblock">
5125 <div class="content">
5126 <pre><code>a b {c d e} {f {g h}}</code></pre>
5127 </div></div>
5128 <div class="paragraph"><p>while <a href="#_concat"><strong><code>concat</code></strong></a> with the same arguments will return</p></div>
5129 <div class="literalblock">
5130 <div class="content">
5131 <pre><code>a b c d e f {g h}</code></pre>
5132 </div></div>
5133 </div>
5134 <div class="sect2">
5135 <h3 id="_llength">llength</h3>
5136 <div class="paragraph"><p><code><strong>llength</strong> <em>list</em></code></p></div>
5137 <div class="paragraph"><p>Treats <code><em>list</em></code> as a list and returns a decimal string giving
5138 the number of elements in it.</p></div>
5139 </div>
5140 <div class="sect2">
5141 <h3 id="_lset">lset</h3>
5142 <div class="paragraph"><p><code><strong>lset</strong> <em>varName ?index ..? newValue</em></code></p></div>
5143 <div class="paragraph"><p>Sets an element in a list.</p></div>
5144 <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
5145 as the name of a variable containing a Tcl list. It also accepts
5146 zero or more indices into the list. Finally, it accepts a new value
5147 for an element of varName. If no indices are presented, the command
5148 takes the form:</p></div>
5149 <div class="literalblock">
5150 <div class="content">
5151 <pre><code>lset varName newValue</code></pre>
5152 </div></div>
5153 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
5154 varName.</p></div>
5155 <div class="paragraph"><p>When presented with a single index, the <a href="#_lset"><strong><code>lset</code></strong></a> command
5156 treats the content of the varName variable as a Tcl list. It addresses
5157 the index&#8217;th element in it (0 refers to the first element of the
5158 list). When interpreting the list, <a href="#_lset"><strong><code>lset</code></strong></a> observes the same rules
5159 concerning braces and quotes and backslashes as the Tcl command
5160 interpreter; however, variable substitution and command substitution
5161 do not occur. The command constructs a new list in which the
5162 designated element is replaced with newValue. This new list is
5163 stored in the variable varName, and is also the return value from
5164 the <a href="#_lset"><strong><code>lset</code></strong></a> command.</p></div>
5165 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
5166 elements in $varName, then an error occurs.</p></div>
5167 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>index</em></code>.</p></div>
5168 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
5169 used in turn to address an element within a sublist designated by
5170 the previous indexing operation, allowing the script to alter
5171 elements in sublists. The command,</p></div>
5172 <div class="literalblock">
5173 <div class="content">
5174 <pre><code>lset a 1 2 newValue</code></pre>
5175 </div></div>
5176 <div class="paragraph"><p>replaces element 2 of sublist 1 with <code><em>newValue</em></code>.</p></div>
5177 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
5178 or equal to zero. The integer appearing in each index argument must
5179 be strictly less than the length of the corresponding list. In other
5180 words, the <a href="#_lset"><strong><code>lset</code></strong></a> command cannot change the size of a list. If an
5181 index is outside the permitted range, an error is reported.</p></div>
5182 </div>
5183 <div class="sect2">
5184 <h3 id="_lmap">lmap</h3>
5185 <div class="paragraph"><p><code><strong>lmap</strong> <em>varName list body</em></code></p></div>
5186 <div class="paragraph"><p><code><strong>lmap</strong> <em>varList list ?varList2 list2 ...? body</em></code></p></div>
5187 <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>
5188 <div class="paragraph"><p>For example:</p></div>
5189 <div class="literalblock">
5190 <div class="content">
5191 <pre><code>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
5192 1 4 9 16 25
5193 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
5194 {1 A} {2 B} {3 C}</code></pre>
5195 </div></div>
5196 <div class="paragraph"><p>If the body invokes <a href="#_continue"><strong><code>continue</code></strong></a>, no value is added for this iteration.
5197 If the body invokes <a href="#_break"><strong><code>break</code></strong></a>, the loop ends and no more values are added.</p></div>
5198 </div>
5199 <div class="sect2">
5200 <h3 id="_load">load</h3>
5201 <div class="paragraph"><p><code><strong>load</strong> <em>filename</em></code></p></div>
5202 <div class="paragraph"><p>Loads the dynamic extension, <code><em>filename</em></code>. Generally the filename should have
5203 the extension <code>.so</code>. The initialisation function for the module must be based
5204 on the name of the file. For example loading <code>hwaccess.so</code> will invoke
5205 the initialisation function, <code>Jim_hwaccessInit</code>. Normally the <a href="#_load"><strong><code>load</code></strong></a> command
5206 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>
5207 </div>
5208 <div class="sect2">
5209 <h3 id="_lrange">lrange</h3>
5210 <div class="paragraph"><p><code><strong>lrange</strong> <em>list first last</em></code></p></div>
5211 <div class="paragraph"><p><code><em>list</em></code> must be a valid Tcl list. This command will return a new
5212 list consisting of elements <code><em>first</em></code> through <code><em>last</em></code>, inclusive.</p></div>
5213 <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>
5214 <div class="paragraph"><p>If <code><em>last</em></code> is greater than or equal to the number of elements
5215 in the list, then it is treated as if it were <code>end</code>.</p></div>
5216 <div class="paragraph"><p>If <code><em>first</em></code> is greater than <code><em>last</em></code> then an empty string
5217 is returned.</p></div>
5218 <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
5219 same result as <code>"<a href="#_lindex"><strong><code>lindex</code></strong></a> <em>list first</em>"</code> (although it often does
5220 for simple fields that aren&#8217;t enclosed in braces); it does, however,
5221 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>
5222 </div>
5223 <div class="sect2">
5224 <h3 id="_lreplace">lreplace</h3>
5225 <div class="paragraph"><p><code><strong>lreplace</strong> <em>list first last ?element element ...?</em></code></p></div>
5226 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
5227 <code><em>list</em></code> with the <code><em>element</em></code> arguments.</p></div>
5228 <div class="paragraph"><p><code><em>first</em></code> gives the index in <code><em>list</em></code> of the first element
5229 to be replaced.</p></div>
5230 <div class="paragraph"><p>If <code><em>first</em></code> is less than zero then it refers to the first
5231 element of <code><em>list</em></code>; the element indicated by <code><em>first</em></code>
5232 must exist in the list.</p></div>
5233 <div class="paragraph"><p><code><em>last</em></code> gives the index in <code><em>list</em></code> of the last element
5234 to be replaced; it must be greater than or equal to <code><em>first</em></code>.</p></div>
5235 <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>
5236 <div class="paragraph"><p>The <code><em>element</em></code> arguments specify zero or more new arguments to
5237 be added to the list in place of those that were deleted.</p></div>
5238 <div class="paragraph"><p>Each <code><em>element</em></code> argument will become a separate element of
5239 the list.</p></div>
5240 <div class="paragraph"><p>If no <code><em>element</em></code> arguments are specified, then the elements
5241 between <code><em>first</em></code> and <code><em>last</em></code> are simply deleted.</p></div>
5242 </div>
5243 <div class="sect2">
5244 <h3 id="_lrepeat">lrepeat</h3>
5245 <div class="paragraph"><p><code><strong>lrepeat</strong> <em>number element1 ?element2 ...?</em></code></p></div>
5246 <div class="paragraph"><p>Build a list by repeating elements <code><em>number</em></code> times (which must be
5247 a positive integer).</p></div>
5248 <div class="literalblock">
5249 <div class="content">
5250 <pre><code>jim&gt; lrepeat 3 a b
5251 a b a b a b</code></pre>
5252 </div></div>
5253 </div>
5254 <div class="sect2">
5255 <h3 id="_lreverse">lreverse</h3>
5256 <div class="paragraph"><p><code><strong>lreverse</strong> <em>list</em></code></p></div>
5257 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
5258 <div class="literalblock">
5259 <div class="content">
5260 <pre><code>jim&gt; lreverse {1 2 3}
5261 3 2 1</code></pre>
5262 </div></div>
5263 </div>
5264 <div class="sect2">
5265 <h3 id="_lsearch">lsearch</h3>
5266 <div class="paragraph"><p><code><strong>lsearch</strong> <em>?options? list pattern</em></code></p></div>
5267 <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
5268 command returns the index of the first matching element (unless the options <code>-all</code>, <code>-inline</code> or <code>-bool</code> are
5269 specified.) If not, the command returns -1. The option arguments indicates how the elements of
5270 the list are to be matched against pattern and must have one of the values below:</p></div>
5271 <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>
5272 <div class="dlist"><dl>
5273 <dt class="hdlist1">
5274 <code><strong>-exact</strong></code>
5275 </dt>
5276 <dd>
5278 <code><em>pattern</em></code> is a literal string that is compared for exact equality against each list element.
5279 This is the default.
5280 </p>
5281 </dd>
5282 <dt class="hdlist1">
5283 <code><strong>-glob</strong></code>
5284 </dt>
5285 <dd>
5287 <code><em>pattern</em></code> is a glob-style pattern which is matched against each list element using the same
5288 rules as the string match command.
5289 </p>
5290 </dd>
5291 <dt class="hdlist1">
5292 <code><strong>-regexp</strong></code>
5293 </dt>
5294 <dd>
5296 <code><em>pattern</em></code> is treated as a regular expression and matched against each list element using
5297 the rules described by <a href="#_regexp"><strong><code>regexp</code></strong></a>.
5298 </p>
5299 </dd>
5300 <dt class="hdlist1">
5301 <code><strong>-command</strong> <em>cmdname</em></code>
5302 </dt>
5303 <dd>
5305 <code><em>cmdname</em></code> is a command which is used to match the pattern against each element of the
5306 list. It is invoked as <code><em>cmdname</em> ?<strong>-nocase</strong>? <em>pattern listvalue</em></code> and should return 1
5307 for a match, or 0 for no match.
5308 </p>
5309 </dd>
5310 <dt class="hdlist1">
5311 <code><strong>-all</strong></code>
5312 </dt>
5313 <dd>
5315 Changes the result to be the list of all matching indices (or all matching values if
5316 <code>-inline</code> is specified as well). If indices are returned, the indices will be in numeric
5317 order. If values are returned, the order of the values will be the order of those values
5318 within the input list.
5319 </p>
5320 </dd>
5321 <dt class="hdlist1">
5322 <code><strong>-inline</strong></code>
5323 </dt>
5324 <dd>
5326 The matching value is returned instead of its index (or an empty string if no value
5327 matches). If <code>-all</code> is also specified, then the result of the command is the list of all
5328 values that matched. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5329 </p>
5330 </dd>
5331 <dt class="hdlist1">
5332 <code><strong>-bool</strong></code>
5333 </dt>
5334 <dd>
5336 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <code>-all</code> is also specified,
5337 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
5338 the corresponding element matches. The <code>-inline</code> and <code>-bool</code> options are mutually exclusive.
5339 </p>
5340 </dd>
5341 <dt class="hdlist1">
5342 <code><strong>-not</strong></code>
5343 </dt>
5344 <dd>
5346 This negates the sense of the match, returning the index (or value
5347 if <code>-inline</code> is specified) of the first non-matching value in the
5348 list. If <code>-bool</code> is also specified, the <em>0</em> will be returned if a
5349 match is found, or <em>1</em> otherwise. If <code>-all</code> is also specified,
5350 non-matches will be returned rather than matches.
5351 </p>
5352 </dd>
5353 <dt class="hdlist1">
5354 <code><strong>-nocase</strong></code>
5355 </dt>
5356 <dd>
5358 Causes comparisons to be handled in a case-insensitive manner.
5359 </p>
5360 </dd>
5361 </dl></div>
5362 </div>
5363 <div class="sect2">
5364 <h3 id="_lsort">lsort</h3>
5365 <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>
5366 <div class="paragraph"><p>Sort the elements of <code><em>list</em></code>, returning a new list in sorted order.
5367 By default, ASCII (or UTF-8) sorting is used, with the result in increasing order.</p></div>
5368 <div class="paragraph"><p>If <code>-nocase</code> is specified, comparisons are case-insensitive.</p></div>
5369 <div class="paragraph"><p>If <code>-integer</code> is specified, numeric sorting is used.</p></div>
5370 <div class="paragraph"><p>If <code>-real</code> is specified, floating point number sorting is used.</p></div>
5371 <div class="paragraph"><p>If <code>-command <em>cmdname</em></code> is specified, <code><em>cmdname</em></code> is treated as a command
5372 name. For each comparison, <code><em>cmdname $value1 $value2</code></em> is called which
5373 should compare the values and return an integer less than, equal
5374 to, or greater than zero if the <code><em>$value1</em></code> is to be considered less
5375 than, equal to, or greater than <code><em>$value2</em></code>, respectively.</p></div>
5376 <div class="paragraph"><p>If <code>-decreasing</code> is specified, the resulting list is in the opposite
5377 order to what it would be otherwise. <code>-increasing</code> is the default.</p></div>
5378 <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.
5379 Note that duplicates are determined relative to the comparison used in the sort. Thus if <code>-index 0</code> is used,
5380 <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>
5381 <div class="paragraph"><p>If <code>-index <em>listindex</em></code> is specified, each element of the list is treated as a list and
5382 the given index is extracted from the list for comparison. The list index may
5383 be any valid list index, such as <code>1</code>, <code>end</code> or <code>end-2</code>.</p></div>
5384 </div>
5385 <div class="sect2">
5386 <h3 id="_defer">defer</h3>
5387 <div class="paragraph"><p><code><strong>defer</strong> <em>script</em></code></p></div>
5388 <div class="paragraph"><p>This command is a simple helper command to add a script to the <em><code>$jim::defer</code></em> variable
5389 that will run when the current proc or interpreter exits. For example:</p></div>
5390 <div class="literalblock">
5391 <div class="content">
5392 <pre><code>jim&gt; proc a {} { defer {puts "Leaving a"}; puts "Exit" }
5393 jim&gt; a
5394 Exit
5395 Leaving a</code></pre>
5396 </div></div>
5397 <div class="paragraph"><p>If the <em><code>$jim::defer</code></em> variable exists, it is treated as a list of scripts to run
5398 when the proc or interpreter exits.</p></div>
5399 </div>
5400 <div class="sect2">
5401 <h3 id="_open">open</h3>
5402 <div class="paragraph"><p><code><strong>open</strong> <em>fileName ?access?</em></code></p></div>
5403 <div class="paragraph"><p><code><strong>open</strong> <em>|command-pipeline ?access?</em></code></p></div>
5404 <div class="paragraph"><p>Opens a file and returns an identifier
5405 that may be used in future invocations
5406 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>.
5407 <code><em>fileName</em></code> gives the name of the file to open.</p></div>
5408 <div class="paragraph"><p>The <code><em>access</em></code> argument indicates the way in which the file is to be accessed.
5409 It may have any of the following values:</p></div>
5410 <div class="dlist"><dl>
5411 <dt class="hdlist1">
5412 <code>r</code>
5413 </dt>
5414 <dd>
5416 Open the file for reading only; the file must already exist.
5417 </p>
5418 </dd>
5419 <dt class="hdlist1">
5420 <code>r</code>+
5421 </dt>
5422 <dd>
5424 Open the file for both reading and writing; the file must
5425 already exist.
5426 </p>
5427 </dd>
5428 <dt class="hdlist1">
5429 <code>w</code>
5430 </dt>
5431 <dd>
5433 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
5434 exist, create a new file.
5435 </p>
5436 </dd>
5437 <dt class="hdlist1">
5438 <code>w</code>+
5439 </dt>
5440 <dd>
5442 Open the file for reading and writing. Truncate it if it exists.
5443 If it doesn&#8217;t exist, create a new file.
5444 </p>
5445 </dd>
5446 <dt class="hdlist1">
5447 <code>a</code>
5448 </dt>
5449 <dd>
5451 Open the file for writing only. The file must already exist, and the file
5452 is positioned so that new data is appended to the file.
5453 </p>
5454 </dd>
5455 <dt class="hdlist1">
5456 <code>a</code>+
5457 </dt>
5458 <dd>
5460 Open the file for reading and writing. If the file doesn&#8217;t
5461 exist, create a new empty file. Set the initial access position
5462 to the end of the file.
5463 </p>
5464 </dd>
5465 </dl></div>
5466 <div class="paragraph"><p><code><em>access</em></code> defaults to <em>r</em>.</p></div>
5467 <div class="paragraph"><p>If a file is opened for both reading and writing, then <a href="#_seek"><strong><code>seek</code></strong></a>
5468 must be invoked between a read and a write, or vice versa.</p></div>
5469 <div class="paragraph"><p>If the first character of <code><em>fileName</em></code> is "|" then the remaining
5470 characters of <code><em>fileName</em></code> are treated as a list of arguments that
5471 describe a command pipeline to invoke, in the same style as the
5472 arguments for exec. In this case, the channel identifier returned
5473 by open may be used to write to the command&#8217;s input pipe or read
5474 from its output pipe, depending on the value of <code><em>access</em></code>. If write-only
5475 access is used (e.g. <code><em>access</em></code> is <em>w</em>), then standard output for the
5476 pipeline is directed to the current standard output unless overridden
5477 by the command. If read-only access is used (e.g. <code><em>access</em></code> is r),
5478 standard input for the pipeline is taken from the current standard
5479 input unless overridden by the command.</p></div>
5480 <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
5481 forming the command pipeline.</p></div>
5482 <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>
5483 </div>
5484 <div class="sect2">
5485 <h3 id="_package">package</h3>
5486 <div class="paragraph"><p><code><strong>package provide</strong> <em>name ?version?</em></code></p></div>
5487 <div class="paragraph"><p>Indicates that the current script provides the package named <code><em>name</em></code>.
5488 If no version is specified, <em>1.0</em> is used.</p></div>
5489 <div class="paragraph"><p>Any script which provides a package may include this statement
5490 as the first statement, although it is not required.</p></div>
5491 <div class="paragraph"><p><code><strong>package require</strong> <em>name ?version?</em>*</code></p></div>
5492 <div class="paragraph"><p>Searches for the package with the given <code><em>name</em></code> by examining each path
5493 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
5494 or <em>$path/$name.tcl</em> as a script package.</p></div>
5495 <div class="paragraph"><p>The first such file which is found is considered to provide the package.
5496 (The version number is ignored).</p></div>
5497 <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,
5498 otherwise if <em>$name.tcl</em> exists it is loaded with the <a href="#_source"><strong><code>source</code></strong></a> command.</p></div>
5499 <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.
5500 No further attempt will be made to locate the file.</p></div>
5501 </div>
5502 <div class="sect2">
5503 <h3 id="_pid">pid</h3>
5504 <div class="paragraph"><p><code><strong>pid</strong></code></p></div>
5505 <div class="paragraph"><p><code><strong>pid</strong> <em>fileId</em></code></p></div>
5506 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
5507 <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
5508 of the process ids forming the pipeline in the same form as <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>.
5509 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
5510 the empty string is returned instead.</p></div>
5511 <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>
5512 </div>
5513 <div class="sect2">
5514 <h3 id="_proc">proc</h3>
5515 <div class="paragraph"><p><code><strong>proc</strong> <em>name args ?statics? body</em></code></p></div>
5516 <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>.
5517 When the new command is invoked, the contents of <code><em>body</em></code> will be executed.
5518 Tcl interpreter. <code><em>args</em></code> specifies the formal arguments to the procedure.
5519 If specified, <code><em>statics</em></code>, declares static variables which are bound to the
5520 procedure.</p></div>
5521 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
5522 <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>
5523 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
5524 value specified in a <a href="#_return"><strong><code>return</code></strong></a> command. If the procedure doesn&#8217;t
5525 execute an explicit <a href="#_return"><strong><code>return</code></strong></a>, then its return value is the value
5526 of the last command executed in the procedure&#8217;s body.</p></div>
5527 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
5528 procedure-as-a-whole will return that same error.</p></div>
5529 </div>
5530 <div class="sect2">
5531 <h3 id="_puts">puts</h3>
5532 <div class="paragraph"><p><code><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></code></p></div>
5533 <div class="paragraph"><p><code><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></code></p></div>
5534 <div class="paragraph"><p>Writes the characters given by <code><em>string</em></code> to the file given
5535 by <code><em>fileId</em></code>. <code><em>fileId</em></code> must have been the return
5536 value from a previous call to <a href="#_open"><strong><code>open</code></strong></a>, or it may be
5537 <code>stdout</code> or <code>stderr</code> to refer to one of the standard I/O
5538 channels; it must refer to a file that was opened for
5539 writing.</p></div>
5540 <div class="paragraph"><p>In the first form, if no <code><em>fileId</em></code> is specified then it defaults to <code>stdout</code>.
5541 <a href="#_puts"><strong><code>puts</code></strong></a> normally outputs a newline character after <code><em>string</em></code>,
5542 but this feature may be suppressed by specifying the <code>-nonewline</code>
5543 switch.</p></div>
5544 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <a href="#_flush"><strong><code>flush</code></strong></a>
5545 command may be used to force buffered characters to be output.</p></div>
5546 </div>
5547 <div class="sect2">
5548 <h3 id="_pipe">pipe</h3>
5549 <div class="paragraph"><p>Creates a pair of <a href="#_aio"><strong><code>aio</code></strong></a> channels and returns the handles as a list: <code>{read write}</code></p></div>
5550 </div>
5551 <div class="sect2">
5552 <h3 id="_pwd">pwd</h3>
5553 <div class="paragraph"><p><code><strong>pwd</strong></code></p></div>
5554 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
5555 </div>
5556 <div class="sect2">
5557 <h3 id="_rand">rand</h3>
5558 <div class="paragraph"><p><code><strong>rand</strong> <em>?min? ?max?</em></code></p></div>
5559 <div class="paragraph"><p>Returns a random integer between <code><em>min</em></code> (defaults to 0) and <code><em>max</em></code>
5560 (defaults to the maximum integer).</p></div>
5561 <div class="paragraph"><p>If only one argument is given, it is interpreted as <code><em>max</em></code>.</p></div>
5562 </div>
5563 <div class="sect2">
5564 <h3 id="_range">range</h3>
5565 <div class="paragraph"><p><code><strong>range</strong> <em>?start? end ?step?</em></code></p></div>
5566 <div class="paragraph"><p>Returns a list of integers starting at <code><em>start</em></code> (defaults to 0)
5567 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>
5568 <div class="literalblock">
5569 <div class="content">
5570 <pre><code>jim&gt; range 5
5571 0 1 2 3 4
5572 jim&gt; range 2 5
5573 2 3 4
5574 jim&gt; range 2 10 4
5576 jim&gt; range 7 4 -2
5577 7 5</code></pre>
5578 </div></div>
5579 </div>
5580 <div class="sect2">
5581 <h3 id="_read">read</h3>
5582 <div class="paragraph"><p><code><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></code></p></div>
5583 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</code></p></div>
5584 <div class="paragraph"><p><code><strong>read</strong> <em>fileId numBytes</em></code></p></div>
5585 <div class="paragraph"><p><code><em>fileId</em> <strong>read</strong> <em>numBytes</em></code></p></div>
5586 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
5587 given by <code><em>fileId</em></code>; they are returned as the result of the command.
5588 If the <code>-nonewline</code> switch is specified then the last
5589 character of the file is discarded if it is a newline.</p></div>
5590 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
5591 exactly this many bytes will be read and returned, unless there are fewer than
5592 <code><em>numBytes</em></code> bytes left in the file; in this case, all the remaining
5593 bytes are returned.</p></div>
5594 <div class="paragraph"><p><code><em>fileId</em></code> must be <code>stdin</code> or the return value from a previous call
5595 to <a href="#_open"><strong><code>open</code></strong></a>; it must refer to a file that was opened for reading.</p></div>
5596 </div>
5597 <div class="sect2">
5598 <h3 id="_regexp">regexp</h3>
5599 <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>
5600 <div class="paragraph"><p>Determines whether the regular expression <code><em>exp</em></code> matches part or
5601 all of <code><em>string</em></code> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
5602 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
5603 syntax of <code><em>exp</em></code> and how it is matched against <code><em>string</em></code>.</p></div>
5604 <div class="paragraph"><p>If additional arguments are specified after <code><em>string</em></code> then they
5605 are treated as the names of variables to use to return
5606 information about which part(s) of <code><em>string</em></code> matched <code><em>exp</em></code>.
5607 <code><em>matchVar</em></code> will be set to the range of <code><em>string</em></code> that
5608 matched all of <code><em>exp</em></code>. The first <code><em>subMatchVar</em></code> will contain
5609 the characters in <code><em>string</em></code> that matched the leftmost parenthesized
5610 subexpression within <code><em>exp</em></code>, the next <code><em>subMatchVar</em></code> will
5611 contain the characters that matched the next parenthesized
5612 subexpression to the right in <code><em>exp</em></code>, and so on.</p></div>
5613 <div class="paragraph"><p>Normally, <code><em>matchVar</em></code> and the each <code><em>subMatchVar</em></code> are set to hold the
5614 matching characters from <a href="#_string"><strong><code>string</code></strong></a>, however see <code>-indices</code> and
5615 <code>-inline</code> below.</p></div>
5616 <div class="paragraph"><p>If there are more values for <code><em>subMatchVar</em></code> than parenthesized subexpressions
5617 within <code><em>exp</em></code>, or if a particular subexpression in <code><em>exp</em></code> doesn&#8217;t
5618 match the string (e.g. because it was in a portion of the expression
5619 that wasn&#8217;t matched), then the corresponding <code><em>subMatchVar</em></code> will be
5620 set to <code>"-1 -1"</code> if <code>-indices</code> has been specified or to an empty
5621 string otherwise.</p></div>
5622 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regexp</em></code></p></div>
5623 <div class="dlist"><dl>
5624 <dt class="hdlist1">
5625 <code><strong>-nocase</strong></code>
5626 </dt>
5627 <dd>
5629 Causes upper-case and lower-case characters to be treated as
5630 identical during the matching process.
5631 </p>
5632 </dd>
5633 <dt class="hdlist1">
5634 <code><strong>-line</strong></code>
5635 </dt>
5636 <dd>
5638 Use newline-sensitive matching. By default, newline
5639 is a completely ordinary character with no special meaning in
5640 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5641 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5642 string after any newline in the string in addition to its normal
5643 function, and the <code>$</code> anchor matches the null string before any
5644 newline in the string in addition to its normal function.
5645 </p>
5646 </dd>
5647 <dt class="hdlist1">
5648 <code><strong>-indices</strong></code>
5649 </dt>
5650 <dd>
5652 Changes what is stored in the subMatchVars. Instead of
5653 storing the matching characters from string, each variable
5654 will contain a list of two decimal strings giving the indices
5655 in string of the first and last characters in the matching
5656 range of characters.
5657 </p>
5658 </dd>
5659 <dt class="hdlist1">
5660 <code><strong>-start</strong> <em>offset</em></code>
5661 </dt>
5662 <dd>
5664 Specifies a character index offset into the string at which to start
5665 matching the regular expression. If <code>-indices</code> is
5666 specified, the indices will be indexed starting from the
5667 absolute beginning of the input string. <code><em>offset</em></code> will be
5668 constrained to the bounds of the input string.
5669 </p>
5670 </dd>
5671 <dt class="hdlist1">
5672 <code><strong>-all</strong></code>
5673 </dt>
5674 <dd>
5676 Causes the regular expression to be matched as many times as possible
5677 in the string, returning the total number of matches found. If this
5678 is specified with match variables, they will contain information
5679 for the last match only.
5680 </p>
5681 </dd>
5682 <dt class="hdlist1">
5683 <code><strong>-inline</strong></code>
5684 </dt>
5685 <dd>
5687 Causes the command to return, as a list, the data that would otherwise
5688 be placed in match variables. When using <code>-inline</code>, match variables
5689 may not be specified. If used with <code>-all</code>, the list will be concatenated
5690 at each iteration, such that a flat list is always returned. For
5691 each match iteration, the command will append the overall match
5692 data, plus one element for each subexpression in the regular
5693 expression.
5694 </p>
5695 </dd>
5696 <dt class="hdlist1">
5697 <code><strong>--</strong></code>
5698 </dt>
5699 <dd>
5701 Marks the end of switches. The argument following this one will be
5702 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5703 </p>
5704 </dd>
5705 </dl></div>
5706 </div>
5707 <div class="sect2">
5708 <h3 id="_regsub">regsub</h3>
5709 <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>
5710 <div class="paragraph"><p>This command matches the regular expression <code><em>exp</em></code> against
5711 <code><em>string</em></code> using the rules described in REGULAR EXPRESSIONS
5712 above.</p></div>
5713 <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>
5714 with the substitutions detailed below, and returns the number of
5715 substitutions made (normally 1 unless <code>-all</code> is specified).
5716 This is 0 if there were no matches.</p></div>
5717 <div class="paragraph"><p>If <code><em>varName</em></code> is not specified, the substituted string will be returned
5718 instead.</p></div>
5719 <div class="paragraph"><p>When copying <code><em>string</em></code>, the portion of <code><em>string</em></code> that
5720 matched <code><em>exp</em></code> is replaced with <code><em>subSpec</em></code>.
5721 If <code><em>subSpec</em></code> contains a <code>&amp;</code> or <code>\0</code>, then it is replaced
5722 in the substitution with the portion of <code><em>string</em></code> that
5723 matched <code><em>exp</em></code>.</p></div>
5724 <div class="paragraph"><p>If <code><em>subSpec</em></code> contains a <code>\n</code>, where <code><em>n</em></code> is a digit
5725 between 1 and 9, then it is replaced in the substitution with
5726 the portion of <code><em>string</em></code> that matched the <code><em>n</em></code>'-th
5727 parenthesized subexpression of <code><em>exp</em></code>.
5728 Additional backslashes may be used in <code><em>subSpec</em></code> to prevent special
5729 interpretation of <code>&amp;</code> or <code>\0</code> or <code>\n</code> or
5730 backslash.</p></div>
5731 <div class="paragraph"><p>The use of backslashes in <code><em>subSpec</em></code> tends to interact badly
5732 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5733 safest to enclose <code><em>subSpec</em></code> in braces if it includes
5734 backslashes.</p></div>
5735 <div class="paragraph"><p>The following switches modify the behaviour of <code><em>regsub</em></code></p></div>
5736 <div class="dlist"><dl>
5737 <dt class="hdlist1">
5738 <code><strong>-nocase</strong></code>
5739 </dt>
5740 <dd>
5742 Upper-case characters in <code><em>string</em></code> are converted to lower-case
5743 before matching against <code><em>exp</em></code>; however, substitutions
5744 specified by <code><em>subSpec</em></code> use the original unconverted form
5745 of <code><em>string</em></code>.
5746 </p>
5747 </dd>
5748 <dt class="hdlist1">
5749 <code><strong>-all</strong></code>
5750 </dt>
5751 <dd>
5753 All ranges in <code><em>string</em></code> that match <code><em>exp</em></code> are found and substitution
5754 is performed for each of these ranges, rather than only the
5755 first. The <code>&amp;</code> and <code>\n</code> sequences are handled for
5756 each substitution using the information from the corresponding
5757 match.
5758 </p>
5759 </dd>
5760 <dt class="hdlist1">
5761 <code><strong>-line</strong></code>
5762 </dt>
5763 <dd>
5765 Use newline-sensitive matching. By default, newline
5766 is a completely ordinary character with no special meaning in
5767 either REs or strings. With this flag, <code>[<sup></code> bracket expressions
5768 and <code>.</code> never match newline, an <code></sup></code> anchor matches the null
5769 string after any newline in the string in addition to its normal
5770 function, and the <code>$</code> anchor matches the null string before any
5771 newline in the string in addition to its normal function.
5772 </p>
5773 </dd>
5774 <dt class="hdlist1">
5775 <code><strong>-start</strong> <em>offset</em></code>
5776 </dt>
5777 <dd>
5779 Specifies a character index offset into the string at which to
5780 start matching the regular expression. <code><em>offset</em></code> will be
5781 constrained to the bounds of the input string.
5782 </p>
5783 </dd>
5784 <dt class="hdlist1">
5785 <code><strong>--</strong></code>
5786 </dt>
5787 <dd>
5789 Marks the end of switches. The argument following this one will be
5790 treated as <code><em>exp</em></code> even if it starts with a <code>-</code>.
5791 </p>
5792 </dd>
5793 </dl></div>
5794 </div>
5795 <div class="sect2">
5796 <h3 id="_ref">ref</h3>
5797 <div class="paragraph"><p><code><strong>ref</strong> <em>string tag ?finalizer?</em></code></p></div>
5798 <div class="paragraph"><p>Create a new reference containing <code><em>string</em></code> of type <code><em>tag</em></code>.
5799 If <code><em>finalizer</em></code> is specified, it is a command which will be invoked
5800 when the a garbage collection cycle runs and this reference is
5801 no longer accessible.</p></div>
5802 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5803 <div class="literalblock">
5804 <div class="content">
5805 <pre><code>finalizer reference string</code></pre>
5806 </div></div>
5807 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5808 </div>
5809 <div class="sect2">
5810 <h3 id="_rename">rename</h3>
5811 <div class="paragraph"><p><code><strong>rename</strong> <em>oldName newName</em></code></p></div>
5812 <div class="paragraph"><p>Rename the command that used to be called <code><em>oldName</em></code> so that it
5813 is now called <code><em>newName</em></code>. If <code><em>newName</em></code> is an empty string
5814 (e.g. {}) then <code><em>oldName</em></code> is deleted. The <a href="#_rename"><strong><code>rename</code></strong></a> command
5815 returns an empty string as result.</p></div>
5816 </div>
5817 <div class="sect2">
5818 <h3 id="_return">return</h3>
5819 <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>
5820 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5821 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>
5822 is not specified, an empty string will be returned as result.</p></div>
5823 <div class="paragraph"><p>If <code>-code</code> is specified (as either a number or ok, error, break,
5824 continue, signal, return or exit), this code will be used instead
5825 of <code>JIM_OK</code>. This is generally useful when implementing flow of control
5826 commands.</p></div>
5827 <div class="paragraph"><p>If <code>-level</code> is specified and greater than 1, it has the effect of delaying
5828 the new return code from <code>-code</code>. This is useful when rethrowing an error
5829 from <a href="#_catch"><strong><code>catch</code></strong></a>. See the implementation of try/catch in tclcompat.tcl for
5830 an example of how this is done.</p></div>
5831 <div class="paragraph"><p>Note: The following options are only used when <code>-code</code> is JIM_ERR.</p></div>
5832 <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>)
5833 it is used to initialize the stacktrace.</p></div>
5834 <div class="paragraph"><p>If <code>-errorcode</code> is specified, it is used to set the global variable $::errorCode.</p></div>
5835 </div>
5836 <div class="sect2">
5837 <h3 id="_scan">scan</h3>
5838 <div class="paragraph"><p><code><strong>scan</strong> <em>string format varName1 ?varName2 ...?</em></code></p></div>
5839 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5840 as the C <em>sscanf</em> procedure. <code><em>string</em></code> gives the input to be parsed
5841 and <code><em>format</em></code> indicates how to parse it, using <em>%</em> fields as in
5842 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5843 man page for details. Each <code><em>varName</em></code> gives the name of a variable;
5844 when a field is scanned from <code><em>string</em></code>, the result is converted back
5845 into a string and assigned to the corresponding <code><em>varName</em></code>. The
5846 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5847 character value is converted to a decimal string, which is then
5848 assigned to the corresponding <code><em>varName</em></code>; no field width may be
5849 specified for this conversion.</p></div>
5850 </div>
5851 <div class="sect2">
5852 <h3 id="_seek">seek</h3>
5853 <div class="paragraph"><p><code><strong>seek</strong> <em>fileId offset ?origin?</em></code></p></div>
5854 <div class="paragraph"><p><code><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></code></p></div>
5855 <div class="paragraph"><p>Change the current access position for <code><em>fileId</em></code>.
5856 The <code><em>offset</em></code> and <code><em>origin</em></code> arguments specify the position at
5857 which the next read or write will occur for <code><em>fileId</em></code>.
5858 <code><em>offset</em></code> must be a number (which may be negative) and <code><em>origin</em></code>
5859 must be one of the following:</p></div>
5860 <div class="dlist"><dl>
5861 <dt class="hdlist1">
5862 <code><strong>start</strong></code>
5863 </dt>
5864 <dd>
5866 The new access position will be <code><em>offset</em></code> bytes from the start
5867 of the file.
5868 </p>
5869 </dd>
5870 <dt class="hdlist1">
5871 <code><strong>current</strong></code>
5872 </dt>
5873 <dd>
5875 The new access position will be <code><em>offset</em></code> bytes from the current
5876 access position; a negative <code><em>offset</em></code> moves the access position
5877 backwards in the file.
5878 </p>
5879 </dd>
5880 <dt class="hdlist1">
5881 <code><strong>end</strong></code>
5882 </dt>
5883 <dd>
5885 The new access position will be <code><em>offset</em></code> bytes from the end of
5886 the file. A negative <code><em>offset</em></code> places the access position before
5887 the end-of-file, and a positive <code><em>offset</em></code> places the access position
5888 after the end-of-file.
5889 </p>
5890 </dd>
5891 </dl></div>
5892 <div class="paragraph"><p>The <code><em>origin</em></code> argument defaults to <code>start</code>.</p></div>
5893 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
5894 <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
5895 of the standard I/O channels.</p></div>
5896 <div class="paragraph"><p>This command returns an empty string.</p></div>
5897 </div>
5898 <div class="sect2">
5899 <h3 id="_set">set</h3>
5900 <div class="paragraph"><p><code><strong>set</strong> <em>varName ?value?</em></code></p></div>
5901 <div class="paragraph"><p>Returns the value of variable <code><em>varName</em></code>.</p></div>
5902 <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>,
5903 creating a new variable if one doesn&#8217;t already exist, and return
5904 its value.</p></div>
5905 <div class="paragraph"><p>If <code><em>varName</em></code> contains an open parenthesis and ends with a
5906 close parenthesis, then it refers to an array element: the characters
5907 before the open parenthesis are the name of the array, and the characters
5908 between the parentheses are the index within the array.
5909 Otherwise <code><em>varName</em></code> refers to a scalar variable.</p></div>
5910 <div class="paragraph"><p>If no procedure is active, then <code><em>varName</em></code> refers to a global
5911 variable.</p></div>
5912 <div class="paragraph"><p>If a procedure is active, then <code><em>varName</em></code> refers to a parameter
5913 or local variable of the procedure, unless the <code><em>global</em></code> command
5914 has been invoked to declare <code><em>varName</em></code> to be global.</p></div>
5915 <div class="paragraph"><p>The <code>::</code> prefix may also be used to explicitly reference a variable
5916 in the global scope.</p></div>
5917 </div>
5918 <div class="sect2">
5919 <h3 id="_setref">setref</h3>
5920 <div class="paragraph"><p><code><strong>setref</strong> <em>reference string</em></code></p></div>
5921 <div class="paragraph"><p>Store a new string in <code><em>reference</em></code>, replacing the existing string.
5922 The reference must be a valid reference create with the <a href="#_ref"><strong><code>ref</code></strong></a>
5923 command.</p></div>
5924 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA FUNCTION for more detail.</p></div>
5925 </div>
5926 <div class="sect2">
5927 <h3 id="_signal">signal</h3>
5928 <div class="paragraph"><p>Command for signal handling.</p></div>
5929 <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>
5930 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5931 "<code>SIGINT SIGTERM</code>".</p></div>
5932 <div class="dlist"><dl>
5933 <dt class="hdlist1">
5934 <code><strong>signal handle</strong> ?<em>signals ...</em>?</code>
5935 </dt>
5936 <dd>
5938 If no signals are given, returns a list of all signals which are currently
5939 being handled.
5940 If signals are specified, these are added to the list of signals currently
5941 being handled.
5942 </p>
5943 </dd>
5944 <dt class="hdlist1">
5945 <code><strong>signal ignore</strong> ?<em>signals ...</em>?</code>
5946 </dt>
5947 <dd>
5949 If no signals are given, returns a lists all signals which are currently
5950 being ignored.
5951 If signals are specified, these are added to the list of signals
5952 currently being ignored. These signals are still delivered, but
5953 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
5954 <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to determine which signals have occurred but
5955 been ignored.
5956 </p>
5957 </dd>
5958 <dt class="hdlist1">
5959 <code><strong>signal default</strong> ?<em>signals ...</em>?</code>
5960 </dt>
5961 <dd>
5963 If no signals are given, returns a lists all signals which are currently have
5964 the default behaviour.
5965 If signals are specified, these are added to the list of signals which have
5966 the default behaviour.
5967 </p>
5968 </dd>
5969 <dt class="hdlist1">
5970 <code><strong>signal check ?-clear?</strong> ?<em>signals ...</em>?</code>
5971 </dt>
5972 <dd>
5974 Returns a list of signals which have been delivered to the process
5975 but are <em>ignored</em>. If signals are specified, only that set of signals will
5976 be checked, otherwise all signals will be checked.
5977 If <code>-clear</code> is specified, any signals returned are removed and will not be
5978 returned by subsequent calls to <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> unless delivered again.
5979 </p>
5980 </dd>
5981 <dt class="hdlist1">
5982 <code><strong>signal throw</strong> ?<em>signal</em>?</code>
5983 </dt>
5984 <dd>
5986 Raises the given signal, which defaults to <code>SIGINT</code> if not specified.
5987 The behaviour is identical to:
5988 </p>
5989 <div class="literalblock">
5990 <div class="content">
5991 <pre><code>kill signal [pid]</code></pre>
5992 </div></div>
5993 </dd>
5994 </dl></div>
5995 <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
5996 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>
5997 to immediately abort execution when the signal is delivered. Alternatively, <a href="#_signal"><strong><code>signal</code></strong></a> <code>ignore</code>
5998 is used in conjunction with <a href="#_signal"><strong><code>signal</code></strong></a> <code>check</code> to handle signal synchronously. Consider the
5999 two examples below.</p></div>
6000 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
6001 <div class="literalblock">
6002 <div class="content">
6003 <pre><code>signal handle SIGALRM
6004 alarm 20
6005 try -signal {
6006 .. possibly long running process ..
6007 alarm 0
6008 } on signal {sig} {
6009 puts stderr "Process took too long"
6010 }</code></pre>
6011 </div></div>
6012 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
6013 <div class="literalblock">
6014 <div class="content">
6015 <pre><code>signal ignore SIGHUP
6016 while {1} {
6017 ... handle configuration/reconfiguration ...
6018 while {[signal check -clear SIGHUP] eq ""} {
6019 ... do processing ..
6021 # Received SIGHUP, so reconfigure
6022 }</code></pre>
6023 </div></div>
6024 <div class="paragraph"><p>Note: signal handling is currently not supported in child interpreters.
6025 In these interpreters, the signal command does not exist.</p></div>
6026 </div>
6027 <div class="sect2">
6028 <h3 id="_sleep">sleep</h3>
6029 <div class="paragraph"><p><code><strong>sleep</strong> <em>seconds</em></code></p></div>
6030 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
6031 point value less than one to sleep for less than a second, or an
6032 integer to sleep for one or more seconds.</p></div>
6033 </div>
6034 <div class="sect2">
6035 <h3 id="_source">source</h3>
6036 <div class="paragraph"><p><code><strong>source</strong> <em>fileName</em></code></p></div>
6037 <div class="paragraph"><p>Read file <code><em>fileName</em></code> and pass the contents to the Tcl interpreter
6038 as a sequence of commands to execute in the normal fashion. The return
6039 value of <a href="#_source"><strong><code>source</code></strong></a> is the return value of the last command executed
6040 from the file. If an error occurs in executing the contents of the
6041 file, then the <a href="#_source"><strong><code>source</code></strong></a> command will return that error.</p></div>
6042 <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
6043 the file will be skipped and the <a href="#_source"><strong><code>source</code></strong></a> command will return
6044 normally with the result from the <a href="#_return"><strong><code>return</code></strong></a> command.</p></div>
6045 </div>
6046 <div class="sect2">
6047 <h3 id="_split">split</h3>
6048 <div class="paragraph"><p><code><strong>split</strong> <em>string ?splitChars?</em></code></p></div>
6049 <div class="paragraph"><p>Returns a list created by splitting <code><em>string</em></code> at each character
6050 that is in the <code><em>splitChars</em></code> argument.</p></div>
6051 <div class="paragraph"><p>Each element of the result list will consist of the
6052 characters from <code><em>string</em></code> between instances of the
6053 characters in <code><em>splitChars</em></code>.</p></div>
6054 <div class="paragraph"><p>Empty list elements will be generated if <code><em>string</em></code> contains
6055 adjacent characters in <code><em>splitChars</em></code>, or if the first or last
6056 character of <code><em>string</em></code> is in <code><em>splitChars</em></code>.</p></div>
6057 <div class="paragraph"><p>If <code><em>splitChars</em></code> is an empty string then each character of
6058 <code><em>string</em></code> becomes a separate element of the result list.</p></div>
6059 <div class="paragraph"><p><code><em>splitChars</em></code> defaults to the standard white-space characters.
6060 For example,</p></div>
6061 <div class="literalblock">
6062 <div class="content">
6063 <pre><code>split "comp.unix.misc" .</code></pre>
6064 </div></div>
6065 <div class="paragraph"><p>returns <code><em>"comp unix misc"</em></code> and</p></div>
6066 <div class="literalblock">
6067 <div class="content">
6068 <pre><code>split "Hello world" {}</code></pre>
6069 </div></div>
6070 <div class="paragraph"><p>returns <code><em>"H e l l o { } w o r l d"</em></code>.</p></div>
6071 </div>
6072 <div class="sect2">
6073 <h3 id="_stackdump">stackdump</h3>
6074 <div class="paragraph"><p><code><strong>stackdump</strong> <em>stacktrace</em></code></p></div>
6075 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
6076 </div>
6077 <div class="sect2">
6078 <h3 id="_stacktrace">stacktrace</h3>
6079 <div class="paragraph"><p><code><strong>stacktrace</strong></code></p></div>
6080 <div class="paragraph"><p>Returns a live stack trace as a list of <code>proc file line proc file line ...</code>.
6081 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
6082 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>
6083 <div class="paragraph"><p>See also <a href="#_stackdump"><strong><code>stackdump</code></strong></a>.</p></div>
6084 </div>
6085 <div class="sect2">
6086 <h3 id="_string">string</h3>
6087 <div class="paragraph"><p><code><strong>string</strong> <em>option arg ?arg ...?</em></code></p></div>
6088 <div class="paragraph"><p>Perform one of several string operations, depending on <code><em>option</em></code>.
6089 The legal options (which may be abbreviated) are:</p></div>
6090 <div class="dlist"><dl>
6091 <dt class="hdlist1">
6092 <code><strong>string bytelength</strong> <em>string</em></code>
6093 </dt>
6094 <dd>
6096 Returns the length of the string in bytes. This will return
6097 the same value as <a href="#_string"><strong><code>string</code></strong></a> <code>length</code> if UTF-8 support is not enabled,
6098 or if the string is composed entirely of ASCII characters.
6099 See UTF-8 AND UNICODE.
6100 </p>
6101 </dd>
6102 <dt class="hdlist1">
6103 <code><strong>string byterange</strong> <em>string first last</em></code>
6104 </dt>
6105 <dd>
6107 Like <a href="#_string"><strong><code>string</code></strong></a> <code>range</code> except works on bytes rather than characters.
6108 These commands are identical if UTF-8 support is not enabled.
6109 </p>
6110 </dd>
6111 <dt class="hdlist1">
6112 <code><strong>string cat</strong> <em>?string1 string2 ...?</em></code>
6113 </dt>
6114 <dd>
6116 Concatenates the given strings into a single string.
6117 </p>
6118 </dd>
6119 <dt class="hdlist1">
6120 <code><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></code>
6121 </dt>
6122 <dd>
6124 Perform a character-by-character comparison of strings <code><em>string1</em></code> and
6125 <code><em>string2</em></code> in the same way as the C <em>strcmp</em> procedure. Return
6126 -1, 0, or 1, depending on whether <code><em>string1</em></code> is lexicographically
6127 less than, equal to, or greater than <code><em>string2</em></code>. If <code>-length</code>
6128 is specified, then only the first <code><em>len</em></code> characters are used
6129 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
6130 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6131 </p>
6132 </dd>
6133 <dt class="hdlist1">
6134 <code><strong>string equal ?-nocase?</strong> <em>?<strong>-length</strong> len?</em> <em>string1 string2</em></code>
6135 </dt>
6136 <dd>
6138 Returns 1 if the strings are equal, or 0 otherwise. If <code>-length</code>
6139 is specified, then only the first <code><em>len</em></code> characters are used
6140 in the comparison. If <code><em>len</em></code> is negative, it is ignored.
6141 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6142 </p>
6143 </dd>
6144 <dt class="hdlist1">
6145 <code><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></code>
6146 </dt>
6147 <dd>
6149 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6150 the characters in <code><em>string1</em></code>. If found, return the index of the
6151 first character in the first such match within <code><em>string2</em></code>. If not
6152 found, return -1. If <code><em>firstIndex</em></code> is specified, matching will start
6153 from <code><em>firstIndex</em></code> of <code><em>string1</em></code>.
6154 </p>
6155 </dd>
6156 <dt class="hdlist1">
6158 </dt>
6159 <dd>
6161 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>firstIndex</em></code>.
6162 </p>
6163 </dd>
6164 <dt class="hdlist1">
6165 <code><strong>string index</strong> <em>string charIndex</em></code>
6166 </dt>
6167 <dd>
6169 Returns the <code><em>charIndex</em></code><em>th character of the <code>'string</em></code>
6170 argument. A <code><em>charIndex</em></code> of 0 corresponds to the first
6171 character of the string.
6172 If <code><em>charIndex</em></code> is less than 0 or greater than
6173 or equal to the length of the string then an empty string is
6174 returned.
6175 </p>
6176 </dd>
6177 <dt class="hdlist1">
6179 </dt>
6180 <dd>
6182 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>charIndex</em></code>.
6183 </p>
6184 </dd>
6185 <dt class="hdlist1">
6186 <code><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></code>
6187 </dt>
6188 <dd>
6190 Returns 1 if <code><em>string</em></code> is a valid member of the specified character
6191 class, otherwise returns 0. If <code>-strict</code> is specified, then an
6192 empty string returns 0, otherwise an empty string will return 1
6193 on any class. The following character classes are recognized
6194 (the class name can be abbreviated):
6195 </p>
6196 </dd>
6197 <dt class="hdlist1">
6199 </dt>
6200 <dd>
6201 <div class="dlist"><dl>
6202 <dt class="hdlist1">
6203 <code>alnum</code>
6204 </dt>
6205 <dd>
6207 Any alphabet or digit character.
6208 </p>
6209 </dd>
6210 <dt class="hdlist1">
6211 <code>alpha</code>
6212 </dt>
6213 <dd>
6215 Any alphabet character.
6216 </p>
6217 </dd>
6218 <dt class="hdlist1">
6219 <code>ascii</code>
6220 </dt>
6221 <dd>
6223 Any character with a value less than 128 (those that are in the 7-bit ascii range).
6224 </p>
6225 </dd>
6226 <dt class="hdlist1">
6227 <code>boolean</code>
6228 </dt>
6229 <dd>
6231 Any of the valid string formats for a boolean value in Tcl (0, false, no, off, 1, true, yes, on)
6232 </p>
6233 </dd>
6234 <dt class="hdlist1">
6235 <code>control</code>
6236 </dt>
6237 <dd>
6239 Any control character.
6240 </p>
6241 </dd>
6242 <dt class="hdlist1">
6243 <code>digit</code>
6244 </dt>
6245 <dd>
6247 Any digit character.
6248 </p>
6249 </dd>
6250 <dt class="hdlist1">
6251 <code>double</code>
6252 </dt>
6253 <dd>
6255 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
6256 In case of under/overflow in the value, 0 is returned.
6257 </p>
6258 </dd>
6259 <dt class="hdlist1">
6260 <code>graph</code>
6261 </dt>
6262 <dd>
6264 Any printing character, except space.
6265 </p>
6266 </dd>
6267 <dt class="hdlist1">
6268 <code>integer</code>
6269 </dt>
6270 <dd>
6272 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
6273 </p>
6274 </dd>
6275 <dt class="hdlist1">
6276 <code>lower</code>
6277 </dt>
6278 <dd>
6280 Any lower case alphabet character.
6281 </p>
6282 </dd>
6283 <dt class="hdlist1">
6284 <code>print</code>
6285 </dt>
6286 <dd>
6288 Any printing character, including space.
6289 </p>
6290 </dd>
6291 <dt class="hdlist1">
6292 <code>punct</code>
6293 </dt>
6294 <dd>
6296 Any punctuation character.
6297 </p>
6298 </dd>
6299 <dt class="hdlist1">
6300 <code>space</code>
6301 </dt>
6302 <dd>
6304 Any space character.
6305 </p>
6306 </dd>
6307 <dt class="hdlist1">
6308 <code>upper</code>
6309 </dt>
6310 <dd>
6312 Any upper case alphabet character.
6313 </p>
6314 </dd>
6315 <dt class="hdlist1">
6316 <code>xdigit</code>
6317 </dt>
6318 <dd>
6320 Any hexadecimal digit character ([0-9A-Fa-f]).
6321 </p>
6322 </dd>
6323 </dl></div>
6324 </dd>
6325 <dt class="hdlist1">
6327 </dt>
6328 <dd>
6330 Note that string classification does <code><em>not</em></code> respect UTF-8. See UTF-8 AND UNICODE
6331 </p>
6332 </dd>
6333 <dt class="hdlist1">
6335 </dt>
6336 <dd>
6338 Note that only <code><em>lowercase</em></code> boolean values are recognized (Tcl accepts any case).
6339 </p>
6340 </dd>
6341 <dt class="hdlist1">
6342 <code><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></code>
6343 </dt>
6344 <dd>
6346 Search <code><em>string2</em></code> for a sequence of characters that exactly match
6347 the characters in <code><em>string1</em></code>. If found, return the index of the
6348 first character in the last such match within <code><em>string2</em></code>. If there
6349 is no match, then return -1. If <code><em>lastIndex</em></code> is specified, only characters
6350 up to <code><em>lastIndex</em></code> of <code><em>string2</em></code> will be considered in the match.
6351 </p>
6352 </dd>
6353 <dt class="hdlist1">
6355 </dt>
6356 <dd>
6358 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>lastIndex</em></code>.
6359 </p>
6360 </dd>
6361 <dt class="hdlist1">
6362 <code><strong>string length</strong> <em>string</em></code>
6363 </dt>
6364 <dd>
6366 Returns a decimal string giving the number of characters in <code><em>string</em></code>.
6367 If UTF-8 support is enabled, this may be different than the number of bytes.
6368 See UTF-8 AND UNICODE
6369 </p>
6370 </dd>
6371 <dt class="hdlist1">
6372 <code><strong>string map ?-nocase?</strong> <em>mapping string</em></code>
6373 </dt>
6374 <dd>
6376 Replaces substrings in <code><em>string</em></code> based on the key-value pairs in
6377 <code><em>mapping</em></code>, which is a list of <code>key value key value ...</code> as in the form
6378 returned by <a href="#_array"><strong><code>array</code></strong></a> <code>get</code>. Each instance of a key in the string will be
6379 replaced with its corresponding value. If <code>-nocase</code> is specified, then
6380 matching is done without regard to case differences. Both key and value may
6381 be multiple characters. Replacement is done in an ordered manner, so the
6382 key appearing first in the list will be checked first, and so on. <code><em>string</em></code> is
6383 only iterated over once, so earlier key replacements will have no affect for
6384 later key matches. For example,
6385 </p>
6386 <div class="literalblock">
6387 <div class="content">
6388 <pre><code>string map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc</code></pre>
6389 </div></div>
6390 </dd>
6391 <dt class="hdlist1">
6393 </dt>
6394 <dd>
6396 will return the string <code>01321221</code>.
6397 </p>
6398 </dd>
6399 <dt class="hdlist1">
6401 </dt>
6402 <dd>
6404 Note that if an earlier key is a prefix of a later one, it will completely mask the later
6405 one. So if the previous example is reordered like this,
6406 </p>
6407 <div class="literalblock">
6408 <div class="content">
6409 <pre><code>string map {1 0 ab 2 a 3 abc 1} 1abcaababcabababc</code></pre>
6410 </div></div>
6411 </dd>
6412 <dt class="hdlist1">
6414 </dt>
6415 <dd>
6417 it will return the string <code>02c322c222c</code>.
6418 </p>
6419 </dd>
6420 <dt class="hdlist1">
6421 <code><strong>string match ?-nocase?</strong> <em>pattern string</em></code>
6422 </dt>
6423 <dd>
6425 See if <code><em>pattern</em></code> matches <code><em>string</em></code>; return 1 if it does, 0
6426 if it doesn&#8217;t. Matching is done in a fashion similar to that
6427 used by the C-shell. For the two strings to match, their contents
6428 must be identical except that the following special sequences
6429 may appear in <code><em>pattern</em></code>:
6430 </p>
6431 <div class="dlist"><dl>
6432 <dt class="hdlist1">
6433 <code>*</code>
6434 </dt>
6435 <dd>
6437 Matches any sequence of characters in <code><em>string</em></code>,
6438 including a null string.
6439 </p>
6440 </dd>
6441 <dt class="hdlist1">
6442 <code>?</code>
6443 </dt>
6444 <dd>
6446 Matches any single character in <code><em>string</em></code>.
6447 </p>
6448 </dd>
6449 <dt class="hdlist1">
6450 <code>[<em>chars</em>]</code>
6451 </dt>
6452 <dd>
6454 Matches any character in the set given by <code><em>chars</em></code>.
6455 If a sequence of the form <code><em>x-y</em></code> appears in <code><em>chars</em></code>,
6456 then any character between <code><em>x</em></code> and <code><em>y</em></code>, inclusive,
6457 will match.
6458 </p>
6459 </dd>
6460 <dt class="hdlist1">
6461 <code>\x</code>
6462 </dt>
6463 <dd>
6465 Matches the single character <code><em>x</em></code>. This provides a way of
6466 avoiding the special interpretation of the characters <code>\*?[]</code>
6467 in <code><em>pattern</em></code>.
6468 </p>
6469 </dd>
6470 </dl></div>
6471 </dd>
6472 <dt class="hdlist1">
6474 </dt>
6475 <dd>
6477 Performs a case-insensitive comparison if <code>-nocase</code> is specified.
6478 </p>
6479 </dd>
6480 <dt class="hdlist1">
6481 <code><strong>string range</strong> <em>string first last</em></code>
6482 </dt>
6483 <dd>
6485 Returns a range of consecutive characters from <code><em>string</em></code>, starting
6486 with the character whose index is <code><em>first</em></code> and ending with the
6487 character whose index is <code><em>last</em></code>. An index of 0 refers to the
6488 first character of the string.
6489 </p>
6490 </dd>
6491 <dt class="hdlist1">
6493 </dt>
6494 <dd>
6496 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <code><em>first</em></code> and <code><em>last</em></code>.
6497 </p>
6498 </dd>
6499 <dt class="hdlist1">
6501 </dt>
6502 <dd>
6504 If <code><em>first</em></code> is less than zero then it is treated as if it were zero, and
6505 if <code><em>last</em></code> is greater than or equal to the length of the string then
6506 it is treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than
6507 <code><em>last</em></code> then an empty string is returned.
6508 </p>
6509 </dd>
6510 <dt class="hdlist1">
6511 <code><strong>string repeat</strong> <em>string count</em></code>
6512 </dt>
6513 <dd>
6515 Returns a new string consisting of <code><em>string</em></code> repeated <code><em>count</em></code> times.
6516 </p>
6517 </dd>
6518 <dt class="hdlist1">
6519 <code><strong>string replace</strong> <em>string first last ?newstring?</em></code>
6520 </dt>
6521 <dd>
6523 Removes a range of consecutive characters from <code><em>string</em></code>, starting
6524 with the character whose index is <code><em>first</em></code> and ending with the
6525 character whose index is <code><em>last</em></code>. If <code><em>newstring</em></code> is specified,
6526 then it is placed in the removed character range. If <code><em>first</em></code> is
6527 less than zero then it is treated as if it were zero, and if <code><em>last</em></code>
6528 is greater than or equal to the length of the string then it is
6529 treated as if it were <code>end</code>. If <code><em>first</em></code> is greater than <code><em>last</em></code>
6530 or the length of the initial string, or <code><em>last</em></code> is less than 0,
6531 then the initial string is returned untouched.
6532 </p>
6533 </dd>
6534 <dt class="hdlist1">
6535 <code><strong>string reverse</strong> <em>string</em></code>
6536 </dt>
6537 <dd>
6539 Returns a string that is the same length as <code><em>string</em></code> but
6540 with its characters in the reverse order.
6541 </p>
6542 </dd>
6543 <dt class="hdlist1">
6544 <code><strong>string tolower</strong> <em>string</em></code>
6545 </dt>
6546 <dd>
6548 Returns a value equal to <code><em>string</em></code> except that all upper case
6549 letters have been converted to lower case.
6550 </p>
6551 </dd>
6552 <dt class="hdlist1">
6553 <code><strong>string totitle</strong> <em>string</em></code>
6554 </dt>
6555 <dd>
6557 Returns a value equal to <code><em>string</em></code> except that the first character
6558 is converted to title case (or upper case if there is no UTF-8 titlecase variant)
6559 and all remaining characters have been converted to lower case.
6560 </p>
6561 </dd>
6562 <dt class="hdlist1">
6563 <code><strong>string toupper</strong> <em>string</em></code>
6564 </dt>
6565 <dd>
6567 Returns a value equal to <code><em>string</em></code> except that all lower case
6568 letters have been converted to upper case.
6569 </p>
6570 </dd>
6571 <dt class="hdlist1">
6572 <code><strong>string trim</strong> <em>string ?chars?</em></code>
6573 </dt>
6574 <dd>
6576 Returns a value equal to <code><em>string</em></code> except that any leading
6577 or trailing characters from the set given by <code><em>chars</em></code> are
6578 removed.
6579 If <code><em>chars</em></code> is not specified then white space is removed
6580 (spaces, tabs, newlines, and carriage returns).
6581 </p>
6582 </dd>
6583 <dt class="hdlist1">
6584 <code><strong>string trimleft</strong> <em>string ?chars?</em></code>
6585 </dt>
6586 <dd>
6588 Returns a value equal to <code><em>string</em></code> except that any
6589 leading characters from the set given by <code><em>chars</em></code> are
6590 removed.
6591 If <code><em>chars</em></code> is not specified then white space is removed
6592 (spaces, tabs, newlines, and carriage returns).
6593 </p>
6594 </dd>
6595 <dt class="hdlist1">
6596 <code><strong>string trimright</strong> <em>string ?chars?</em></code>
6597 </dt>
6598 <dd>
6600 Returns a value equal to <code><em>string</em></code> except that any
6601 trailing characters from the set given by <code><em>chars</em></code> are
6602 removed.
6603 If <code><em>chars</em></code> is not specified then white space is removed
6604 (spaces, tabs, newlines, and carriage returns).
6605 Null characters are always removed.
6606 </p>
6607 </dd>
6608 </dl></div>
6609 </div>
6610 <div class="sect2">
6611 <h3 id="_subst">subst</h3>
6612 <div class="paragraph"><p><code><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></code></p></div>
6613 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
6614 and backslash substitutions on its string argument and returns the
6615 fully-substituted result. The substitutions are performed in exactly
6616 the same way as for Tcl commands. As a result, the string argument
6617 is actually substituted twice, once by the Tcl parser in the usual
6618 fashion for Tcl commands, and again by the subst command.</p></div>
6619 <div class="paragraph"><p>If any of the <code>-nobackslashes</code>, <code>-nocommands</code>, or <code>-novariables</code> are
6620 specified, then the corresponding substitutions are not performed.
6621 For example, if <code>-nocommands</code> is specified, no command substitution
6622 is performed: open and close brackets are treated as ordinary
6623 characters with no special interpretation.</p></div>
6624 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
6625 special treatment to double quotes or curly braces. For example,
6626 the following script returns <code>xyz {44}</code>, not <code>xyz {$a}</code>.</p></div>
6627 <div class="literalblock">
6628 <div class="content">
6629 <pre><code>set a 44
6630 subst {xyz {$a}}</code></pre>
6631 </div></div>
6632 </div>
6633 <div class="sect2">
6634 <h3 id="_switch">switch</h3>
6635 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string pattern body ?pattern body ...?</em></code></p></div>
6636 <div class="paragraph"><p><code><strong>switch</strong> <em>?options? string {pattern body ?pattern body ...?}</em></code></p></div>
6637 <div class="paragraph"><p>The <a href="#_switch"><strong><code>switch</code></strong></a> command matches its string argument against each of
6638 the pattern arguments in order. As soon as it finds a pattern that
6639 matches string it evaluates the following body and returns the
6640 result of that evaluation. If the last pattern argument is default
6641 then it matches anything. If no pattern argument matches string and
6642 no default is given, then the <a href="#_switch"><strong><code>switch</code></strong></a> command returns an empty string.
6643 If the initial arguments to switch start with - then they are treated
6644 as options. The following options are currently supported:</p></div>
6645 <div class="dlist"><dl>
6646 <dt class="hdlist1">
6647 <code>-exact</code>
6648 </dt>
6649 <dd>
6651 Use exact matching when comparing string to a
6652 pattern. This is the default.
6653 </p>
6654 </dd>
6655 <dt class="hdlist1">
6656 <code>-glob</code>
6657 </dt>
6658 <dd>
6660 When matching string to the patterns, use glob-style
6661 matching (i.e. the same as implemented by the string
6662 match command).
6663 </p>
6664 </dd>
6665 <dt class="hdlist1">
6666 <code>-regexp</code>
6667 </dt>
6668 <dd>
6670 When matching string to the patterns, use regular
6671 expression matching (i.e. the same as implemented
6672 by the regexp command).
6673 </p>
6674 </dd>
6675 <dt class="hdlist1">
6676 <code>-command <em>commandname</em></code>
6677 </dt>
6678 <dd>
6680 When matching string to the patterns, use the given command, which
6681 must be a single word. The command is invoked as
6682 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
6683 and must return 1 if matched, or 0 if not.
6684 </p>
6685 </dd>
6686 <dt class="hdlist1">
6687 <code>--</code>
6688 </dt>
6689 <dd>
6691 Marks the end of options. The argument following
6692 this one will be treated as string even if it starts
6693 with a <code>-</code>.
6694 </p>
6695 </dd>
6696 </dl></div>
6697 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
6698 first uses a separate argument for each of the patterns and commands;
6699 this form is convenient if substitutions are desired on some of the
6700 patterns or commands. The second form places all of the patterns
6701 and commands together into a single argument; the argument must
6702 have proper list structure, with the elements of the list being the
6703 patterns and commands. The second form makes it easy to construct
6704 multi-line <a href="#_switch"><strong><code>switch</code></strong></a> commands, since the braces around the whole list
6705 make it unnecessary to include a backslash at the end of each line.
6706 Since the pattern arguments are in braces in the second form, no
6707 command or variable substitutions are performed on them; this makes
6708 the behaviour of the second form different than the first form in
6709 some cases.</p></div>
6710 <div class="paragraph"><p>If a body is specified as <code>-</code> it means that the body for the next
6711 pattern should also be used as the body for this pattern (if the
6712 next pattern also has a body of <code>-</code> then the body after that is
6713 used, and so on). This feature makes it possible to share a single
6714 body among several patterns.</p></div>
6715 <div class="paragraph"><p>Below are some examples of <a href="#_switch"><strong><code>switch</code></strong></a> commands:</p></div>
6716 <div class="literalblock">
6717 <div class="content">
6718 <pre><code>switch abc a - b {format 1} abc {format 2} default {format 3}</code></pre>
6719 </div></div>
6720 <div class="paragraph"><p>will return 2,</p></div>
6721 <div class="literalblock">
6722 <div class="content">
6723 <pre><code>switch -regexp aaab {
6724 ^a.*b$ -
6725 b {format 1}
6726 a* {format 2}
6727 default {format 3}
6728 }</code></pre>
6729 </div></div>
6730 <div class="paragraph"><p>will return 1, and</p></div>
6731 <div class="literalblock">
6732 <div class="content">
6733 <pre><code>switch xyz {
6735 b {format 1}
6736 a* {format 2}
6737 default {format 3}
6738 }</code></pre>
6739 </div></div>
6740 <div class="paragraph"><p>will return 3.</p></div>
6741 </div>
6742 <div class="sect2">
6743 <h3 id="_tailcall">tailcall</h3>
6744 <div class="paragraph"><p><code><strong>tailcall</strong> <em>cmd ?arg...?</em></code></p></div>
6745 <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
6746 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
6747 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
6748 <div class="literalblock">
6749 <div class="content">
6750 <pre><code>tailcall a b c</code></pre>
6751 </div></div>
6752 <div class="literalblock">
6753 <div class="content">
6754 <pre><code>return [uplevel 1 [list a b c]]</code></pre>
6755 </div></div>
6756 <div class="paragraph"><p><a href="#_tailcall"><strong><code>tailcall</code></strong></a> is useful as a dispatch mechanism:</p></div>
6757 <div class="literalblock">
6758 <div class="content">
6759 <pre><code>proc a {cmd args} {
6760 tailcall sub_$cmd {*}$args
6762 proc sub_cmd1 ...
6763 proc sub_cmd2 ...</code></pre>
6764 </div></div>
6765 </div>
6766 <div class="sect2">
6767 <h3 id="_tell">tell</h3>
6768 <div class="paragraph"><p><code><strong>tell</strong> <em>fileId</em></code></p></div>
6769 <div class="paragraph"><p><code><em>fileId</em> <strong>tell</strong></code></p></div>
6770 <div class="paragraph"><p>Returns a decimal string giving the current access position in
6771 <code><em>fileId</em></code>.</p></div>
6772 <div class="paragraph"><p><code><em>fileId</em></code> must have been the return value from a previous call to
6773 <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
6774 of the standard I/O channels.</p></div>
6775 </div>
6776 <div class="sect2">
6777 <h3 id="_throw">throw</h3>
6778 <div class="paragraph"><p><code><strong>throw</strong> <em>code ?msg?</em></code></p></div>
6779 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
6780 This command is mostly for convenient usage with <a href="#_try"><strong><code>try</code></strong></a>.</p></div>
6781 <div class="paragraph"><p>The command <code>throw break</code> is equivalent to <code>break</code>.
6782 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>
6783 </div>
6784 <div class="sect2">
6785 <h3 id="_time">time</h3>
6786 <div class="paragraph"><p><code><strong>time</strong> <em>command ?count?</em></code></p></div>
6787 <div class="paragraph"><p>This command will call the Tcl interpreter <code><em>count</em></code>
6788 times to execute <code><em>command</em></code> (or once if <code><em>count</em></code> isn&#8217;t
6789 specified). It will then return a string of the form</p></div>
6790 <div class="literalblock">
6791 <div class="content">
6792 <pre><code>503 microseconds per iteration</code></pre>
6793 </div></div>
6794 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
6795 in microseconds.</p></div>
6796 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
6797 </div>
6798 <div class="sect2">
6799 <h3 id="_try">try</h3>
6800 <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>
6801 <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>
6802 <div class="paragraph"><p>This interpeter first evaluates <code><em>tryscript</em></code> under the effect of the catch
6803 options <code><em>catchopts</em></code> (e.g. <code>-signal -noexit --</code>, see <a href="#_catch"><strong><code>catch</code></strong></a>).</p></div>
6804 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
6805 (there many be zero or more) based on the return code from the <a href="#_try"><strong><code>try</code></strong></a>
6806 section. For example a normal <code>JIM_ERR</code> error will be matched by
6807 an <em>on error</em> handler.</p></div>
6808 <div class="paragraph"><p>Finally, any <code><em>finalscript</em></code> is evaluated.</p></div>
6809 <div class="paragraph"><p>The result of this command is the result of <code><em>tryscript</em></code>, except in the
6810 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
6811 in which case the result is this new exception.</p></div>
6812 <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.)
6813 or as integers.</p></div>
6814 <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
6815 the matching handler.</p></div>
6816 <div class="paragraph"><p>For example:</p></div>
6817 <div class="literalblock">
6818 <div class="content">
6819 <pre><code>set f [open input]
6820 try -signal {
6821 process $f
6822 } on {continue break} {} {
6823 error "Unexpected break/continue"
6824 } on error {msg opts} {
6825 puts "Dealing with error"
6826 return {*}$opts $msg
6827 } on signal sig {
6828 puts "Got signal: $sig"
6829 } finally {
6830 $f close
6831 }</code></pre>
6832 </div></div>
6833 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6834 handler.</p></div>
6835 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6836 <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>
6837 </div>
6838 <div class="sect2">
6839 <h3 id="_unknown">unknown</h3>
6840 <div class="paragraph"><p><code><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></code></p></div>
6841 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6842 invoke it if it does exist.</p></div>
6843 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6844 is not a defined command, then Tcl checks for the existence of
6845 a command named <a href="#_unknown"><strong><code>unknown</code></strong></a>.</p></div>
6846 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6847 error.</p></div>
6848 <div class="paragraph"><p>If the <a href="#_unknown"><strong><code>unknown</code></strong></a> command exists, then it is invoked with
6849 arguments consisting of the fully-substituted name and arguments
6850 for the original non-existent command.</p></div>
6851 <div class="paragraph"><p>The <a href="#_unknown"><strong><code>unknown</code></strong></a> command typically does things like searching
6852 through library directories for a command procedure with the name
6853 <code><em>cmdName</em></code>, or expanding abbreviated command names to full-length,
6854 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6855 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <a href="#_unknown"><strong><code>unknown</code></strong></a> will
6856 change the original command slightly and then (re-)execute it.
6857 The result of the <a href="#_unknown"><strong><code>unknown</code></strong></a> command is used as the result for
6858 the original non-existent command.</p></div>
6859 </div>
6860 <div class="sect2">
6861 <h3 id="_unset">unset</h3>
6862 <div class="paragraph"><p><code><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></code></p></div>
6863 <div class="paragraph"><p>Remove variables.
6864 Each <code><em>name</em></code> is a variable name, specified in any of the
6865 ways acceptable to the <a href="#_set"><strong><code>set</code></strong></a> command.</p></div>
6866 <div class="paragraph"><p>If a <code><em>name</em></code> refers to an element of an array, then that
6867 element is removed without affecting the rest of the array.</p></div>
6868 <div class="paragraph"><p>If a <code><em>name</em></code> consists of an array name with no parenthesized
6869 index, then the entire array is deleted.</p></div>
6870 <div class="paragraph"><p>The <a href="#_unset"><strong><code>unset</code></strong></a> command returns an empty string as result.</p></div>
6871 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6872 is specified. The <em>--</em> argument may be specified to stop option processing
6873 in case the variable name may be <em>-nocomplain</em>.</p></div>
6874 </div>
6875 <div class="sect2">
6876 <h3 id="_upcall">upcall</h3>
6877 <div class="paragraph"><p><code><strong>upcall</strong> <em>command ?args &#8230;?</em></code></p></div>
6878 <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
6879 the previous, hidden version of the same command.</p></div>
6880 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6881 </div>
6882 <div class="sect2">
6883 <h3 id="_uplevel">uplevel</h3>
6884 <div class="paragraph"><p><code><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></code></p></div>
6885 <div class="paragraph"><p>All of the <code><em>command</em></code> arguments are concatenated as if they had
6886 been passed to <a href="#_concat"><strong><code>concat</code></strong></a>; the result is then evaluated in the
6887 variable context indicated by <code><em>level</em></code>. <a href="#_uplevel"><strong><code>uplevel</code></strong></a> returns
6888 the result of that evaluation. If <code><em>level</em></code> is an integer, then
6889 it gives a distance (up the procedure calling stack) to move before
6890 executing the command. If <code><em>level</em></code> consists of <code>#</code> followed by
6891 a number then the number gives an absolute level number. If <code><em>level</em></code>
6892 is omitted then it defaults to <code>1</code>. <code><em>level</em></code> cannot be
6893 defaulted if the first <code><em>command</em></code> argument starts with a digit or <code>#</code>.</p></div>
6894 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6895 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6896 Suppose that <em>c</em> invokes the <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command. If <code><em>level</em></code>
6897 is <code>1</code> or <code>#2</code> or omitted, then the command will be executed
6898 in the variable context of <em>b</em>. If <code><em>level</em></code> is <code>2</code> or <code>#1</code>
6899 then the command will be executed in the variable context of <em>a</em>.</p></div>
6900 <div class="paragraph"><p>If <code><em>level</em></code> is <em>3</em> or <code>#0</code> then the command will be executed
6901 at top-level (only global variables will be visible).
6902 The <a href="#_uplevel"><strong><code>uplevel</code></strong></a> command causes the invoking procedure to disappear
6903 from the procedure calling stack while the command is being executed.
6904 In the above example, suppose <em>c</em> invokes the command</p></div>
6905 <div class="literalblock">
6906 <div class="content">
6907 <pre><code>uplevel 1 {set x 43; d}</code></pre>
6908 </div></div>
6909 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <a href="#_set"><strong><code>set</code></strong></a> command will
6910 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6911 at level 3, as if called from <em>b</em>. If it in turn executes
6912 the command</p></div>
6913 <div class="literalblock">
6914 <div class="content">
6915 <pre><code>uplevel {set x 42}</code></pre>
6916 </div></div>
6917 <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
6918 context: the procedure 'c</em> does not appear to be on the call stack
6919 when <em>d</em> is executing. The command <a href="#_info"><strong><code>info</code></strong></a> <code>level</code> may
6920 be used to obtain the level of the current procedure.</p></div>
6921 <div class="paragraph"><p><a href="#_uplevel"><strong><code>uplevel</code></strong></a> makes it possible to implement new control
6922 constructs as Tcl procedures (for example, <a href="#_uplevel"><strong><code>uplevel</code></strong></a> could
6923 be used to implement the <a href="#_while"><strong><code>while</code></strong></a> construct as a Tcl procedure).</p></div>
6924 </div>
6925 <div class="sect2">
6926 <h3 id="_upvar">upvar</h3>
6927 <div class="paragraph"><p><code><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></code></p></div>
6928 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6929 procedure to refer to variables in an enclosing procedure call or
6930 to global variables.</p></div>
6931 <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>
6932 command, and may be omitted if the first letter of the first <code><em>otherVar</em></code>
6933 isn&#8217;t <code>#</code> or a digit (it defaults to <em>1</em>).</p></div>
6934 <div class="paragraph"><p>For each <code><em>otherVar</em></code> argument, <a href="#_upvar"><strong><code>upvar</code></strong></a> makes the variable
6935 by that name in the procedure frame given by <code><em>level</em></code> (or at
6936 global level, if <code><em>level</em></code> is <code>#0</code>) accessible
6937 in the current procedure by the name given in the corresponding
6938 <code><em>myVar</em></code> argument.</p></div>
6939 <div class="paragraph"><p>The variable named by <code><em>otherVar</em></code> need not exist at the time of the
6940 call; it will be created the first time <code><em>myVar</em></code> is referenced, just like
6941 an ordinary variable.</p></div>
6942 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> may only be invoked from within procedures.</p></div>
6943 <div class="paragraph"><p><a href="#_upvar"><strong><code>upvar</code></strong></a> returns an empty string.</p></div>
6944 <div class="paragraph"><p>The <a href="#_upvar"><strong><code>upvar</code></strong></a> command simplifies the implementation of call-by-name
6945 procedure calling and also makes it easier to build new control constructs
6946 as Tcl procedures.
6947 For example, consider the following procedure:</p></div>
6948 <div class="literalblock">
6949 <div class="content">
6950 <pre><code>proc add2 name {
6951 upvar $name x
6952 set x [expr $x+2]
6953 }</code></pre>
6954 </div></div>
6955 <div class="paragraph"><p><em>add2</em> is invoked with an argument giving the name of a variable,
6956 and it adds two to the value of that variable.
6957 Although <em>add2</em> could have been implemented using <a href="#_uplevel"><strong><code>uplevel</code></strong></a>
6958 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>
6959 to access the variable in the caller&#8217;s procedure frame.</p></div>
6960 </div>
6961 <div class="sect2">
6962 <h3 id="_wait">wait</h3>
6963 <div class="paragraph"><p><code><strong>wait</strong></code></p></div>
6964 <div class="paragraph"><p><code><strong>wait -nohang</strong> <em>pid</em></code></p></div>
6965 <div class="paragraph"><p>With no arguments, cleans up any processes started by <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code> that have completed
6966 (reaps zombie processes).</p></div>
6967 <div class="paragraph"><p>With one or two arguments, waits for a process by id, either returned by <a href="#_exec"><strong><code>exec</code></strong></a> <code>... &amp;</code>
6968 or by <a href="#cmd_1"><strong><code>os.fork</code></strong></a> (if supported).</p></div>
6969 <div class="paragraph"><p>Waits for the process to complete, unless <code>-nohang</code> is specified, in which case returns
6970 immediately if the process is still running.</p></div>
6971 <div class="paragraph"><p>Returns a list of 3 elements.</p></div>
6972 <div class="paragraph"><p><code>{NONE x x}</code> if the process does not exist or has already been waited for, or
6973 if -nohang is specified, and the process is still alive.</p></div>
6974 <div class="paragraph"><p><code>{CHILDSTATUS &lt;pid&gt; &lt;exit-status&gt;}</code> if the process exited normally.</p></div>
6975 <div class="paragraph"><p><code>{CHILDKILLED &lt;pid&gt; &lt;signal&gt;}</code> if the process terminated on a signal.</p></div>
6976 <div class="paragraph"><p><code>{CHILDSUSP &lt;pid&gt; none}</code> if the process terminated for some other reason.</p></div>
6977 <div class="paragraph"><p>Note that on platforms supporting waitpid(2), <code>pid</code> can also be given special values such
6978 as 0 or -1. See waitpid(2) for more detail.</p></div>
6979 </div>
6980 <div class="sect2">
6981 <h3 id="_while">while</h3>
6982 <div class="paragraph"><p><code><strong>while</strong> <em>test body</em></code></p></div>
6983 <div class="paragraph"><p>The <code><em>while</em></code> command evaluates <code><em>test</em></code> as an expression
6984 (in the same way that <a href="#_expr"><strong><code>expr</code></strong></a> evaluates its argument).
6985 The value of the expression must be numeric; if it is non-zero
6986 then <code><em>body</em></code> is executed by passing it to the Tcl interpreter.</p></div>
6987 <div class="paragraph"><p>Once <code><em>body</em></code> has been executed then <code><em>test</em></code> is evaluated
6988 again, and the process repeats until eventually <code><em>test</em></code>
6989 evaluates to a zero numeric value. <a href="#_continue"><strong><code>continue</code></strong></a>
6990 commands may be executed inside <code><em>body</em></code> to terminate the current
6991 iteration of the loop, and <a href="#_break"><strong><code>break</code></strong></a>
6992 commands may be executed inside <code><em>body</em></code> to cause immediate
6993 termination of the <a href="#_while"><strong><code>while</code></strong></a> command.</p></div>
6994 <div class="paragraph"><p>The <a href="#_while"><strong><code>while</code></strong></a> command always returns an empty string.</p></div>
6995 </div>
6996 </div>
6997 </div>
6998 <div class="sect1">
6999 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
7000 <div class="sectionbody">
7001 <div class="paragraph"><p>The following extensions may or may not be available depending upon
7002 what options were selected when Jim Tcl was built.</p></div>
7003 <div class="sect2">
7004 <h3 id="cmd_1">posix: os.fork, os.gethostname, os.getids, os.uptime</h3>
7005 <div class="dlist"><dl>
7006 <dt class="hdlist1">
7007 <code><strong>os.fork</strong></code>
7008 </dt>
7009 <dd>
7011 Invokes <em>fork(2)</em> and returns the result.
7012 </p>
7013 </dd>
7014 <dt class="hdlist1">
7015 <code><strong>os.gethostname</strong></code>
7016 </dt>
7017 <dd>
7019 Invokes <em>gethostname(3)</em> and returns the result.
7020 </p>
7021 </dd>
7022 <dt class="hdlist1">
7023 <code><strong>os.getids</strong></code>
7024 </dt>
7025 <dd>
7027 Returns the various user/group ids for the current process.
7028 </p>
7029 <div class="literalblock">
7030 <div class="content">
7031 <pre><code>jim&gt; os.getids
7032 uid 1000 euid 1000 gid 100 egid 100</code></pre>
7033 </div></div>
7034 </dd>
7035 <dt class="hdlist1">
7036 <code><strong>os.uptime</strong></code>
7037 </dt>
7038 <dd>
7040 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
7041 </p>
7042 </dd>
7043 </dl></div>
7044 </div>
7045 </div>
7046 </div>
7047 <div class="sect1">
7048 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
7049 <div class="sectionbody">
7050 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
7051 <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>
7052 <div class="sect2">
7053 <h3 id="_aio">aio</h3>
7054 <div class="dlist"><dl>
7055 <dt class="hdlist1">
7056 <code>$handle <strong>accept</strong> ?addrvar?</code>
7057 </dt>
7058 <dd>
7060 Server socket only: Accept a connection and return stream.
7061 If <code><em>addrvar</em></code> is specified, the address of the connected client is stored
7062 in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
7063 </p>
7064 </dd>
7065 <dt class="hdlist1">
7066 <code>$handle <strong>buffering none|line|full</strong></code>
7067 </dt>
7068 <dd>
7070 Sets the buffering mode of the stream.
7071 </p>
7072 </dd>
7073 <dt class="hdlist1">
7074 <code>$handle <strong>close</strong> ?r(ead)|w(rite)?</code>
7075 </dt>
7076 <dd>
7078 Closes the stream.
7079 The two-argument form is a "half-close" on a socket. See the <code>shutdown(2)</code> man page.
7080 </p>
7081 </dd>
7082 <dt class="hdlist1">
7083 <code>$handle <strong>copyto</strong> <em>tofd ?size?</em></code>
7084 </dt>
7085 <dd>
7087 Copy bytes to the file descriptor <code><em>tofd</em></code>. If <code><em>size</em></code> is specified, at most
7088 that many bytes will be copied. Otherwise copying continues until the end
7089 of the input file. Returns the number of bytes actually copied.
7090 </p>
7091 </dd>
7092 <dt class="hdlist1">
7093 <code>$handle <strong>eof</strong></code>
7094 </dt>
7095 <dd>
7097 Returns 1 if stream is at eof
7098 </p>
7099 </dd>
7100 <dt class="hdlist1">
7101 <code>$handle <strong>filename</strong></code>
7102 </dt>
7103 <dd>
7105 Returns the original filename associated with the handle.
7106 Handles returned by <a href="#_socket"><strong><code>socket</code></strong></a> give the socket type instead of a filename.
7107 </p>
7108 </dd>
7109 <dt class="hdlist1">
7110 <code>$handle <strong>flush</strong></code>
7111 </dt>
7112 <dd>
7114 Flush the stream
7115 </p>
7116 </dd>
7117 <dt class="hdlist1">
7118 <code>$handle <strong>gets</strong> <em>?var?</em></code>
7119 </dt>
7120 <dd>
7122 Read one line and return it or store it in the var
7123 </p>
7124 </dd>
7125 <dt class="hdlist1">
7126 <code>$handle <strong>isatty</strong></code>
7127 </dt>
7128 <dd>
7130 Returns 1 if the stream is a tty device.
7131 </p>
7132 </dd>
7133 <dt class="hdlist1">
7134 <code>$handle <strong>lock</strong></code>
7135 </dt>
7136 <dd>
7138 Apply a POSIX lock to the open file associated with the handle using
7139 fcntl(2).
7140 The handle must be open for write access.
7141 Returns 1 if the lock was successfully obtained, 0 otherwise.
7142 An error occurs if the handle is not suitable for locking (e.g.
7143 if it is not open for write)
7144 </p>
7145 </dd>
7146 <dt class="hdlist1">
7147 <code>$handle <strong>ndelay ?0|1?</strong></code>
7148 </dt>
7149 <dd>
7151 Set O_NDELAY (if arg). Returns current/new setting.
7152 Note that in general ANSI I/O interacts badly with non-blocking I/O.
7153 Use with care.
7154 </p>
7155 </dd>
7156 <dt class="hdlist1">
7157 <code>$handle <strong>puts ?-nonewline?</strong> <em>str</em></code>
7158 </dt>
7159 <dd>
7161 Write the string, with newline unless -nonewline
7162 </p>
7163 </dd>
7164 <dt class="hdlist1">
7165 <code>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></code>
7166 </dt>
7167 <dd>
7169 Read and return bytes from the stream. To eof if no len.
7170 </p>
7171 </dd>
7172 <dt class="hdlist1">
7173 <code>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></code>
7174 </dt>
7175 <dd>
7177 Receives a message from the handle via recvfrom(2) and returns it.
7178 At most <code><em>maxlen</em></code> bytes are read.
7179 If <code><em>addrvar</em></code> is specified, the sending address of the message is stored in
7180 the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><code>socket</code></strong></a> for details.
7181 </p>
7182 </dd>
7183 <dt class="hdlist1">
7184 <code>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></code>
7185 </dt>
7186 <dd>
7188 Seeks in the stream (default <em>current</em>)
7189 </p>
7190 </dd>
7191 <dt class="hdlist1">
7192 <code>$handle <strong>sendto</strong> <em>str ?addr:?port</em></code>
7193 </dt>
7194 <dd>
7196 Sends the string, <code><em>str</em></code>, to the given address via the socket using sendto(2).
7197 This is intended for udp/dgram sockets and may give an error or behave in unintended
7198 ways for other handle types.
7199 Returns the number of bytes written.
7200 </p>
7201 </dd>
7202 <dt class="hdlist1">
7203 <code>$handle <strong>sockopt</strong> <em>?name value?</em></code>
7204 </dt>
7205 <dd>
7207 With no arguments, returns a dictionary of socket options currently set for the handle
7208 (will be empty for a non-socket). With <code><em>name</em></code> and <code><em>value</em></code>, sets the socket option
7209 to the given value. Currently supports the following boolean socket options:
7210 <code>broadcast, debug, keepalive, nosigpipe, oobinline, tcp_nodelay</code>, and the following
7211 integer socket options: <code>sndbuf, rcvbuf</code>
7212 </p>
7213 </dd>
7214 <dt class="hdlist1">
7215 <code>$handle <strong>sync</strong></code>
7216 </dt>
7217 <dd>
7219 Flush the stream, then fsync(2) to commit any changes to storage.
7220 Only available on platforms that support fsync(2).
7221 </p>
7222 </dd>
7223 <dt class="hdlist1">
7224 <code>$handle <strong>tell</strong></code>
7225 </dt>
7226 <dd>
7228 Returns the current seek position
7229 </p>
7230 </dd>
7231 <dt class="hdlist1">
7232 <code>$handle <strong>tty</strong> ?settings?</code>
7233 </dt>
7234 <dd>
7236 If no arguments are given, returns a dictionary containing the tty settings for the stream.
7237 If arguments are given, they must either be a dictionary, or <code>setting value ...</code>
7238 Abbrevations are supported for both settings and values, so the following is acceptable:
7239 <code>$f tty parity e input c out raw</code>.
7240 Only available on platforms that support termios(3). Supported settings are:
7241 </p>
7242 <div class="dlist"><dl>
7243 <dt class="hdlist1">
7244 <code><strong>baud</strong> <em>rate</em></code>
7245 </dt>
7246 <dd>
7248 Baud rate. e.g. 115200
7249 </p>
7250 </dd>
7251 <dt class="hdlist1">
7252 <code><strong>data 5|6|7|8</strong></code>
7253 </dt>
7254 <dd>
7256 Number of data bits
7257 </p>
7258 </dd>
7259 <dt class="hdlist1">
7260 <code><strong>stop 1|2</strong></code>
7261 </dt>
7262 <dd>
7264 Number of stop bits
7265 </p>
7266 </dd>
7267 <dt class="hdlist1">
7268 <code><strong>parity even|odd|none</strong></code>
7269 </dt>
7270 <dd>
7272 Parity setting
7273 </p>
7274 </dd>
7275 <dt class="hdlist1">
7276 <code><strong>handshake xonxoff|rtscts|none</strong></code>
7277 </dt>
7278 <dd>
7280 Handshaking type
7281 </p>
7282 </dd>
7283 <dt class="hdlist1">
7284 <code><strong>input raw|cooked</strong></code>
7285 </dt>
7286 <dd>
7288 Input character processing. In raw mode, the usual key sequences such as ^C do
7289 not generate signals.
7290 </p>
7291 </dd>
7292 <dt class="hdlist1">
7293 <code><strong>output raw|cooked</strong></code>
7294 </dt>
7295 <dd>
7297 Output character processing. Typically CR &#8594; CRNL is disabled in raw mode.
7298 </p>
7299 </dd>
7300 <dt class="hdlist1">
7301 <code><strong>vmin</strong> <em>numchars</em></code>
7302 </dt>
7303 <dd>
7305 Minimum number of characters to read.
7306 </p>
7307 </dd>
7308 <dt class="hdlist1">
7309 <code><strong>vtime</strong> <em>time</em></code>
7310 </dt>
7311 <dd>
7313 Timeout for noncanonical read (units of 0.1 seconds)
7314 </p>
7315 </dd>
7316 </dl></div>
7317 </dd>
7318 <dt class="hdlist1">
7319 <code>$handle <strong>ssl</strong> <strong>?-server cert priv?</strong></code>
7320 </dt>
7321 <dd>
7323 Upgrades the stream to a SSL/TLS session and returns the handle.
7324 </p>
7325 </dd>
7326 <dt class="hdlist1">
7327 <code>$handle <strong>unlock</strong></code>
7328 </dt>
7329 <dd>
7331 Release a POSIX lock previously acquired by <a href="#_aio"><strong><code>aio</code></strong></a> <code>lock</code>.
7332 </p>
7333 </dd>
7334 <dt class="hdlist1">
7335 <code>$handle <strong>verify</strong></code>
7336 </dt>
7337 <dd>
7339 Verifies the certificate of a SSL/TLS stream peer
7340 </p>
7341 </dd>
7342 <dt class="hdlist1">
7343 <code><strong>load_ssl_certs</strong> <em>dir</em></code>
7344 </dt>
7345 <dd>
7347 Loads SSL/TLS CA certificates for use during verification
7348 </p>
7349 </dd>
7350 </dl></div>
7351 </div>
7352 <div class="sect2">
7353 <h3 id="_fconfigure">fconfigure</h3>
7354 <div class="dlist"><dl>
7355 <dt class="hdlist1">
7356 <code><strong>fconfigure</strong> <em>handle</em> <strong>?-blocking 0|1? ?-buffering noneline|full? ?-translation</strong> <em>mode</em>?</code>
7357 </dt>
7358 <dd>
7360 For compatibility with Tcl, a limited form of the <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a>
7361 command is supported.
7362 </p>
7363 <div class="ulist"><ul>
7364 <li>
7366 <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>
7367 </p>
7368 </li>
7369 <li>
7371 <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>
7372 </p>
7373 </li>
7374 <li>
7376 <a href="#_fconfigure"><strong><code>fconfigure</code></strong></a> <code>... -translation</code> is accepted but ignored
7377 </p>
7378 </li>
7379 </ul></div>
7380 </dd>
7381 </dl></div>
7382 </div>
7383 <div class="sect2">
7384 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
7385 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
7386 If no script is given, returns the current script. If the given script is the empty, the
7387 handler is removed.</p></div>
7388 <div class="dlist"><dl>
7389 <dt class="hdlist1">
7390 <code>$handle <strong>readable</strong> <em>?readable-script?</em></code>
7391 </dt>
7392 <dd>
7394 Sets or returns the script for when the socket is readable.
7395 </p>
7396 </dd>
7397 <dt class="hdlist1">
7398 <code>$handle <strong>writable</strong> <em>?writable-script?</em></code>
7399 </dt>
7400 <dd>
7402 Sets or returns the script for when the socket is writable.
7403 </p>
7404 </dd>
7405 <dt class="hdlist1">
7406 <code>$handle <strong>onexception</strong> <em>?exception-script?</em></code>
7407 </dt>
7408 <dd>
7410 Sets or returns the script for when oob data received.
7411 </p>
7412 </dd>
7413 </dl></div>
7414 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <code>fileevent</code>. e.g.</p></div>
7415 <div class="dlist"><dl>
7416 <dt class="hdlist1">
7418 </dt>
7419 <dd>
7421 <code>fileevent $handle <strong>readable</strong> <em>...</em></code>
7422 </p>
7423 </dd>
7424 </dl></div>
7425 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
7426 <div class="dlist"><dl>
7427 <dt class="hdlist1">
7428 <code><strong>after</strong> <em>ms</em></code>
7429 </dt>
7430 <dd>
7432 Sleeps for the given number of milliseconds. No events are
7433 processed during this time.
7434 </p>
7435 </dd>
7436 <dt class="hdlist1">
7437 <code><strong>after</strong> <em>ms</em>|<strong>idle</strong> <em>script ?script ...?</em></code>
7438 </dt>
7439 <dd>
7441 The scripts are concatenated and executed after the given
7442 number of milliseconds have elapsed. If <em>idle</em> is specified,
7443 the script will run the next time the event loop is processed
7444 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
7445 then removed. Returns an event id.
7446 </p>
7447 </dd>
7448 <dt class="hdlist1">
7449 <code><strong>after cancel</strong> <em>id|command</em></code>
7450 </dt>
7451 <dd>
7453 Cancels an <a href="#cmd_2"><strong><code>after</code></strong></a> event with the given event id or matching
7454 command (script). Returns the number of milliseconds
7455 remaining until the event would have fired. Returns the
7456 empty string if no matching event is found.
7457 </p>
7458 </dd>
7459 <dt class="hdlist1">
7460 <code><strong>after info</strong> <em>?id?</em></code>
7461 </dt>
7462 <dd>
7464 If <code><em>id</em></code> is not given, returns a list of current <a href="#cmd_2"><strong><code>after</code></strong></a>
7465 events. If <code><em>id</em></code> is given, returns a list containing the
7466 associated script and either <em>timer</em> or <em>idle</em> to indicated
7467 the type of the event. An error occurs if <code><em>id</em></code> does not
7468 match an event.
7469 </p>
7470 </dd>
7471 <dt class="hdlist1">
7472 <code><strong>vwait</strong> <em>variable</em></code>
7473 </dt>
7474 <dd>
7476 A call to <a href="#cmd_2"><strong><code>vwait</code></strong></a> enters the eventloop. <a href="#cmd_2"><strong><code>vwait</code></strong></a> processes
7477 events until the named (global) variable changes or all
7478 event handlers are removed. The variable need not exist
7479 beforehand. If there are no event handlers defined, <a href="#cmd_2"><strong><code>vwait</code></strong></a>
7480 returns immediately.
7481 </p>
7482 </dd>
7483 <dt class="hdlist1">
7484 <code><strong>update ?idletasks?</strong></code>
7485 </dt>
7486 <dd>
7488 A call to <a href="#cmd_2"><strong><code>update</code></strong></a> enters the eventloop to process expired events, but
7489 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
7490 not file events.
7491 Returns once handlers have been run for all expired events.
7492 </p>
7493 </dd>
7494 </dl></div>
7495 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
7496 an attempt is made to call (the user-defined command) <code>bgerror</code> with the details of the error.
7497 If the <code>bgerror</code> command does not exist, the error message details are printed to stderr instead.</p></div>
7498 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
7499 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
7500 <div class="dlist"><dl>
7501 <dt class="hdlist1">
7502 <code><strong>bgerror</strong> <em>msg</em></code>
7503 </dt>
7504 <dd>
7506 Called when an event handler script generates an error. Note that the normal command resolution
7507 rules are used for bgerror. First the name is resolved in the current namespace, then in the
7508 global scope.
7509 </p>
7510 </dd>
7511 </dl></div>
7512 </div>
7513 <div class="sect2">
7514 <h3 id="_socket">socket</h3>
7515 <div class="paragraph"><p>Various socket types may be created.</p></div>
7516 <div class="dlist"><dl>
7517 <dt class="hdlist1">
7518 <code><strong>socket unix</strong> <em>path</em></code>
7519 </dt>
7520 <dd>
7522 A unix domain socket client.
7523 </p>
7524 </dd>
7525 <dt class="hdlist1">
7526 <code><strong>socket unix.server</strong> <em>path</em></code>
7527 </dt>
7528 <dd>
7530 A unix domain socket server.
7531 </p>
7532 </dd>
7533 <dt class="hdlist1">
7534 <code><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></code>
7535 </dt>
7536 <dd>
7538 A TCP socket client. (See the forms for <code><em>addr</em></code> below)
7539 </p>
7540 </dd>
7541 <dt class="hdlist1">
7542 <code><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></code>
7543 </dt>
7544 <dd>
7546 A TCP socket server (<code><em>addr</em></code> defaults to <code>0.0.0.0</code> for IPv4 or <code>[::]</code> for IPv6).
7547 </p>
7548 </dd>
7549 <dt class="hdlist1">
7550 <code><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</code>
7551 </dt>
7552 <dd>
7554 A UDP socket client. If the address is not specified,
7555 the client socket will be unbound and <em>sendto</em> must be used
7556 to indicated the destination.
7557 </p>
7558 </dd>
7559 <dt class="hdlist1">
7560 <code><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></code>
7561 </dt>
7562 <dd>
7564 A UDP socket server.
7565 </p>
7566 </dd>
7567 <dt class="hdlist1">
7568 <code><strong>socket pipe</strong></code>
7569 </dt>
7570 <dd>
7572 A synonym for <a href="#_pipe"><strong><code>pipe</code></strong></a>
7573 </p>
7574 </dd>
7575 <dt class="hdlist1">
7576 <code><strong>socket pair</strong></code>
7577 </dt>
7578 <dd>
7580 A socketpair (see socketpair(2)). Like <a href="#_pipe"><strong><code>pipe</code></strong></a>, this command returns
7581 a list of two channels: {s1 s2}. These channels are both readable and writable.
7582 </p>
7583 </dd>
7584 </dl></div>
7585 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
7586 address.</p></div>
7587 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
7588 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
7589 <div class="olist arabic"><ol class="arabic">
7590 <li>
7592 set f [socket stream www.google.com:80]
7593 aio.sockstream1
7594 </p>
7595 </li>
7596 <li>
7598 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
7599 </p>
7600 </li>
7601 <li>
7603 $f gets
7604 HTTP/1.0 302 Found
7605 </p>
7606 </li>
7607 <li>
7609 $f close
7610 </p>
7611 </li>
7612 </ol></div>
7613 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
7614 the EVENTLOOP API.</p></div>
7615 <div class="literalblock">
7616 <div class="content">
7617 <pre><code>set f [socket stream.server 80]
7618 $f readable {
7619 set client [$f accept]
7620 $client gets $buf
7622 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
7623 $client close
7625 vwait done</code></pre>
7626 </div></div>
7627 <div class="paragraph"><p>The address, <code><em>addr</em></code>, can be given in one of the following forms:</p></div>
7628 <div class="olist arabic"><ol class="arabic">
7629 <li>
7631 For IPv4 socket types, an IPv4 address such as 192.168.1.1
7632 </p>
7633 </li>
7634 <li>
7636 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
7637 </p>
7638 </li>
7639 <li>
7641 A hostname
7642 </p>
7643 </li>
7644 </ol></div>
7645 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
7646 also accept requests via IPv4.</p></div>
7647 <div class="paragraph"><p>Where a hostname is specified, the <code><em>first</em></code> returned address is used
7648 which matches the socket type is used.</p></div>
7649 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
7650 <div class="literalblock">
7651 <div class="content">
7652 <pre><code>lassign [socket pipe] r w</code></pre>
7653 </div></div>
7654 <div class="literalblock">
7655 <div class="content">
7656 <pre><code># Must close $w after exec
7657 exec ps &gt;@$w &amp;
7658 $w close</code></pre>
7659 </div></div>
7660 <div class="literalblock">
7661 <div class="content">
7662 <pre><code>$r readable ...</code></pre>
7663 </div></div>
7664 </div>
7665 <div class="sect2">
7666 <h3 id="_syslog">syslog</h3>
7667 <div class="paragraph"><p><code><strong>syslog</strong> <em>?options? ?priority? message</em></code></p></div>
7668 <div class="paragraph"><p>This command sends message to system syslog facility with given
7669 priority. Valid priorities are:</p></div>
7670 <div class="literalblock">
7671 <div class="content">
7672 <pre><code>emerg, alert, crit, err, error, warning, notice, info, debug</code></pre>
7673 </div></div>
7674 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
7675 priority of info is used.</p></div>
7676 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
7677 argv0 is used as ident string. However, any of the following options
7678 may be specified before priority to control these parameters:</p></div>
7679 <div class="dlist"><dl>
7680 <dt class="hdlist1">
7681 <code><strong>-facility</strong> <em>value</em></code>
7682 </dt>
7683 <dd>
7685 Use specified facility instead of user. The following
7686 values for facility are recognized:
7687 </p>
7688 <div class="literalblock">
7689 <div class="content">
7690 <pre><code>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
7691 uucp, local0-local7</code></pre>
7692 </div></div>
7693 </dd>
7694 <dt class="hdlist1">
7695 <code><strong>-ident</strong> <em>string</em></code>
7696 </dt>
7697 <dd>
7699 Use given string instead of argv0 variable for ident string.
7700 </p>
7701 </dd>
7702 <dt class="hdlist1">
7703 <code><strong>-options</strong> <em>integer</em></code>
7704 </dt>
7705 <dd>
7707 Set syslog options such as <code>LOG_CONS</code>, <code>LOG_NDELAY</code>. You should
7708 use numeric values of those from your system syslog.h file,
7709 because I haven&#8217;t got time to implement yet another hash
7710 table.
7711 </p>
7712 </dd>
7713 </dl></div>
7714 </div>
7715 <div class="sect2">
7716 <h3 id="cmd_3">pack: pack, unpack</h3>
7717 <div class="paragraph"><p>The optional <em>pack</em> extension provides commands to encode and decode binary strings.</p></div>
7718 <div class="dlist"><dl>
7719 <dt class="hdlist1">
7720 <code><strong>pack</strong> <em>varName value</em> <strong>-intle|-intbe|-floatle|-floatbe|-str</strong> <em>bitwidth ?bitoffset?</em></code>
7721 </dt>
7722 <dd>
7724 Packs the binary representation of <code><em>value</em></code> into the variable
7725 <code><em>varName</em></code>. The value is packed according to the given type
7726 (integer/floating point/string, big-endian/little-endian), width and bit offset.
7727 The variable is created if necessary (like <a href="#_append"><strong><code>append</code></strong></a>).
7728 The variable is expanded if necessary.
7729 </p>
7730 </dd>
7731 <dt class="hdlist1">
7732 <code><strong>unpack</strong> <em>binvalue</em> <strong>-intbe|-intle|-uintbe|-uintle|-floatbe|-floatle|-str</strong> <em>bitpos bitwidth</em></code>
7733 </dt>
7734 <dd>
7736 Unpacks bits from <code><em>binvalue</em></code> at bit position <code><em>bitpos</em></code> and with <code><em>bitwidth</em></code>.
7737 Interprets the value according to the type (integer/floating point/string, big-endian/little-endian
7738 and signed/unsigned) and returns it. For integer types, <code><em>bitwidth</em></code>
7739 may be up to the size of a Jim Tcl integer (typically 64 bits). For floating point types,
7740 <code><em>bitwidth</em></code> may be 32 bits (for single precision numbers) or 64 bits (for double precision).
7741 For the string type, both the width and the offset must be on a byte boundary (multiple of 8). Attempting to
7742 access outside the length of the value will return 0 for integer types, 0.0 for floating point types
7743 or the empty string for the string type.
7744 </p>
7745 </dd>
7746 </dl></div>
7747 </div>
7748 <div class="sect2">
7749 <h3 id="_zlib">zlib</h3>
7750 <div class="paragraph"><p>The optional <em>zlib</em> extension provides a Tcl-compatible subset of the <a href="#_zlib"><strong><code>zlib</code></strong></a> command.</p></div>
7751 <div class="dlist"><dl>
7752 <dt class="hdlist1">
7753 <code><strong>crc32</strong> <em>data</em> <em>?startValue?</em></code>
7754 </dt>
7755 <dd>
7757 Returns the CRC32 checksum of a buffer. Optionally, an initial value may be specified; this is most useful
7758 for calculating the checksum of chunked data read from a stream (for instance, a pipe).
7759 </p>
7760 </dd>
7761 <dt class="hdlist1">
7762 <code><strong>deflate</strong> <em>string</em> <em>?level?</em></code>
7763 </dt>
7764 <dd>
7766 Compresses a buffer and outputs a raw, Deflate-compressed stream. Optionally, a compression level (1-9) may
7767 be specified to choose the desired speed vs. compression rate ratio.
7768 </p>
7769 </dd>
7770 <dt class="hdlist1">
7771 <code><strong>inflate</strong> <em>data</em> <em>?bufferSize?</em></code>
7772 </dt>
7773 <dd>
7775 Decompresses a raw, Deflate-compressed stream. When the uncompressed data size is known and specified, memory
7776 allocation is more efficient. Otherwise, decomperssion is chunked and therefore slower.
7777 </p>
7778 </dd>
7779 <dt class="hdlist1">
7780 <code><strong>gzip</strong> <em>string</em> <em>?-level level?</em></code>
7781 </dt>
7782 <dd>
7784 Compresses a buffer and adds a gzip header.
7785 </p>
7786 </dd>
7787 <dt class="hdlist1">
7788 <code><strong>gunzip</strong> <em>data</em> <em>?-buffersize size?</em></code>
7789 </dt>
7790 <dd>
7792 Decompresses a gzip-compressed buffer. Decompression is chunked, with a default, small buffer size of 64K
7793 which guarantees lower memory footprint at the cost of speed. It is recommended to use a bigger size, on
7794 systems without a severe memory constraint.
7795 </p>
7796 </dd>
7797 </dl></div>
7798 </div>
7799 <div class="sect2">
7800 <h3 id="_binary">binary</h3>
7801 <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>
7802 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>
7803 <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>
7804 <div class="paragraph"><p>Note that <em>binary format</em> with f/r/R specifiers (single-precision float) uses the value of Infinity
7805 in case of overflow.</p></div>
7806 </div>
7807 <div class="sect2">
7808 <h3 id="cmd_4">oo: class, super</h3>
7809 <div class="paragraph"><p>The optional, pure-Tcl <em>oo</em> extension provides object-oriented (OO) support for Jim Tcl.</p></div>
7810 <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>
7811 <div class="dlist"><dl>
7812 <dt class="hdlist1">
7813 <code><strong>class</strong> <em>classname ?baseclasses? classvars</em></code>
7814 </dt>
7815 <dd>
7817 Create a new class, <code><em>classname</em></code>, with the given dictionary
7818 (<code><em>classvars</em></code>) as class variables. These are the initial variables
7819 which all newly created objects of this class are initialised with.
7820 If a list of baseclasses is given, methods and instance variables
7821 are inherited.
7822 </p>
7823 </dd>
7824 <dt class="hdlist1">
7825 <code><strong>super</strong> <em>method ?args ...?</em></code>
7826 </dt>
7827 <dd>
7829 From within a method, invokes the given method on the base class.
7830 Note that this will only call the last baseclass given.
7831 </p>
7832 </dd>
7833 </dl></div>
7834 </div>
7835 <div class="sect2">
7836 <h3 id="_tree">tree</h3>
7837 <div class="paragraph"><p>The optional, pure-Tcl <em>tree</em> extension implements an OO, general purpose tree structure
7838 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>
7839 <div class="paragraph"><p>A tree is a collection of nodes, where each node (except the root node) has a single parent
7840 and zero or more child nodes (ordered), as well as zero or more attribute/value pairs.</p></div>
7841 <div class="dlist"><dl>
7842 <dt class="hdlist1">
7843 <code><strong>tree</strong></code>
7844 </dt>
7845 <dd>
7847 Creates and returns a new tree object with a single node named "root".
7848 All operations on the tree are invoked through this object.
7849 </p>
7850 </dd>
7851 <dt class="hdlist1">
7852 <code>$tree <strong>destroy</strong></code>
7853 </dt>
7854 <dd>
7856 Destroy the tree and all it&#8217;s nodes. (Note that the tree will also
7857 be automatically garbage collected once it goes out of scope).
7858 </p>
7859 </dd>
7860 <dt class="hdlist1">
7861 <code>$tree <strong>set</strong> <em>nodename key value</em></code>
7862 </dt>
7863 <dd>
7865 Set the value for the given attribute key.
7866 </p>
7867 </dd>
7868 <dt class="hdlist1">
7869 <code>$tree <strong>lappend</strong> <em>nodename key value ...</em></code>
7870 </dt>
7871 <dd>
7873 Append to the (list) value(s) for the given attribute key, or set if not yet set.
7874 </p>
7875 </dd>
7876 <dt class="hdlist1">
7877 <code>$tree <strong>keyexists</strong> <em>nodename key</em></code>
7878 </dt>
7879 <dd>
7881 Returns 1 if the given attribute key exists.
7882 </p>
7883 </dd>
7884 <dt class="hdlist1">
7885 <code>$tree <strong>get</strong> <em>nodename key</em></code>
7886 </dt>
7887 <dd>
7889 Returns the value associated with the given attribute key.
7890 </p>
7891 </dd>
7892 <dt class="hdlist1">
7893 <code>$tree <strong>getall</strong> <em>nodename</em></code>
7894 </dt>
7895 <dd>
7897 Returns the entire attribute dictionary associated with the given key.
7898 </p>
7899 </dd>
7900 <dt class="hdlist1">
7901 <code>$tree <strong>depth</strong> <em>nodename</em></code>
7902 </dt>
7903 <dd>
7905 Returns the depth of the given node. The depth of "root" is 0.
7906 </p>
7907 </dd>
7908 <dt class="hdlist1">
7909 <code>$tree <strong>parent</strong> <em>nodename</em></code>
7910 </dt>
7911 <dd>
7913 Returns the node name of the parent node, or "" for the root node.
7914 </p>
7915 </dd>
7916 <dt class="hdlist1">
7917 <code>$tree <strong>numchildren</strong> <em>nodename</em></code>
7918 </dt>
7919 <dd>
7921 Returns the number of child nodes.
7922 </p>
7923 </dd>
7924 <dt class="hdlist1">
7925 <code>$tree <strong>children</strong> <em>nodename</em></code>
7926 </dt>
7927 <dd>
7929 Returns a list of the child nodes.
7930 </p>
7931 </dd>
7932 <dt class="hdlist1">
7933 <code>$tree <strong>next</strong> <em>nodename</em></code>
7934 </dt>
7935 <dd>
7937 Returns the next sibling node, or "" if none.
7938 </p>
7939 </dd>
7940 <dt class="hdlist1">
7941 <code>$tree <strong>insert</strong> <em>nodename ?index?</em></code>
7942 </dt>
7943 <dd>
7945 Add a new child node to the given node. The index is a list index
7946 such as <code>3</code> or <code>end-2</code>. The default index is <code>end</code>.
7947 Returns the name of the newly added node.
7948 </p>
7949 </dd>
7950 <dt class="hdlist1">
7951 <code>$tree <strong>walk</strong> <em>nodename</em> <strong>dfs|bfs</strong> {<em>actionvar nodevar</em>} <em>script</em></code>
7952 </dt>
7953 <dd>
7955 Walks the tree starting from the given node, either breadth first (<code>bfs</code>)
7956 depth first (<code>dfs</code>).
7957 The value <code>"enter"</code> or <code>"exit"</code> is stored in variable <code><em>actionvar</em></code>.
7958 The name of each node is stored in <code><em>nodevar</em></code>.
7959 The script is evaluated twice for each node, on entry and exit.
7960 </p>
7961 </dd>
7962 <dt class="hdlist1">
7963 <code>$tree <strong>dump</strong></code>
7964 </dt>
7965 <dd>
7967 Dumps the tree contents to stdout
7968 </p>
7969 </dd>
7970 </dl></div>
7971 </div>
7972 <div class="sect2">
7973 <h3 id="_tcl_prefix">tcl::prefix</h3>
7974 <div class="paragraph"><p>The optional tclprefix extension provides the Tcl8.6-compatible <a href="#_tcl_prefix"><strong><code>tcl::prefix</code></strong></a> command
7975 (<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
7976 of possible values (typically commands or options).</p></div>
7977 <div class="dlist"><dl>
7978 <dt class="hdlist1">
7979 <code><strong>tcl::prefix all</strong> <em>table string</em></code>
7980 </dt>
7981 <dd>
7983 Returns a list of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7984 </p>
7985 </dd>
7986 <dt class="hdlist1">
7987 <code><strong>tcl::prefix longest</strong> <em>table string</em></code>
7988 </dt>
7989 <dd>
7991 Returns the longest common prefix of all elements in <code><em>table</em></code> that begin with the prefix <code><em>string</em></code>.
7992 </p>
7993 </dd>
7994 <dt class="hdlist1">
7995 <code><strong>tcl::prefix match</strong> <em>?options? table string</em></code>
7996 </dt>
7997 <dd>
7999 If <code><em>string</em></code> equals one element in <code><em>table</em></code> or is a prefix to
8000 exactly one element, the matched element is returned. If not, the
8001 result depends on the <code>-error</code> option.
8002 </p>
8003 <div class="ulist"><ul>
8004 <li>
8006 <code><strong>-exact</strong></code> Accept only exact matches.
8007 </p>
8008 </li>
8009 <li>
8011 <code><strong>-message</strong> <em>string</em></code> Use <code><em>string</em></code> in the error message at a mismatch. Default is "option".
8012 </p>
8013 </li>
8014 <li>
8016 <code><strong>-error</strong> <em>options</em></code> The options are used when no match is found. If <code><em>options</em></code> is
8017 empty, no error is generated and an empty string is returned.
8018 Otherwise the options are used as return options when
8019 generating the error message. The default corresponds to
8020 setting <code>-level 0</code>.
8021 </p>
8022 </li>
8023 </ul></div>
8024 </dd>
8025 </dl></div>
8026 </div>
8027 <div class="sect2">
8028 <h3 id="_tcl_autocomplete">tcl::autocomplete</h3>
8029 <div class="paragraph"><p>Scriptable command line completion is supported in the interactive shell, <em>jimsh</em>, through
8030 the <a href="#_tcl_autocomplete"><strong><code>tcl::autocomplete</code></strong></a> callback. A simple implementation is provided, however this may
8031 be replaced with a custom command instead if desired.</p></div>
8032 <div class="paragraph"><p>In the interactive shell, press &lt;TAB&gt; to activate command line completion.</p></div>
8033 <div class="dlist"><dl>
8034 <dt class="hdlist1">
8035 <code><strong>tcl::autocomplete</strong> <em>commandline</em></code>
8036 </dt>
8037 <dd>
8039 This command is called with the current command line when the user presses &lt;TAB&gt;.
8040 The command should return a list of all possible command lines that match the current command line.
8041 For example if <code><strong>pr</strong></code> is the current command line, the list <code><strong>{prefix proc}</strong></code> may be returned.
8042 </p>
8043 </dd>
8044 </dl></div>
8045 </div>
8046 <div class="sect2">
8047 <h3 id="_history">history</h3>
8048 <div class="paragraph"><p>The optional history extension provides script access to the command line editing
8049 and history support available in <em>jimsh</em>. See <em>examples/jtclsh.tcl</em> for an example.
8050 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
8051 the remaining subcommands do nothing.</p></div>
8052 <div class="dlist"><dl>
8053 <dt class="hdlist1">
8054 <code><strong>history load</strong> <em>filename</em></code>
8055 </dt>
8056 <dd>
8058 Load history from a (text) file. If the file does not exist or is not readable,
8059 it is ignored.
8060 </p>
8061 </dd>
8062 <dt class="hdlist1">
8063 <code><strong>history getline</strong> <em>prompt ?varname?</em></code>
8064 </dt>
8065 <dd>
8067 Displays the given prompt and allows a line to be entered. Similarly to <a href="#_gets"><strong><code>gets</code></strong></a>,
8068 if <code><em>varname</em></code> is given, it receives the line and the length of the line is returned,
8069 or -1 on EOF. If <code><em>varname</em></code> is not given, the line is returned directly.
8070 </p>
8071 </dd>
8072 <dt class="hdlist1">
8073 <code><strong>history completion</strong> <em>command</em></code>
8074 </dt>
8075 <dd>
8077 Sets an autocompletion command (see <a href="#_tcl_autocomplete"><strong><code>tcl::autocomplete</code></strong></a>) that is active during <a href="#_history"><strong><code>history</code></strong></a> <code>getline</code>.
8078 If the command is empty, autocompletion is disabled.
8079 </p>
8080 </dd>
8081 <dt class="hdlist1">
8082 <code><strong>history add</strong> <em>line</em></code>
8083 </dt>
8084 <dd>
8086 Adds the given line to the history buffer.
8087 </p>
8088 </dd>
8089 <dt class="hdlist1">
8090 <code><strong>history save</strong> <em>filename</em></code>
8091 </dt>
8092 <dd>
8094 Saves the current history buffer to the given file.
8095 </p>
8096 </dd>
8097 <dt class="hdlist1">
8098 <code><strong>history show</strong></code>
8099 </dt>
8100 <dd>
8102 Displays the current history buffer to standard output.
8103 </p>
8104 </dd>
8105 </dl></div>
8106 </div>
8107 <div class="sect2">
8108 <h3 id="_namespace">namespace</h3>
8109 <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>
8110 <div class="dlist"><dl>
8111 <dt class="hdlist1">
8112 <code><strong>namespace code</strong> <em>script</em></code>
8113 </dt>
8114 <dd>
8116 Captures the current namespace context for later execution of
8117 the script <code><em>script</em></code>. It returns a new script in which script has
8118 been wrapped in a <code><strong>namespace inscope</strong></code> command.
8119 </p>
8120 </dd>
8121 <dt class="hdlist1">
8122 <code><strong>namespace current</strong></code>
8123 </dt>
8124 <dd>
8126 Returns the fully-qualified name for the current namespace.
8127 </p>
8128 </dd>
8129 <dt class="hdlist1">
8130 <code><strong>namespace delete</strong> <em>?namespace &#8230;?</em></code>
8131 </dt>
8132 <dd>
8134 Deletes all commands and variables with the given namespace prefixes.
8135 </p>
8136 </dd>
8137 <dt class="hdlist1">
8138 <code><strong>namespace eval</strong> <em>namespace arg ?arg&#8230;?</em></code>
8139 </dt>
8140 <dd>
8142 Activates a namespace called <code><em>namespace</em></code> and evaluates some code in that context.
8143 </p>
8144 </dd>
8145 <dt class="hdlist1">
8146 <code><strong>namespace origin</strong> <em>command</em></code>
8147 </dt>
8148 <dd>
8150 Returns the fully-qualified name of the original command to which the imported command <code><em>command</em></code> refers.
8151 </p>
8152 </dd>
8153 <dt class="hdlist1">
8154 <code><strong>namespace parent</strong> ?namespace?</code>
8155 </dt>
8156 <dd>
8158 Returns the fully-qualified name of the parent namespace for namespace <code><em>namespace</em></code>, if given, otherwise
8159 for the current namespace.
8160 </p>
8161 </dd>
8162 <dt class="hdlist1">
8163 <code><strong>namespace qualifiers</strong> <em>string</em></code>
8164 </dt>
8165 <dd>
8167 Returns any leading namespace qualifiers for <code><em>string</em></code>
8168 </p>
8169 </dd>
8170 <dt class="hdlist1">
8171 <code><strong>namespace tail</strong> <em>string</em></code>
8172 </dt>
8173 <dd>
8175 Returns the simple name at the end of a qualified string.
8176 </p>
8177 </dd>
8178 <dt class="hdlist1">
8179 <code><strong>namespace upvar</strong> <em>namespace ?arg&#8230;?</em></code>
8180 </dt>
8181 <dd>
8183 This command arranges for zero or more local variables in the current procedure to refer to variables in <code><em>namespace</em></code>
8184 </p>
8185 </dd>
8186 <dt class="hdlist1">
8187 <code><strong>namespace which</strong> <em>?-command|-variable? name</em></code>
8188 </dt>
8189 <dd>
8191 Looks up <code><em>name</em></code> as either a command (the default) or variable and returns its fully-qualified name.
8192 </p>
8193 </dd>
8194 </dl></div>
8195 </div>
8196 <div class="sect2">
8197 <h3 id="_interp">interp</h3>
8198 <div class="paragraph"><p>The optional <em>interp</em> command allows sub-interpreters to be created where commands may be run
8199 independently (but synchronously) of the main interpreter.</p></div>
8200 <div class="dlist"><dl>
8201 <dt class="hdlist1">
8202 <code><strong>interp</strong></code>
8203 </dt>
8204 <dd>
8206 Creates and returns a new interpreter object (command).
8207 The created interpeter contains any built-in commands along with static extensions,
8208 but does not include any dynamically loaded commands (package require, load).
8209 These must be reloaded in the child interpreter if required.
8210 </p>
8211 </dd>
8212 <dt class="hdlist1">
8213 <code><strong>$interp delete</strong></code>
8214 </dt>
8215 <dd>
8217 Deletes the interpeter object.
8218 </p>
8219 </dd>
8220 <dt class="hdlist1">
8221 <code><strong>$interp eval</strong> <em>script</em> &#8230;</code>
8222 </dt>
8223 <dd>
8225 Evaluates a script in the context for the child interpreter, in the same way as <em>eval</em>.
8226 </p>
8227 </dd>
8228 <dt class="hdlist1">
8229 <code><strong>$interp alias</strong> <em>alias childcmd parentcmd ?arg &#8230;?</em></code>
8230 </dt>
8231 <dd>
8233 Similar to <em>alias</em>, but creates a command, <code><em>childcmd</em></code>, in the child interpreter that is an
8234 alias for <code><em>parentcmd</em></code> in the parent interpreter, with the given, fixed arguments.
8235 The alias may be deleted in the child with <em>rename</em>.
8236 </p>
8237 </dd>
8238 </dl></div>
8239 </div>
8240 </div>
8241 </div>
8242 <div class="sect1">
8243 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
8244 <div class="sectionbody">
8245 <div class="paragraph"><p>The following global variables are created automatically
8246 by the Tcl library.</p></div>
8247 <div class="dlist"><dl>
8248 <dt class="hdlist1">
8249 <code><strong>env</strong></code>
8250 </dt>
8251 <dd>
8253 This variable is set by Jim as an array
8254 whose elements are the environment variables for the process.
8255 Reading an element will return the value of the corresponding
8256 environment variable.
8257 This array is initialised at startup from the <a href="#_env"><strong><code>env</code></strong></a> command.
8258 It may be modified and will affect the environment passed to
8259 commands invoked with <a href="#_exec"><strong><code>exec</code></strong></a>.
8260 </p>
8261 </dd>
8262 <dt class="hdlist1">
8263 <code><strong>platform_tcl</strong></code>
8264 </dt>
8265 <dd>
8267 This variable is set by Jim as an array containing information
8268 about the platform on which Jim was built. Currently this includes
8269 <em>os</em> and <em>platform</em>.
8270 </p>
8271 </dd>
8272 <dt class="hdlist1">
8273 <code><strong>auto_path</strong></code>
8274 </dt>
8275 <dd>
8277 This variable contains a list of paths to search for packages.
8278 It defaults to a location based on where jim is installed
8279 (e.g. <code>/usr/local/lib/jim</code>), but may be changed by <code>jimsh</code>
8280 or the embedding application. Note that <code>jimsh</code> will consider
8281 the environment variable <code>$JIMLIB</code> to be a list of colon-separated
8282 list of paths to add to <code><strong>auto_path</strong></code>.
8283 </p>
8284 </dd>
8285 <dt class="hdlist1">
8286 <code><strong>errorCode</strong></code>
8287 </dt>
8288 <dd>
8290 This variable holds the value of the -errorcode return
8291 option set by the most recent error that occurred in this
8292 interpreter. This list value represents additional information
8293 about the error in a form that is easy to process with
8294 programs. The first element of the list identifies a general
8295 class of errors, and determines the format of the rest of
8296 the list. The following formats for -errorcode return options
8297 are used by the Tcl core; individual applications may define
8298 additional formats. Currently only <a href="#_exec"><strong><code>exec</code></strong></a> sets this variable.
8299 Otherwise it will be <code>NONE</code>.
8300 </p>
8301 </dd>
8302 </dl></div>
8303 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
8304 <div class="dlist"><dl>
8305 <dt class="hdlist1">
8306 <code><strong>tcl_interactive</strong></code>
8307 </dt>
8308 <dd>
8310 This variable is set to 1 if jimsh is started in interactive mode
8311 or 0 otherwise.
8312 </p>
8313 </dd>
8314 <dt class="hdlist1">
8315 <code><strong>tcl_platform</strong></code>
8316 </dt>
8317 <dd>
8319 This variable is set by Jim as an array containing information
8320 about the platform upon which Jim was built. The following is an
8321 example of the contents of this array.
8322 </p>
8323 <div class="literalblock">
8324 <div class="content">
8325 <pre><code>tcl_platform(byteOrder) = littleEndian
8326 tcl_platform(engine) = Jim
8327 tcl_platform(os) = Darwin
8328 tcl_platform(platform) = unix
8329 tcl_platform(pointerSize) = 8
8330 tcl_platform(threaded) = 0
8331 tcl_platform(wordSize) = 8
8332 tcl_platform(pathSeparator) = :</code></pre>
8333 </div></div>
8334 </dd>
8335 <dt class="hdlist1">
8336 <code><strong>argv0</strong></code>
8337 </dt>
8338 <dd>
8340 If jimsh is invoked to run a script, this variable contains the name
8341 of the script.
8342 </p>
8343 </dd>
8344 <dt class="hdlist1">
8345 <code><strong>argv</strong></code>
8346 </dt>
8347 <dd>
8349 If jimsh is invoked to run a script, this variable contains a list
8350 of any arguments supplied to the script.
8351 </p>
8352 </dd>
8353 <dt class="hdlist1">
8354 <code><strong>argc</strong></code>
8355 </dt>
8356 <dd>
8358 If jimsh is invoked to run a script, this variable contains the number
8359 of arguments supplied to the script.
8360 </p>
8361 </dd>
8362 <dt class="hdlist1">
8363 <code><strong>jim::argv0</strong></code>
8364 </dt>
8365 <dd>
8367 The value of argv[0] when jimsh was invoked.
8368 </p>
8369 </dd>
8370 </dl></div>
8371 <div class="paragraph"><p>The following variables have special meaning to Jim Tcl:</p></div>
8372 <div class="dlist"><dl>
8373 <dt class="hdlist1">
8374 <code><strong>jim::defer</strong></code>
8375 </dt>
8376 <dd>
8378 If this variable is set, it is considered to be a list of scripts to evaluate
8379 when the current proc exits (local variables), or the interpreter exits (global variable).
8380 See <a href="#_defer"><strong><code>defer</code></strong></a>.
8381 </p>
8382 </dd>
8383 <dt class="hdlist1">
8384 <code><strong>history::multiline</strong></code>
8385 </dt>
8386 <dd>
8388 If this variable is set to "1", interactive line editing operates in multiline mode.
8389 That is, long lines will wrap across multiple lines rather than scrolling within a
8390 single line.
8391 </p>
8392 </dd>
8393 </dl></div>
8394 </div>
8395 </div>
8396 <div class="sect1">
8397 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
8398 <div class="sectionbody">
8399 <div class="sect2">
8400 <h3 id="_in_v0_70">In v0.70</h3>
8401 <div class="olist arabic"><ol class="arabic">
8402 <li>
8404 <code>platform_tcl()</code> settings are now automatically determined
8405 </p>
8406 </li>
8407 <li>
8409 Add aio <code>$handle filename</code>
8410 </p>
8411 </li>
8412 <li>
8414 Add <a href="#_info"><strong><code>info</code></strong></a> <code>channels</code>
8415 </p>
8416 </li>
8417 <li>
8419 The <em>bio</em> extension is gone. Now <a href="#_aio"><strong><code>aio</code></strong></a> supports <em>copyto</em>.
8420 </p>
8421 </li>
8422 <li>
8424 Add <a href="#_exists"><strong><code>exists</code></strong></a> command
8425 </p>
8426 </li>
8427 <li>
8429 Add the pure-Tcl <em>oo</em> extension
8430 </p>
8431 </li>
8432 <li>
8434 The <a href="#_exec"><strong><code>exec</code></strong></a> command now only uses vfork(), not fork()
8435 </p>
8436 </li>
8437 <li>
8439 Unit test framework is less verbose and more Tcl-compatible
8440 </p>
8441 </li>
8442 <li>
8444 Optional UTF-8 support
8445 </p>
8446 </li>
8447 <li>
8449 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
8450 </p>
8451 </li>
8452 <li>
8454 Command line editing in interactive mode, e.g. <em>jimsh</em>
8455 </p>
8456 </li>
8457 </ol></div>
8458 </div>
8459 <div class="sect2">
8460 <h3 id="_in_v0_63">In v0.63</h3>
8461 <div class="olist arabic"><ol class="arabic">
8462 <li>
8464 <a href="#_source"><strong><code>source</code></strong></a> now checks that a script is complete (.i.e. not missing a brace)
8465 </p>
8466 </li>
8467 <li>
8469 <em>info complete</em> now uses the real parser and so is 100% accurate
8470 </p>
8471 </li>
8472 <li>
8474 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>
8475 </p>
8476 </li>
8477 <li>
8479 <a href="#_tailcall"><strong><code>tailcall</code></strong></a> no longer loses stack trace information
8480 </p>
8481 </li>
8482 <li>
8484 Add <a href="#_alias"><strong><code>alias</code></strong></a> and <a href="#_curry"><strong><code>curry</code></strong></a>
8485 </p>
8486 </li>
8487 <li>
8489 <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
8490 </p>
8491 </li>
8492 <li>
8494 <a href="#_local"><strong><code>local</code></strong></a> allows procedures to be deleted automatically at the end of the current procedure
8495 </p>
8496 </li>
8497 <li>
8499 udp sockets are now supported for both clients and servers.
8500 </p>
8501 </li>
8502 <li>
8504 vfork-based exec is now working correctly
8505 </p>
8506 </li>
8507 <li>
8509 Add <em>file tempfile</em>
8510 </p>
8511 </li>
8512 <li>
8514 Add <em>socket pipe</em>
8515 </p>
8516 </li>
8517 <li>
8519 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
8520 </p>
8521 </li>
8522 <li>
8524 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>
8525 </p>
8526 </li>
8527 <li>
8529 IPv6 support is now included
8530 </p>
8531 </li>
8532 <li>
8534 Add <em>string is</em>
8535 </p>
8536 </li>
8537 <li>
8539 Event handlers works better if an error occurs. eof handler has been removed.
8540 </p>
8541 </li>
8542 <li>
8544 <a href="#_exec"><strong><code>exec</code></strong></a> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
8545 </p>
8546 </li>
8547 <li>
8549 Command pipelines via open "|&#8230;" are now supported
8550 </p>
8551 </li>
8552 <li>
8554 <a href="#_pid"><strong><code>pid</code></strong></a> can now return pids of a command pipeline
8555 </p>
8556 </li>
8557 <li>
8559 Add <em>info references</em>
8560 </p>
8561 </li>
8562 <li>
8564 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>
8565 </p>
8566 </li>
8567 <li>
8569 <a href="#_exec"><strong><code>exec</code></strong></a> now sets environment based on $::env
8570 </p>
8571 </li>
8572 <li>
8574 Add <em>dict keys</em>
8575 </p>
8576 </li>
8577 <li>
8579 Add support for <em>lsort -index</em>
8580 </p>
8581 </li>
8582 </ol></div>
8583 </div>
8584 <div class="sect2">
8585 <h3 id="_in_v0_62">In v0.62</h3>
8586 <div class="olist arabic"><ol class="arabic">
8587 <li>
8589 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>
8590 </p>
8591 </li>
8592 <li>
8594 Fix <a href="#_exec"><strong><code>exec</code></strong></a> error messages when special token (e.g. <em>&gt;</em>) is the last token
8595 </p>
8596 </li>
8597 <li>
8599 Fix <a href="#_subst"><strong><code>subst</code></strong></a> handling of backslash escapes.
8600 </p>
8601 </li>
8602 <li>
8604 Allow abbreviated options for <a href="#_subst"><strong><code>subst</code></strong></a>
8605 </p>
8606 </li>
8607 <li>
8609 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
8610 </p>
8611 </li>
8612 <li>
8614 Many <a href="#_expr"><strong><code>expr</code></strong></a> bug fixes
8615 </p>
8616 </li>
8617 <li>
8619 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
8620 </p>
8621 </li>
8622 <li>
8624 The variable name argument to <a href="#_regsub"><strong><code>regsub</code></strong></a> is now optional
8625 </p>
8626 </li>
8627 <li>
8629 Add support for <em>unset -nocomplain</em>
8630 </p>
8631 </li>
8632 <li>
8634 Add support for list commands: <a href="#_lassign"><strong><code>lassign</code></strong></a>, <a href="#_lrepeat"><strong><code>lrepeat</code></strong></a>
8635 </p>
8636 </li>
8637 <li>
8639 Fully-functional <a href="#_lsearch"><strong><code>lsearch</code></strong></a> is now implemented
8640 </p>
8641 </li>
8642 <li>
8644 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
8645 </p>
8646 </li>
8647 <li>
8649 Allow <a href="#_catch"><strong><code>catch</code></strong></a> to determine what return codes are caught
8650 </p>
8651 </li>
8652 <li>
8654 Allow <a href="#_incr"><strong><code>incr</code></strong></a> to increment an unset variable by first setting to 0
8655 </p>
8656 </li>
8657 <li>
8659 Allow <em>args</em> and optional arguments to the left or required arguments in <a href="#_proc"><strong><code>proc</code></strong></a>
8660 </p>
8661 </li>
8662 <li>
8664 Add <em>file copy</em>
8665 </p>
8666 </li>
8667 <li>
8669 Add <em>try &#8230; finally</em> command
8670 </p>
8671 </li>
8672 </ol></div>
8673 </div>
8674 </div>
8675 </div>
8676 <div class="sect1">
8677 <h2 id="_licence">LICENCE</h2>
8678 <div class="sectionbody">
8679 <div class="literalblock">
8680 <div class="content">
8681 <pre><code>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
8682 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
8683 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
8684 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
8685 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
8686 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
8687 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
8688 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</code></pre>
8689 </div></div>
8690 <div class="literalblock">
8691 <div class="content">
8692 <pre><code>Redistribution and use in source and binary forms, with or without
8693 modification, are permitted provided that the following conditions
8694 are met:
8695 1. Redistributions of source code must retain the above copyright
8696 notice, this list of conditions and the following disclaimer.
8697 2. Redistributions in binary form must reproduce the above
8698 copyright notice, this list of conditions and the following
8699 disclaimer in the documentation and/or other materials
8700 provided with the distribution.</code></pre>
8701 </div></div>
8702 <div class="literalblock">
8703 <div class="content">
8704 <pre><code>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
8705 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
8706 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
8707 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
8708 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
8709 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8710 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
8711 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8712 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8713 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8714 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
8715 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre>
8716 </div></div>
8717 <div class="literalblock">
8718 <div class="content">
8719 <pre><code>The views and conclusions contained in the software and documentation
8720 are those of the authors and should not be interpreted as representing
8721 official policies, either expressed or implied, of the Jim Tcl Project.</code></pre>
8722 </div></div>
8723 </div>
8724 </div>
8725 </div>
8726 <div id="footnotes"><hr /></div>
8727 <div id="footer">
8728 </div>
8729 </body>
8730 </html>