Track source locations in expressions
[jimtcl.git] / Tcl_shipped.html
blobda333b47f4060d24c94bafd0ab70e34b2509f5a1
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.3" />
7 <title>Jim Tcl(n)</title>
8 <style type="text/css">
9 /* Sans-serif font. */
10 h1, h2, h3, h4, h5, h6,
11 div.title, caption.title,
12 thead, p.table.header,
13 div#toctitle,
14 span#author, span#revnumber, span#revdate, span#revremark,
15 div#footer {
16 font-family: Arial,Helvetica,sans-serif;
19 /* Serif font. */
20 div.sectionbody {
21 font-family: Georgia,"Times New Roman",Times,serif;
24 /* Monospace font. */
25 tt {
26 font-size: inherit;
29 body {
30 margin: 1em 5% 1em 5%;
33 a {
34 color: blue;
35 text-decoration: underline;
37 a:visited {
38 color: fuchsia;
41 em {
42 font-style: italic;
43 color: navy;
46 strong {
47 font-weight: bold;
48 color: #083194;
51 tt {
52 font-size: inherit;
53 color: navy;
56 h1, h2, h3, h4, h5, h6 {
57 color: #527bbd;
58 margin-top: 1.2em;
59 margin-bottom: 0.5em;
60 line-height: 1.3;
63 h1, h2, h3 {
64 border-bottom: 2px solid silver;
66 h2 {
67 padding-top: 0.5em;
69 h3 {
70 float: left;
72 h3 + * {
73 clear: left;
76 div.sectionbody {
77 margin-left: 0;
80 hr {
81 border: 1px solid silver;
84 p {
85 margin-top: 0.5em;
86 margin-bottom: 0.5em;
89 ul, ol, li > p {
90 margin-top: 0;
92 ul > li { color: #aaa; }
93 ul > li > * { color: black; }
95 pre {
96 padding: 0;
97 margin: 0;
100 span#author {
101 color: #527bbd;
102 font-weight: bold;
103 font-size: 1.1em;
105 span#email {
107 span#revnumber, span#revdate, span#revremark {
110 div#footer {
111 font-size: small;
112 border-top: 2px solid silver;
113 padding-top: 0.5em;
114 margin-top: 4.0em;
116 div#footer-text {
117 float: left;
118 padding-bottom: 0.5em;
120 div#footer-badges {
121 float: right;
122 padding-bottom: 0.5em;
125 div#preamble {
126 margin-top: 1.5em;
127 margin-bottom: 1.5em;
129 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
130 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
131 div.admonitionblock {
132 margin-top: 1.0em;
133 margin-bottom: 1.5em;
135 div.admonitionblock {
136 margin-top: 2.0em;
137 margin-bottom: 2.0em;
138 margin-right: 10%;
139 color: #606060;
142 div.content { /* Block element content. */
143 padding: 0;
146 /* Block element titles. */
147 div.title, caption.title {
148 color: #527bbd;
149 font-weight: bold;
150 text-align: left;
151 margin-top: 1.0em;
152 margin-bottom: 0.5em;
154 div.title + * {
155 margin-top: 0;
158 td div.title:first-child {
159 margin-top: 0.0em;
161 div.content div.title:first-child {
162 margin-top: 0.0em;
164 div.content + div.title {
165 margin-top: 0.0em;
168 div.sidebarblock > div.content {
169 background: #ffffee;
170 border: 1px solid #dddddd;
171 border-left: 4px solid #f0f0f0;
172 padding: 0.5em;
175 div.listingblock > div.content {
176 border: 1px solid #dddddd;
177 border-left: 5px solid #f0f0f0;
178 background: #f8f8f8;
179 padding: 0.5em;
182 div.quoteblock, div.verseblock {
183 padding-left: 1.0em;
184 margin-left: 1.0em;
185 margin-right: 10%;
186 border-left: 5px solid #f0f0f0;
187 color: #777777;
190 div.quoteblock > div.attribution {
191 padding-top: 0.5em;
192 text-align: right;
195 div.verseblock > pre.content {
196 font-family: inherit;
197 font-size: inherit;
199 div.verseblock > div.attribution {
200 padding-top: 0.75em;
201 text-align: left;
203 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
204 div.verseblock + div.attribution {
205 text-align: left;
208 div.admonitionblock .icon {
209 vertical-align: top;
210 font-size: 1.1em;
211 font-weight: bold;
212 text-decoration: underline;
213 color: #527bbd;
214 padding-right: 0.5em;
216 div.admonitionblock td.content {
217 padding-left: 0.5em;
218 border-left: 3px solid #dddddd;
221 div.exampleblock > div.content {
222 border-left: 3px solid #dddddd;
223 padding-left: 0.5em;
226 div.imageblock div.content { padding-left: 0; }
227 span.image img { border-style: none; }
228 a.image:visited { color: white; }
230 dl {
231 margin-top: 0.8em;
232 margin-bottom: 0.8em;
234 dt {
235 margin-top: 0.5em;
236 margin-bottom: 0;
237 font-style: normal;
238 color: navy;
240 dd > *:first-child {
241 margin-top: 0.1em;
244 ul, ol {
245 list-style-position: outside;
247 ol.arabic {
248 list-style-type: decimal;
250 ol.loweralpha {
251 list-style-type: lower-alpha;
253 ol.upperalpha {
254 list-style-type: upper-alpha;
256 ol.lowerroman {
257 list-style-type: lower-roman;
259 ol.upperroman {
260 list-style-type: upper-roman;
263 div.compact ul, div.compact ol,
264 div.compact p, div.compact p,
265 div.compact div, div.compact div {
266 margin-top: 0.1em;
267 margin-bottom: 0.1em;
270 div.tableblock > table {
271 border: 3px solid #527bbd;
273 thead, p.table.header {
274 font-weight: bold;
275 color: #527bbd;
277 tfoot {
278 font-weight: bold;
280 td > div.verse {
281 white-space: pre;
283 p.table {
284 margin-top: 0;
286 /* Because the table frame attribute is overriden by CSS in most browsers. */
287 div.tableblock > table[frame="void"] {
288 border-style: none;
290 div.tableblock > table[frame="hsides"] {
291 border-left-style: none;
292 border-right-style: none;
294 div.tableblock > table[frame="vsides"] {
295 border-top-style: none;
296 border-bottom-style: none;
300 div.hdlist {
301 margin-top: 0.8em;
302 margin-bottom: 0.8em;
304 div.hdlist tr {
305 padding-bottom: 15px;
307 dt.hdlist1.strong, td.hdlist1.strong {
308 font-weight: bold;
310 td.hdlist1 {
311 vertical-align: top;
312 font-style: normal;
313 padding-right: 0.8em;
314 color: navy;
316 td.hdlist2 {
317 vertical-align: top;
319 div.hdlist.compact tr {
320 margin: 0;
321 padding-bottom: 0;
324 .comment {
325 background: yellow;
328 .footnote, .footnoteref {
329 font-size: 0.8em;
332 span.footnote, span.footnoteref {
333 vertical-align: super;
336 #footnotes {
337 margin: 20px 0 20px 0;
338 padding: 7px 0 0 0;
341 #footnotes div.footnote {
342 margin: 0 0 5px 0;
345 #footnotes hr {
346 border: none;
347 border-top: 1px solid silver;
348 height: 1px;
349 text-align: left;
350 margin-left: 0;
351 width: 20%;
352 min-width: 100px;
355 div.colist td {
356 padding-right: 0.5em;
357 padding-bottom: 0.3em;
358 vertical-align: top;
360 div.colist td img {
361 margin-top: 0.3em;
364 @media print {
365 div#footer-badges { display: none; }
368 div#toc {
369 margin-bottom: 2.5em;
372 div#toctitle {
373 color: #527bbd;
374 font-size: 1.1em;
375 font-weight: bold;
376 margin-top: 1.0em;
377 margin-bottom: 0.1em;
380 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
381 margin-top: 0;
382 margin-bottom: 0;
384 div.toclevel2 {
385 margin-left: 2em;
386 font-size: 0.9em;
388 div.toclevel3 {
389 margin-left: 4em;
390 font-size: 0.9em;
392 div.toclevel4 {
393 margin-left: 6em;
394 font-size: 0.9em;
397 /* Overrides for manpage documents */
398 h1 {
399 padding-top: 0.5em;
400 padding-bottom: 0.5em;
401 border-top: 2px solid silver;
402 border-bottom: 2px solid silver;
404 h2 {
405 border-style: none;
407 div.sectionbody {
408 margin-left: 5%;
411 @media print {
412 div#toc { display: none; }
415 </style>
416 <script type="text/javascript">
417 /*<![CDATA[*/
418 window.onload = function(){asciidoc.footnotes();}
419 var asciidoc = { // Namespace.
421 /////////////////////////////////////////////////////////////////////
422 // Table Of Contents generator
423 /////////////////////////////////////////////////////////////////////
425 /* Author: Mihai Bazon, September 2002
426 * http://students.infoiasi.ro/~mishoo
428 * Table Of Content generator
429 * Version: 0.4
431 * Feel free to use this script under the terms of the GNU General Public
432 * License, as long as you do not remove or alter this notice.
435 /* modified by Troy D. Hanson, September 2006. License: GPL */
436 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
438 // toclevels = 1..4.
439 toc: function (toclevels) {
441 function getText(el) {
442 var text = "";
443 for (var i = el.firstChild; i != null; i = i.nextSibling) {
444 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
445 text += i.data;
446 else if (i.firstChild != null)
447 text += getText(i);
449 return text;
452 function TocEntry(el, text, toclevel) {
453 this.element = el;
454 this.text = text;
455 this.toclevel = toclevel;
458 function tocEntries(el, toclevels) {
459 var result = new Array;
460 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
461 // Function that scans the DOM tree for header elements (the DOM2
462 // nodeIterator API would be a better technique but not supported by all
463 // browsers).
464 var iterate = function (el) {
465 for (var i = el.firstChild; i != null; i = i.nextSibling) {
466 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
467 var mo = re.exec(i.tagName);
468 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
469 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
471 iterate(i);
475 iterate(el);
476 return result;
479 var toc = document.getElementById("toc");
480 var entries = tocEntries(document.getElementById("content"), toclevels);
481 for (var i = 0; i < entries.length; ++i) {
482 var entry = entries[i];
483 if (entry.element.id == "")
484 entry.element.id = "_toc_" + i;
485 var a = document.createElement("a");
486 a.href = "#" + entry.element.id;
487 a.appendChild(document.createTextNode(entry.text));
488 var div = document.createElement("div");
489 div.appendChild(a);
490 div.className = "toclevel" + entry.toclevel;
491 toc.appendChild(div);
493 if (entries.length == 0)
494 toc.parentNode.removeChild(toc);
498 /////////////////////////////////////////////////////////////////////
499 // Footnotes generator
500 /////////////////////////////////////////////////////////////////////
502 /* Based on footnote generation code from:
503 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
506 footnotes: function () {
507 var cont = document.getElementById("content");
508 var noteholder = document.getElementById("footnotes");
509 var spans = cont.getElementsByTagName("span");
510 var refs = {};
511 var n = 0;
512 for (i=0; i<spans.length; i++) {
513 if (spans[i].className == "footnote") {
514 n++;
515 // Use [\s\S] in place of . so multi-line matches work.
516 // Because JavaScript has no s (dotall) regex flag.
517 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
518 noteholder.innerHTML +=
519 "<div class='footnote' id='_footnote_" + n + "'>" +
520 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
521 n + "</a>. " + note + "</div>";
522 spans[i].innerHTML =
523 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
524 "' title='View footnote' class='footnote'>" + n + "</a>]";
525 var id =spans[i].getAttribute("id");
526 if (id != null) refs["#"+id] = n;
529 if (n == 0)
530 noteholder.parentNode.removeChild(noteholder);
531 else {
532 // Process footnoterefs.
533 for (i=0; i<spans.length; i++) {
534 if (spans[i].className == "footnoteref") {
535 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
536 href = href.match(/#.*/)[0]; // Because IE return full URL.
537 n = refs[href];
538 spans[i].innerHTML =
539 "[<a href='#_footnote_" + n +
540 "' title='View footnote' class='footnote'>" + n + "</a>]";
547 /*]]>*/
548 </script>
549 </head>
550 <body class="manpage">
551 <div id="header">
552 <h1>
553 Jim Tcl(n) Manual Page
554 </h1>
555 <h2>NAME</h2>
556 <div class="sectionbody">
557 <p>Jim Tcl v0.72 -
558 overview of the Jim tool command language facilities
559 </p>
560 </div>
561 </div>
562 <div id="content">
563 <div class="sect1">
564 <h2 id="_synopsis">SYNOPSIS</h2>
565 <div class="sectionbody">
566 <div class="literalblock">
567 <div class="content">
568 <pre><tt>cc &lt;source&gt; -ljim</tt></pre>
569 </div></div>
570 <div class="paragraph"><p>or</p></div>
571 <div class="literalblock">
572 <div class="content">
573 <pre><tt>jimsh [&lt;scriptfile&gt;]
574 jimsh -e '&lt;immediate-script&gt;'
575 jimsh --version</tt></pre>
576 </div></div>
577 <div class="ulist"><div class="title">Quick Index</div><ul>
578 <li>
580 <a href="#CommandIndex">Command Reference</a>
581 </p>
582 </li>
583 <li>
585 <a href="#OperatorPrecedence">Operator Precedence</a>
586 </p>
587 </li>
588 <li>
590 <a href="#BuiltinVariables">Builtin Variables</a>
591 </p>
592 </li>
593 <li>
595 <a href="#BackslashSequences">Backslash Sequences</a>
596 </p>
597 </li>
598 </ul></div>
599 </div>
600 </div>
601 <div class="sect1">
602 <h2 id="_introduction">INTRODUCTION</h2>
603 <div class="sectionbody">
604 <div class="paragraph"><p>Jim is a reimplementation of Tcl, combining some features from
605 earlier, smaller versions of Tcl (6.x) as well as more modern
606 features from later versions of Tcl (7.x, 8.x). It also has some some
607 entirely new features not available in any version of Tcl.</p></div>
608 <div class="paragraph"><p>This version is about double the size of "tinytcl" (6.8), depending upon
609 the features selected, but is significantly faster and has many new features.</p></div>
610 <div class="paragraph"><p>Note that most of this man page is the original 6.8 Tcl man page, with
611 changes made for differences with Jim.</p></div>
612 <div class="paragraph"><p>The major differences with Tcl 8.5/8.6 are:</p></div>
613 <div class="olist arabic"><ol class="arabic">
614 <li>
616 Object-based I/O (aio), but with a Tcl-compatibility layer
617 </p>
618 </li>
619 <li>
621 I/O: Support for sockets and pipes including udp, unix domain sockets and IPv6
622 </p>
623 </li>
624 <li>
626 Integers are 64bit
627 </p>
628 </li>
629 <li>
631 Support for references (<em>ref</em>/<em>getref</em>/<em>setref</em>) and garbage collection
632 </p>
633 </li>
634 <li>
636 Builtin dictionary type (<em>dict</em>) with some limitations compared to Tcl 8.6
637 </p>
638 </li>
639 <li>
641 <em>env</em> command to access environment variables
642 </p>
643 </li>
644 <li>
646 <em>os.fork</em>, <em>os.wait</em>, <em>os.uptime</em>, <em>rand</em>
647 </p>
648 </li>
649 <li>
651 Much better error reporting. <em>info stacktrace</em> as a replacement for <em>errorInfo</em>, <em>errorCode</em>
652 </p>
653 </li>
654 <li>
656 Support for "static" variables in procedures
657 </p>
658 </li>
659 <li>
661 Namespaces are not support
662 </p>
663 </li>
664 <li>
666 Variable traces are not supported
667 </p>
668 </li>
669 <li>
671 Direct command line editing rather than the <em>history</em> command
672 </p>
673 </li>
674 <li>
676 Expression shorthand syntax: <tt>$(&#8230;)</tt>
677 </p>
678 </li>
679 </ol></div>
680 </div>
681 </div>
682 <div class="sect1">
683 <h2 id="_recent_changes">RECENT CHANGES</h2>
684 <div class="sectionbody">
685 <div class="sect2">
686 <h3 id="_changes_between_0_71_and_0_72">Changes between 0.71 and 0.72</h3>
687 <div class="olist arabic"><ol class="arabic">
688 <li>
690 procs now allow <em>args</em> and optional parameters in any position
691 </p>
692 </li>
693 <li>
695 Add Tcl-compatible expr functions, <em>rand()</em> and <em>srand()</em>
696 </p>
697 </li>
698 <li>
700 Add support for the <em>-force</em> option to <em>file delete</em>
701 </p>
702 </li>
703 <li>
705 Better diagnostics when <em>source</em> fails to load a script with a missing quote or bracket
706 </p>
707 </li>
708 <li>
710 New <tt>tcl_platform(pathSeparator)</tt>
711 </p>
712 </li>
713 </ol></div>
714 </div>
715 <div class="sect2">
716 <h3 id="_changes_between_0_70_and_0_71">Changes between 0.70 and 0.71</h3>
717 <div class="olist arabic"><ol class="arabic">
718 <li>
720 Allow <em>args</em> to be renamed in procs
721 </p>
722 </li>
723 <li>
725 Add <tt>$(&#8230;)</tt> shorthand syntax for expressions
726 </p>
727 </li>
728 <li>
730 Add automatic reference variables in procs with <tt>&amp;var</tt> syntax
731 </p>
732 </li>
733 <li>
735 Support <tt>jimsh --version</tt>
736 </p>
737 </li>
738 <li>
740 Additional variables in <tt>tcl_platform()</tt>
741 </p>
742 </li>
743 <li>
745 <em>local</em> procs now push existing commands and <em>upcall</em> can call them
746 </p>
747 </li>
748 <li>
750 Add <em>loop</em> command (TclX compatible)
751 </p>
752 </li>
753 <li>
755 Add <em>aio</em> <em>buffering</em> command
756 </p>
757 </li>
758 <li>
760 <em>info complete</em> can now return the missing character
761 </p>
762 </li>
763 <li>
765 <em>binary format</em> and <em>binary scan</em> are now (optionally) supported
766 </p>
767 </li>
768 <li>
770 Add <em>string byterange</em>
771 </p>
772 </li>
773 <li>
775 Built-in regexp now support non-greedy repetition (*?, +?, ??)
776 </p>
777 </li>
778 </ol></div>
779 </div>
780 <div class="sect2">
781 <h3 id="_changes_between_0_63_and_0_70">Changes between 0.63 and 0.70</h3>
782 <div class="olist arabic"><ol class="arabic">
783 <li>
785 <tt>platform_tcl()</tt> settings are now automatically determined
786 </p>
787 </li>
788 <li>
790 Add aio <em>$handle filename</em>
791 </p>
792 </li>
793 <li>
795 Add <em>info channels</em>
796 </p>
797 </li>
798 <li>
800 The <em>bio</em> extension is gone. Now <em>aio</em> supports <em>copyto</em>.
801 </p>
802 </li>
803 <li>
805 Add <em>exists</em> command
806 </p>
807 </li>
808 <li>
810 Add the pure-Tcl <em>oo</em> extension
811 </p>
812 </li>
813 <li>
815 The <em>exec</em> command now only uses vfork(), not fork()
816 </p>
817 </li>
818 <li>
820 Unit test framework is less verbose and more Tcl-compatible
821 </p>
822 </li>
823 <li>
825 Optional UTF-8 support
826 </p>
827 </li>
828 <li>
830 Optional built-in regexp engine for better Tcl compatibility and UTF-8 support
831 </p>
832 </li>
833 <li>
835 Command line editing in interactive mode, e.g. <em>jimsh</em>
836 </p>
837 </li>
838 </ol></div>
839 </div>
840 </div>
841 </div>
842 <div class="sect1">
843 <h2 id="_tcl_introduction">TCL INTRODUCTION</h2>
844 <div class="sectionbody">
845 <div class="paragraph"><p>Tcl stands for <em>tool command language</em> and is pronounced <em>tickle.</em>
846 It is actually two things: a language and a library.</p></div>
847 <div class="paragraph"><p>First, Tcl is a simple textual language, intended primarily for
848 issuing commands to interactive programs such as text editors,
849 debuggers, illustrators, and shells. It has a simple syntax and is also
850 programmable, so Tcl users can write command procedures to provide more
851 powerful commands than those in the built-in set.</p></div>
852 <div class="paragraph"><p>Second, Tcl is a library package that can be embedded in application
853 programs. The Tcl library consists of a parser for the Tcl language,
854 routines to implement the Tcl built-in commands, and procedures that
855 allow each application to extend Tcl with additional commands specific
856 to that application. The application program generates Tcl commands and
857 passes them to the Tcl parser for execution. Commands may be generated
858 by reading characters from an input source, or by associating command
859 strings with elements of the application&#8217;s user interface, such as menu
860 entries, buttons, or keystrokes.</p></div>
861 <div class="paragraph"><p>When the Tcl library receives commands it parses them into component
862 fields and executes built-in commands directly. For commands implemented
863 by the application, Tcl calls back to the application to execute the
864 commands. In many cases commands will invoke recursive invocations of the
865 Tcl interpreter by passing in additional strings to execute (procedures,
866 looping commands, and conditional commands all work in this way).</p></div>
867 <div class="paragraph"><p>An application program gains three advantages by using Tcl for its command
868 language. First, Tcl provides a standard syntax: once users know Tcl,
869 they will be able to issue commands easily to any Tcl-based application.
870 Second, Tcl provides programmability. All a Tcl application needs
871 to do is to implement a few application-specific low-level commands.
872 Tcl provides many utility commands plus a general programming interface
873 for building up complex command procedures. By using Tcl, applications
874 need not re-implement these features.</p></div>
875 <div class="paragraph"><p>Third, Tcl can be used as a common language for communicating between
876 applications. Inter-application communication is not built into the
877 Tcl core described here, but various add-on libraries, such as the Tk
878 toolkit, allow applications to issue commands to each other. This makes
879 it possible for applications to work together in much more powerful ways
880 than was previously possible.</p></div>
881 <div class="paragraph"><p>Fourth, Jim Tcl includes a command processor, <tt>jimsh</tt>, which can be
882 used to run standalone Tcl scripts, or to run Tcl commands interactively.</p></div>
883 <div class="paragraph"><p>This manual page focuses primarily on the Tcl language. It describes
884 the language syntax and the built-in commands that will be available
885 in any application based on Tcl. The individual library procedures are
886 described in more detail in separate manual pages, one per procedure.</p></div>
887 </div>
888 </div>
889 <div class="sect1">
890 <h2 id="_jimsh_command_interpreter">JIMSH COMMAND INTERPRETER</h2>
891 <div class="sectionbody">
892 <div class="paragraph"><p>A simple, but powerful command processor, <tt>jimsh</tt>, is part of Jim Tcl.
893 It may be invoked in interactive mode as:</p></div>
894 <div class="literalblock">
895 <div class="content">
896 <pre><tt>jimsh</tt></pre>
897 </div></div>
898 <div class="paragraph"><p>or to process the Tcl script in a file with:</p></div>
899 <div class="literalblock">
900 <div class="content">
901 <pre><tt>jimsh filename</tt></pre>
902 </div></div>
903 <div class="paragraph"><p>It may also be invoked to execute an immediate script with:</p></div>
904 <div class="literalblock">
905 <div class="content">
906 <pre><tt>jimsh -e "script"</tt></pre>
907 </div></div>
908 <div class="sect2">
909 <h3 id="_interactive_mode">Interactive Mode</h3>
910 <div class="paragraph"><p>Interactive mode reads Tcl commands from standard input, evaluates
911 those commands and prints the results.</p></div>
912 <div class="literalblock">
913 <div class="content">
914 <pre><tt>$ jimsh
915 Welcome to Jim version 0.71, Copyright (c) 2005-8 Salvatore Sanfilippo
916 . info version
917 0.71
918 . lsort [info commands p*]
919 package parray pid popen proc puts pwd
920 . foreach i {a b c} {
921 {&gt; puts $i
922 {&gt; }
926 . bad
927 invalid command name "bad"
928 [error] . exit
929 $</tt></pre>
930 </div></div>
931 <div class="paragraph"><p>If <tt>jimsh</tt> is configured with line editing (it is by default) and a VT-100-compatible
932 terminal is detected, Emacs-style line editing commands are available, including:
933 arrow keys, <tt>^W</tt> to erase a word, <tt>^U</tt> to erase the line, <tt>^R</tt> for reverse incremental search
934 in history. Additionally, the <tt>h</tt> command may be used to display the command history.</p></div>
935 <div class="paragraph"><p>Command line history is automatically saved and loaded from <tt>~/.jim_history</tt></p></div>
936 <div class="paragraph"><p>In interactive mode, <tt>jimsh</tt> automatically runs the script <tt>~/.jimrc</tt> at startup
937 if it exists.</p></div>
938 </div>
939 </div>
940 </div>
941 <div class="sect1">
942 <h2 id="_interpreters">INTERPRETERS</h2>
943 <div class="sectionbody">
944 <div class="paragraph"><p>The central data structure in Tcl is an interpreter (C type <em>Jim_Interp</em>).
945 An interpreter consists of a set of command bindings, a set of variable
946 values, and a few other miscellaneous pieces of state. Each Tcl command
947 is interpreted in the context of a particular interpreter.</p></div>
948 <div class="paragraph"><p>Some Tcl-based applications will maintain multiple interpreters
949 simultaneously, each associated with a different widget or portion of
950 the application. Interpreters are relatively lightweight structures.
951 They can be created and deleted quickly, so application programmers should
952 feel free to use multiple interpreters if that simplifies the application.</p></div>
953 </div>
954 </div>
955 <div class="sect1">
956 <h2 id="_data_types">DATA TYPES</h2>
957 <div class="sectionbody">
958 <div class="paragraph"><p>Tcl supports only one type of data: strings. All commands, all arguments
959 to commands, all command results, and all variable values are strings.</p></div>
960 <div class="paragraph"><p>Where commands require numeric arguments or return numeric results,
961 the arguments and results are passed as strings. Many commands expect
962 their string arguments to have certain formats, but this interpretation
963 is up to the individual commands. For example, arguments often contain
964 Tcl command strings, which may get executed as part of the commands.
965 The easiest way to understand the Tcl interpreter is to remember that
966 everything is just an operation on a string. In many cases Tcl constructs
967 will look similar to more structured constructs from other languages.
968 However, the Tcl constructs are not structured at all; they are just
969 strings of characters, and this gives them a different behaviour than
970 the structures they may look like.</p></div>
971 <div class="paragraph"><p>Although the exact interpretation of a Tcl string depends on who is doing
972 the interpretation, there are three common forms that strings take:
973 commands, expressions, and lists. The major sections below discuss
974 these three forms in more detail.</p></div>
975 </div>
976 </div>
977 <div class="sect1">
978 <h2 id="_basic_command_syntax">BASIC COMMAND SYNTAX</h2>
979 <div class="sectionbody">
980 <div class="paragraph"><p>The Tcl language has syntactic similarities to both the Unix shells
981 and Lisp. However, the interpretation of commands is different
982 in Tcl than in either of those other two systems.
983 A Tcl command string consists of one or more commands separated
984 by newline characters or semi-colons.
985 Each command consists of a collection of fields separated by
986 white space (spaces or tabs).
987 The first field must be the name of a command, and the
988 additional fields, if any, are arguments that will be passed to
989 that command. For example, the command:</p></div>
990 <div class="literalblock">
991 <div class="content">
992 <pre><tt>set a 22</tt></pre>
993 </div></div>
994 <div class="paragraph"><p>has three fields: the first, <em>set</em>, is the name of a Tcl command, and
995 the last two, <em>a</em> and <em>22</em>, will be passed as arguments to
996 the <em>set</em> command. The command name may refer either to a built-in
997 Tcl command, an application-specific command bound in with the library
998 procedure <em>Jim_CreateCommand</em>, or a command procedure defined with the
999 <em>proc</em> built-in command.</p></div>
1000 <div class="paragraph"><p>Arguments are passed literally as text strings. Individual commands may
1001 interpret those strings in any fashion they wish. The <em>set</em> command,
1002 for example, will treat its first argument as the name of a variable
1003 and its second argument as a string value to assign to that variable.
1004 For other commands arguments may be interpreted as integers, lists,
1005 file names, or Tcl commands.</p></div>
1006 <div class="paragraph"><p>Command names should normally be typed completely (e.g. no abbreviations).
1007 However, if the Tcl interpreter cannot locate a command it invokes a
1008 special command named <em>unknown</em> which attempts to find or create the
1009 command.</p></div>
1010 <div class="paragraph"><p>For example, at many sites <em>unknown</em> will search through library
1011 directories for the desired command and create it as a Tcl procedure if
1012 it is found. The <em>unknown</em> command often provides automatic completion
1013 of abbreviated commands, but usually only for commands that were typed
1014 interactively.</p></div>
1015 <div class="paragraph"><p>It&#8217;s probably a bad idea to use abbreviations in command scripts and
1016 other forms that will be re-used over time: changes to the command set
1017 may cause abbreviations to become ambiguous, resulting in scripts that
1018 no longer work.</p></div>
1019 </div>
1020 </div>
1021 <div class="sect1">
1022 <h2 id="_comments">COMMENTS</h2>
1023 <div class="sectionbody">
1024 <div class="paragraph"><p>If the first non-blank character in a command is <tt>#</tt>, then everything
1025 from the <tt>#</tt> up through the next newline character is treated as
1026 a comment and ignored. When comments are embedded inside nested
1027 commands (e.g. fields enclosed in braces) they must have properly-matched
1028 braces (this is necessary because when Tcl parses the top-level command
1029 it doesn&#8217;t yet know that the nested field will be used as a command so
1030 it cannot process the nested comment character as a comment).</p></div>
1031 </div>
1032 </div>
1033 <div class="sect1">
1034 <h2 id="_grouping_arguments_with_double_quotes">GROUPING ARGUMENTS WITH DOUBLE-QUOTES</h2>
1035 <div class="sectionbody">
1036 <div class="paragraph"><p>Normally each argument field ends at the next white space, but
1037 double-quotes may be used to create arguments with embedded space.</p></div>
1038 <div class="paragraph"><p>If an argument field begins with a double-quote, then the argument isn&#8217;t
1039 terminated by white space (including newlines) or a semi-colon (see below
1040 for information on semi-colons); instead it ends at the next double-quote
1041 character. The double-quotes are not included in the resulting argument.
1042 For example, the command</p></div>
1043 <div class="literalblock">
1044 <div class="content">
1045 <pre><tt>set a "This is a single argument"</tt></pre>
1046 </div></div>
1047 <div class="paragraph"><p>will pass two arguments to <em>set</em>: <em>a</em> and <em>This is a single argument</em>.</p></div>
1048 <div class="paragraph"><p>Within double-quotes, command substitutions, variable substitutions,
1049 and backslash substitutions still occur, as described below. If the
1050 first character of a command field is not a quote, then quotes receive
1051 no special interpretation in the parsing of that field.</p></div>
1052 </div>
1053 </div>
1054 <div class="sect1">
1055 <h2 id="_grouping_arguments_with_braces">GROUPING ARGUMENTS WITH BRACES</h2>
1056 <div class="sectionbody">
1057 <div class="paragraph"><p>Curly braces may also be used for grouping arguments. They are similar
1058 to quotes except for two differences. First, they nest; this makes them
1059 easier to use for complicated arguments like nested Tcl command strings.
1060 Second, the substitutions described below for commands, variables, and
1061 backslashes do <strong>not</strong> occur in arguments enclosed in braces, so braces
1062 can be used to prevent substitutions where they are undesirable.</p></div>
1063 <div class="paragraph"><p>If an argument field begins with a left brace, then the argument ends
1064 at the matching right brace. Tcl will strip off the outermost layer
1065 of braces and pass the information between the braces to the command
1066 without any further modification. For example, in the command</p></div>
1067 <div class="literalblock">
1068 <div class="content">
1069 <pre><tt>set a {xyz a {b c d}}</tt></pre>
1070 </div></div>
1071 <div class="paragraph"><p>the <em>set</em> command will receive two arguments: <em>a</em>
1072 and <em>xyz a {b c d}</em>.</p></div>
1073 <div class="paragraph"><p>When braces or quotes are in effect, the matching brace or quote need
1074 not be on the same line as the starting quote or brace; in this case
1075 the newline will be included in the argument field along with any other
1076 characters up to the matching brace or quote. For example, the <em>eval</em>
1077 command takes one argument, which is a command string; <em>eval</em> invokes
1078 the Tcl interpreter to execute the command string. The command</p></div>
1079 <div class="literalblock">
1080 <div class="content">
1081 <pre><tt>eval {
1082 set a 22
1083 set b 33
1084 }</tt></pre>
1085 </div></div>
1086 <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>
1087 <div class="paragraph"><p>If the first character of a command field is not a left
1088 brace, then neither left nor right
1089 braces in the field will be treated specially (except as part of
1090 variable substitution; see below).</p></div>
1091 </div>
1092 </div>
1093 <div class="sect1">
1094 <h2 id="_command_substitution_with_brackets">COMMAND SUBSTITUTION WITH BRACKETS</h2>
1095 <div class="sectionbody">
1096 <div class="paragraph"><p>If an open bracket occurs in a field of a command, then command
1097 substitution occurs (except for fields enclosed in braces). All of the
1098 text up to the matching close bracket is treated as a Tcl command and
1099 executed immediately. Then the result of that command is substituted
1100 for the bracketed text. For example, consider the command</p></div>
1101 <div class="literalblock">
1102 <div class="content">
1103 <pre><tt>set a [set b]</tt></pre>
1104 </div></div>
1105 <div class="paragraph"><p>When the <em>set</em> command has only a single argument, it is the name of a
1106 variable and <em>set</em> returns the contents of that variable. In this case,
1107 if variable <em>b</em> has the value <em>foo</em>, then the command above is equivalent
1108 to the command</p></div>
1109 <div class="literalblock">
1110 <div class="content">
1111 <pre><tt>set a foo</tt></pre>
1112 </div></div>
1113 <div class="paragraph"><p>Brackets can be used in more complex ways. For example, if the variable
1114 <em>b</em> has the value <em>foo</em> and the variable <em>c</em> has the value <em>gorp</em>,
1115 then the command</p></div>
1116 <div class="literalblock">
1117 <div class="content">
1118 <pre><tt>set a xyz[set b].[set c]</tt></pre>
1119 </div></div>
1120 <div class="paragraph"><p>is equivalent to the command</p></div>
1121 <div class="literalblock">
1122 <div class="content">
1123 <pre><tt>set a xyzfoo.gorp</tt></pre>
1124 </div></div>
1125 <div class="paragraph"><p>A bracketed command may contain multiple commands separated by newlines
1126 or semi-colons in the usual fashion. In this case the value of the last
1127 command is used for substitution. For example, the command</p></div>
1128 <div class="literalblock">
1129 <div class="content">
1130 <pre><tt>set a x[set b 22
1131 expr $b+2]x</tt></pre>
1132 </div></div>
1133 <div class="paragraph"><p>is equivalent to the command</p></div>
1134 <div class="literalblock">
1135 <div class="content">
1136 <pre><tt>set a x24x</tt></pre>
1137 </div></div>
1138 <div class="paragraph"><p>If a field is enclosed in braces then the brackets and the characters
1139 between them are not interpreted specially; they are passed through to
1140 the argument verbatim.</p></div>
1141 </div>
1142 </div>
1143 <div class="sect1">
1144 <h2 id="_variable_substitution_with">VARIABLE SUBSTITUTION WITH $</h2>
1145 <div class="sectionbody">
1146 <div class="paragraph"><p>The dollar sign (<em>$</em>) may be used as a special shorthand form for
1147 substituting variable values. If <em>$</em> appears in an argument that isn&#8217;t
1148 enclosed in braces then variable substitution will occur. The characters
1149 after the <em>$</em>, up to the first character that isn&#8217;t a number, letter,
1150 or underscore, are taken as a variable name and the string value of that
1151 variable is substituted for the name.</p></div>
1152 <div class="paragraph"><p>For example, if variable <em>foo</em> has the value <em>test</em>, then the command</p></div>
1153 <div class="literalblock">
1154 <div class="content">
1155 <pre><tt>set a $foo.c</tt></pre>
1156 </div></div>
1157 <div class="paragraph"><p>is equivalent to the command</p></div>
1158 <div class="literalblock">
1159 <div class="content">
1160 <pre><tt>set a test.c</tt></pre>
1161 </div></div>
1162 <div class="paragraph"><p>There are two special forms for variable substitution. If the next
1163 character after the name of the variable is an open parenthesis, then
1164 the variable is assumed to be an array name, and all of the characters
1165 between the open parenthesis and the next close parenthesis are taken as
1166 an index into the array. Command substitutions and variable substitutions
1167 are performed on the information between the parentheses before it is
1168 used as an index.</p></div>
1169 <div class="paragraph"><p>For example, if the variable <em>x</em> is an array with one element named
1170 <em>first</em> and value <em>87</em> and another element named <em>14</em> and value <em>more</em>,
1171 then the command</p></div>
1172 <div class="literalblock">
1173 <div class="content">
1174 <pre><tt>set a xyz$x(first)zyx</tt></pre>
1175 </div></div>
1176 <div class="paragraph"><p>is equivalent to the command</p></div>
1177 <div class="literalblock">
1178 <div class="content">
1179 <pre><tt>set a xyz87zyx</tt></pre>
1180 </div></div>
1181 <div class="paragraph"><p>If the variable <em>index</em> has the value <em>14</em>, then the command</p></div>
1182 <div class="literalblock">
1183 <div class="content">
1184 <pre><tt>set a xyz$x($index)zyx</tt></pre>
1185 </div></div>
1186 <div class="paragraph"><p>is equivalent to the command</p></div>
1187 <div class="literalblock">
1188 <div class="content">
1189 <pre><tt>set a xyzmorezyx</tt></pre>
1190 </div></div>
1191 <div class="paragraph"><p>For more information on arrays, see VARIABLES AND ARRAYS below.</p></div>
1192 <div class="paragraph"><p>The second special form for variables occurs when the dollar sign is
1193 followed by an open curly brace. In this case the variable name consists
1194 of all the characters up to the next curly brace.</p></div>
1195 <div class="paragraph"><p>Array references are not possible in this form: the name between braces
1196 is assumed to refer to a scalar variable. For example, if variable
1197 <em>foo</em> has the value <em>test</em>, then the command</p></div>
1198 <div class="literalblock">
1199 <div class="content">
1200 <pre><tt>set a abc${foo}bar</tt></pre>
1201 </div></div>
1202 <div class="paragraph"><p>is equivalent to the command</p></div>
1203 <div class="literalblock">
1204 <div class="content">
1205 <pre><tt>set a abctestbar</tt></pre>
1206 </div></div>
1207 <div class="paragraph"><p>Variable substitution does not occur in arguments that are enclosed in
1208 braces: the dollar sign and variable name are passed through to the
1209 argument verbatim.</p></div>
1210 <div class="paragraph"><p>The dollar sign abbreviation is simply a shorthand form. <em>$a</em> is
1211 completely equivalent to <em>[set a]</em>; it is provided as a convenience
1212 to reduce typing.</p></div>
1213 </div>
1214 </div>
1215 <div class="sect1">
1216 <h2 id="_separating_commands_with_semi_colons">SEPARATING COMMANDS WITH SEMI-COLONS</h2>
1217 <div class="sectionbody">
1218 <div class="paragraph"><p>Normally, each command occupies one line (the command is terminated by a
1219 newline character). However, semi-colon (<em>;</em>) is treated as a command
1220 separator character; multiple commands may be placed on one line by
1221 separating them with a semi-colon. Semi-colons are not treated as
1222 command separators if they appear within curly braces or double-quotes.</p></div>
1223 </div>
1224 </div>
1225 <div class="sect1">
1226 <h2 id="_backslash_substitution">BACKSLASH SUBSTITUTION</h2>
1227 <div class="sectionbody">
1228 <div class="paragraph"><p>Backslashes may be used to insert non-printing characters into command
1229 fields and also to insert special characters like braces and brackets
1230 into fields without them being interpreted specially as described above.</p></div>
1231 <div class="paragraph"><p>The backslash sequences understood by the Tcl interpreter are
1232 listed below. In each case, the backslash
1233 sequence is replaced by the given character:</p></div>
1234 <div class="dlist" id="BackslashSequences"><dl>
1235 <dt class="hdlist1">
1236 <tt>\b</tt>
1237 </dt>
1238 <dd>
1240 Backspace (0x8)
1241 </p>
1242 </dd>
1243 <dt class="hdlist1">
1244 <tt>\f</tt>
1245 </dt>
1246 <dd>
1248 Form feed (0xc)
1249 </p>
1250 </dd>
1251 <dt class="hdlist1">
1252 <tt>\n</tt>
1253 </dt>
1254 <dd>
1256 Newline (0xa)
1257 </p>
1258 </dd>
1259 <dt class="hdlist1">
1260 <tt>\r</tt>
1261 </dt>
1262 <dd>
1264 Carriage-return (0xd).
1265 </p>
1266 </dd>
1267 <dt class="hdlist1">
1268 <tt>\t</tt>
1269 </dt>
1270 <dd>
1272 Tab (0x9).
1273 </p>
1274 </dd>
1275 <dt class="hdlist1">
1276 <tt>\v</tt>
1277 </dt>
1278 <dd>
1280 Vertical tab (0xb).
1281 </p>
1282 </dd>
1283 <dt class="hdlist1">
1284 <tt>\{</tt>
1285 </dt>
1286 <dd>
1288 Left brace ({).
1289 </p>
1290 </dd>
1291 <dt class="hdlist1">
1292 <tt>\}</tt>
1293 </dt>
1294 <dd>
1296 Right brace (}).
1297 </p>
1298 </dd>
1299 <dt class="hdlist1">
1300 <tt>\[</tt>
1301 </dt>
1302 <dd>
1304 Open bracket ([).
1305 </p>
1306 </dd>
1307 <dt class="hdlist1">
1308 <tt>\]</tt>
1309 </dt>
1310 <dd>
1312 Close bracket (]).
1313 </p>
1314 </dd>
1315 <dt class="hdlist1">
1316 <tt>\$</tt>
1317 </dt>
1318 <dd>
1320 Dollar sign ($).
1321 </p>
1322 </dd>
1323 <dt class="hdlist1">
1324 <tt>\&lt;space&gt;</tt>
1325 </dt>
1326 <dd>
1328 Space ( ): doesn&#8217;t terminate argument.
1329 </p>
1330 </dd>
1331 <dt class="hdlist1">
1332 <tt>\;</tt>
1333 </dt>
1334 <dd>
1336 Semi-colon: doesn&#8217;t terminate command.
1337 </p>
1338 </dd>
1339 <dt class="hdlist1">
1340 <tt>\"</tt>
1341 </dt>
1342 <dd>
1344 Double-quote.
1345 </p>
1346 </dd>
1347 <dt class="hdlist1">
1348 <tt>\&lt;newline&gt;</tt>
1349 </dt>
1350 <dd>
1352 Nothing: this joins two lines together
1353 into a single line. This backslash feature is unique in that
1354 it will be applied even when the sequence occurs within braces.
1355 </p>
1356 </dd>
1357 <dt class="hdlist1">
1358 <tt>\\</tt>
1359 </dt>
1360 <dd>
1362 Backslash (<em>\</em>).
1363 </p>
1364 </dd>
1365 <dt class="hdlist1">
1366 <tt>\<strong>ddd</strong></tt>
1367 </dt>
1368 <dd>
1370 The digits <strong>ddd</strong> (one, two, or three of them) give the octal value of
1371 the character. Note that Jim supports null characters in strings.
1372 </p>
1373 </dd>
1374 <dt class="hdlist1">
1375 <tt>\<strong>unnnn</strong></tt>
1376 </dt>
1377 <dd>
1379 The hex digits <strong>nnnn</strong> (between one and four of them) give a unicode codepoint.
1380 The UTF-8 encoding of the codepoint is inserted.
1381 </p>
1382 </dd>
1383 </dl></div>
1384 <div class="paragraph"><p>For example, in the command</p></div>
1385 <div class="literalblock">
1386 <div class="content">
1387 <pre><tt>set a \{x\[\ yz\141</tt></pre>
1388 </div></div>
1389 <div class="paragraph"><p>the second argument to <em>set</em> will be <em>{x[ yza</em>.</p></div>
1390 <div class="paragraph"><p>If a backslash is followed by something other than one of the options
1391 described above, then the backslash is transmitted to the argument
1392 field without any special processing, and the Tcl scanner continues
1393 normal processing with the next character. For example, in the
1394 command</p></div>
1395 <div class="literalblock">
1396 <div class="content">
1397 <pre><tt>set \*a \\\{foo</tt></pre>
1398 </div></div>
1399 <div class="paragraph"><p>The first argument to <em>set</em> will be <em>\*a</em> and the second
1400 argument will be <em>\{foo</em>.</p></div>
1401 <div class="paragraph"><p>If an argument is enclosed in braces, then backslash sequences inside
1402 the argument are parsed but no substitution occurs (except for
1403 backslash-newline): the backslash
1404 sequence is passed through to the argument as is, without making
1405 any special interpretation of the characters in the backslash sequence.
1406 In particular, backslashed braces are not counted in locating the
1407 matching right brace that terminates the argument.
1408 For example, in the
1409 command</p></div>
1410 <div class="literalblock">
1411 <div class="content">
1412 <pre><tt>set a {\{abc}</tt></pre>
1413 </div></div>
1414 <div class="paragraph"><p>the second argument to <em>set</em> will be <em>\{abc</em>.</p></div>
1415 <div class="paragraph"><p>This backslash mechanism is not sufficient to generate absolutely
1416 any argument structure; it only covers the
1417 most common cases. To produce particularly complicated arguments
1418 it is probably easiest to use the <em>format</em> command along with
1419 command substitution.</p></div>
1420 </div>
1421 </div>
1422 <div class="sect1">
1423 <h2 id="_string_and_list_index_specifications">STRING AND LIST INDEX SPECIFICATIONS</h2>
1424 <div class="sectionbody">
1425 <div class="paragraph"><p>Many string and list commands take one or more <em>index</em> parameters which
1426 specify a position in the string relative to the start or end of the string/list.</p></div>
1427 <div class="paragraph"><p>The index may be one of the following forms:</p></div>
1428 <div class="dlist"><dl>
1429 <dt class="hdlist1">
1430 <tt>integer</tt>
1431 </dt>
1432 <dd>
1434 A simple integer, where <em>0</em> refers to the first element of the string
1435 or list.
1436 </p>
1437 </dd>
1438 <dt class="hdlist1">
1439 <tt>integer+integer</tt> or
1440 </dt>
1441 <dt class="hdlist1">
1442 <tt>integer-integer</tt>
1443 </dt>
1444 <dd>
1446 The sum or difference of the two integers. e.g. <tt>2+3</tt> refers to the 5th element.
1447 This is useful when used with (e.g.) <tt>$i+1</tt> rather than the more verbose
1448 <tt>[expr {$i+1}]</tt>
1449 </p>
1450 </dd>
1451 <dt class="hdlist1">
1452 <tt>end</tt>
1453 </dt>
1454 <dd>
1456 The last element of the string or list.
1457 </p>
1458 </dd>
1459 <dt class="hdlist1">
1460 <tt>end-integer</tt>
1461 </dt>
1462 <dd>
1464 The <em>nth-from-last</em> element of the string or list.
1465 </p>
1466 </dd>
1467 </dl></div>
1468 </div>
1469 </div>
1470 <div class="sect1">
1471 <h2 id="_command_summary">COMMAND SUMMARY</h2>
1472 <div class="sectionbody">
1473 <div class="olist arabic"><ol class="arabic">
1474 <li>
1476 A command is just a string.
1477 </p>
1478 </li>
1479 <li>
1481 Within a string commands are separated by newlines or semi-colons
1482 (unless the newline or semi-colon is within braces or brackets
1483 or is backslashed).
1484 </p>
1485 </li>
1486 <li>
1488 A command consists of fields. The first field is the name of the command.
1489 The other fields are strings that are passed to that command as arguments.
1490 </p>
1491 </li>
1492 <li>
1494 Fields are normally separated by white space.
1495 </p>
1496 </li>
1497 <li>
1499 Double-quotes allow white space and semi-colons to appear within
1500 a single argument.
1501 Command substitution, variable substitution, and backslash substitution
1502 still occur inside quotes.
1503 </p>
1504 </li>
1505 <li>
1507 Braces defer interpretation of special characters.
1508 If a field begins with a left brace, then it consists of everything
1509 between the left brace and the matching right brace. The
1510 braces themselves are not included in the argument.
1511 No further processing is done on the information between the braces
1512 except that backslash-newline sequences are eliminated.
1513 </p>
1514 </li>
1515 <li>
1517 If a field doesn&#8217;t begin with a brace then backslash,
1518 variable, and command substitution are done on the field. Only a
1519 single level of processing is done: the results of one substitution
1520 are not scanned again for further substitutions or any other
1521 special treatment. Substitution can
1522 occur on any field of a command, including the command name
1523 as well as the arguments.
1524 </p>
1525 </li>
1526 <li>
1528 If the first non-blank character of a command is a <tt>#</tt>, everything
1529 from the <tt>#</tt> up through the next newline is treated as a comment
1530 and ignored.
1531 </p>
1532 </li>
1533 </ol></div>
1534 </div>
1535 </div>
1536 <div class="sect1">
1537 <h2 id="_expressions">EXPRESSIONS</h2>
1538 <div class="sectionbody">
1539 <div class="paragraph"><p>The second major interpretation applied to strings in Tcl is
1540 as expressions. Several commands, such as <em>expr</em>, <em>for</em>,
1541 and <em>if</em>, treat one or more of their arguments as expressions
1542 and call the Tcl expression processors (<em>Jim_ExprLong</em>,
1543 <em>Jim_ExprBoolean</em>, etc.) to evaluate them.</p></div>
1544 <div class="paragraph"><p>The operators permitted in Tcl expressions are a subset of
1545 the operators permitted in C expressions, and they have the
1546 same meaning and precedence as the corresponding C operators.
1547 Expressions almost always yield numeric results
1548 (integer or floating-point values).
1549 For example, the expression</p></div>
1550 <div class="literalblock">
1551 <div class="content">
1552 <pre><tt>8.2 + 6</tt></pre>
1553 </div></div>
1554 <div class="paragraph"><p>evaluates to 14.2.</p></div>
1555 <div class="paragraph"><p>Tcl expressions differ from C expressions in the way that
1556 operands are specified, and in that Tcl expressions support
1557 non-numeric operands and string comparisons.</p></div>
1558 <div class="paragraph"><p>A Tcl expression consists of a combination of operands, operators,
1559 and parentheses.</p></div>
1560 <div class="paragraph"><p>White space may be used between the operands and operators and
1561 parentheses; it is ignored by the expression processor.
1562 Where possible, operands are interpreted as integer values.</p></div>
1563 <div class="paragraph"><p>Integer values may be specified in decimal (the normal case), in octal (if the
1564 first character of the operand is <em>0</em>), or in hexadecimal (if the first
1565 two characters of the operand are <em>0x</em>).</p></div>
1566 <div class="paragraph"><p>If an operand does not have one of the integer formats given
1567 above, then it is treated as a floating-point number if that is
1568 possible. Floating-point numbers may be specified in any of the
1569 ways accepted by an ANSI-compliant C compiler (except that the
1570 <em>f</em>, <em>F</em>, <em>l</em>, and <em>L</em> suffixes will not be permitted in
1571 most installations). For example, all of the
1572 following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16.</p></div>
1573 <div class="paragraph"><p>If no numeric interpretation is possible, then an operand is left
1574 as a string (and only a limited set of operators may be applied to
1575 it).</p></div>
1576 <div class="olist arabic"><ol class="arabic">
1577 <li>
1579 Operands may be specified in any of the following ways:
1580 </p>
1581 </li>
1582 <li>
1584 As a numeric value, either integer or floating-point.
1585 </p>
1586 </li>
1587 <li>
1589 As a Tcl variable, using standard <em>$</em> notation.
1590 The variable&#8217;s value will be used as the operand.
1591 </p>
1592 </li>
1593 <li>
1595 As a string enclosed in double-quotes.
1596 The expression parser will perform backslash, variable, and
1597 command substitutions on the information between the quotes,
1598 and use the resulting value as the operand
1599 </p>
1600 </li>
1601 <li>
1603 As a string enclosed in braces.
1604 The characters between the open brace and matching close brace
1605 will be used as the operand without any substitutions.
1606 </p>
1607 </li>
1608 <li>
1610 As a Tcl command enclosed in brackets.
1611 The command will be executed and its result will be used as
1612 the operand.
1613 </p>
1614 </li>
1615 </ol></div>
1616 <div class="paragraph"><p>Where substitutions occur above (e.g. inside quoted strings), they
1617 are performed by the expression processor.
1618 However, an additional layer of substitution may already have
1619 been performed by the command parser before the expression
1620 processor was called.</p></div>
1621 <div class="paragraph"><p>As discussed below, it is usually best to enclose expressions
1622 in braces to prevent the command parser from performing substitutions
1623 on the contents.</p></div>
1624 <div class="paragraph"><p>For some examples of simple expressions, suppose the variable <em>a</em> has
1625 the value 3 and the variable <em>b</em> has the value 6. Then the expression
1626 on the left side of each of the lines below will evaluate to the value
1627 on the right side of the line:</p></div>
1628 <div class="literalblock">
1629 <div class="content">
1630 <pre><tt>$a + 3.1 6.1
1631 2 + "$a.$b" 5.6
1632 4*[llength "6 2"] 8
1633 {word one} &lt; "word $a" 0</tt></pre>
1634 </div></div>
1635 <div class="paragraph"><p>The valid operators are listed below, grouped in decreasing order
1636 of precedence:</p></div>
1637 <div class="dlist" id="OperatorPrecedence"><dl>
1638 <dt class="hdlist1">
1639 <tt>int() double() round() abs(), rand(), srand()</tt>
1640 </dt>
1641 <dd>
1643 Unary functions (except rand() which takes no arguments)
1644 int() converts the numeric argument to an integer by truncating down.
1645 double() converts the numeric argument to floating point.
1646 round() converts the numeric argument to the closest integer value.
1647 abs() takes the absolute value of the numeric argument.
1648 rand() takes the absolute value of the numeric argument.
1649 rand() returns a pseudo-random floating-point value in the range (0,1).
1650 srand() takes an integer argument to (re)seed the random number generator. Returns the first random number from that seed.
1651 </p>
1652 </dd>
1653 <dt class="hdlist1">
1654 <tt>sin() cos() tan() asin() acos() atan() sinh() cosh() tanh() ceil() floor() exp() log() log10() sqrt()</tt>
1655 </dt>
1656 <dd>
1658 Unary math functions.
1659 If Jim is compiled with math support, these functions are available.
1660 </p>
1661 </dd>
1662 <dt class="hdlist1">
1663 <tt>- + ~ !</tt>
1664 </dt>
1665 <dd>
1667 Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands
1668 may be applied to string operands, and bit-wise NOT may be
1669 applied only to integers.
1670 </p>
1671 </dd>
1672 <dt class="hdlist1">
1673 <tt>**</tt>
1674 </dt>
1675 <dd>
1677 Power. e.g. pow(). If Jim is compiled with math support, supports doubles and
1678 integers. Otherwise supports integers only.
1679 </p>
1680 </dd>
1681 <dt class="hdlist1">
1682 <tt>* / %</tt>
1683 </dt>
1684 <dd>
1686 Multiply, divide, remainder. None of these operands may be
1687 applied to string operands, and remainder may be applied only
1688 to integers.
1689 </p>
1690 </dd>
1691 <dt class="hdlist1">
1692 <tt>+ -</tt>
1693 </dt>
1694 <dd>
1696 Add and subtract. Valid for any numeric operands.
1697 </p>
1698 </dd>
1699 <dt class="hdlist1">
1700 <tt>&lt;&lt; &gt;&gt; &lt;&lt;&lt; &gt;&gt;&gt;</tt>
1701 </dt>
1702 <dd>
1704 Left and right shift, left and right rotate. Valid for integer operands only.
1705 </p>
1706 </dd>
1707 <dt class="hdlist1">
1708 <tt>&lt; &gt; &lt;= &gt;=</tt>
1709 </dt>
1710 <dd>
1712 Boolean less, greater, less than or equal, and greater than or equal.
1713 Each operator produces 1 if the condition is true, 0 otherwise.
1714 These operators may be applied to strings as well as numeric operands,
1715 in which case string comparison is used.
1716 </p>
1717 </dd>
1718 <dt class="hdlist1">
1719 <tt>== !=</tt>
1720 </dt>
1721 <dd>
1723 Boolean equal and not equal. Each operator produces a zero/one result.
1724 Valid for all operand types. <strong>Note</strong> that values will be converted to integers
1725 if possible, then floating point types, and finally strings will be compared.
1726 It is recommended that <em>eq</em> and <em>ne</em> should be used for string comparison.
1727 </p>
1728 </dd>
1729 <dt class="hdlist1">
1730 <tt>eq ne</tt>
1731 </dt>
1732 <dd>
1734 String equal and not equal. Uses the string value directly without
1735 attempting to convert to a number first.
1736 </p>
1737 </dd>
1738 <dt class="hdlist1">
1739 <tt>in ni</tt>
1740 </dt>
1741 <dd>
1743 String in list and not in list. For <em>in</em>, result is 1 if the left operand (as a string)
1744 is contained in the right operand (as a list), or 0 otherwise. The result for
1745 <em>{$a ni $list}</em> is equivalent to <em>{!($a in $list)}</em>.
1746 </p>
1747 </dd>
1748 <dt class="hdlist1">
1749 <tt>&amp;</tt>
1750 </dt>
1751 <dd>
1753 Bit-wise AND. Valid for integer operands only.
1754 </p>
1755 </dd>
1756 <dt class="hdlist1">
1757 <tt>|</tt>
1758 </dt>
1759 <dd>
1761 Bit-wise OR. Valid for integer operands only.
1762 </p>
1763 </dd>
1764 <dt class="hdlist1">
1765 <tt>^</tt>
1766 </dt>
1767 <dd>
1769 Bit-wise exclusive OR. Valid for integer operands only.
1770 </p>
1771 </dd>
1772 <dt class="hdlist1">
1773 <tt>&amp;&amp;</tt>
1774 </dt>
1775 <dd>
1777 Logical AND. Produces a 1 result if both operands are non-zero, 0 otherwise.
1778 Valid for numeric operands only (integers or floating-point).
1779 </p>
1780 </dd>
1781 <dt class="hdlist1">
1782 <tt>||</tt>
1783 </dt>
1784 <dd>
1786 Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
1787 Valid for numeric operands only (integers or floating-point).
1788 </p>
1789 </dd>
1790 <dt class="hdlist1">
1791 <tt>x ? y : z</tt>
1792 </dt>
1793 <dd>
1795 If-then-else, as in C. If <strong>x</strong>
1796 evaluates to non-zero, then the result is the value of <strong>y</strong>.
1797 Otherwise the result is the value of <strong>z</strong>.
1798 The <strong>x</strong> operand must have a numeric value, while <strong>y</strong> and <strong>z</strong> can
1799 be of any type.
1800 </p>
1801 </dd>
1802 </dl></div>
1803 <div class="paragraph"><p>See the C manual for more details on the results
1804 produced by each operator.
1805 All of the binary operators group left-to-right within the same
1806 precedence level. For example, the expression</p></div>
1807 <div class="literalblock">
1808 <div class="content">
1809 <pre><tt>4*2 &lt; 7</tt></pre>
1810 </div></div>
1811 <div class="paragraph"><p>evaluates to 0.</p></div>
1812 <div class="paragraph"><p>The <em>&amp;&amp;</em>, <em>||</em>, and <em>?:</em> operators have <em>lazy
1813 evaluation</em>, just as in C,
1814 which means that operands are not evaluated if they are
1815 not needed to determine the outcome. For example, in</p></div>
1816 <div class="literalblock">
1817 <div class="content">
1818 <pre><tt>$v ? [a] : [b]</tt></pre>
1819 </div></div>
1820 <div class="paragraph"><p>only one of <em>[a]</em> or <em>[b]</em> will actually be evaluated,
1821 depending on the value of <em>$v</em>.</p></div>
1822 <div class="paragraph"><p>All internal computations involving integers are done with the C
1823 type <em>long long</em> if available, or <em>long</em> otherwise, and all internal
1824 computations involving floating-point are done with the C type
1825 <em>double</em>.</p></div>
1826 <div class="paragraph"><p>When converting a string to floating-point, exponent overflow is
1827 detected and results in a Tcl error.
1828 For conversion to integer from string, detection of overflow depends
1829 on the behaviour of some routines in the local C library, so it should
1830 be regarded as unreliable.
1831 In any case, overflow and underflow are generally not detected
1832 reliably for intermediate results.</p></div>
1833 <div class="paragraph"><p>Conversion among internal representations for integer, floating-point,
1834 and string operands is done automatically as needed.
1835 For arithmetic computations, integers are used until some
1836 floating-point number is introduced, after which floating-point is used.
1837 For example,</p></div>
1838 <div class="literalblock">
1839 <div class="content">
1840 <pre><tt>5 / 4</tt></pre>
1841 </div></div>
1842 <div class="paragraph"><p>yields the result 1, while</p></div>
1843 <div class="literalblock">
1844 <div class="content">
1845 <pre><tt>5 / 4.0
1846 5 / ( [string length "abcd"] + 0.0 )</tt></pre>
1847 </div></div>
1848 <div class="paragraph"><p>both yield the result 1.25.</p></div>
1849 <div class="paragraph"><p>String values may be used as operands of the comparison operators,
1850 although the expression evaluator tries to do comparisons as integer
1851 or floating-point when it can.
1852 If one of the operands of a comparison is a string and the other
1853 has a numeric value, the numeric operand is converted back to
1854 a string using the C <em>sprintf</em> format specifier
1855 <em>%d</em> for integers and <em>%g</em> for floating-point values.
1856 For example, the expressions</p></div>
1857 <div class="literalblock">
1858 <div class="content">
1859 <pre><tt>"0x03" &gt; "2"
1860 "0y" &lt; "0x12"</tt></pre>
1861 </div></div>
1862 <div class="paragraph"><p>both evaluate to 1. The first comparison is done using integer
1863 comparison, and the second is done using string comparison after
1864 the second operand is converted to the string <em>18</em>.</p></div>
1865 <div class="paragraph"><p>In general it is safest to enclose an expression in braces when
1866 entering it in a command: otherwise, if the expression contains
1867 any white space then the Tcl interpreter will split it
1868 among several arguments. For example, the command</p></div>
1869 <div class="literalblock">
1870 <div class="content">
1871 <pre><tt>expr $a + $b</tt></pre>
1872 </div></div>
1873 <div class="paragraph"><p>results in three arguments being passed to <em>expr</em>: <em>$a</em>,
1874 <em>+</em>, and <em>$b</em>. In addition, if the expression isn&#8217;t in braces
1875 then the Tcl interpreter will perform variable and command substitution
1876 immediately (it will happen in the command parser rather than in
1877 the expression parser). In many cases the expression is being
1878 passed to a command that will evaluate the expression later (or
1879 even many times if, for example, the expression is to be used to
1880 decide when to exit a loop). Usually the desired goal is to re-do
1881 the variable or command substitutions each time the expression is
1882 evaluated, rather than once and for all at the beginning. For example,
1883 the command</p></div>
1884 <div class="literalblock">
1885 <div class="content">
1886 <pre><tt>for {set i 1} $i&lt;=10 {incr i} {...} *** WRONG ***</tt></pre>
1887 </div></div>
1888 <div class="paragraph"><p>is probably intended to iterate over all values of <tt>i</tt> from 1 to 10.
1889 After each iteration of the body of the loop, <em>for</em> will pass
1890 its second argument to the expression evaluator to see whether or not
1891 to continue processing. Unfortunately, in this case the value of <tt>i</tt>
1892 in the second argument will be substituted once and for all when the
1893 <em>for</em> command is parsed. If <tt>i</tt> was 0 before the <em>for</em>
1894 command was invoked then for&#8217;s second argument will be <tt>0&lt;=10</tt>
1895 which will always evaluate to 1, even though <tt>i</tt> eventually
1896 becomes greater than 10. In the above case the loop will never
1897 terminate. Instead, the expression should be placed in braces:</p></div>
1898 <div class="literalblock">
1899 <div class="content">
1900 <pre><tt>for {set i 1} {$i&lt;=10} {incr i} {...} *** RIGHT ***</tt></pre>
1901 </div></div>
1902 <div class="paragraph"><p>This causes the substitution of <em>i</em>
1903 to be delayed; it will be re-done each time the expression is
1904 evaluated, which is the desired result.</p></div>
1905 </div>
1906 </div>
1907 <div class="sect1">
1908 <h2 id="_lists">LISTS</h2>
1909 <div class="sectionbody">
1910 <div class="paragraph"><p>The third major way that strings are interpreted in Tcl is as lists.
1911 A list is just a string with a list-like structure
1912 consisting of fields separated by white space. For example, the
1913 string</p></div>
1914 <div class="literalblock">
1915 <div class="content">
1916 <pre><tt>Al Sue Anne John</tt></pre>
1917 </div></div>
1918 <div class="paragraph"><p>is a list with four elements or fields.
1919 Lists have the same basic structure as command strings, except
1920 that a newline character in a list is treated as a field separator
1921 just like space or tab. Conventions for braces and quotes
1922 and backslashes are the same for lists as for commands. For example,
1923 the string</p></div>
1924 <div class="literalblock">
1925 <div class="content">
1926 <pre><tt>a b\ c {d e {f g h}}</tt></pre>
1927 </div></div>
1928 <div class="paragraph"><p>is a list with three elements: <tt>a</tt>, <tt>b c</tt>, and <tt>d e {f g h}</tt>.</p></div>
1929 <div class="paragraph"><p>Whenever an element is extracted from a list, the same rules about
1930 braces and quotes and backslashes are applied as for commands. Thus in
1931 the example above when the third element is extracted from the list,
1932 the result is</p></div>
1933 <div class="literalblock">
1934 <div class="content">
1935 <pre><tt>d e {f g h}</tt></pre>
1936 </div></div>
1937 <div class="paragraph"><p>(when the field was extracted, all that happened was to strip off
1938 the outermost layer of braces). Command substitution and
1939 variable substitution are never
1940 made on a list (at least, not by the list-processing commands; the
1941 list can always be passed to the Tcl interpreter for evaluation).</p></div>
1942 <div class="paragraph"><p>The Tcl commands <em>concat</em>, <em>foreach</em>, <em>lappend</em>, <em>lindex</em>, <em>linsert</em>,
1943 <em>list</em>, <em>llength</em>, <em>lrange</em>, <em>lreplace</em>, <em>lsearch</em>, and <em>lsort</em> allow
1944 you to build lists, extract elements from them, search them, and perform
1945 other list-related functions.</p></div>
1946 <div class="paragraph"><p>Advanced list commands include <em>lrepeat</em>, <em>lreverse</em>, <em>lmap</em>, <em>lassign</em>, <em>lset</em>.</p></div>
1947 </div>
1948 </div>
1949 <div class="sect1">
1950 <h2 id="_list_expansion">LIST EXPANSION</h2>
1951 <div class="sectionbody">
1952 <div class="paragraph"><p>A new addition to Tcl 8.5 is the ability to expand a list into separate
1953 arguments. Support for this feature is also available in Jim.</p></div>
1954 <div class="paragraph"><p>Consider the following attempt to exec a list:</p></div>
1955 <div class="literalblock">
1956 <div class="content">
1957 <pre><tt>set cmd {ls -l}
1958 exec $cmd</tt></pre>
1959 </div></div>
1960 <div class="paragraph"><p>This will attempt to exec the a command named "ls -l", which will clearly not
1961 work. Typically eval and concat are required to solve this problem, however
1962 it can be solved much more easily with <em>{*}</em>.</p></div>
1963 <div class="literalblock">
1964 <div class="content">
1965 <pre><tt>exec {*}$cmd</tt></pre>
1966 </div></div>
1967 <div class="paragraph"><p>This will expand the following argument into individual elements and then evaluate
1968 the resulting command.</p></div>
1969 <div class="paragraph"><p>Note that the official Tcl syntax is <em>{*}</em>, however <em>{expand}</em> is retained
1970 for backward compatibility with experimental versions of this feature.</p></div>
1971 </div>
1972 </div>
1973 <div class="sect1">
1974 <h2 id="_regular_expressions">REGULAR EXPRESSIONS</h2>
1975 <div class="sectionbody">
1976 <div class="paragraph"><p>Tcl provides two commands that support string matching using regular
1977 expressions, <em>regexp</em> and <em>regsub</em>, as well as <em>switch -regexp</em> and
1978 <em>lsearch -regexp</em>.</p></div>
1979 <div class="paragraph"><p>Regular expressions may be implemented one of two ways. Either using the system&#8217;s C library
1980 POSIX regular expression support, or using the built-in regular expression engine.
1981 The differences between these are described below.</p></div>
1982 <div class="paragraph"><p><strong>NOTE</strong> Tcl 7.x and 8.x use perl-style Advanced Regular Expressions (<tt>ARE</tt>).</p></div>
1983 <div class="sect2">
1984 <h3 id="_posix_regular_expressions">POSIX Regular Expressions</h3>
1985 <div class="paragraph"><p>If the system supports POSIX regular expressions, and UTF-8 support is not enabled,
1986 this support will be used by default. The type of regular expressions supported are
1987 Extended Regular Expressions (<tt>ERE</tt>) rather than Basic Regular Expressions (<tt>BRE</tt>).
1988 See REG_EXTENDED in the documentation.</p></div>
1989 <div class="paragraph"><p>Using the system-supported POSIX regular expressions will typically
1990 make for the smallest code size, but some features such as UTF-8
1991 and <tt>\w</tt>, <tt>\d</tt>, <tt>\s</tt> are not supported.</p></div>
1992 <div class="paragraph"><p>See regex(3) and regex(7) for full details.</p></div>
1993 </div>
1994 <div class="sect2">
1995 <h3 id="_jim_built_in_regular_expressions">Jim built-in Regular Expressions</h3>
1996 <div class="paragraph"><p>The Jim built-in regulare expression engine may be selected with <tt>./configure --with-jim-regexp</tt>
1997 or it will be selected automatically if UTF-8 support is enabled.</p></div>
1998 <div class="paragraph"><p>This engine supports UTF-8 as well as some <tt>ARE</tt> features. The differences with both Tcl 7.x/8.x
1999 and POSIX are highlighted below.</p></div>
2000 <div class="olist arabic"><ol class="arabic">
2001 <li>
2003 UTF-8 strings and patterns are both supported
2004 </p>
2005 </li>
2006 <li>
2008 Supported character classes: <tt>[:alnum:]</tt>, <tt>[:digit:]</tt> and <tt>[:space:]</tt>
2009 </p>
2010 </li>
2011 <li>
2013 Supported shorthand character classes: <tt>\w = +[:alnum:]</tt>, <tt>\d</tt> = <tt>[:digit:],</tt> <tt>\s</tt> = <tt>[:space:]</tt>
2014 </p>
2015 </li>
2016 <li>
2018 Character classes apply to ASCII characters only
2019 </p>
2020 </li>
2021 <li>
2023 Supported constraint escapes: <tt>\m</tt> = <tt>\&lt;</tt> = start of word, <tt>\M</tt> = <tt>\&gt;</tt> = end of word
2024 </p>
2025 </li>
2026 <li>
2028 Backslash escapes may be used within regular expressions, such as <tt>\n</tt> = newline, <tt>\uNNNN</tt> = unicode
2029 </p>
2030 </li>
2031 <li>
2033 No support for the <tt>?</tt> non-greedy quantifier. e.g. <tt>*?</tt>
2034 </p>
2035 </li>
2036 </ol></div>
2037 </div>
2038 </div>
2039 </div>
2040 <div class="sect1">
2041 <h2 id="_command_results">COMMAND RESULTS</h2>
2042 <div class="sectionbody">
2043 <div class="paragraph"><p>Each command produces two results: a code and a string. The
2044 code indicates whether the command completed successfully or not,
2045 and the string gives additional information. The valid codes are
2046 defined in jim.h, and are:</p></div>
2047 <div class="dlist"><dl>
2048 <dt class="hdlist1">
2049 <tt>JIM_OK(0)</tt>
2050 </dt>
2051 <dd>
2053 This is the normal return code, and indicates that the command completed
2054 successfully. The string gives the command&#8217;s return value.
2055 </p>
2056 </dd>
2057 <dt class="hdlist1">
2058 <tt>JIM_ERR(1)</tt>
2059 </dt>
2060 <dd>
2062 Indicates that an error occurred; the string gives a message describing
2063 the error.
2064 </p>
2065 </dd>
2066 <dt class="hdlist1">
2067 <tt>JIM_RETURN(2)</tt>
2068 </dt>
2069 <dd>
2071 Indicates that the <em>return</em> command has been invoked, and that the
2072 current procedure (or top-level command or <em>source</em> command)
2073 should return immediately. The
2074 string gives the return value for the procedure or command.
2075 </p>
2076 </dd>
2077 <dt class="hdlist1">
2078 <tt>JIM_BREAK(3)</tt>
2079 </dt>
2080 <dd>
2082 Indicates that the <em>break</em> command has been invoked, so the
2083 innermost loop should abort immediately. The string should always
2084 be empty.
2085 </p>
2086 </dd>
2087 <dt class="hdlist1">
2088 <tt>JIM_CONTINUE(4)</tt>
2089 </dt>
2090 <dd>
2092 Indicates that the <em>continue</em> command has been invoked, so the
2093 innermost loop should go on to the next iteration. The string
2094 should always be empty.
2095 </p>
2096 </dd>
2097 <dt class="hdlist1">
2098 <tt>JIM_SIGNAL(5)</tt>
2099 </dt>
2100 <dd>
2102 Indicates that a signal was caught while executing a commands.
2103 The string contains the name of the signal caught.
2104 See the <em>signal</em> and <em>catch</em> commands.
2105 </p>
2106 </dd>
2107 <dt class="hdlist1">
2108 <tt>JIM_EXIT(6)</tt>
2109 </dt>
2110 <dd>
2112 Indicates that the command called the <em>exit</em> command.
2113 The string contains the exit code.
2114 </p>
2115 </dd>
2116 </dl></div>
2117 <div class="paragraph"><p>Tcl programmers do not normally need to think about return codes,
2118 since <tt>JIM_OK</tt> is almost always returned. If anything else is returned
2119 by a command, then the Tcl interpreter immediately stops processing
2120 commands and returns to its caller. If there are several nested
2121 invocations of the Tcl interpreter in progress, then each nested
2122 command will usually return the error to its caller, until eventually
2123 the error is reported to the top-level application code. The
2124 application will then display the error message for the user.</p></div>
2125 <div class="paragraph"><p>In a few cases, some commands will handle certain <em>error</em> conditions
2126 themselves and not return them upwards. For example, the <em>for</em>
2127 command checks for the <tt>JIM_BREAK</tt> code; if it occurs, then <em>for</em>
2128 stops executing the body of the loop and returns <tt>JIM_OK</tt> to its
2129 caller. The <em>for</em> command also handles <tt>JIM_CONTINUE</tt> codes and the
2130 procedure interpreter handles <tt>JIM_RETURN</tt> codes. The <em>catch</em>
2131 command allows Tcl programs to catch errors and handle them without
2132 aborting command interpretation any further.</p></div>
2133 <div class="paragraph"><p>The <em>info returncodes</em> command may be used to programmatically map between
2134 return codes and names.</p></div>
2135 </div>
2136 </div>
2137 <div class="sect1">
2138 <h2 id="_procedures">PROCEDURES</h2>
2139 <div class="sectionbody">
2140 <div class="paragraph"><p>Tcl allows you to extend the command interface by defining
2141 procedures. A Tcl procedure can be invoked just like any other Tcl
2142 command (it has a name and it receives one or more arguments).
2143 The only difference is that its body isn&#8217;t a piece of C code linked
2144 into the program; it is a string containing one or more other
2145 Tcl commands.</p></div>
2146 <div class="paragraph"><p>The <em>proc</em> command is used to create a new Tcl command procedure:</p></div>
2147 <div class="paragraph"><p><tt><strong>proc</strong> <em>name arglist ?statics? body</em></tt></p></div>
2148 <div class="paragraph"><p>The new command is name <strong>name</strong>, and it replaces any existing command
2149 there may have been by that name. Whenever the new command is
2150 invoked, the contents of <strong>body</strong> will be executed by the Tcl
2151 interpreter.</p></div>
2152 <div class="paragraph"><p><strong>arglist</strong> specifies the formal arguments to the procedure.
2153 It consists of a list, possibly empty, of the following
2154 argument specifiers:</p></div>
2155 <div class="dlist"><dl>
2156 <dt class="hdlist1">
2157 <tt>name</tt>
2158 </dt>
2159 <dd>
2161 Required Argument - A simple argument name.
2162 </p>
2163 </dd>
2164 <dt class="hdlist1">
2165 <tt>name default</tt>
2166 </dt>
2167 <dd>
2169 Optional Argument - A two-element list consisting of the
2170 argument name, followed by the default value, which will
2171 be used if the corresponding argument is not supplied.
2172 </p>
2173 </dd>
2174 <dt class="hdlist1">
2175 <tt>&amp;name</tt>
2176 </dt>
2177 <dd>
2179 Reference Argument - The caller is expected to pass the name of
2180 an existing variable. An implicit <tt>upvar 1 <strong>origname</strong> <strong>name</strong></tt> is done
2181 to make the variable available in the proc scope.
2182 </p>
2183 </dd>
2184 <dt class="hdlist1">
2185 <tt><strong>args</strong></tt>
2186 </dt>
2187 <dd>
2189 Variable Argument - The special name <strong>args</strong>, which is
2190 assigned all remaining arguments (including none) as a list. The
2191 variable argument may only be specified once. Note that
2192 the syntax <tt>args newname</tt> may be used to retain the special
2193 behaviour of <strong>args</strong> with a different local name. In this case,
2194 the variable is named <strong>newname</strong> rather than <strong>args</strong>.
2195 </p>
2196 </dd>
2197 </dl></div>
2198 <div class="paragraph"><p>When the command is invoked, a local variable will be created for each of
2199 the formal arguments to the procedure; its value will be the value
2200 of corresponding argument in the invoking command or the argument&#8217;s
2201 default value.</p></div>
2202 <div class="paragraph"><p>Arguments with default values need not be specified in a procedure
2203 invocation. However, there must be enough actual arguments for all
2204 required arguments, and there must not be any extra actual arguments
2205 (unless the Variable Argument is specified).</p></div>
2206 <div class="paragraph"><p>Actual arguments are assigned to formal arguments as in left-to-right
2207 order with the following precedence.</p></div>
2208 <div class="olist arabic"><ol class="arabic">
2209 <li>
2211 Required Arguments (including Reference Arguments)
2212 </p>
2213 </li>
2214 <li>
2216 Optional Arguments
2217 </p>
2218 </li>
2219 <li>
2221 Variable Argument
2222 </p>
2223 </li>
2224 </ol></div>
2225 <div class="paragraph"><p>The following example illustrates precedence. Assume a procedure declaration:</p></div>
2226 <div class="literalblock">
2227 <div class="content">
2228 <pre><tt>proc p {{a A} args b {c C} d} {...}</tt></pre>
2229 </div></div>
2230 <div class="paragraph"><p>This procedure requires at least two arguments, but can accept an unlimited number.
2231 The following table shows how various numbers of arguments are assigned.
2232 Values marked as <em>-</em> are assigned the default value.</p></div>
2233 <div class="tableblock">
2234 <table rules="all"
2235 width="40%"
2236 frame="hsides"
2237 cellspacing="0" cellpadding="4">
2238 <col width="16%" />
2239 <col width="16%" />
2240 <col width="16%" />
2241 <col width="16%" />
2242 <col width="16%" />
2243 <col width="16%" />
2244 <thead>
2245 <tr>
2246 <th align="left" valign="top">Number of arguments</th>
2247 <th align="left" valign="top">a</th>
2248 <th align="left" valign="top">args</th>
2249 <th align="left" valign="top">b</th>
2250 <th align="left" valign="top">c</th>
2251 <th align="left" valign="top">d</th>
2252 </tr>
2253 </thead>
2254 <tbody>
2255 <tr>
2256 <td align="left" valign="top"><p class="table">2</p></td>
2257 <td align="left" valign="top"><p class="table">-</p></td>
2258 <td align="left" valign="top"><p class="table">-</p></td>
2259 <td align="left" valign="top"><p class="table">1</p></td>
2260 <td align="left" valign="top"><p class="table">-</p></td>
2261 <td align="left" valign="top"><p class="table">2</p></td>
2262 </tr>
2263 <tr>
2264 <td align="left" valign="top"><p class="table">3</p></td>
2265 <td align="left" valign="top"><p class="table">1</p></td>
2266 <td align="left" valign="top"><p class="table">-</p></td>
2267 <td align="left" valign="top"><p class="table">2</p></td>
2268 <td align="left" valign="top"><p class="table">-</p></td>
2269 <td align="left" valign="top"><p class="table">3</p></td>
2270 </tr>
2271 <tr>
2272 <td align="left" valign="top"><p class="table">4</p></td>
2273 <td align="left" valign="top"><p class="table">1</p></td>
2274 <td align="left" valign="top"><p class="table">-</p></td>
2275 <td align="left" valign="top"><p class="table">2</p></td>
2276 <td align="left" valign="top"><p class="table">3</p></td>
2277 <td align="left" valign="top"><p class="table">4</p></td>
2278 </tr>
2279 <tr>
2280 <td align="left" valign="top"><p class="table">5</p></td>
2281 <td align="left" valign="top"><p class="table">1</p></td>
2282 <td align="left" valign="top"><p class="table">2</p></td>
2283 <td align="left" valign="top"><p class="table">3</p></td>
2284 <td align="left" valign="top"><p class="table">4</p></td>
2285 <td align="left" valign="top"><p class="table">5</p></td>
2286 </tr>
2287 <tr>
2288 <td align="left" valign="top"><p class="table">6</p></td>
2289 <td align="left" valign="top"><p class="table">1</p></td>
2290 <td align="left" valign="top"><p class="table">2,3</p></td>
2291 <td align="left" valign="top"><p class="table">4</p></td>
2292 <td align="left" valign="top"><p class="table">5</p></td>
2293 <td align="left" valign="top"><p class="table">6</p></td>
2294 </tr>
2295 </tbody>
2296 </table>
2297 </div>
2298 <div class="paragraph"><p>When <strong>body</strong> is being executed, variable names normally refer to local
2299 variables, which are created automatically when referenced and deleted
2300 when the procedure returns. One local variable is automatically created
2301 for each of the procedure&#8217;s arguments. Global variables can be
2302 accessed by invoking the <em>global</em> command or via the <em>::</em> prefix.</p></div>
2303 <div class="sect2">
2304 <h3 id="_new_in_jim">New in Jim</h3>
2305 <div class="paragraph"><p>In addition to procedure arguments, Jim procedures may declare static variables.
2306 These variables scoped to the procedure and initialised at procedure definition.
2307 Either from the static variable definition, or from the enclosing scope.</p></div>
2308 <div class="paragraph"><p>Consider the following example:</p></div>
2309 <div class="literalblock">
2310 <div class="content">
2311 <pre><tt>jim&gt; set a 1
2312 jim&gt; proc a {} {a {b 2}} {
2313 set c 1
2314 puts "$a $b $c"
2315 incr a
2316 incr b
2317 incr c
2319 jim&gt; a
2320 1 2 1
2321 jim&gt; a
2322 2 3 1</tt></pre>
2323 </div></div>
2324 <div class="paragraph"><p>The static variable <strong>a</strong> has no initialiser, so it is initialised from
2325 the enclosing scope with the value 1. (Note that it is an error if there
2326 is no variable with the same name in the enclosing scope). However <strong>b</strong>
2327 has an initialiser, so it is initialised to 2.</p></div>
2328 <div class="paragraph"><p>Unlike a local variable, the value of a static variable is retained across
2329 invocations of the procedure.</p></div>
2330 <div class="paragraph"><p>See the <em>proc</em> command for information on
2331 how to define procedures and what happens when they are invoked.</p></div>
2332 </div>
2333 </div>
2334 </div>
2335 <div class="sect1">
2336 <h2 id="_variables_scalars_and_arrays">VARIABLES - SCALARS AND ARRAYS</h2>
2337 <div class="sectionbody">
2338 <div class="paragraph"><p>Tcl allows the definition of variables and the use of their values
2339 either through <em>$</em>-style variable substitution, the <em>set</em>
2340 command, or a few other mechanisms.</p></div>
2341 <div class="paragraph"><p>Variables need not be declared: a new variable will automatically
2342 be created each time a new variable name is used.</p></div>
2343 <div class="paragraph"><p>Tcl supports two types of variables: scalars and arrays.
2344 A scalar variable has a single value, whereas an array variable
2345 can have any number of elements, each with a name (called
2346 its <em>index</em>) and a value.</p></div>
2347 <div class="paragraph"><p>Array indexes may be arbitrary strings; they need not be numeric.
2348 Parentheses are used refer to array elements in Tcl commands.
2349 For example, the command</p></div>
2350 <div class="literalblock">
2351 <div class="content">
2352 <pre><tt>set x(first) 44</tt></pre>
2353 </div></div>
2354 <div class="paragraph"><p>will modify the element of <em>x</em> whose index is <em>first</em>
2355 so that its new value is <em>44</em>.</p></div>
2356 <div class="paragraph"><p>Two-dimensional arrays can be simulated in Tcl by using indexes
2357 that contain multiple concatenated values.
2358 For example, the commands</p></div>
2359 <div class="literalblock">
2360 <div class="content">
2361 <pre><tt>set a(2,3) 1
2362 set a(3,6) 2</tt></pre>
2363 </div></div>
2364 <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>
2365 <div class="paragraph"><p>In general, array elements may be used anywhere in Tcl that scalar
2366 variables may be used.</p></div>
2367 <div class="paragraph"><p>If an array is defined with a particular name, then there may
2368 not be a scalar variable with the same name.</p></div>
2369 <div class="paragraph"><p>Similarly, if there is a scalar variable with a particular
2370 name then it is not possible to make array references to the
2371 variable.</p></div>
2372 <div class="paragraph"><p>To convert a scalar variable to an array or vice versa, remove
2373 the existing variable with the <em>unset</em> command.</p></div>
2374 <div class="paragraph"><p>The <em>array</em> command provides several features for dealing
2375 with arrays, such as querying the names of all the elements of
2376 the array and converting between an array and a list.</p></div>
2377 <div class="paragraph"><p>Variables may be either global or local. If a variable
2378 name is used when a procedure isn&#8217;t being executed, then it
2379 automatically refers to a global variable. Variable names used
2380 within a procedure normally refer to local variables associated with that
2381 invocation of the procedure. Local variables are deleted whenever
2382 a procedure exits. Either <em>global</em> command may be used to request
2383 that a name refer to a global variable for the duration of the current
2384 procedure (this is somewhat analogous to <em>extern</em> in C), or the variable
2385 may be explicitly scoped with the <em>::</em> prefix. For example</p></div>
2386 <div class="literalblock">
2387 <div class="content">
2388 <pre><tt>set a 1
2389 set b 2
2390 proc p {} {
2391 set c 3
2392 global a</tt></pre>
2393 </div></div>
2394 <div class="literalblock">
2395 <div class="content">
2396 <pre><tt> puts "$a $::b $c"
2398 p</tt></pre>
2399 </div></div>
2400 <div class="paragraph"><p>will output:</p></div>
2401 <div class="literalblock">
2402 <div class="content">
2403 <pre><tt>1 2 3</tt></pre>
2404 </div></div>
2405 </div>
2406 </div>
2407 <div class="sect1">
2408 <h2 id="_arrays_as_lists_in_jim">ARRAYS AS LISTS IN JIM</h2>
2409 <div class="sectionbody">
2410 <div class="paragraph"><p>Unlike Tcl, Jim can automatically convert between a list (with an even
2411 number of elements) and an array value. This is similar to the way Tcl
2412 can convert between a string and a list.</p></div>
2413 <div class="paragraph"><p>For example:</p></div>
2414 <div class="literalblock">
2415 <div class="content">
2416 <pre><tt>set a {1 one 2 two}
2417 puts $a(2)</tt></pre>
2418 </div></div>
2419 <div class="paragraph"><p>will output:</p></div>
2420 <div class="literalblock">
2421 <div class="content">
2422 <pre><tt>two</tt></pre>
2423 </div></div>
2424 <div class="paragraph"><p>Thus <em>array set</em> is equivalent to <em>set</em> when the variable does not
2425 exist or is empty.</p></div>
2426 <div class="paragraph"><p>The reverse is also true where an array will be converted into
2427 a list.</p></div>
2428 <div class="literalblock">
2429 <div class="content">
2430 <pre><tt>set a(1) one; set a(2) two
2431 puts $a</tt></pre>
2432 </div></div>
2433 <div class="paragraph"><p>will output:</p></div>
2434 <div class="literalblock">
2435 <div class="content">
2436 <pre><tt>1 one 2 two</tt></pre>
2437 </div></div>
2438 </div>
2439 </div>
2440 <div class="sect1">
2441 <h2 id="_dictionary_values">DICTIONARY VALUES</h2>
2442 <div class="sectionbody">
2443 <div class="paragraph"><p>Tcl 8.5 introduced the dict command, and Jim Tcl has added a version
2444 of this command. Dictionaries provide efficient access to key-value
2445 pairs, just like arrays, but dictionaries are pure values. This
2446 means that you can pass them to a procedure just as a list or a
2447 string. Tcl dictionaries are therefore much more like Tcl lists,
2448 except that they represent a mapping from keys to values, rather
2449 than an ordered sequence.</p></div>
2450 <div class="paragraph"><p>You can nest dictionaries, so that the value for a particular key
2451 consists of another dictionary. That way you can elegantly build
2452 complicated data structures, such as hierarchical databases. You
2453 can also combine dictionaries with other Tcl data structures. For
2454 instance, you can build a list of dictionaries that themselves
2455 contain lists.</p></div>
2456 <div class="paragraph"><p>Dictionaries are values that contain an efficient, order-preserving
2457 mapping from arbitrary keys to arbitrary values. Each key in the
2458 dictionary maps to a single value. They have a textual format that
2459 is exactly that of any list with an even number of elements, with
2460 each mapping in the dictionary being represented as two items in
2461 the list. When a command takes a dictionary and produces a new
2462 dictionary based on it (either returning it or writing it back into
2463 the variable that the starting dictionary was read from) the new
2464 dictionary will have the same order of keys, modulo any deleted
2465 keys and with new keys added on to the end. When a string is
2466 interpreted as a dictionary and it would otherwise have duplicate
2467 keys, only the last value for a particular key is used; the others
2468 are ignored, meaning that, "apple banana" and "apple carrot apple
2469 banana" are equivalent dictionaries (with different string
2470 representations).</p></div>
2471 <div class="paragraph"><p>Note that in Jim, arrays are implemented as dictionaries.
2472 Thus automatic conversion between lists and dictionaries applies
2473 as it does for arrays.</p></div>
2474 <div class="literalblock">
2475 <div class="content">
2476 <pre><tt>jim&gt; dict set a 1 one
2477 1 one
2478 jim&gt; dict set a 2 two
2479 1 one 2 two
2480 jim&gt; puts $a
2481 1 one 2 two
2482 jim&gt; puts $a(2)
2484 jim&gt; dict set a 3 T three
2485 1 one 2 two 3 {T three}</tt></pre>
2486 </div></div>
2487 <div class="paragraph"><p>See the <em>dict</em> command for more details.</p></div>
2488 </div>
2489 </div>
2490 <div class="sect1">
2491 <h2 id="_garbage_collection_references_lambda">GARBAGE COLLECTION, REFERENCES, LAMBDA</h2>
2492 <div class="sectionbody">
2493 <div class="paragraph"><p>Unlike Tcl, Jim has some sophisticated support for functional programming.
2494 These are described briefly below.</p></div>
2495 <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>
2496 <div class="sect2">
2497 <h3 id="_references">References</h3>
2498 <div class="paragraph"><p>A reference can be thought of as holding a value with one level of indirection,
2499 where the value may be garbage collected when unreferenced.
2500 Consider the following example:</p></div>
2501 <div class="literalblock">
2502 <div class="content">
2503 <pre><tt>jim&gt; set r [ref "One String" test]
2504 &lt;reference.&lt;test___&gt;.00000000000000000000&gt;
2505 jim&gt; getref $r
2506 One String</tt></pre>
2507 </div></div>
2508 <div class="paragraph"><p>The operation <em>ref</em> creates a references to the value specified by the
2509 first argument. (The second argument is a "type" used for documentation purposes).</p></div>
2510 <div class="paragraph"><p>The operation <em>getref</em> is the dereferencing operation which retrieves the value
2511 stored in the reference.</p></div>
2512 <div class="literalblock">
2513 <div class="content">
2514 <pre><tt>jim&gt; setref $r "New String"
2515 New String
2516 jim&gt; getref $r
2517 New String</tt></pre>
2518 </div></div>
2519 <div class="paragraph"><p>The operation <em>setref</em> replaces the value stored by the reference. If the old value
2520 is no longer accessible by any reference, it will eventually be automatically be garbage
2521 collected.</p></div>
2522 </div>
2523 <div class="sect2">
2524 <h3 id="_garbage_collection">Garbage Collection</h3>
2525 <div class="paragraph"><p>Normally, all values in Tcl are passed by value. As such values are copied and released
2526 automatically as necessary.</p></div>
2527 <div class="paragraph"><p>With the introduction of references, it is possible to create values whose lifetime
2528 transcend their scope. To support this, case, the Jim system will periodically identify
2529 and discard objects which are no longer accessible by any reference.</p></div>
2530 <div class="paragraph"><p>The <em>collect</em> command may be used to force garbage collection. Consider a reference created
2531 with a finalizer:</p></div>
2532 <div class="literalblock">
2533 <div class="content">
2534 <pre><tt>jim&gt; proc f {ref value} { puts "Finaliser called for $ref,$value" }
2535 jim&gt; set r [ref "One String" test f]
2536 &lt;reference.&lt;test___&gt;.00000000000
2537 jim&gt; collect
2539 jim&gt; set r ""
2540 jim&gt; collect
2541 Finaliser called for &lt;reference.&lt;test___&gt;.00000000000,One String
2542 1</tt></pre>
2543 </div></div>
2544 <div class="paragraph"><p>Note that once the reference, <em>r</em>, was modified so that it no longer
2545 contained a reference to the value, the garbage collector discarded
2546 the value (after calling the finalizer).</p></div>
2547 <div class="paragraph"><p>The finalizer for a reference may be examined or changed with the <em>finalize</em> command</p></div>
2548 <div class="literalblock">
2549 <div class="content">
2550 <pre><tt>jim&gt; finalize $r
2552 jim&gt; finalize $r newf
2553 newf</tt></pre>
2554 </div></div>
2555 </div>
2556 <div class="sect2">
2557 <h3 id="_lambda">Lambda</h3>
2558 <div class="paragraph"><p>Jim provides a garbage collected lambda function. This is a procedure
2559 which is able to create an anonymous procedure. Consider:</p></div>
2560 <div class="literalblock">
2561 <div class="content">
2562 <pre><tt>jim&gt; set f [lambda {a} {{x 0}} { incr x $a }]
2563 jim&gt; $f 1
2565 jim&gt; $f 2
2567 jim&gt; set f ""</tt></pre>
2568 </div></div>
2569 <div class="paragraph"><p>This create an anonymous procedure (with the name stored in <em>f</em>), with a static variable
2570 which is incremented by the supplied value and the result returned.</p></div>
2571 <div class="paragraph"><p>Once the procedure name is no longer accessible, it will automatically be deleted
2572 when the garbage collector runs.</p></div>
2573 <div class="paragraph"><p>The procedure may also be delete immediately by renaming it "". e.g.</p></div>
2574 <div class="literalblock">
2575 <div class="content">
2576 <pre><tt>jim&gt; rename $f ""</tt></pre>
2577 </div></div>
2578 </div>
2579 </div>
2580 </div>
2581 <div class="sect1">
2582 <h2 id="_utf_8_and_unicode">UTF-8 AND UNICODE</h2>
2583 <div class="sectionbody">
2584 <div class="paragraph"><p>If Jim is built with UTF-8 support enabled (configure --enable-utf),
2585 then most string-related commands become UTF-8 aware. These include,
2586 but are not limited to, <em>string match</em>, <em>split</em>, <em>glob</em>, <em>scan</em> and
2587 <em>format</em>.</p></div>
2588 <div class="paragraph"><p>UTF-8 encoding has many advantages, but one of the complications is that
2589 characters can take a variable number of bytes. Thus the addition of
2590 <em>string bytelength</em> which returns the number of bytes in a string,
2591 while <em>string length</em> returns the number of characters.</p></div>
2592 <div class="paragraph"><p>If UTF-8 support is not enabled, all commands treat bytes as characters
2593 and <em>string bytelength</em> returns the same value as <em>string length</em>.</p></div>
2594 <div class="paragraph"><p>Note that even if UTF-8 support is not enabled, the <tt>\uNNNN</tt> syntax
2595 is still available to embed UTF-8 sequences.</p></div>
2596 <div class="sect2">
2597 <h3 id="_string_matching">String Matching</h3>
2598 <div class="paragraph"><p>Commands such as <em>string match</em>, <em>lsearch -glob</em>, <em>array names</em> and others use string
2599 pattern matching rules. These commands support UTF-8. For example:</p></div>
2600 <div class="literalblock">
2601 <div class="content">
2602 <pre><tt>string match a\[\ua0-\ubf\]b "a\u00a3b"</tt></pre>
2603 </div></div>
2604 </div>
2605 <div class="sect2">
2606 <h3 id="_format_and_scan">format and scan</h3>
2607 <div class="paragraph"><p><tt>format %c</tt> allows a unicode codepoint to be be encoded. For example, the following will return
2608 a string with two bytes and one character. The same as <tt>\ub5</tt></p></div>
2609 <div class="literalblock">
2610 <div class="content">
2611 <pre><tt>format %c 0xb5</tt></pre>
2612 </div></div>
2613 <div class="paragraph"><p><em>format</em> respects widths as character widths, not byte widths. For example, the following will
2614 return a string with three characters, not three bytes.</p></div>
2615 <div class="literalblock">
2616 <div class="content">
2617 <pre><tt>format %.3s \ub5\ub6\ub7\ub8</tt></pre>
2618 </div></div>
2619 <div class="paragraph"><p>Similarly, <tt>scan &#8230; %c</tt> allows a UTF-8 to be decoded to a unicode codepoint. The following will set
2620 <strong>a</strong> to 181 (0xb5) and <strong>b</strong> to 65 (0x41).</p></div>
2621 <div class="literalblock">
2622 <div class="content">
2623 <pre><tt>scan \u00b5A %c%c a b</tt></pre>
2624 </div></div>
2625 <div class="paragraph"><p><em>scan %s</em> will also accept a character class, including unicode ranges.</p></div>
2626 </div>
2627 <div class="sect2">
2628 <h3 id="_string_classes">String Classes</h3>
2629 <div class="paragraph"><p><em>string is</em> has <strong>not</strong> been extended to classify UTF-8 characters. Therefore, the following
2630 will return 0, even though the string may be considered to be alphabetic.</p></div>
2631 <div class="literalblock">
2632 <div class="content">
2633 <pre><tt>string is alpha \ub5Test</tt></pre>
2634 </div></div>
2635 <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>
2636 </div>
2637 <div class="sect2">
2638 <h3 id="_case_mapping_and_conversion">Case Mapping and Conversion</h3>
2639 <div class="paragraph"><p>Jim provides a simplified unicode case mapping. This means that case conversion
2640 and comparison will not increase or decrease the number of characters in a string.</p></div>
2641 <div class="paragraph"><p><em>string toupper</em> will convert any lowercase letters to their uppercase equivalent.
2642 Any character which is not a letter or has no uppercase equivalent is left unchanged.
2643 Similarly for <em>string tolower</em>.</p></div>
2644 <div class="paragraph"><p>Commands which perform case insensitive matches, such as <em>string compare -nocase</em>
2645 and <em>lsearch -nocase</em> fold both strings to uppercase before comparison.</p></div>
2646 </div>
2647 <div class="sect2">
2648 <h3 id="_invalid_utf_8_sequences">Invalid UTF-8 Sequences</h3>
2649 <div class="paragraph"><p>Some UTF-8 character sequences are invalid, such as those beginning with <em>0xff</em>,
2650 those which represent character sequences longer than 3 bytes (greater than U+FFFF),
2651 and those which end prematurely, such as a lone <em>0xc2</em>.</p></div>
2652 <div class="paragraph"><p>In these situations, the offending bytes are treated as single characters. For example,
2653 the following returns 2.</p></div>
2654 <div class="literalblock">
2655 <div class="content">
2656 <pre><tt>string bytelength \xff\xff</tt></pre>
2657 </div></div>
2658 </div>
2659 <div class="sect2">
2660 <h3 id="_regular_expressions_2">Regular Expressions</h3>
2661 <div class="paragraph"><p>If UTF-8 support is enabled, the built-in regular expression engine will be
2662 selected which supports UTF-8 strings and patterns.</p></div>
2663 <div class="paragraph"><p>See REGULAR EXPRESSIONS</p></div>
2664 </div>
2665 </div>
2666 </div>
2667 <div class="sect1">
2668 <h2 id="_built_in_commands">BUILT-IN COMMANDS</h2>
2669 <div class="sectionbody">
2670 <div class="paragraph"><p>The Tcl library provides the following built-in commands, which will
2671 be available in any application using Tcl. In addition to these
2672 built-in commands, there may be additional commands defined by each
2673 application, plus commands defined as Tcl procedures.</p></div>
2674 <div class="paragraph"><p>In the command syntax descriptions below, words in <tt><strong>boldface</strong></tt> are
2675 literals that you type verbatim to Tcl.</p></div>
2676 <div class="paragraph"><p>Words in <tt><em>italics</em></tt> are meta-symbols; they serve as names for any of
2677 a range of values that you can type.</p></div>
2678 <div class="paragraph"><p>Optional arguments or groups of arguments are indicated by enclosing them
2679 in <tt>?question-marks?</tt>.</p></div>
2680 <div class="paragraph"><p>Ellipses (<tt>&#8230;</tt>) indicate that any number of additional
2681 arguments or groups of arguments may appear, in the same format
2682 as the preceding argument(s).</p></div>
2683 <div class="sect2">
2684 <h3 id="CommandIndex">Command Index</h3>
2685 <div class="tableblock">
2686 <table rules="none"
2687 width="100%"
2688 frame="void"
2689 cellspacing="0" cellpadding="4">
2690 <col width="12%" />
2691 <col width="12%" />
2692 <col width="12%" />
2693 <col width="12%" />
2694 <col width="12%" />
2695 <col width="12%" />
2696 <col width="12%" />
2697 <col width="12%" />
2698 <tbody>
2699 <tr>
2700 <td align="left" valign="top"><p class="table"><a href="#cmd_2">after</a></p></td>
2701 <td align="left" valign="top"><p class="table"><a href="#_aio">aio</a></p></td>
2702 <td align="left" valign="top"><p class="table"><a href="#_alarm">alarm</a></p></td>
2703 <td align="left" valign="top"><p class="table"><a href="#_alias">alias</a></p></td>
2704 <td align="left" valign="top"><p class="table"><a href="#_append">append</a></p></td>
2705 <td align="left" valign="top"><p class="table"><a href="#_array">array</a></p></td>
2706 <td align="left" valign="top"><p class="table"><a href="#_break">break</a></p></td>
2707 <td align="left" valign="top"><p class="table"><a href="#_case">case</a></p></td>
2708 </tr>
2709 <tr>
2710 <td align="left" valign="top"><p class="table"><a href="#_catch">catch</a></p></td>
2711 <td align="left" valign="top"><p class="table"><a href="#_cd">cd</a></p></td>
2712 <td align="left" valign="top"><p class="table"><a href="#_clock">clock</a></p></td>
2713 <td align="left" valign="top"><p class="table"><a href="#_close">close</a></p></td>
2714 <td align="left" valign="top"><p class="table"><a href="#_collect">collect</a></p></td>
2715 <td align="left" valign="top"><p class="table"><a href="#_concat">concat</a></p></td>
2716 <td align="left" valign="top"><p class="table"><a href="#_continue">continue</a></p></td>
2717 <td align="left" valign="top"><p class="table"><a href="#_curry">curry</a></p></td>
2718 </tr>
2719 <tr>
2720 <td align="left" valign="top"><p class="table"><a href="#_dict">dict</a></p></td>
2721 <td align="left" valign="top"><p class="table"><a href="#_env">env</a></p></td>
2722 <td align="left" valign="top"><p class="table"><a href="#_eof">eof</a></p></td>
2723 <td align="left" valign="top"><p class="table"><a href="#_error">error</a></p></td>
2724 <td align="left" valign="top"><p class="table"><a href="#_errorInfo">errorInfo</a></p></td>
2725 <td align="left" valign="top"><p class="table"><a href="#_eval">eval</a></p></td>
2726 <td align="left" valign="top"><p class="table"><a href="#cmd_2">eventloop</a></p></td>
2727 <td align="left" valign="top"><p class="table"><a href="#_exec">exec</a></p></td>
2728 </tr>
2729 <tr>
2730 <td align="left" valign="top"><p class="table"><a href="#_exists">exists</a></p></td>
2731 <td align="left" valign="top"><p class="table"><a href="#_exit">exit</a></p></td>
2732 <td align="left" valign="top"><p class="table"><a href="#_expr">expr</a></p></td>
2733 <td align="left" valign="top"><p class="table"><a href="#_file">file</a></p></td>
2734 <td align="left" valign="top"><p class="table"><a href="#_finalize">finalize</a></p></td>
2735 <td align="left" valign="top"><p class="table"><a href="#_flush">flush</a></p></td>
2736 <td align="left" valign="top"><p class="table"><a href="#_for">for</a></p></td>
2737 <td align="left" valign="top"><p class="table"><a href="#_foreach">foreach</a></p></td>
2738 </tr>
2739 <tr>
2740 <td align="left" valign="top"><p class="table"><a href="#_format">format</a></p></td>
2741 <td align="left" valign="top"><p class="table"><a href="#_getref">getref</a></p></td>
2742 <td align="left" valign="top"><p class="table"><a href="#_gets">gets</a></p></td>
2743 <td align="left" valign="top"><p class="table"><a href="#_glob">glob</a></p></td>
2744 <td align="left" valign="top"><p class="table"><a href="#_global">global</a></p></td>
2745 <td align="left" valign="top"><p class="table"><a href="#_if">if</a></p></td>
2746 <td align="left" valign="top"><p class="table"><a href="#_incr">incr</a></p></td>
2747 <td align="left" valign="top"><p class="table"><a href="#_info">info</a></p></td>
2748 </tr>
2749 <tr>
2750 <td align="left" valign="top"><p class="table"><a href="#_join">join</a></p></td>
2751 <td align="left" valign="top"><p class="table"><a href="#_kill">kill</a></p></td>
2752 <td align="left" valign="top"><p class="table"><a href="#_lambda">lambda</a></p></td>
2753 <td align="left" valign="top"><p class="table"><a href="#_lappend">lappend</a></p></td>
2754 <td align="left" valign="top"><p class="table"><a href="#_lassign">lassign</a></p></td>
2755 <td align="left" valign="top"><p class="table"><a href="#_lindex">lindex</a></p></td>
2756 <td align="left" valign="top"><p class="table"><a href="#_linsert">linsert</a></p></td>
2757 <td align="left" valign="top"><p class="table"><a href="#_list">list</a></p></td>
2758 </tr>
2759 <tr>
2760 <td align="left" valign="top"><p class="table"><a href="#_llength">llength</a></p></td>
2761 <td align="left" valign="top"><p class="table"><a href="#_lmap">lmap</a></p></td>
2762 <td align="left" valign="top"><p class="table"><a href="#_load">load</a></p></td>
2763 <td align="left" valign="top"><p class="table"><a href="#_local">local</a></p></td>
2764 <td align="left" valign="top"><p class="table"><a href="#_loop">loop</a></p></td>
2765 <td align="left" valign="top"><p class="table"><a href="#_lrange">lrange</a></p></td>
2766 <td align="left" valign="top"><p class="table"><a href="#_lrepeat">lrepeat</a></p></td>
2767 <td align="left" valign="top"><p class="table"><a href="#_lreplace">lreplace</a></p></td>
2768 </tr>
2769 <tr>
2770 <td align="left" valign="top"><p class="table"><a href="#_lreverse">lreverse</a></p></td>
2771 <td align="left" valign="top"><p class="table"><a href="#_lsearch">lsearch</a></p></td>
2772 <td align="left" valign="top"><p class="table"><a href="#_lset">lset</a></p></td>
2773 <td align="left" valign="top"><p class="table"><a href="#_lsort">lsort</a></p></td>
2774 <td align="left" valign="top"><p class="table"><a href="#_open">open</a></p></td>
2775 <td align="left" valign="top"><p class="table"><a href="#cmd_1">os.fork</a></p></td>
2776 <td align="left" valign="top"><p class="table"><a href="#cmd_1">os.gethostname</a></p></td>
2777 <td align="left" valign="top"><p class="table"><a href="#cmd_1">os.getids</a></p></td>
2778 </tr>
2779 <tr>
2780 <td align="left" valign="top"><p class="table"><a href="#cmd_1">os.uptime</a></p></td>
2781 <td align="left" valign="top"><p class="table"><a href="#cmd_1">os.wait</a></p></td>
2782 <td align="left" valign="top"><p class="table"><a href="#_package">package</a></p></td>
2783 <td align="left" valign="top"><p class="table"><a href="#_pid">pid</a></p></td>
2784 <td align="left" valign="top"><p class="table"><a href="#cmd_1">posix</a></p></td>
2785 <td align="left" valign="top"><p class="table"><a href="#_proc">proc</a></p></td>
2786 <td align="left" valign="top"><p class="table"><a href="#_puts">puts</a></p></td>
2787 <td align="left" valign="top"><p class="table"><a href="#_pwd">pwd</a></p></td>
2788 </tr>
2789 <tr>
2790 <td align="left" valign="top"><p class="table"><a href="#_rand">rand</a></p></td>
2791 <td align="left" valign="top"><p class="table"><a href="#_range">range</a></p></td>
2792 <td align="left" valign="top"><p class="table"><a href="#_read">read</a></p></td>
2793 <td align="left" valign="top"><p class="table"><a href="#_ref">ref</a></p></td>
2794 <td align="left" valign="top"><p class="table"><a href="#_regexp">regexp</a></p></td>
2795 <td align="left" valign="top"><p class="table"><a href="#_regsub">regsub</a></p></td>
2796 <td align="left" valign="top"><p class="table"><a href="#_rename">rename</a></p></td>
2797 <td align="left" valign="top"><p class="table"><a href="#_return">return</a></p></td>
2798 </tr>
2799 <tr>
2800 <td align="left" valign="top"><p class="table"><a href="#_scan">scan</a></p></td>
2801 <td align="left" valign="top"><p class="table"><a href="#_seek">seek</a></p></td>
2802 <td align="left" valign="top"><p class="table"><a href="#_set">set</a></p></td>
2803 <td align="left" valign="top"><p class="table"><a href="#_setref">setref</a></p></td>
2804 <td align="left" valign="top"><p class="table"><a href="#_signal">signal</a></p></td>
2805 <td align="left" valign="top"><p class="table"><a href="#_sleep">sleep</a></p></td>
2806 <td align="left" valign="top"><p class="table"><a href="#_socket">socket</a></p></td>
2807 <td align="left" valign="top"><p class="table"><a href="#_source">source</a></p></td>
2808 </tr>
2809 <tr>
2810 <td align="left" valign="top"><p class="table"><a href="#_split">split</a></p></td>
2811 <td align="left" valign="top"><p class="table"><a href="#_stackdump">stackdump</a></p></td>
2812 <td align="left" valign="top"><p class="table"><a href="#_stacktrace">stacktrace</a></p></td>
2813 <td align="left" valign="top"><p class="table"><a href="#_string">string</a></p></td>
2814 <td align="left" valign="top"><p class="table"><a href="#_subst">subst</a></p></td>
2815 <td align="left" valign="top"><p class="table"><a href="#_switch">switch</a></p></td>
2816 <td align="left" valign="top"><p class="table"><a href="#_syslog">syslog</a></p></td>
2817 <td align="left" valign="top"><p class="table"><a href="#_tailcall">tailcall</a></p></td>
2818 </tr>
2819 <tr>
2820 <td align="left" valign="top"><p class="table"><a href="#_tell">tell</a></p></td>
2821 <td align="left" valign="top"><p class="table"><a href="#_throw">throw</a></p></td>
2822 <td align="left" valign="top"><p class="table"><a href="#_time">time</a></p></td>
2823 <td align="left" valign="top"><p class="table"><a href="#_try">try</a></p></td>
2824 <td align="left" valign="top"><p class="table"><a href="#_unknown">unknown</a></p></td>
2825 <td align="left" valign="top"><p class="table"><a href="#_unset">unset</a></p></td>
2826 <td align="left" valign="top"><p class="table"><a href="#_upcall">upcall</a></p></td>
2827 <td align="left" valign="top"><p class="table"><a href="#cmd_2">update</a></p></td>
2828 </tr>
2829 <tr>
2830 <td align="left" valign="top"><p class="table"><a href="#_uplevel">uplevel</a></p></td>
2831 <td align="left" valign="top"><p class="table"><a href="#_upvar">upvar</a></p></td>
2832 <td align="left" valign="top"><p class="table"><a href="#cmd_2">vwait</a></p></td>
2833 <td align="left" valign="top"><p class="table"><a href="#_while">while</a></p></td>
2834 <td align="left" valign="top"><p class="table"></p></td>
2835 <td align="left" valign="top"><p class="table"></p></td>
2836 <td align="left" valign="top"><p class="table"></p></td>
2837 <td align="left" valign="top"><p class="table"></p></td>
2838 </tr>
2839 </tbody>
2840 </table>
2841 </div>
2842 </div>
2843 <div class="sect2">
2844 <h3 id="_alarm">alarm</h3>
2845 <div class="paragraph"><p><tt><strong>alarm</strong> <em>seconds</em></tt></p></div>
2846 <div class="paragraph"><p>Delivers the <em>SIGALRM</em> signal to the process after the given
2847 number of seconds. If the platform supports <em>ualarm(3)</em> then
2848 the argument may be a floating point value. Otherwise it must
2849 be an integer.</p></div>
2850 <div class="paragraph"><p>Note that unless a signal handler for <em>SIGALRM</em> has been installed
2851 (see <em>signal</em>), the process will exit on this signal.</p></div>
2852 </div>
2853 <div class="sect2">
2854 <h3 id="_alias">alias</h3>
2855 <div class="paragraph"><p><tt><strong>alias</strong> <em>name args&#8230;</em></tt></p></div>
2856 <div class="paragraph"><p>Creates a single word alias (proc) for one or more words. For example,
2857 the following creates an alias for the command <em>info exists</em>.</p></div>
2858 <div class="literalblock">
2859 <div class="content">
2860 <pre><tt>alias e info exists
2861 if {[e var]} {
2863 }</tt></pre>
2864 </div></div>
2865 <div class="paragraph"><p><em>alias</em> returns <strong>name</strong>, allowing it to be used with 'local.</p></div>
2866 <div class="paragraph"><p>See also <em>proc</em>, <em>curry</em>, <em>lambda</em>, <em>local</em>.</p></div>
2867 </div>
2868 <div class="sect2">
2869 <h3 id="_append">append</h3>
2870 <div class="paragraph"><p><tt><strong>append</strong> <em>varName value ?value value &#8230;?</em></tt></p></div>
2871 <div class="paragraph"><p>Append all of the <strong>value</strong> arguments to the current value
2872 of variable <strong>varName</strong>. If <strong>varName</strong> doesn&#8217;t exist,
2873 it is given a value equal to the concatenation of all the
2874 <strong>value</strong> arguments.</p></div>
2875 <div class="paragraph"><p>This command provides an efficient way to build up long
2876 variables incrementally.
2877 For example, <em>append a $b</em> is much more efficient than
2878 <em>set a $a$b</em> if <em>$a</em> is long.</p></div>
2879 </div>
2880 <div class="sect2">
2881 <h3 id="_array">array</h3>
2882 <div class="paragraph"><p><tt><strong>array</strong> <em>option arrayName ?arg arg &#8230;?</em></tt></p></div>
2883 <div class="paragraph"><p>This command performs one of several operations on the
2884 variable given by <strong>arrayName</strong>.</p></div>
2885 <div class="paragraph"><p>Note that in general, if the named array does not exist, the <strong>array</strong> command behaves
2886 as though the array exists but is empty.</p></div>
2887 <div class="paragraph"><p>The <strong>option</strong> argument determines what action is carried out by the
2888 command. The legal <strong>options</strong> (which may be abbreviated) are:</p></div>
2889 <div class="dlist"><dl>
2890 <dt class="hdlist1">
2891 <tt><strong>array exists</strong> <em>arrayName</em></tt>
2892 </dt>
2893 <dd>
2895 Returns 1 if arrayName is an array variable, 0 if there is
2896 no variable by that name. This command is essentially
2897 identical to <em>info exists</em>
2898 </p>
2899 </dd>
2900 <dt class="hdlist1">
2901 <tt><strong>array get</strong> <em>arrayName ?pattern?</em></tt>
2902 </dt>
2903 <dd>
2905 Returns a list containing pairs of elements. The first
2906 element in each pair is the name of an element in arrayName
2907 and the second element of each pair is the value of the
2908 array element. The order of the pairs is undefined. If
2909 pattern is not specified, then all of the elements of the
2910 array are included in the result. If pattern is specified,
2911 then only those elements whose names match pattern (using
2912 the matching rules of string match) are included. If arrayName
2913 isn&#8217;t the name of an array variable, or if the array contains
2914 no elements, then an empty list is returned.
2915 </p>
2916 </dd>
2917 <dt class="hdlist1">
2918 <tt><strong>array names</strong> <em>arrayName ?pattern?</em></tt>
2919 </dt>
2920 <dd>
2922 Returns a list containing the names of all of the elements
2923 in the array that match pattern. If pattern is omitted then
2924 the command returns all of the element names in the array.
2925 If pattern is specified, then only those elements whose
2926 names match pattern (using the matching rules of string
2927 match) are included. If there are no (matching) elements
2928 in the array, or if arrayName isn&#8217;t the name of an array
2929 variable, then an empty string is returned.
2930 </p>
2931 </dd>
2932 <dt class="hdlist1">
2933 <tt><strong>array set</strong> <em>arrayName list</em></tt>
2934 </dt>
2935 <dd>
2937 Sets the values of one or more elements in arrayName. list
2938 must have a form like that returned by array get, consisting
2939 of an even number of elements. Each odd-numbered element
2940 in list is treated as an element name within arrayName, and
2941 the following element in list is used as a new value for
2942 that array element. If the variable arrayName does not
2943 already exist and list is empty, arrayName is created with
2944 an empty array value.
2945 </p>
2946 </dd>
2947 <dt class="hdlist1">
2948 <tt><strong>array size</strong> <em>arrayName</em></tt>
2949 </dt>
2950 <dd>
2952 Returns the number of elements in the array. If arrayName
2953 isn&#8217;t the name of an array then 0 is returned.
2954 </p>
2955 </dd>
2956 <dt class="hdlist1">
2957 <tt><strong>array unset</strong> <em>arrayName ?pattern?</em></tt>
2958 </dt>
2959 <dd>
2961 Unsets all of the elements in the array that match pattern
2962 (using the matching rules of string match). If arrayName
2963 isn&#8217;t the name of an array variable or there are no matching
2964 elements in the array, no error will be raised. If pattern
2965 is omitted and arrayName is an array variable, then the
2966 command unsets the entire array. The command always returns
2967 an empty string.
2968 </p>
2969 </dd>
2970 </dl></div>
2971 </div>
2972 <div class="sect2">
2973 <h3 id="_break">break</h3>
2974 <div class="paragraph"><p><tt><strong>break</strong></tt></p></div>
2975 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command
2976 such as <em>for</em> or <em>foreach</em> or <em>while</em>. It returns a <tt>JIM_BREAK</tt> code
2977 to signal the innermost containing loop command to return immediately.</p></div>
2978 </div>
2979 <div class="sect2">
2980 <h3 id="_case">case</h3>
2981 <div class="paragraph"><p><tt><strong>case</strong> <em>string</em> ?<strong>in</strong>? <em>patList body ?patList body &#8230;?</em></tt></p></div>
2982 <div class="paragraph"><p><tt><strong>case</strong> <em>string</em> ?<strong>in</strong>? {<em>patList body ?patList body &#8230;?</em>}</tt></p></div>
2983 <div class="paragraph"><p><strong>Note</strong> that the switch command should generally be preferred unless compatibility
2984 with Tcl 6.x is desired.</p></div>
2985 <div class="paragraph"><p>Match <strong>string</strong> against each of the <strong>patList</strong> arguments
2986 in order. If one matches, then evaluate the following <strong>body</strong> argument
2987 by passing it recursively to the Tcl interpreter, and return the result
2988 of that evaluation. Each <strong>patList</strong> argument consists of a single
2989 pattern or list of patterns. Each pattern may contain any of the wild-cards
2990 described under <em>string match</em>.</p></div>
2991 <div class="paragraph"><p>If a <strong>patList</strong> argument is <em>default</em>, the corresponding body will be
2992 evaluated if no <strong>patList</strong> matches <strong>string</strong>. If no <strong>patList</strong> argument
2993 matches <strong>string</strong> and no default is given, then the <em>case</em> command returns
2994 an empty string.</p></div>
2995 <div class="paragraph"><p>Two syntaxes are provided.</p></div>
2996 <div class="paragraph"><p>The first uses a separate argument for each of the patterns and commands;
2997 this form is convenient if substitutions are desired on some of the
2998 patterns or commands.</p></div>
2999 <div class="paragraph"><p>The second form places all of the patterns and commands together into
3000 a single argument; the argument must have proper list structure, with
3001 the elements of the list being the patterns and commands.</p></div>
3002 <div class="paragraph"><p>The second form makes it easy to construct multi-line case commands,
3003 since the braces around the whole list make it unnecessary to include a
3004 backslash at the end of each line.</p></div>
3005 <div class="paragraph"><p>Since the <strong>patList</strong> arguments are in braces in the second form,
3006 no command or variable substitutions are performed on them; this makes
3007 the behaviour of the second form different than the first form in some
3008 cases.</p></div>
3009 <div class="paragraph"><p>Below are some examples of <em>case</em> commands:</p></div>
3010 <div class="literalblock">
3011 <div class="content">
3012 <pre><tt>case abc in {a b} {format 1} default {format 2} a* {format 3}</tt></pre>
3013 </div></div>
3014 <div class="paragraph"><p>will return <em>3</em>,</p></div>
3015 <div class="literalblock">
3016 <div class="content">
3017 <pre><tt>case a in {
3018 {a b} {format 1}
3019 default {format 2}
3020 a* {format 3}
3021 }</tt></pre>
3022 </div></div>
3023 <div class="paragraph"><p>will return <em>1</em>, and</p></div>
3024 <div class="literalblock">
3025 <div class="content">
3026 <pre><tt>case xyz {
3027 {a b}
3028 {format 1}
3029 default
3030 {format 2}
3032 {format 3}
3033 }</tt></pre>
3034 </div></div>
3035 <div class="paragraph"><p>will return <em>2</em>.</p></div>
3036 </div>
3037 <div class="sect2">
3038 <h3 id="_catch">catch</h3>
3039 <div class="paragraph"><p><tt><strong>catch</strong> <em>?-?no?code &#8230;?</em> <strong>?--?</strong> <em>command ?resultVarName? ?optionsVarName?</em></tt></p></div>
3040 <div class="paragraph"><p>The <em>catch</em> command may be used to prevent errors from aborting
3041 command interpretation. <em>Catch</em> evaluates <strong>command</strong>, and returns a
3042 <tt>JIM_OK</tt> code, regardless of any errors that might occur while
3043 executing <strong>command</strong> (with the possible exception of <tt>JIM_SIGNAL</tt> -
3044 see below).</p></div>
3045 <div class="paragraph"><p>The return value from <em>catch</em> is a decimal string giving the code
3046 returned by the Tcl interpreter after executing <strong>command</strong>. This
3047 will be <em>0</em> (<tt>JIM_OK</tt>) if there were no errors in <strong>command</strong>; otherwise
3048 it will have a non-zero value corresponding to one of the exceptional
3049 return codes (see jim.h for the definitions of code values, or the
3050 <em>info returncodes</em> command).</p></div>
3051 <div class="paragraph"><p>If the <strong>resultVarName</strong> argument is given, then it gives the name
3052 of a variable; <em>catch</em> will set the value of the variable to the
3053 string returned from <strong>command</strong> (either a result or an error message).</p></div>
3054 <div class="paragraph"><p>If the <strong>optionsVarName</strong> argument is given, then it gives the name
3055 of a variable; <em>catch</em> will set the value of the variable to a
3056 dictionary. For any return code other than <tt>JIM_RETURN</tt>, the value
3057 for the key <tt>-code</tt> will be set to the return code. For <tt>JIM_RETURN</tt>
3058 it will be set to the code given in <em>return -code</em>. Additionally,
3059 for the return code <tt>JIM_ERR</tt>, the value of the key <tt>-errorinfo</tt>
3060 will contain the current stack trace (the same result as <em>info
3061 stacktrace</em>), the value of the key <tt>-errorcode</tt> will contain the
3062 same value as the global variable $::errorCode, and the value of
3063 the key <tt>-level</tt> will be the current return level (see <em>return
3064 -level</em>). This can be useful to rethrow an error:</p></div>
3065 <div class="literalblock">
3066 <div class="content">
3067 <pre><tt>if {[catch {...} msg opts]} {
3068 ...maybe do something with the error...
3069 incr opts(-level)
3070 return {*}$opts $msg
3071 }</tt></pre>
3072 </div></div>
3073 <div class="paragraph"><p>Normally <em>catch</em> will <strong>not</strong> catch any of the codes <tt>JIM_EXIT</tt>, <tt>JIM_EVAL</tt> or <tt>JIM_SIGNAL</tt>.
3074 The set of codes which will be caught may be modified by specifying the one more codes before
3075 <strong>command</strong>.</p></div>
3076 <div class="paragraph"><p>e.g. To catch <tt>JIM_EXIT</tt> but not <tt>JIM_BREAK</tt> or <tt>JIM_CONTINUE</tt></p></div>
3077 <div class="literalblock">
3078 <div class="content">
3079 <pre><tt>catch -exit -nobreak -nocontinue -- { ... }</tt></pre>
3080 </div></div>
3081 <div class="paragraph"><p>The use of <tt>--</tt> is optional. It signifies that no more return code options follow.</p></div>
3082 <div class="paragraph"><p>Note that if a signal marked as <em>signal handle</em> is caught with <em>catch -signal</em>, the return value
3083 (stored in <strong>resultVarName</strong>) is name of the signal caught.</p></div>
3084 </div>
3085 <div class="sect2">
3086 <h3 id="_cd">cd</h3>
3087 <div class="paragraph"><p><tt><strong>cd</strong> <em>dirName</em></tt></p></div>
3088 <div class="paragraph"><p>Change the current working directory to <strong>dirName</strong>.</p></div>
3089 <div class="paragraph"><p>Returns an empty string.</p></div>
3090 <div class="paragraph"><p>This command can potentially be disruptive to an application, so it may
3091 be removed in some applications.</p></div>
3092 </div>
3093 <div class="sect2">
3094 <h3 id="_clock">clock</h3>
3095 <div class="dlist"><dl>
3096 <dt class="hdlist1">
3097 <tt><strong>clock seconds</strong></tt>
3098 </dt>
3099 <dd>
3101 Returns the current time as seconds since the epoch.
3102 </p>
3103 </dd>
3104 <dt class="hdlist1">
3105 <tt><strong>clock format</strong> <em>seconds</em> ?<strong>-format</strong> <em>format?</em></tt>
3106 </dt>
3107 <dd>
3109 Format the given time (seconds since the epoch) according to the given
3110 format. See strftime(3) for supported formats.
3111 If no format is supplied, "%c" is used.
3112 </p>
3113 </dd>
3114 <dt class="hdlist1">
3115 <tt><strong>clock scan</strong> <em>str</em> <strong>-format</strong> <em>format</em></tt>
3116 </dt>
3117 <dd>
3119 Scan the given time string using the given format string.
3120 See strptime(3) for supported formats.
3121 </p>
3122 </dd>
3123 </dl></div>
3124 </div>
3125 <div class="sect2">
3126 <h3 id="_close">close</h3>
3127 <div class="paragraph"><p><tt><strong>close</strong> <em>fileId</em></tt></p></div>
3128 <div class="paragraph"><p><tt><em>fileId</em> <strong>close</strong></tt></p></div>
3129 <div class="paragraph"><p>Closes the file given by <strong>fileId</strong>.
3130 <strong>fileId</strong> must be the return value from a previous invocation
3131 of the <em>open</em> command; after this command, it should not be
3132 used anymore.</p></div>
3133 </div>
3134 <div class="sect2">
3135 <h3 id="_collect">collect</h3>
3136 <div class="paragraph"><p><tt><strong>collect</strong></tt></p></div>
3137 <div class="paragraph"><p>Normally reference garbage collection is automatically performed periodically.
3138 However it may be run immediately with the <em>collect</em> command.</p></div>
3139 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3140 </div>
3141 <div class="sect2">
3142 <h3 id="_concat">concat</h3>
3143 <div class="paragraph"><p><tt><strong>concat</strong> <em>arg ?arg &#8230;?</em></tt></p></div>
3144 <div class="paragraph"><p>This command treats each argument as a list and concatenates them
3145 into a single list. It permits any number of arguments. For example,
3146 the command</p></div>
3147 <div class="literalblock">
3148 <div class="content">
3149 <pre><tt>concat a b {c d e} {f {g h}}</tt></pre>
3150 </div></div>
3151 <div class="paragraph"><p>will return</p></div>
3152 <div class="literalblock">
3153 <div class="content">
3154 <pre><tt>a b c d e f {g h}</tt></pre>
3155 </div></div>
3156 <div class="paragraph"><p>as its result.</p></div>
3157 </div>
3158 <div class="sect2">
3159 <h3 id="_continue">continue</h3>
3160 <div class="paragraph"><p><tt><strong>continue</strong></tt></p></div>
3161 <div class="paragraph"><p>This command may be invoked only inside the body of a loop command such
3162 as <em>for</em> or <em>foreach</em> or <em>while</em>. It returns a <tt>JIM_CONTINUE</tt> code to
3163 signal the innermost containing loop command to skip the remainder of
3164 the loop&#8217;s body but continue with the next iteration of the loop.</p></div>
3165 </div>
3166 <div class="sect2">
3167 <h3 id="_curry">curry</h3>
3168 <div class="paragraph"><p><tt><strong>alias</strong> <em>args&#8230;</em></tt></p></div>
3169 <div class="paragraph"><p>Similar to <em>alias</em> except it creates an anonymous procedure (lambda) instead of
3170 a named procedure.</p></div>
3171 <div class="paragraph"><p>the following creates a local, unnamed alias for the command <em>info exists</em>.</p></div>
3172 <div class="literalblock">
3173 <div class="content">
3174 <pre><tt>set e [local curry info exists]
3175 if {[$e var]} {
3177 }</tt></pre>
3178 </div></div>
3179 <div class="paragraph"><p><em>curry</em> returns the name of the procedure.</p></div>
3180 <div class="paragraph"><p>See also <em>proc</em>, <em>alias</em>, <em>lambda</em>, <em>local</em>.</p></div>
3181 </div>
3182 <div class="sect2">
3183 <h3 id="_dict">dict</h3>
3184 <div class="paragraph"><p><tt><strong>dict</strong> <em>option ?arg arg &#8230;?</em></tt></p></div>
3185 <div class="paragraph"><p>Performs one of several operations on dictionary values.</p></div>
3186 <div class="paragraph"><p>The <strong>option</strong> argument determines what action is carried out by the
3187 command. The legal <strong>options</strong> are:</p></div>
3188 <div class="dlist"><dl>
3189 <dt class="hdlist1">
3190 <tt><strong>dict create</strong> <em>?key value &#8230;?</em></tt>
3191 </dt>
3192 <dd>
3194 Create and return a new dictionary value that contains each of
3195 the key/value mappings listed as arguments (keys and values
3196 alternating, with each key being followed by its associated
3197 value.)
3198 </p>
3199 </dd>
3200 <dt class="hdlist1">
3201 <tt><strong>dict exists</strong> <em>dictionary key ?key &#8230;?</em></tt>
3202 </dt>
3203 <dd>
3205 Returns a boolean value indicating whether the given key (or path
3206 of keys through a set of nested dictionaries) exists in the given
3207 dictionary value. This returns a true value exactly when <em>dict get</em>
3208 on that path will succeed.
3209 </p>
3210 </dd>
3211 <dt class="hdlist1">
3212 <tt><strong>dict get</strong> <em>dictionary ?key &#8230;?</em></tt>
3213 </dt>
3214 <dd>
3216 Given a dictionary value (first argument) and a key (second argument),
3217 this will retrieve the value for that key. Where several keys are
3218 supplied, the behaviour of the command shall be as if the result
3219 of <em>dict get $dictVal $key</em> was passed as the first argument to
3220 dict get with the remaining arguments as second (and possibly
3221 subsequent) arguments. This facilitates lookups in nested dictionaries.
3222 If no keys are provided, dict would return a list containing pairs
3223 of elements in a man- ner similar to array get. That is, the first
3224 element of each pair would be the key and the second element would
3225 be the value for that key. It is an error to attempt to retrieve
3226 a value for a key that is not present in the dictionary.
3227 </p>
3228 </dd>
3229 <dt class="hdlist1">
3230 <tt><strong>dict keys</strong> <em>dictionary ?pattern?</em></tt>
3231 </dt>
3232 <dd>
3234 Returns a list of the keys in the dictionary.
3235 If pattern is specified, then only those keys whose
3236 names match <strong>pattern</strong> (using the matching rules of string
3237 match) are included.
3238 </p>
3239 </dd>
3240 <dt class="hdlist1">
3241 <tt><strong>dict keys</strong> <em>dictionary ?pattern?</em></tt>
3242 </dt>
3243 <dd>
3245 Returns a list of the keys in the dictionary.
3246 If pattern is specified, then only those keys whose
3247 names match <strong>pattern</strong> (using the matching rules of string
3248 match) are included.
3249 </p>
3250 </dd>
3251 <dt class="hdlist1">
3252 <tt><strong>dict set</strong> <em>dictionaryName key ?key &#8230;? value</em></tt>
3253 </dt>
3254 <dd>
3256 This operation takes the <strong>name</strong> of a variable containing a dictionary
3257 value and places an updated dictionary value in that variable
3258 containing a mapping from the given key to the given value. When
3259 multiple keys are present, this operation creates or updates a chain
3260 of nested dictionaries.
3261 </p>
3262 </dd>
3263 <dt class="hdlist1">
3264 <tt><strong>dict unset</strong> <em>dictionaryName key ?key &#8230;? value</em></tt>
3265 </dt>
3266 <dd>
3268 This operation (the companion to <em>dict set</em>) takes the name of a
3269 variable containing a dictionary value and places an updated
3270 dictionary value in that variable that does not contain a mapping
3271 for the given key. Where multiple keys are present, this describes
3272 a path through nested dictionaries to the mapping to remove. At
3273 least one key must be specified, but the last key on the key-path
3274 need not exist. All other components on the path must exist.
3275 </p>
3276 </dd>
3277 </dl></div>
3278 </div>
3279 <div class="sect2">
3280 <h3 id="_env">env</h3>
3281 <div class="paragraph"><p><tt><strong>env</strong> <em>?name? ?default?</em></tt></p></div>
3282 <div class="paragraph"><p>If <strong>name</strong> is supplied, returns the value of <strong>name</strong> from the initial
3283 environment (see getenv(3)). An error is returned if <strong>name</strong> does not
3284 exist in the environment, unless <strong>default</strong> is supplied - in which case
3285 that value is returned instead.</p></div>
3286 <div class="paragraph"><p>If no arguments are supplied, returns a list of all environment variables
3287 and their values as <tt>{name value &#8230;}</tt></p></div>
3288 <div class="paragraph"><p>See also the global variable <em>::env</em></p></div>
3289 </div>
3290 <div class="sect2">
3291 <h3 id="_eof">eof</h3>
3292 <div class="paragraph"><p><tt><strong>eof</strong> <em>fileId</em></tt></p></div>
3293 <div class="paragraph"><p><tt><em>fileId</em> <strong>eof</strong></tt></p></div>
3294 <div class="paragraph"><p>Returns 1 if an end-of-file condition has occurred on <strong>fileId</strong>,
3295 0 otherwise.</p></div>
3296 <div class="paragraph"><p><strong>fileId</strong> must have been the return value from a previous call to <em>open</em>,
3297 or it may be <em>stdin</em>, <em>stdout</em>, or <em>stderr</em> to refer to one of the
3298 standard I/O channels.</p></div>
3299 </div>
3300 <div class="sect2">
3301 <h3 id="_error">error</h3>
3302 <div class="paragraph"><p><tt><strong>error</strong> <em>message ?stacktrace?</em></tt></p></div>
3303 <div class="paragraph"><p>Returns a <tt>JIM_ERR</tt> code, which causes command interpretation to be
3304 unwound. <strong>message</strong> is a string that is returned to the application
3305 to indicate what went wrong.</p></div>
3306 <div class="paragraph"><p>If the <strong>stacktrace</strong> argument is provided and is non-empty,
3307 it is used to initialize the stacktrace.</p></div>
3308 <div class="paragraph"><p>This feature is most useful in conjunction with the <em>catch</em> command:
3309 if a caught error cannot be handled successfully, <strong>stacktrace</strong> can be used
3310 to return a stack trace reflecting the original point of occurrence
3311 of the error:</p></div>
3312 <div class="literalblock">
3313 <div class="content">
3314 <pre><tt>catch {...} errMsg
3316 error $errMsg [info stacktrace]</tt></pre>
3317 </div></div>
3318 <div class="paragraph"><p>See also <em>errorInfo</em>, <em>info stacktrace</em>, <em>catch</em> and <em>return</em></p></div>
3319 </div>
3320 <div class="sect2">
3321 <h3 id="_errorinfo">errorInfo</h3>
3322 <div class="paragraph"><p><tt><strong>errorInfo</strong> <em>error ?stacktrace?</em></tt></p></div>
3323 <div class="paragraph"><p>Returns a human-readable representation of the given error message and stack trace.
3324 Typical usage is:</p></div>
3325 <div class="literalblock">
3326 <div class="content">
3327 <pre><tt>if {[catch {...} error]} {
3328 puts stderr [errorInfo $error [info stacktrace]]
3329 exit 1
3330 }</tt></pre>
3331 </div></div>
3332 <div class="paragraph"><p>See also <em>error</em>.</p></div>
3333 </div>
3334 <div class="sect2">
3335 <h3 id="_eval">eval</h3>
3336 <div class="paragraph"><p><tt><strong>eval</strong> <em>arg ?arg &#8230;?</em></tt></p></div>
3337 <div class="paragraph"><p><em>eval</em> takes one or more arguments, which together comprise a Tcl
3338 command (or collection of Tcl commands separated by newlines in the
3339 usual way). <em>eval</em> concatenates all its arguments in the same
3340 fashion as the <em>concat</em> command, passes the concatenated string to the
3341 Tcl interpreter recursively, and returns the result of that
3342 evaluation (or any error generated by it).</p></div>
3343 </div>
3344 <div class="sect2">
3345 <h3 id="_exec">exec</h3>
3346 <div class="paragraph"><p><tt><strong>exec</strong> <em>arg ?arg &#8230;?</em></tt></p></div>
3347 <div class="paragraph"><p>This command treats its arguments as the specification
3348 of one or more UNIX commands to execute as subprocesses.
3349 The commands take the form of a standard shell pipeline;
3350 <em>|</em> arguments separate commands in the
3351 pipeline and cause standard output of the preceding command
3352 to be piped into standard input of the next command (or <em>|&amp;</em> for
3353 both standard output and standard error).</p></div>
3354 <div class="paragraph"><p>Under normal conditions the result of the <em>exec</em> command
3355 consists of the standard output produced by the last command
3356 in the pipeline.</p></div>
3357 <div class="paragraph"><p>If any of the commands in the pipeline exit abnormally or
3358 are killed or suspended, then <em>exec</em> will return an error
3359 and the error message will include the pipeline&#8217;s output followed by
3360 error messages describing the abnormal terminations.</p></div>
3361 <div class="paragraph"><p>If any of the commands writes to its standard error file,
3362 then <em>exec</em> will return an error, and the error message
3363 will include the pipeline&#8217;s output, followed by messages
3364 about abnormal terminations (if any), followed by the standard error
3365 output.</p></div>
3366 <div class="paragraph"><p>If the last character of the result or error message
3367 is a newline then that character is deleted from the result
3368 or error message for consistency with normal
3369 Tcl return values.</p></div>
3370 <div class="paragraph"><p>An <strong>arg</strong> may have one of the following special forms:</p></div>
3371 <div class="dlist"><dl>
3372 <dt class="hdlist1">
3373 <tt>&gt;filename</tt>
3374 </dt>
3375 <dd>
3377 The standard output of the last command in the pipeline
3378 is redirected to the file. In this situation <em>exec</em>
3379 will normally return an empty string.
3380 </p>
3381 </dd>
3382 <dt class="hdlist1">
3383 <tt>&gt;&gt;filename</tt>
3384 </dt>
3385 <dd>
3387 As above, but append to the file.
3388 </p>
3389 </dd>
3390 <dt class="hdlist1">
3391 <tt>&gt;@fileId</tt>
3392 </dt>
3393 <dd>
3395 The standard output of the last command in the pipeline is
3396 redirected to the given (writable) file descriptor (e.g. stdout,
3397 stderr, or the result of <em>open</em>). In this situation <em>exec</em>
3398 will normally return an empty string.
3399 </p>
3400 </dd>
3401 <dt class="hdlist1">
3402 <tt>2&gt;filename</tt>
3403 </dt>
3404 <dd>
3406 The standard error of the last command in the pipeline
3407 is redirected to the file.
3408 </p>
3409 </dd>
3410 <dt class="hdlist1">
3411 <tt>2&gt;&gt;filename</tt>
3412 </dt>
3413 <dd>
3415 As above, but append to the file.
3416 </p>
3417 </dd>
3418 <dt class="hdlist1">
3419 <tt>2&gt;@fileId</tt>
3420 </dt>
3421 <dd>
3423 The standard error of the last command in the pipeline is
3424 redirected to the given (writable) file descriptor.
3425 </p>
3426 </dd>
3427 <dt class="hdlist1">
3428 <tt>2&gt;@1</tt>
3429 </dt>
3430 <dd>
3432 The standard error of the last command in the pipeline is
3433 redirected to the same file descriptor as the standard output.
3434 </p>
3435 </dd>
3436 <dt class="hdlist1">
3437 <tt>&gt;&amp;filename</tt>
3438 </dt>
3439 <dd>
3441 Both the standard output and standard error of the last command
3442 in the pipeline is redirected to the file.
3443 </p>
3444 </dd>
3445 <dt class="hdlist1">
3446 <tt>&gt;&gt;&amp;filename</tt>
3447 </dt>
3448 <dd>
3450 As above, but append to the file.
3451 </p>
3452 </dd>
3453 <dt class="hdlist1">
3454 <tt>&lt;filename</tt>
3455 </dt>
3456 <dd>
3458 The standard input of the first command in the pipeline
3459 is taken from the file.
3460 </p>
3461 </dd>
3462 <dt class="hdlist1">
3463 <tt>&lt;&lt;string</tt>
3464 </dt>
3465 <dd>
3467 The standard input of the first command is taken as the
3468 given immediate value.
3469 </p>
3470 </dd>
3471 <dt class="hdlist1">
3472 <tt>&lt;@fileId</tt>
3473 </dt>
3474 <dd>
3476 The standard input of the first command in the pipeline
3477 is taken from the given (readable) file descriptor.
3478 </p>
3479 </dd>
3480 </dl></div>
3481 <div class="paragraph"><p>If there is no redirection of standard input, standard error
3482 or standard output, these are connected to the corresponding
3483 input or output of the application.</p></div>
3484 <div class="paragraph"><p>If the last <strong>arg</strong> is <em>&amp;</em> then the command will be
3485 executed in background.
3486 In this case the standard output from the last command
3487 in the pipeline will
3488 go to the application&#8217;s standard output unless
3489 redirected in the command, and error output from all
3490 the commands in the pipeline will go to the application&#8217;s
3491 standard error file. The return value of exec in this case
3492 is a list of process ids (pids) in the pipeline.</p></div>
3493 <div class="paragraph"><p>Each <strong>arg</strong> becomes one word for a command, except for
3494 <em>|</em>, <em>&lt;</em>, <em>&lt;&lt;</em>, <em>&gt;</em>, and <em>&amp;</em> arguments, and the
3495 arguments that follow <em>&lt;</em>, <em>&lt;&lt;</em>, and <em>&gt;</em>.</p></div>
3496 <div class="paragraph"><p>The first word in each command is taken as the command name;
3497 the directories in the PATH environment variable are searched for
3498 an executable by the given name.</p></div>
3499 <div class="paragraph"><p>No <em>glob</em> expansion or other shell-like substitutions
3500 are performed on the arguments to commands.</p></div>
3501 <div class="paragraph"><p>If the command fails, the global $::errorCode (and the -errorcode
3502 option in <em>catch</em>) will be set to a list, as follows:</p></div>
3503 <div class="dlist"><dl>
3504 <dt class="hdlist1">
3505 <tt><strong>CHILDKILLED</strong> <em>pid sigName msg</em></tt>
3506 </dt>
3507 <dd>
3509 This format is used when a child process has been killed
3510 because of a signal. The pid element will be the process&#8217;s
3511 identifier (in decimal). The sigName element will be the
3512 symbolic name of the signal that caused the process to
3513 terminate; it will be one of the names from the include
3514 file signal.h, such as SIGPIPE. The msg element will be a
3515 short human-readable message describing the signal, such
3516 as "write on pipe with no readers" for SIGPIPE.
3517 </p>
3518 </dd>
3519 <dt class="hdlist1">
3520 <tt><strong>CHILDSUSP</strong> <em>pid sigName msg</em></tt>
3521 </dt>
3522 <dd>
3524 This format is used when a child process has been suspended
3525 because of a signal. The pid element will be the process&#8217;s
3526 identifier, in decimal. The sigName element will be the
3527 symbolic name of the signal that caused the process to
3528 suspend; this will be one of the names from the include
3529 file signal.h, such as SIGTTIN. The msg element will be a
3530 short human-readable message describing the signal, such
3531 as "background tty read" for SIGTTIN.
3532 </p>
3533 </dd>
3534 <dt class="hdlist1">
3535 <tt><strong>CHILDSTATUS</strong> <em>pid code</em></tt>
3536 </dt>
3537 <dd>
3539 This format is used when a child process has exited with a
3540 non-zero exit status. The pid element will be the process&#8217;s
3541 identifier (in decimal) and the code element will be the
3542 exit code returned by the process (also in decimal).
3543 </p>
3544 </dd>
3545 </dl></div>
3546 <div class="paragraph"><p>The environment for the executed command is set from $::env (unless
3547 this variable is unset, in which case the original environment is used).</p></div>
3548 </div>
3549 <div class="sect2">
3550 <h3 id="_exists">exists</h3>
3551 <div class="paragraph"><p><tt><strong>exists ?-var|-proc|-command?</strong> <em>name</em></tt></p></div>
3552 <div class="paragraph"><p>Checks the existence of the given variable, procedure or command
3553 respectively and returns 1 if it exists or 0 if not. This command
3554 provides a more simplified/convenient version of <em>info exists</em>,
3555 <em>info procs</em> and <em>info commands</em>.</p></div>
3556 <div class="paragraph"><p>If the type is omitted, a type of <em>-var</em> is used. The type may be abbreviated.</p></div>
3557 </div>
3558 <div class="sect2">
3559 <h3 id="_exit">exit</h3>
3560 <div class="paragraph"><p><tt><strong>exit</strong> <em>?returnCode?</em></tt></p></div>
3561 <div class="paragraph"><p>Terminate the process, returning <strong>returnCode</strong> to the
3562 parent as the exit status.</p></div>
3563 <div class="paragraph"><p>If <strong>returnCode</strong> isn&#8217;t specified then it defaults
3564 to 0.</p></div>
3565 <div class="paragraph"><p>Note that exit can be caught with <strong>catch</strong>.</p></div>
3566 </div>
3567 <div class="sect2">
3568 <h3 id="_expr">expr</h3>
3569 <div class="paragraph"><p><tt><strong>expr</strong> <em>arg</em></tt></p></div>
3570 <div class="paragraph"><p>Calls the expression processor to evaluate <strong>arg</strong>, and returns
3571 the result as a string. See the section EXPRESSIONS above.</p></div>
3572 <div class="paragraph"><p>Note that Jim supports a shorthand syntax for <em>expr</em> as <tt>$(&#8230;)</tt>
3573 The following two are identical.</p></div>
3574 <div class="literalblock">
3575 <div class="content">
3576 <pre><tt>set x [expr {3 * 2 + 1}]
3577 set x $(3 * 2 + 1)</tt></pre>
3578 </div></div>
3579 </div>
3580 <div class="sect2">
3581 <h3 id="_file">file</h3>
3582 <div class="paragraph"><p><tt><strong>file</strong> <em>option name ?arg arg &#8230;?</em></tt></p></div>
3583 <div class="paragraph"><p>Operate on a file or a file name. <strong>name</strong> is the name of a file.</p></div>
3584 <div class="paragraph"><p><strong>Option</strong> indicates what to do with the file name. Any unique
3585 abbreviation for <strong>option</strong> is acceptable. The valid options are:</p></div>
3586 <div class="dlist"><dl>
3587 <dt class="hdlist1">
3588 <tt><strong>file atime</strong> <em>name</em></tt>
3589 </dt>
3590 <dd>
3592 Return a decimal string giving the time at which file <strong>name</strong>
3593 was last accessed. The time is measured in the standard UNIX
3594 fashion as seconds from a fixed starting time (often January 1, 1970).
3595 If the file doesn&#8217;t exist or its access time cannot be queried then an
3596 error is generated.
3597 </p>
3598 </dd>
3599 <dt class="hdlist1">
3600 <tt><strong>file copy ?-force?</strong> <em>source target</em></tt>
3601 </dt>
3602 <dd>
3604 Copies file <strong>source</strong> to file <strong>target</strong>. The source file must exist.
3605 The target file must not exist, unless <strong>-force</strong> is specified.
3606 </p>
3607 </dd>
3608 <dt class="hdlist1">
3609 <tt><strong>file delete ?-force?</strong> <em>name &#8230;</em></tt>
3610 </dt>
3611 <dd>
3613 Deletes file or directory <strong>name</strong>. If the file or directory doesn&#8217;t exist, nothing happens.
3614 If it can&#8217;t be deleted, an error is generated. Non-empty directories will not be deleted
3615 unless the <em>-force</em> options is given. In this case no errors will be generated, even
3616 if the file/directory can&#8217;t be deleted.
3617 </p>
3618 </dd>
3619 <dt class="hdlist1">
3620 <tt><strong>file dirname</strong> <em>name</em></tt>
3621 </dt>
3622 <dd>
3624 Return all of the characters in <strong>name</strong> up to but not including
3625 the last slash character. If there are no slashes in <strong>name</strong>
3626 then return <em>.</em> (a single dot). If the last slash in <strong>name</strong> is its first
3627 character, then return <em>/</em>.
3628 </p>
3629 </dd>
3630 <dt class="hdlist1">
3631 <tt><strong>file executable</strong> <em>name</em></tt>
3632 </dt>
3633 <dd>
3635 Return <em>1</em> if file <strong>name</strong> is executable by
3636 the current user, <em>0</em> otherwise.
3637 </p>
3638 </dd>
3639 <dt class="hdlist1">
3640 <tt><strong>file exists</strong> <em>name</em></tt>
3641 </dt>
3642 <dd>
3644 Return <em>1</em> if file <strong>name</strong> exists and the current user has
3645 search privileges for the directories leading to it, <em>0</em> otherwise.
3646 </p>
3647 </dd>
3648 <dt class="hdlist1">
3649 <tt><strong>file extension</strong> <em>name</em></tt>
3650 </dt>
3651 <dd>
3653 Return all of the characters in <strong>name</strong> after and including the
3654 last dot in <strong>name</strong>. If there is no dot in <strong>name</strong> then return
3655 the empty string.
3656 </p>
3657 </dd>
3658 <dt class="hdlist1">
3659 <tt><strong>file isdirectory</strong> <em>name</em></tt>
3660 </dt>
3661 <dd>
3663 Return <em>1</em> if file <strong>name</strong> is a directory,
3664 <em>0</em> otherwise.
3665 </p>
3666 </dd>
3667 <dt class="hdlist1">
3668 <tt><strong>file isfile</strong> <em>name</em></tt>
3669 </dt>
3670 <dd>
3672 Return <em>1</em> if file <strong>name</strong> is a regular file,
3673 <em>0</em> otherwise.
3674 </p>
3675 </dd>
3676 <dt class="hdlist1">
3677 <tt><strong>file join</strong> <em>arg arg &#8230;</em></tt>
3678 </dt>
3679 <dd>
3681 Joins multiple path components. Note that if any components is
3682 an absolute path, the preceding components are ignored.
3683 Thus <em>file join /tmp /root</em> returns <em>/root</em>.
3684 </p>
3685 </dd>
3686 <dt class="hdlist1">
3687 <tt><strong>file lstat</strong> <em>name varName</em></tt>
3688 </dt>
3689 <dd>
3691 Same as <em>stat</em> option (see below) except uses the <strong>lstat</strong>
3692 kernel call instead of <strong>stat</strong>. This means that if <strong>name</strong>
3693 refers to a symbolic link the information returned in <strong>varName</strong>
3694 is for the link rather than the file it refers to. On systems that
3695 don&#8217;t support symbolic links this option behaves exactly the same
3696 as the <em>stat</em> option.
3697 </p>
3698 </dd>
3699 <dt class="hdlist1">
3700 <tt><strong>file mkdir</strong> <em>dir1 ?dir2? &#8230;</em></tt>
3701 </dt>
3702 <dd>
3704 Creates each directory specified. For each pathname <strong>dir</strong> specified,
3705 this command will create all non-existing parent directories
3706 as well as <strong>dir</strong> itself. If an existing directory is specified,
3707 then no action is taken and no error is returned. Trying to
3708 overwrite an existing file with a directory will result in an
3709 error. Arguments are processed in the order specified, halting
3710 at the first error, if any.
3711 </p>
3712 </dd>
3713 <dt class="hdlist1">
3714 <tt><strong>file mtime</strong> <em>name</em></tt>
3715 </dt>
3716 <dd>
3718 Return a decimal string giving the time at which file <strong>name</strong>
3719 was last modified. The time is measured in the standard UNIX
3720 fashion as seconds from a fixed starting time (often January 1, 1970).
3721 If the file doesn&#8217;t exist or its modified time cannot be queried then an
3722 error is generated.
3723 </p>
3724 </dd>
3725 <dt class="hdlist1">
3726 <tt><strong>file normalize</strong> <em>name</em></tt>
3727 </dt>
3728 <dd>
3730 Return the normalized path of <strong>name</strong>. See realpath(3).
3731 </p>
3732 </dd>
3733 <dt class="hdlist1">
3734 <tt><strong>file owned</strong> <em>name</em></tt>
3735 </dt>
3736 <dd>
3738 Return <em>1</em> if file <strong>name</strong> is owned by the current user,
3739 <em>0</em> otherwise.
3740 </p>
3741 </dd>
3742 <dt class="hdlist1">
3743 <tt><strong>file readable</strong> <em>name</em></tt>
3744 </dt>
3745 <dd>
3747 Return <em>1</em> if file <strong>name</strong> is readable by
3748 the current user, <em>0</em> otherwise.
3749 </p>
3750 </dd>
3751 <dt class="hdlist1">
3752 <tt><strong>file readlink</strong> <em>name</em></tt>
3753 </dt>
3754 <dd>
3756 Returns the value of the symbolic link given by <strong>name</strong> (i.e. the
3757 name of the file it points to). If
3758 <strong>name</strong> isn&#8217;t a symbolic link or its value cannot be read, then
3759 an error is returned. On systems that don&#8217;t support symbolic links
3760 this option is undefined.
3761 </p>
3762 </dd>
3763 <dt class="hdlist1">
3764 <tt><strong>file rename</strong> <em>oldname</em> <em>newname</em></tt>
3765 </dt>
3766 <dd>
3768 Renames the file from the old name to the new name.
3769 </p>
3770 </dd>
3771 <dt class="hdlist1">
3772 <tt><strong>file rootname</strong> <em>name</em></tt>
3773 </dt>
3774 <dd>
3776 Return all of the characters in <strong>name</strong> up to but not including
3777 the last <em>.</em> character in the name. If <strong>name</strong> doesn&#8217;t contain
3778 a dot, then return <strong>name</strong>.
3779 </p>
3780 </dd>
3781 <dt class="hdlist1">
3782 <tt><strong>file size</strong> <em>name</em></tt>
3783 </dt>
3784 <dd>
3786 Return a decimal string giving the size of file <strong>name</strong> in bytes.
3787 If the file doesn&#8217;t exist or its size cannot be queried then an
3788 error is generated.
3789 </p>
3790 </dd>
3791 <dt class="hdlist1">
3792 <tt><strong>file stat</strong> <em>name varName</em></tt>
3793 </dt>
3794 <dd>
3796 Invoke the <em>stat</em> kernel call on <strong>name</strong>, and use the
3797 variable given by <strong>varName</strong> to hold information returned from
3798 the kernel call.
3799 <strong>VarName</strong> is treated as an array variable,
3800 and the following elements of that variable are set: <em>atime</em>,
3801 <em>ctime</em>, <em>dev</em>, <em>gid</em>, <em>ino</em>, <em>mode</em>, <em>mtime</em>,
3802 <em>nlink</em>, <em>size</em>, <em>type</em>, <em>uid</em>.
3803 Each element except <em>type</em> is a decimal string with the value of
3804 the corresponding field from the <em>stat</em> return structure; see the
3805 manual entry for <em>stat</em> for details on the meanings of the values.
3806 The <em>type</em> element gives the type of the file in the same form
3807 returned by the command <em>file type</em>.
3808 This command returns an empty string.
3809 </p>
3810 </dd>
3811 <dt class="hdlist1">
3812 <tt><strong>file tail</strong> <em>name</em></tt>
3813 </dt>
3814 <dd>
3816 Return all of the characters in <strong>name</strong> after the last slash.
3817 If <strong>name</strong> contains no slashes then return <strong>name</strong>.
3818 </p>
3819 </dd>
3820 <dt class="hdlist1">
3821 <tt><strong>file tempfile</strong> <em>?template?</em></tt>
3822 </dt>
3823 <dd>
3825 Creates and returns the name of a unique temporary file. If <strong>template</strong> is omitted, a
3826 default template will be used to place the file in /tmp. See mkstemp(3) for
3827 the format of the template and security concerns.
3828 </p>
3829 </dd>
3830 <dt class="hdlist1">
3831 <tt><strong>file type</strong> <em>name</em></tt>
3832 </dt>
3833 <dd>
3835 Returns a string giving the type of file <strong>name</strong>, which will be
3836 one of <em>file</em>, <em>directory</em>, <em>characterSpecial</em>,
3837 <em>blockSpecial</em>, <em>fifo</em>, <em>link</em>, or <em>socket</em>.
3838 </p>
3839 </dd>
3840 <dt class="hdlist1">
3841 <tt><strong>file writable</strong> <em>name</em></tt>
3842 </dt>
3843 <dd>
3845 Return <em>1</em> if file <strong>name</strong> is writable by
3846 the current user, <em>0</em> otherwise.
3847 </p>
3848 </dd>
3849 </dl></div>
3850 <div class="paragraph"><p>The <em>file</em> commands that return 0/1 results are often used in
3851 conditional or looping commands, for example:</p></div>
3852 <div class="literalblock">
3853 <div class="content">
3854 <pre><tt>if {![file exists foo]} then {error {bad file name}} else {...}</tt></pre>
3855 </div></div>
3856 </div>
3857 <div class="sect2">
3858 <h3 id="_finalize">finalize</h3>
3859 <div class="paragraph"><p><tt><strong>finalize</strong> <em>reference ?command?</em></tt></p></div>
3860 <div class="paragraph"><p>If <strong>command</strong> is omitted, returns the finalizer command for the given reference.</p></div>
3861 <div class="paragraph"><p>Otherwise, sets a new finalizer command for the given reference. <strong>command</strong> may be
3862 the empty string to remove the current finalizer.</p></div>
3863 <div class="paragraph"><p>The reference must be a valid reference create with the <em>ref</em>
3864 command.</p></div>
3865 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3866 </div>
3867 <div class="sect2">
3868 <h3 id="_flush">flush</h3>
3869 <div class="paragraph"><p><tt><strong>flush</strong> <em>fileId</em></tt></p></div>
3870 <div class="paragraph"><p><tt><em>fileId</em> <strong>flush</strong></tt></p></div>
3871 <div class="paragraph"><p>Flushes any output that has been buffered for <strong>fileId</strong>. <strong>fileId</strong> must
3872 have been the return value from a previous call to <em>open</em>, or it may be
3873 <em>stdout</em> or <em>stderr</em> to access one of the standard I/O streams; it must
3874 refer to a file that was opened for writing. This command returns an
3875 empty string.</p></div>
3876 </div>
3877 <div class="sect2">
3878 <h3 id="_for">for</h3>
3879 <div class="paragraph"><p><tt><strong>for</strong> <em>start test next body</em></tt></p></div>
3880 <div class="paragraph"><p><em>For</em> is a looping command, similar in structure to the C <em>for</em> statement.
3881 The <strong>start</strong>, <strong>next</strong>, and <strong>body</strong> arguments must be Tcl command strings,
3882 and <strong>test</strong> is an expression string.</p></div>
3883 <div class="paragraph"><p>The <em>for</em> command first invokes the Tcl interpreter to execute <strong>start</strong>.
3884 Then it repeatedly evaluates <strong>test</strong> as an expression; if the result is
3885 non-zero it invokes the Tcl interpreter on <strong>body</strong>, then invokes the Tcl
3886 interpreter on <strong>next</strong>, then repeats the loop. The command terminates
3887 when <strong>test</strong> evaluates to 0.</p></div>
3888 <div class="paragraph"><p>If a <em>continue</em> command is invoked within <strong>body</strong> then any remaining
3889 commands in the current execution of <strong>body</strong> are skipped; processing
3890 continues by invoking the Tcl interpreter on <strong>next</strong>, then evaluating
3891 <strong>test</strong>, and so on.</p></div>
3892 <div class="paragraph"><p>If a <em>break</em> command is invoked within <strong>body</strong> or <strong>next</strong>, then the <em>for</em>
3893 command will return immediately.</p></div>
3894 <div class="paragraph"><p>The operation of <em>break</em> and <em>continue</em> are similar to the corresponding
3895 statements in C.</p></div>
3896 <div class="paragraph"><p><em>For</em> returns an empty string.</p></div>
3897 </div>
3898 <div class="sect2">
3899 <h3 id="_foreach">foreach</h3>
3900 <div class="paragraph"><p><tt><strong>foreach</strong> <em>varName list body</em></tt></p></div>
3901 <div class="paragraph"><p><tt><strong>foreach</strong> <em>varList list ?varList2 list2 &#8230;? body</em></tt></p></div>
3902 <div class="paragraph"><p>In this command, <strong>varName</strong> is the name of a variable, <strong>list</strong>
3903 is a list of values to assign to <strong>varName</strong>, and <strong>body</strong> is a
3904 collection of Tcl commands.</p></div>
3905 <div class="paragraph"><p>For each field in <strong>list</strong> (in order from left to right),<em>foreach</em> assigns
3906 the contents of the field to <strong>varName</strong> (as if the <em>lindex</em> command
3907 had been used to extract the field), then calls the Tcl interpreter to
3908 execute <strong>body</strong>.</p></div>
3909 <div class="paragraph"><p>If instead of being a simple name, <strong>varList</strong> is used, multiple assignments
3910 are made each time through the loop, one for each element of <strong>varList</strong>.</p></div>
3911 <div class="paragraph"><p>For example, if there are two elements in <strong>varList</strong> and six elements in
3912 the list, the loop will be executed three times.</p></div>
3913 <div class="paragraph"><p>If the length of the list doesn&#8217;t evenly divide by the number of elements
3914 in <strong>varList</strong>, the value of the remaining variables in the last iteration
3915 of the loop are undefined.</p></div>
3916 <div class="paragraph"><p>The <em>break</em> and <em>continue</em> statements may be invoked inside <strong>body</strong>,
3917 with the same effect as in the <em>for</em> command.</p></div>
3918 <div class="paragraph"><p><em>foreach</em> returns an empty string.</p></div>
3919 </div>
3920 <div class="sect2">
3921 <h3 id="_format">format</h3>
3922 <div class="paragraph"><p><tt><strong>format</strong> <em>formatString ?arg arg &#8230;?</em></tt></p></div>
3923 <div class="paragraph"><p>This command generates a formatted string in the same way as the
3924 C <em>sprintf</em> procedure (it uses <em>sprintf</em> in its
3925 implementation). <strong>FormatString</strong> indicates how to format
3926 the result, using <em>%</em> fields as in <em>sprintf</em>, and the additional
3927 arguments, if any, provide values to be substituted into the result.</p></div>
3928 <div class="paragraph"><p>All of the <em>sprintf</em> options are valid; see the <em>sprintf</em>
3929 man page for details. Each <strong>arg</strong> must match the expected type
3930 from the <em>%</em> field in <strong>formatString</strong>; the <em>format</em> command
3931 converts each argument to the correct type (floating, integer, etc.)
3932 before passing it to <em>sprintf</em> for formatting.</p></div>
3933 <div class="paragraph"><p>The only unusual conversion is for <em>%c</em>; in this case the argument
3934 must be a decimal string, which will then be converted to the corresponding
3935 ASCII character value.</p></div>
3936 <div class="paragraph"><p><em>Format</em> does backslash substitution on its <strong>formatString</strong>
3937 argument, so backslash sequences in <strong>formatString</strong> will be handled
3938 correctly even if the argument is in braces.</p></div>
3939 <div class="paragraph"><p>The return value from <em>format</em> is the formatted string.</p></div>
3940 </div>
3941 <div class="sect2">
3942 <h3 id="_getref">getref</h3>
3943 <div class="paragraph"><p><tt><strong>getref</strong> <em>reference</em></tt></p></div>
3944 <div class="paragraph"><p>Returns the string associated with <strong>reference</strong>. The reference must
3945 be a valid reference create with the <em>ref</em> command.</p></div>
3946 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
3947 </div>
3948 <div class="sect2">
3949 <h3 id="_gets">gets</h3>
3950 <div class="paragraph"><p><tt><strong>gets</strong> <em>fileId ?varName?</em></tt></p></div>
3951 <div class="paragraph"><p><tt><em>fileId</em> <strong>gets</strong> <em>?varName?</em></tt></p></div>
3952 <div class="paragraph"><p>Reads the next line from the file given by <strong>fileId</strong> and discards
3953 the terminating newline character.</p></div>
3954 <div class="paragraph"><p>If <strong>varName</strong> is specified, then the line is placed in the variable
3955 by that name and the return value is a count of the number of characters
3956 read (not including the newline).</p></div>
3957 <div class="paragraph"><p>If the end of the file is reached before reading
3958 any characters then -1 is returned and <strong>varName</strong> is set to an
3959 empty string.</p></div>
3960 <div class="paragraph"><p>If <strong>varName</strong> is not specified then the return value will be
3961 the line (minus the newline character) or an empty string if
3962 the end of the file is reached before reading any characters.</p></div>
3963 <div class="paragraph"><p>An empty string will also be returned if a line contains no characters
3964 except the newline, so <em>eof</em> may have to be used to determine
3965 what really happened.</p></div>
3966 <div class="paragraph"><p>If the last character in the file is not a newline character, then
3967 <em>gets</em> behaves as if there were an additional newline character
3968 at the end of the file.</p></div>
3969 <div class="paragraph"><p><strong>fileId</strong> must be <em>stdin</em> or the return value from a previous
3970 call to <em>open</em>; it must refer to a file that was opened
3971 for reading.</p></div>
3972 </div>
3973 <div class="sect2">
3974 <h3 id="_glob">glob</h3>
3975 <div class="paragraph"><p><tt><strong>glob</strong> ?<strong>-nocomplain</strong>? <em>pattern ?pattern &#8230;?</em></tt></p></div>
3976 <div class="paragraph"><p>This command performs filename globbing, using csh rules. The returned
3977 value from <em>glob</em> is the list of expanded filenames.</p></div>
3978 <div class="paragraph"><p>If <em>-nocomplain</em> is specified as the first argument then an empty
3979 list may be returned; otherwise an error is returned if the expanded
3980 list is empty. The <em>-nocomplain</em> argument must be provided
3981 exactly: an abbreviation will not be accepted.</p></div>
3982 </div>
3983 <div class="sect2">
3984 <h3 id="_global">global</h3>
3985 <div class="paragraph"><p><tt><strong>global</strong> <em>varName ?varName &#8230;?</em></tt></p></div>
3986 <div class="paragraph"><p>This command is ignored unless a Tcl procedure is being interpreted.
3987 If so, then it declares each given <strong>varName</strong> to be a global variable
3988 rather than a local one. For the duration of the current procedure
3989 (and only while executing in the current procedure), any reference to
3990 <strong>varName</strong> will be bound to a global variable instead
3991 of a local one.</p></div>
3992 <div class="paragraph"><p>An alternative to using <em>global</em> is to use the <em>::</em> prefix
3993 to explicitly name a variable in the global scope.</p></div>
3994 </div>
3995 <div class="sect2">
3996 <h3 id="_if">if</h3>
3997 <div class="paragraph"><p><tt><strong>if</strong> <em>expr1</em> ?<strong>then</strong>? <em>body1</em> <strong>elseif</strong> <em>expr2</em> ?<strong>then</strong>? <em>body2</em> <strong>elseif</strong> &#8230; ?<strong>else</strong>? ?<em>bodyN</em>?</tt></p></div>
3998 <div class="paragraph"><p>The <em>if</em> command evaluates <strong>expr1</strong> as an expression (in the same way
3999 that <em>expr</em> evaluates its argument). The value of the expression must
4000 be numeric; if it is non-zero then <strong>body1</strong> is executed by passing it to
4001 the Tcl interpreter.</p></div>
4002 <div class="paragraph"><p>Otherwise <strong>expr2</strong> is evaluated as an expression and if it is non-zero
4003 then <strong>body2</strong> is executed, and so on.</p></div>
4004 <div class="paragraph"><p>If none of the expressions evaluates to non-zero then <strong>bodyN</strong> is executed.</p></div>
4005 <div class="paragraph"><p>The <em>then</em> and <em>else</em> arguments are optional <em>noise words</em> to make the
4006 command easier to read.</p></div>
4007 <div class="paragraph"><p>There may be any number of <em>elseif</em> clauses, including zero. <strong>bodyN</strong>
4008 may also be omitted as long as <em>else</em> is omitted too.</p></div>
4009 <div class="paragraph"><p>The return value from the command is the result of the body script that
4010 was executed, or an empty string if none of the expressions was non-zero
4011 and there was no <strong>bodyN</strong>.</p></div>
4012 </div>
4013 <div class="sect2">
4014 <h3 id="_incr">incr</h3>
4015 <div class="paragraph"><p><tt><strong>incr</strong> <em>varName ?increment?</em></tt></p></div>
4016 <div class="paragraph"><p>Increment the value stored in the variable whose name is <strong>varName</strong>.
4017 The value of the variable must be integral.</p></div>
4018 <div class="paragraph"><p>If <strong>increment</strong> is supplied then its value (which must be an
4019 integer) is added to the value of variable <strong>varName</strong>; otherwise
4020 1 is added to <strong>varName</strong>.</p></div>
4021 <div class="paragraph"><p>The new value is stored as a decimal string in variable <strong>varName</strong>
4022 and also returned as result.</p></div>
4023 <div class="paragraph"><p>If the variable does not exist, the variable is implicitly created
4024 and set to <tt>0</tt> first.</p></div>
4025 </div>
4026 <div class="sect2">
4027 <h3 id="_info">info</h3>
4028 <div class="dlist"><dl>
4029 <dt class="hdlist1">
4030 <tt><strong>info</strong> <em>option ?arg arg &#8230;?</em></tt>
4031 </dt>
4032 <dd>
4034 Provide information about various internals to the Tcl interpreter.
4035 The legal <strong>option</strong>'s (which may be abbreviated) are:
4036 </p>
4037 </dd>
4038 <dt class="hdlist1">
4039 <tt><strong>info args</strong> <em>procname</em></tt>
4040 </dt>
4041 <dd>
4043 Returns a list containing the names of the arguments to procedure
4044 <strong>procname</strong>, in order. <strong>Procname</strong> must be the name of a
4045 Tcl command procedure.
4046 </p>
4047 </dd>
4048 <dt class="hdlist1">
4049 <tt><strong>info body</strong> <em>procname</em></tt>
4050 </dt>
4051 <dd>
4053 Returns the body of procedure <strong>procname</strong>. <strong>Procname</strong> must be
4054 the name of a Tcl command procedure.
4055 </p>
4056 </dd>
4057 <dt class="hdlist1">
4058 <tt><strong>info channels</strong></tt>
4059 </dt>
4060 <dd>
4062 Returns a list of all open file handles from <em>open</em> or <em>socket</em>
4063 </p>
4064 </dd>
4065 <dt class="hdlist1">
4066 <tt><strong>info commands</strong> ?<em>pattern</em>?</tt>
4067 </dt>
4068 <dd>
4070 If <strong>pattern</strong> isn&#8217;t specified, returns a list of names of all the
4071 Tcl commands, including both the built-in commands written in C and
4072 the command procedures defined using the <em>proc</em> command.
4073 If <strong>pattern</strong> is specified, only those names matching <strong>pattern</strong>
4074 are returned. Matching is determined using the same rules as for
4075 <em>string match</em>.
4076 </p>
4077 </dd>
4078 <dt class="hdlist1">
4079 <tt><strong>info complete</strong> <em>command</em> ?<em>missing</em>?</tt>
4080 </dt>
4081 <dd>
4083 Returns 1 if <strong>command</strong> is a complete Tcl command in the sense of
4084 having no unclosed quotes, braces, brackets or array element names,
4085 If the command doesn&#8217;t appear to be complete then 0 is returned.
4086 This command is typically used in line-oriented input environments
4087 to allow users to type in commands that span multiple lines; if the
4088 command isn&#8217;t complete, the script can delay evaluating it until additional
4089 lines have been typed to complete the command. If <strong>varName</strong> is specified, the
4090 missing character is stored in the variable with that name.
4091 </p>
4092 </dd>
4093 <dt class="hdlist1">
4094 <tt><strong>info exists</strong> <em>varName</em></tt>
4095 </dt>
4096 <dd>
4098 Returns <em>1</em> if the variable named <strong>varName</strong> exists in the
4099 current context (either as a global or local variable), returns <em>0</em>
4100 otherwise.
4101 </p>
4102 </dd>
4103 <dt class="hdlist1">
4104 <tt><strong>info frame</strong> ?<em>number</em>?</tt>
4105 </dt>
4106 <dd>
4108 If <strong>number</strong> is not specified, this command returns a number
4109 which is the same result as <em>info level</em> - the current stack frame level.
4110 If <strong>number</strong> is specified, then the result is a list consisting of the procedure,
4111 filename and line number for the procedure call at level <strong>number</strong> on the stack.
4112 If <strong>number</strong> is positive then it selects a particular stack level (1 refers
4113 to the top-most active procedure, 2 to the procedure it called, and
4114 so on); otherwise it gives a level relative to the current level
4115 (0 refers to the current procedure, -1 to its caller, and so on).
4116 The level has an identical meaning to <em>info level</em>.
4117 </p>
4118 </dd>
4119 <dt class="hdlist1">
4120 <tt><strong>info globals</strong> ?<em>pattern</em>?</tt>
4121 </dt>
4122 <dd>
4124 If <strong>pattern</strong> isn&#8217;t specified, returns a list of all the names
4125 of currently-defined global variables.
4126 If <strong>pattern</strong> is specified, only those names matching <strong>pattern</strong>
4127 are returned. Matching is determined using the same rules as for
4128 <em>string match</em>.
4129 </p>
4130 </dd>
4131 <dt class="hdlist1">
4132 <tt><strong>info hostname</strong></tt>
4133 </dt>
4134 <dd>
4136 An alias for <em>os.gethostname</em> for compatibility with Tcl 6.x
4137 </p>
4138 </dd>
4139 <dt class="hdlist1">
4140 <tt><strong>info level</strong> ?<em>number</em>?</tt>
4141 </dt>
4142 <dd>
4144 If <strong>number</strong> is not specified, this command returns a number
4145 giving the stack level of the invoking procedure, or 0 if the
4146 command is invoked at top-level. If <strong>number</strong> is specified,
4147 then the result is a list consisting of the name and arguments for the
4148 procedure call at level <strong>number</strong> on the stack. If <strong>number</strong>
4149 is positive then it selects a particular stack level (1 refers
4150 to the top-most active procedure, 2 to the procedure it called, and
4151 so on); otherwise it gives a level relative to the current level
4152 (0 refers to the current procedure, -1 to its caller, and so on).
4153 See the <em>uplevel</em> command for more information on what stack
4154 levels mean.
4155 </p>
4156 </dd>
4157 <dt class="hdlist1">
4158 <tt><strong>info locals</strong> ?<em>pattern</em>?</tt>
4159 </dt>
4160 <dd>
4162 If <strong>pattern</strong> isn&#8217;t specified, returns a list of all the names
4163 of currently-defined local variables, including arguments to the
4164 current procedure, if any. Variables defined with the <em>global</em>
4165 and <em>upvar</em> commands will not be returned. If <strong>pattern</strong> is
4166 specified, only those names matching <strong>pattern</strong> are returned.
4167 Matching is determined using the same rules as for <em>string match</em>.
4168 </p>
4169 </dd>
4170 <dt class="hdlist1">
4171 <tt><strong>info nameofexecutable</strong></tt>
4172 </dt>
4173 <dd>
4175 Returns the name of the binary file from which the application
4176 was invoked. A full path will be returned, unless the path
4177 can&#8217;t be determined, in which case the empty string will be returned.
4178 </p>
4179 </dd>
4180 <dt class="hdlist1">
4181 <tt><strong>info procs</strong> ?<em>pattern</em>?</tt>
4182 </dt>
4183 <dd>
4185 If <strong>pattern</strong> isn&#8217;t specified, returns a list of all the
4186 names of Tcl command procedures.
4187 If <strong>pattern</strong> is specified, only those names matching <strong>pattern</strong>
4188 are returned. Matching is determined using the same rules as for
4189 <em>string match</em>.
4190 </p>
4191 </dd>
4192 <dt class="hdlist1">
4193 <tt><strong>info references</strong></tt>
4194 </dt>
4195 <dd>
4197 Returns a list of all references which have not yet been garbage
4198 collected.
4199 </p>
4200 </dd>
4201 <dt class="hdlist1">
4202 <tt><strong>info returncodes</strong> ?<em>code</em>?</tt>
4203 </dt>
4204 <dd>
4206 Returns a list representing the mapping of standard return codes
4207 to names. e.g. <tt>{0 ok 1 error 2 return &#8230;}</tt>. If a code is given,
4208 instead returns the name for the given code.
4209 </p>
4210 </dd>
4211 <dt class="hdlist1">
4212 <tt><strong>info script</strong></tt>
4213 </dt>
4214 <dd>
4216 If a Tcl script file is currently being evaluated (i.e. there is a
4217 call to <em>Jim_EvalFile</em> active or there is an active invocation
4218 of the <em>source</em> command), then this command returns the name
4219 of the innermost file being processed. Otherwise the command returns an
4220 empty string.
4221 </p>
4222 </dd>
4223 <dt class="hdlist1">
4224 <tt><strong>info source</strong> <em>script</em></tt>
4225 </dt>
4226 <dd>
4228 Returns the original source location of the given script as a list of
4229 <tt>{filename linenumber}</tt>. If the source location can&#8217;t be determined, the
4230 list <tt>{{} 0}</tt> is returned.
4231 </p>
4232 </dd>
4233 <dt class="hdlist1">
4234 <tt><strong>info stacktrace</strong></tt>
4235 </dt>
4236 <dd>
4238 After an error is caught with <em>catch</em>, returns the stack trace as a list
4239 of <tt>{procedure filename line &#8230;}</tt>.
4240 </p>
4241 </dd>
4242 <dt class="hdlist1">
4243 <tt><strong>info version</strong></tt>
4244 </dt>
4245 <dd>
4247 Returns the version number for this version of Jim in the form <strong>x.yy</strong>.
4248 </p>
4249 </dd>
4250 <dt class="hdlist1">
4251 <tt><strong>info vars</strong> ?<em>pattern</em>?</tt>
4252 </dt>
4253 <dd>
4255 If <strong>pattern</strong> isn&#8217;t specified,
4256 returns a list of all the names of currently-visible variables, including
4257 both locals and currently-visible globals.
4258 If <strong>pattern</strong> is specified, only those names matching <strong>pattern</strong>
4259 are returned. Matching is determined using the same rules as for
4260 <em>string match</em>.
4261 </p>
4262 </dd>
4263 </dl></div>
4264 </div>
4265 <div class="sect2">
4266 <h3 id="_join">join</h3>
4267 <div class="paragraph"><p><tt><strong>join</strong> <em>list ?joinString?</em></tt></p></div>
4268 <div class="paragraph"><p>The <strong>list</strong> argument must be a valid Tcl list. This command returns the
4269 string formed by joining all of the elements of <strong>list</strong> together with
4270 <strong>joinString</strong> separating each adjacent pair of elements.</p></div>
4271 <div class="paragraph"><p>The <strong>joinString</strong> argument defaults to a space character.</p></div>
4272 </div>
4273 <div class="sect2">
4274 <h3 id="_kill">kill</h3>
4275 <div class="paragraph"><p><tt><strong>kill</strong> ?<em>SIG</em>|<strong>-0</strong>? <em>pid</em></tt></p></div>
4276 <div class="paragraph"><p>Sends the given signal to the process identified by <strong>pid</strong>.</p></div>
4277 <div class="paragraph"><p>The signal may be specified by name or number in one of the following forms:</p></div>
4278 <div class="ulist"><ul>
4279 <li>
4281 <tt>TERM</tt>
4282 </p>
4283 </li>
4284 <li>
4286 <tt>SIGTERM</tt>
4287 </p>
4288 </li>
4289 <li>
4291 <tt>-TERM</tt>
4292 </p>
4293 </li>
4294 <li>
4296 <tt>15</tt>
4297 </p>
4298 </li>
4299 <li>
4301 <tt>-15</tt>
4302 </p>
4303 </li>
4304 </ul></div>
4305 <div class="paragraph"><p>The signal name may be in either upper or lower case.</p></div>
4306 <div class="paragraph"><p>The special signal name <em>-0</em> simply checks that a signal <strong>could</strong> be sent.</p></div>
4307 <div class="paragraph"><p>If no signal is specified, SIGTERM is used.</p></div>
4308 <div class="paragraph"><p>An error is raised if the signal could not be delivered.</p></div>
4309 </div>
4310 <div class="sect2">
4311 <h3 id="_lambda_2">lambda</h3>
4312 <div class="paragraph"><p><tt><strong>lambda</strong> <em>args ?statics? body</em></tt></p></div>
4313 <div class="paragraph"><p>The <em>lambda</em> command is identical to <em>proc</em>, except rather than
4314 creating a named procedure, it creates an anonymous procedure and returns
4315 the name of the procedure.</p></div>
4316 <div class="paragraph"><p>See <em>proc</em> and GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
4317 </div>
4318 <div class="sect2">
4319 <h3 id="_lappend">lappend</h3>
4320 <div class="paragraph"><p><tt><strong>lappend</strong> <em>varName value ?value value &#8230;?</em></tt></p></div>
4321 <div class="paragraph"><p>Treat the variable given by <strong>varName</strong> as a list and append each of
4322 the <strong>value</strong> arguments to that list as a separate element, with spaces
4323 between elements.</p></div>
4324 <div class="paragraph"><p>If <strong>varName</strong> doesn&#8217;t exist, it is created as a list with elements given
4325 by the <strong>value</strong> arguments. <em>lappend</em> is similar to <em>append</em> except that
4326 each <strong>value</strong> is appended as a list element rather than raw text.</p></div>
4327 <div class="paragraph"><p>This command provides a relatively efficient way to build up large lists.
4328 For example, <em>lappend a $b</em> is much more efficient than</p></div>
4329 <div class="literalblock">
4330 <div class="content">
4331 <pre><tt>set a [concat $a [list $b]]</tt></pre>
4332 </div></div>
4333 <div class="paragraph"><p>when <em>$a</em> is long.</p></div>
4334 </div>
4335 <div class="sect2">
4336 <h3 id="_lassign">lassign</h3>
4337 <div class="paragraph"><p><tt><strong>lassign</strong> <em>list varName ?varName? &#8230;</em></tt></p></div>
4338 <div class="paragraph"><p>This command treats the value <strong>list</strong> as a list and assigns successive elements from that list to
4339 the variables given by the <strong>varName</strong> arguments in order. If there are more variable names than
4340 list elements, the remaining variables are set to the empty string. If there are more list ele-
4341 ments than variables, a list of unassigned elements is returned.</p></div>
4342 <div class="literalblock">
4343 <div class="content">
4344 <pre><tt>jim&gt; lassign {1 2 3} a b; puts a=$a,b=$b
4346 a=1,b=2</tt></pre>
4347 </div></div>
4348 </div>
4349 <div class="sect2">
4350 <h3 id="_local">local</h3>
4351 <div class="paragraph"><p><tt><strong>local</strong> <em>args</em></tt></p></div>
4352 <div class="paragraph"><p>Executes it&#8217;s arguments as a command (per <em>eval</em>) and considers the return
4353 value to be a procedure name, which is marked as having local scope.
4354 This means that when the current procedure exits, the specified
4355 procedure is deleted. This can be useful with <em>lambda</em> or simply
4356 local procedures.</p></div>
4357 <div class="paragraph"><p>In addition, if a command already exists with the same name,
4358 the existing command will be kept rather than deleted, and may be called
4359 via <em>upcall</em>. The previous command will be restored when the current
4360 command is deleted. See <em>upcall</em> for more details.</p></div>
4361 <div class="paragraph"><p>In this example, a local procedure is created. Note that the procedure
4362 continues to have global scope while it is active.</p></div>
4363 <div class="literalblock">
4364 <div class="content">
4365 <pre><tt>proc outer {} {
4366 # proc ... returns "inner" which is marked local
4367 local proc inner {} {
4368 # will be deleted when 'outer' exits
4369 }</tt></pre>
4370 </div></div>
4371 <div class="literalblock">
4372 <div class="content">
4373 <pre><tt> inner
4375 }</tt></pre>
4376 </div></div>
4377 <div class="paragraph"><p>In this example, the lambda is deleted at the end of the procedure rather
4378 than waiting until garbage collection.</p></div>
4379 <div class="literalblock">
4380 <div class="content">
4381 <pre><tt>proc outer {} {
4382 set x [lambda inner {args} {
4383 # will be deleted when 'outer' exits
4385 # Use 'function' here which simply returns $x
4386 local function $x</tt></pre>
4387 </div></div>
4388 <div class="literalblock">
4389 <div class="content">
4390 <pre><tt> $x ...
4392 }</tt></pre>
4393 </div></div>
4394 </div>
4395 <div class="sect2">
4396 <h3 id="_loop">loop</h3>
4397 <div class="paragraph"><p><tt><strong>loop</strong> <em>var first limit ?incr? body</em></tt></p></div>
4398 <div class="paragraph"><p>Similar to <em>for</em> except simpler and possibly more efficient.
4399 With a positive increment, equivalent to:</p></div>
4400 <div class="literalblock">
4401 <div class="content">
4402 <pre><tt>for {set var $first} {$var &lt; $limit} {incr var $incr} $body</tt></pre>
4403 </div></div>
4404 <div class="paragraph"><p>If <strong>incr</strong> is not specified, 1 is used.
4405 Note that setting the loop variable inside the loop does not
4406 affect the loop count.</p></div>
4407 </div>
4408 <div class="sect2">
4409 <h3 id="_lindex">lindex</h3>
4410 <div class="paragraph"><p><tt><strong>lindex</strong> <em>list index</em></tt></p></div>
4411 <div class="paragraph"><p>Treats <strong>list</strong> as a Tcl list and returns element <strong>index</strong> from it
4412 (0 refers to the first element of the list).
4413 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>index</strong>.</p></div>
4414 <div class="paragraph"><p>In extracting the element, <strong>lindex</strong> observes the same rules concerning
4415 braces and quotes and backslashes as the Tcl command interpreter; however,
4416 variable substitution and command substitution do not occur.</p></div>
4417 <div class="paragraph"><p>If <strong>index</strong> is negative or greater than or equal to the number of elements
4418 in <strong>value</strong>, then an empty string is returned.</p></div>
4419 </div>
4420 <div class="sect2">
4421 <h3 id="_linsert">linsert</h3>
4422 <div class="paragraph"><p><tt><strong>linsert</strong> <em>list index element ?element element &#8230;?</em></tt></p></div>
4423 <div class="paragraph"><p>This command produces a new list from <strong>list</strong> by inserting all
4424 of the <strong>element</strong> arguments just before the element <strong>index</strong>
4425 of <strong>list</strong>. Each <strong>element</strong> argument will become
4426 a separate element of the new list. If <strong>index</strong> is less than
4427 or equal to zero, then the new elements are inserted at the
4428 beginning of the list. If <strong>index</strong> is greater than or equal
4429 to the number of elements in the list, then the new elements are
4430 appended to the list.</p></div>
4431 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>index</strong>.</p></div>
4432 </div>
4433 <div class="sect2">
4434 <h3 id="_list">list</h3>
4435 <div class="paragraph"><p><tt><strong>list</strong> <em>arg ?arg &#8230;?</em></tt></p></div>
4436 <div class="paragraph"><p>This command returns a list comprised of all the arguments, <strong>arg</strong>. Braces
4437 and backslashes get added as necessary, so that the <em>index</em> command
4438 may be used on the result to re-extract the original arguments, and also
4439 so that <em>eval</em> may be used to execute the resulting list, with
4440 <strong>arg1</strong> comprising the command&#8217;s name and the other args comprising
4441 its arguments. <em>List</em> produces slightly different results than
4442 <em>concat</em>: <em>concat</em> removes one level of grouping before forming
4443 the list, while <em>list</em> works directly from the original arguments.
4444 For example, the command</p></div>
4445 <div class="literalblock">
4446 <div class="content">
4447 <pre><tt>list a b {c d e} {f {g h}}</tt></pre>
4448 </div></div>
4449 <div class="paragraph"><p>will return</p></div>
4450 <div class="literalblock">
4451 <div class="content">
4452 <pre><tt>a b {c d e} {f {g h}}</tt></pre>
4453 </div></div>
4454 <div class="paragraph"><p>while <em>concat</em> with the same arguments will return</p></div>
4455 <div class="literalblock">
4456 <div class="content">
4457 <pre><tt>a b c d e f {g h}</tt></pre>
4458 </div></div>
4459 </div>
4460 <div class="sect2">
4461 <h3 id="_llength">llength</h3>
4462 <div class="paragraph"><p><tt><strong>llength</strong> <em>list</em></tt></p></div>
4463 <div class="paragraph"><p>Treats <strong>list</strong> as a list and returns a decimal string giving
4464 the number of elements in it.</p></div>
4465 </div>
4466 <div class="sect2">
4467 <h3 id="_lset">lset</h3>
4468 <div class="paragraph"><p><tt><strong>lset</strong> <em>varName ?index ..? newValue</em></tt></p></div>
4469 <div class="paragraph"><p>Sets an element in a list.</p></div>
4470 <div class="paragraph"><p>The <em>lset</em> command accepts a parameter, <strong>varName</strong>, which it interprets
4471 as the name of a variable containing a Tcl list. It also accepts
4472 zero or more indices into the list. Finally, it accepts a new value
4473 for an element of varName. If no indices are presented, the command
4474 takes the form:</p></div>
4475 <div class="literalblock">
4476 <div class="content">
4477 <pre><tt>lset varName newValue</tt></pre>
4478 </div></div>
4479 <div class="paragraph"><p>In this case, newValue replaces the old value of the variable
4480 varName.</p></div>
4481 <div class="paragraph"><p>When presented with a single index, the <em>lset</em> command
4482 treats the content of the varName variable as a Tcl list. It addresses
4483 the index&#8217;th element in it (0 refers to the first element of the
4484 list). When interpreting the list, <em>lset</em> observes the same rules
4485 concerning braces and quotes and backslashes as the Tcl command
4486 interpreter; however, variable substitution and command substitution
4487 do not occur. The command constructs a new list in which the
4488 designated element is replaced with newValue. This new list is
4489 stored in the variable varName, and is also the return value from
4490 the <em>lset</em> command.</p></div>
4491 <div class="paragraph"><p>If index is negative or greater than or equal to the number of
4492 elements in $varName, then an error occurs.</p></div>
4493 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>index</strong>.</p></div>
4494 <div class="paragraph"><p>If additional index arguments are supplied, then each argument is
4495 used in turn to address an element within a sublist designated by
4496 the previous indexing operation, allowing the script to alter
4497 elements in sublists. The command,</p></div>
4498 <div class="literalblock">
4499 <div class="content">
4500 <pre><tt>lset a 1 2 newValue</tt></pre>
4501 </div></div>
4502 <div class="paragraph"><p>replaces element 2 of sublist 1 with <strong>newValue</strong>.</p></div>
4503 <div class="paragraph"><p>The integer appearing in each index argument must be greater than
4504 or equal to zero. The integer appearing in each index argument must
4505 be strictly less than the length of the corresponding list. In other
4506 words, the <em>lset</em> command cannot change the size of a list. If an
4507 index is outside the permitted range, an error is reported.</p></div>
4508 </div>
4509 <div class="sect2">
4510 <h3 id="_lmap">lmap</h3>
4511 <div class="paragraph"><p><tt><strong>lmap</strong> <em>varName list body</em></tt></p></div>
4512 <div class="paragraph"><p><tt><strong>lmap</strong> <em>varList list ?varList2 list2 &#8230;? body</em></tt></p></div>
4513 <div class="paragraph"><p><em>lmap</em> is a "collecting <em>foreach</em>" which returns a list of its results.</p></div>
4514 <div class="paragraph"><p>For example:</p></div>
4515 <div class="literalblock">
4516 <div class="content">
4517 <pre><tt>jim&gt; lmap i {1 2 3 4 5} {expr $i*$i}
4518 1 4 9 16 25
4519 jim&gt; lmap a {1 2 3} b {A B C} {list $a $b}
4520 {1 A} {2 B} {3 C}</tt></pre>
4521 </div></div>
4522 <div class="paragraph"><p>If the body invokes <em>continue</em>, no value is added for this iteration.
4523 If the body invokes <em>break</em>, the loop ends and no more values are added.</p></div>
4524 </div>
4525 <div class="sect2">
4526 <h3 id="_load">load</h3>
4527 <div class="paragraph"><p><tt><strong>load</strong> <em>filename</em></tt></p></div>
4528 <div class="paragraph"><p>Loads the dynamic extension, <strong>filename</strong>. Generally the filename should have
4529 the extension <em>.so</em>. The initialisation function for the module must be based
4530 on the name of the file. For example loading <tt>hwaccess.so</tt> will invoke
4531 the initialisation function, <tt>Jim_hwaccessInit</tt>. Normally the <em>load</em> command
4532 should not be used directly. Instead it is invoked automatically by <em>package require</em>.</p></div>
4533 </div>
4534 <div class="sect2">
4535 <h3 id="_lrange">lrange</h3>
4536 <div class="paragraph"><p><tt><strong>lrange</strong> <em>list first last</em></tt></p></div>
4537 <div class="paragraph"><p><strong>List</strong> must be a valid Tcl list. This command will return a new
4538 list consisting of elements <strong>first</strong> through <strong>last</strong>, inclusive.</p></div>
4539 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>first</strong> and <strong>last</strong>.</p></div>
4540 <div class="paragraph"><p>If <strong>last</strong> is greater than or equal to the number of elements
4541 in the list, then it is treated as if it were <em>end</em>.</p></div>
4542 <div class="paragraph"><p>If <strong>first</strong> is greater than <strong>last</strong> then an empty string
4543 is returned.</p></div>
4544 <div class="paragraph"><p>Note: <em>lrange <strong>list first first</strong></em> does not always produce the
4545 same result as <em>lindex <strong>list first</strong></em> (although it often does
4546 for simple fields that aren&#8217;t enclosed in braces); it does, however,
4547 produce exactly the same results as <em>list [lindex <strong>list first</strong>]</em></p></div>
4548 </div>
4549 <div class="sect2">
4550 <h3 id="_lreplace">lreplace</h3>
4551 <div class="paragraph"><p><tt><strong>lreplace</strong> <em>list first last ?element element &#8230;?</em></tt></p></div>
4552 <div class="paragraph"><p>Returns a new list formed by replacing one or more elements of
4553 <strong>list</strong> with the <strong>element</strong> arguments.</p></div>
4554 <div class="paragraph"><p><strong>First</strong> gives the index in <strong>list</strong> of the first element
4555 to be replaced.</p></div>
4556 <div class="paragraph"><p>If <strong>first</strong> is less than zero then it refers to the first
4557 element of <strong>list</strong>; the element indicated by <strong>first</strong>
4558 must exist in the list.</p></div>
4559 <div class="paragraph"><p><strong>Last</strong> gives the index in <strong>list</strong> of the last element
4560 to be replaced; it must be greater than or equal to <strong>first</strong>.</p></div>
4561 <div class="paragraph"><p>See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>first</strong> and <strong>last</strong>.</p></div>
4562 <div class="paragraph"><p>The <strong>element</strong> arguments specify zero or more new arguments to
4563 be added to the list in place of those that were deleted.</p></div>
4564 <div class="paragraph"><p>Each <strong>element</strong> argument will become a separate element of
4565 the list.</p></div>
4566 <div class="paragraph"><p>If no <strong>element</strong> arguments are specified, then the elements
4567 between <strong>first</strong> and <strong>last</strong> are simply deleted.</p></div>
4568 </div>
4569 <div class="sect2">
4570 <h3 id="_lrepeat">lrepeat</h3>
4571 <div class="paragraph"><p><tt><strong>lrepeat</strong> <em>number element1 ?element2 &#8230;?</em></tt></p></div>
4572 <div class="paragraph"><p>Build a list by repeating elements <strong>number</strong> times (which must be
4573 a positive integer).</p></div>
4574 <div class="literalblock">
4575 <div class="content">
4576 <pre><tt>jim&gt; lrepeat 3 a b
4577 a b a b a b</tt></pre>
4578 </div></div>
4579 </div>
4580 <div class="sect2">
4581 <h3 id="_lreverse">lreverse</h3>
4582 <div class="paragraph"><p><tt><strong>lreverse</strong> <em>list</em></tt></p></div>
4583 <div class="paragraph"><p>Returns the list in reverse order.</p></div>
4584 <div class="literalblock">
4585 <div class="content">
4586 <pre><tt>jim&gt; lreverse {1 2 3}
4587 3 2 1</tt></pre>
4588 </div></div>
4589 </div>
4590 <div class="sect2">
4591 <h3 id="_lsearch">lsearch</h3>
4592 <div class="paragraph"><p><tt><strong>lsearch</strong> <em>?options? list pattern</em></tt></p></div>
4593 <div class="paragraph"><p>This command searches the elements <strong>list</strong> to see if one of them matches <strong>pattern</strong>. If so, the
4594 command returns the index of the first matching element (unless the options -all, -inline or -bool are
4595 specified.) If not, the command returns -1. The option arguments indicates how the elements of
4596 the list are to be matched against pattern and must have one of the values below:</p></div>
4597 <div class="paragraph"><p><strong>Note</strong> that this command is different from Tcl in that default match type is <em>-exact</em> rather than <em>-glob</em>.</p></div>
4598 <div class="dlist"><dl>
4599 <dt class="hdlist1">
4600 <tt><em>-exact</em></tt>
4601 </dt>
4602 <dd>
4604 <strong>pattern</strong> is a literal string that is compared for exact equality against each list element.
4605 This is the default.
4606 </p>
4607 </dd>
4608 <dt class="hdlist1">
4609 <tt><em>-glob</em></tt>
4610 </dt>
4611 <dd>
4613 <strong>pattern</strong> is a glob-style pattern which is matched against each list element using the same
4614 rules as the string match command.
4615 </p>
4616 </dd>
4617 <dt class="hdlist1">
4618 <tt><em>-regexp</em></tt>
4619 </dt>
4620 <dd>
4622 <strong>pattern</strong> is treated as a regular expression and matched against each list element using
4623 the rules described by <em>regexp</em>.
4624 </p>
4625 </dd>
4626 <dt class="hdlist1">
4627 <tt><em>-all</em></tt>
4628 </dt>
4629 <dd>
4631 Changes the result to be the list of all matching indices (or all matching values if
4632 <em>-inline</em> is specified as well). If indices are returned, the indices will be in numeric
4633 order. If values are returned, the order of the values will be the order of those values
4634 within the input list.
4635 </p>
4636 </dd>
4637 <dt class="hdlist1">
4638 <tt><em>-inline</em></tt>
4639 </dt>
4640 <dd>
4642 The matching value is returned instead of its index (or an empty string if no value
4643 matches). If <em>-all</em> is also specified, then the result of the command is the list of all
4644 values that matched. The <em>-inline</em> and <em>-bool</em> options are mutually exclusive.
4645 </p>
4646 </dd>
4647 <dt class="hdlist1">
4648 <tt><em>-bool</em></tt>
4649 </dt>
4650 <dd>
4652 Changes the result to <em>1</em> if a match was found, or <em>0</em> otherwise. If <em>-all</em> is also specified,
4653 the result will be a list of <em>0</em> and <em>1</em> for each element of the list depending upon whether
4654 the corresponding element matches. The <em>-inline</em> and <em>-bool</em> options are mutually exclusive.
4655 </p>
4656 </dd>
4657 <dt class="hdlist1">
4658 <tt><em>-not</em></tt>
4659 </dt>
4660 <dd>
4662 This negates the sense of the match, returning the index (or value
4663 if <em>-inline</em> is specified) of the first non-matching value in the
4664 list. If <em>-bool</em> is also specified, the <em>0</em> will be returned if a
4665 match is found, or <em>1</em> otherwise. If <em>-all</em> is also specified,
4666 non-matches will be returned rather than matches.
4667 </p>
4668 </dd>
4669 <dt class="hdlist1">
4670 <tt><em>-nocase</em></tt>
4671 </dt>
4672 <dd>
4674 Causes comparisons to be handled in a case-insensitive manner.
4675 </p>
4676 </dd>
4677 </dl></div>
4678 </div>
4679 <div class="sect2">
4680 <h3 id="_lsort">lsort</h3>
4681 <div class="paragraph"><p><tt><strong>lsort</strong> ?<strong>-index</strong> <em>listindex</em>? ?<strong>-integer</strong>|<strong>-command</strong> <em>cmdname</em>? ?<strong>-decreasing</strong>|<strong>-increasing</strong>? <em>list</em></tt></p></div>
4682 <div class="paragraph"><p>Sort the elements of <strong>list</strong>, returning a new list in sorted order.
4683 By default, ASCII sorting is used, with the result in increasing order.</p></div>
4684 <div class="paragraph"><p>If <strong>-integer</strong> is specified, numeric sorting is used.</p></div>
4685 <div class="paragraph"><p>If <strong>-command cmdname</strong> is specified, <strong>cmdname</strong> is treated as a command
4686 name. For each comparison, <strong>cmdname $value1 $value2</strong> is called which
4687 should compare the values and return an integer less than, equal
4688 to, or greater than zero if the <strong>$value1</strong> is to be considered less
4689 than, equal to, or greater than <strong>$value2</strong>, respectively.</p></div>
4690 <div class="paragraph"><p>If <strong>-decreasing</strong> is specified, the resulting list is in the opposite
4691 order to what it would be otherwise. <strong>-increasing</strong> is the default.</p></div>
4692 <div class="paragraph"><p>If <strong>-index listindex</strong> is specified, each element of the list is treated as a list and
4693 the given index is extracted from the list for comparison. The list index may
4694 be any valid list index, such as <em>1</em>, <em>end</em> or <em>end-2</em>.</p></div>
4695 <div class="paragraph"><p>If <strong>-index listindex</strong> is specified, each element of the list is treated as a list and
4696 the given index is extracted from the list for comparison. The list index may
4697 be any valid list index, such as <em>1</em>, <em>end</em> or <em>end-2</em>.</p></div>
4698 </div>
4699 <div class="sect2">
4700 <h3 id="_open">open</h3>
4701 <div class="paragraph"><p><tt><strong>open</strong> <em>fileName ?access?</em></tt></p></div>
4702 <div class="paragraph"><p><tt><strong>open</strong> <em>|command-pipeline ?access?</em></tt></p></div>
4703 <div class="paragraph"><p>Opens a file and returns an identifier
4704 that may be used in future invocations
4705 of commands like <em>read</em>, <em>puts</em>, and <em>close</em>.
4706 <strong>fileName</strong> gives the name of the file to open.</p></div>
4707 <div class="paragraph"><p>The <strong>access</strong> argument indicates the way in which the file is to be accessed.
4708 It may have any of the following values:</p></div>
4709 <div class="dlist"><dl>
4710 <dt class="hdlist1">
4711 <tt>r</tt>
4712 </dt>
4713 <dd>
4715 Open the file for reading only; the file must already exist.
4716 </p>
4717 </dd>
4718 <dt class="hdlist1">
4719 <tt>r</tt>+
4720 </dt>
4721 <dd>
4723 Open the file for both reading and writing; the file must
4724 already exist.
4725 </p>
4726 </dd>
4727 <dt class="hdlist1">
4728 <tt>w</tt>
4729 </dt>
4730 <dd>
4732 Open the file for writing only. Truncate it if it exists. If it doesn&#8217;t
4733 exist, create a new file.
4734 </p>
4735 </dd>
4736 <dt class="hdlist1">
4737 <tt>w</tt>+
4738 </dt>
4739 <dd>
4741 Open the file for reading and writing. Truncate it if it exists.
4742 If it doesn&#8217;t exist, create a new file.
4743 </p>
4744 </dd>
4745 <dt class="hdlist1">
4746 <tt>a</tt>
4747 </dt>
4748 <dd>
4750 Open the file for writing only. The file must already exist, and the file
4751 is positioned so that new data is appended to the file.
4752 </p>
4753 </dd>
4754 <dt class="hdlist1">
4755 <tt>a</tt>+
4756 </dt>
4757 <dd>
4759 Open the file for reading and writing. If the file doesn&#8217;t
4760 exist, create a new empty file. Set the initial access position
4761 to the end of the file.
4762 </p>
4763 </dd>
4764 </dl></div>
4765 <div class="paragraph"><p><strong>Access</strong> defaults to <em>r</em>.</p></div>
4766 <div class="paragraph"><p>If a file is opened for both reading and writing, then <em>seek</em>
4767 must be invoked between a read and a write, or vice versa.</p></div>
4768 <div class="paragraph"><p>If the first character of <strong>fileName</strong> is "|" then the remaining
4769 characters of <strong>fileName</strong> are treated as a list of arguments that
4770 describe a command pipeline to invoke, in the same style as the
4771 arguments for exec. In this case, the channel identifier returned
4772 by open may be used to write to the command&#8217;s input pipe or read
4773 from its output pipe, depending on the value of <strong>access</strong>. If write-only
4774 access is used (e.g. <strong>access</strong> is <em>w</em>), then standard output for the
4775 pipeline is directed to the current standard output unless overridden
4776 by the command. If read-only access is used (e.g. <strong>access</strong> is r),
4777 standard input for the pipeline is taken from the current standard
4778 input unless overridden by the command.</p></div>
4779 <div class="paragraph"><p>The <em>pid</em> command may be used to return the process ids of the commands
4780 forming the command pipeline.</p></div>
4781 <div class="paragraph"><p>See also <em>socket</em>, <em>pid</em>, <em>exec</em></p></div>
4782 </div>
4783 <div class="sect2">
4784 <h3 id="_package">package</h3>
4785 <div class="paragraph"><p><tt><strong>package provide</strong> <em>name ?version?</em></tt></p></div>
4786 <div class="paragraph"><p>Indicates that the current script provides the package named <strong>name</strong>.
4787 If no version is specified, <em>1.0</em> is used.</p></div>
4788 <div class="paragraph"><p>Any script which provides a package may include this statement
4789 as the first statement, although it is not required.</p></div>
4790 <div class="paragraph"><p><tt><strong>package require</strong> <em>name ?version?</em>*</tt></p></div>
4791 <div class="paragraph"><p>Searches for the package with the given <strong>name</strong> by examining each path
4792 in <em>$::auto_path</em> and trying to load <em>$path/$name.so</em> as a dynamic extension,
4793 or <em>$path/$name.tcl</em> as a script package.</p></div>
4794 <div class="paragraph"><p>The first such file which is found is considered to provide the the package.
4795 (The version number is ignored).</p></div>
4796 <div class="paragraph"><p>If <em>$name.so</em> exists, it is loaded with the <em>load</em> command,
4797 otherwise if <em>$name.tcl</em> exists it is loaded with the <em>source</em> command.</p></div>
4798 <div class="paragraph"><p>If <em>load</em> or <em>source</em> fails, <em>package require</em> will fail immediately.
4799 No further attempt will be made to locate the file.</p></div>
4800 </div>
4801 <div class="sect2">
4802 <h3 id="_pid">pid</h3>
4803 <div class="paragraph"><p><tt><strong>pid</strong></tt></p></div>
4804 <div class="paragraph"><p><tt><strong>pid</strong> <em>fileId</em></tt></p></div>
4805 <div class="paragraph"><p>The first form returns the process identifier of the current process.</p></div>
4806 <div class="paragraph"><p>The second form accepts a handle returned by <em>open</em> and returns a list
4807 of the process ids forming the pipeline in the same form as <em>exec &#8230; &amp;</em>.
4808 If <em>fileId</em> represents a regular file handle rather than a command pipeline,
4809 the empty string is returned instead.</p></div>
4810 <div class="paragraph"><p>See also <em>open</em>, <em>exec</em></p></div>
4811 </div>
4812 <div class="sect2">
4813 <h3 id="_proc">proc</h3>
4814 <div class="paragraph"><p><tt><strong>proc</strong> <em>name args ?statics? body</em></tt></p></div>
4815 <div class="paragraph"><p>The <em>proc</em> command creates a new Tcl command procedure, <strong>name</strong>.
4816 When the new command is invoked, the contents of <strong>body</strong> will be executed.
4817 Tcl interpreter. <strong>args</strong> specifies the formal arguments to the procedure.
4818 If specified, <strong>static</strong>, declares static variables which are bound to the
4819 procedure.</p></div>
4820 <div class="paragraph"><p>See PROCEDURES for detailed information about Tcl procedures.</p></div>
4821 <div class="paragraph"><p>The <em>proc</em> command returns <strong>name</strong> (which is useful with <em>local</em>).</p></div>
4822 <div class="paragraph"><p>When a procedure is invoked, the procedure&#8217;s return value is the
4823 value specified in a <em>return</em> command. If the procedure doesn&#8217;t
4824 execute an explicit <em>return</em>, then its return value is the value
4825 of the last command executed in the procedure&#8217;s body.</p></div>
4826 <div class="paragraph"><p>If an error occurs while executing the procedure body, then the
4827 procedure-as-a-whole will return that same error.</p></div>
4828 </div>
4829 <div class="sect2">
4830 <h3 id="_puts">puts</h3>
4831 <div class="paragraph"><p><tt><strong>puts</strong> ?<strong>-nonewline</strong>? <em>?fileId? string</em></tt></p></div>
4832 <div class="paragraph"><p><tt><em>fileId</em> <strong>puts</strong> ?<strong>-nonewline</strong>? <em>string</em></tt></p></div>
4833 <div class="paragraph"><p>Writes the characters given by <strong>string</strong> to the file given
4834 by <strong>fileId</strong>. <strong>fileId</strong> must have been the return
4835 value from a previous call to <em>open</em>, or it may be
4836 <em>stdout</em> or <em>stderr</em> to refer to one of the standard I/O
4837 channels; it must refer to a file that was opened for
4838 writing.</p></div>
4839 <div class="paragraph"><p>In the first form, if no <strong>fileId</strong> is specified then it defaults to <em>stdout</em>.
4840 <em>puts</em> normally outputs a newline character after <strong>string</strong>,
4841 but this feature may be suppressed by specifying the <em>-nonewline</em>
4842 switch.</p></div>
4843 <div class="paragraph"><p>Output to files is buffered internally by Tcl; the <em>flush</em>
4844 command may be used to force buffered characters to be output.</p></div>
4845 </div>
4846 <div class="sect2">
4847 <h3 id="_pwd">pwd</h3>
4848 <div class="paragraph"><p><tt><strong>pwd</strong></tt></p></div>
4849 <div class="paragraph"><p>Returns the path name of the current working directory.</p></div>
4850 </div>
4851 <div class="sect2">
4852 <h3 id="_rand">rand</h3>
4853 <div class="paragraph"><p><tt><strong>rand</strong> <em>?min? ?max?</em></tt></p></div>
4854 <div class="paragraph"><p>Returns a random integer between <strong>min</strong> (defaults to 0) and <strong>max</strong>
4855 (defaults to the maximum integer).</p></div>
4856 <div class="paragraph"><p>If only one argument is given, it is interpreted as <strong>max</strong>.</p></div>
4857 </div>
4858 <div class="sect2">
4859 <h3 id="_range">range</h3>
4860 <div class="paragraph"><p><tt><strong>range</strong> <em>?start? end ?step?</em></tt></p></div>
4861 <div class="paragraph"><p>Returns a list of integers starting at <strong>start</strong> (defaults to 0)
4862 and ranging up to but not including <strong>end</strong> in steps of <strong>step</strong> defaults to 1).</p></div>
4863 <div class="literalblock">
4864 <div class="content">
4865 <pre><tt>jim&gt; range 5
4866 0 1 2 3 4
4867 jim&gt; range 2 5
4868 2 3 4
4869 jim&gt; range 2 10 4
4871 jim&gt; range 7 4 -2
4872 7 5</tt></pre>
4873 </div></div>
4874 </div>
4875 <div class="sect2">
4876 <h3 id="_read">read</h3>
4877 <div class="paragraph"><p><tt><strong>read</strong> ?<strong>-nonewline</strong>? <em>fileId</em></tt></p></div>
4878 <div class="paragraph"><p><tt><em>fileId</em> <strong>read</strong> ?<strong>-nonewline</strong>?</tt></p></div>
4879 <div class="paragraph"><p><tt><strong>read</strong> <em>fileId numBytes</em></tt></p></div>
4880 <div class="paragraph"><p><tt><em>fileId</em> <strong>read</strong> <em>numBytes</em></tt></p></div>
4881 <div class="paragraph"><p>In the first form, all of the remaining bytes are read from the file
4882 given by <strong>fileId</strong>; they are returned as the result of the command.
4883 If the <em>-nonewline</em> switch is specified then the last
4884 character of the file is discarded if it is a newline.</p></div>
4885 <div class="paragraph"><p>In the second form, the extra argument specifies how many bytes to read;
4886 exactly this many bytes will be read and returned, unless there are fewer than
4887 <strong>numBytes</strong> bytes left in the file; in this case, all the remaining
4888 bytes are returned.</p></div>
4889 <div class="paragraph"><p><strong>fileId</strong> must be <em>stdin</em> or the return value from a previous call
4890 to <em>open</em>; it must refer to a file that was opened for reading.</p></div>
4891 </div>
4892 <div class="sect2">
4893 <h3 id="_regexp">regexp</h3>
4894 <div class="paragraph"><p><tt><strong>regexp ?-nocase? ?-line? ?-indices? ?-start</strong> <em>offset</em>? <strong>?-all? ?-inline? ?--?</strong> <em>exp string ?matchVar? ?subMatchVar subMatchVar &#8230;?</em></tt></p></div>
4895 <div class="paragraph"><p>Determines whether the regular expression <strong>exp</strong> matches part or
4896 all of <strong>string</strong> and returns 1 if it does, 0 if it doesn&#8217;t.</p></div>
4897 <div class="paragraph"><p>See REGULAR EXPRESSIONS above for complete information on the
4898 syntax of <strong>exp</strong> and how it is matched against <strong>string</strong>.</p></div>
4899 <div class="paragraph"><p>If additional arguments are specified after <strong>string</strong> then they
4900 are treated as the names of variables to use to return
4901 information about which part(s) of <strong>string</strong> matched <strong>exp</strong>.
4902 <strong>matchVar</strong> will be set to the range of <strong>string</strong> that
4903 matched all of <strong>exp</strong>. The first <strong>subMatchVar</strong> will contain
4904 the characters in <strong>string</strong> that matched the leftmost parenthesized
4905 subexpression within <strong>exp</strong>, the next <strong>subMatchVar</strong> will
4906 contain the characters that matched the next parenthesized
4907 subexpression to the right in <strong>exp</strong>, and so on.</p></div>
4908 <div class="paragraph"><p>Normally, <strong>matchVar</strong> and the each <strong>subMatchVar</strong> are set to hold the
4909 matching characters from <em>string</em>, however see <em>-indices</em> and
4910 <em>-inline</em> below.</p></div>
4911 <div class="paragraph"><p>If there are more values for <strong>subMatchVar</strong> than parenthesized subexpressions
4912 within <strong>exp</strong>, or if a particular subexpression in <strong>exp</strong> doesn&#8217;t
4913 match the string (e.g. because it was in a portion of the expression
4914 that wasn&#8217;t matched), then the corresponding <strong>subMatchVar</strong> will be
4915 set to <em>"-1 -1"</em> if <em>-indices</em> has been specified or to an empty
4916 string otherwise.</p></div>
4917 <div class="paragraph"><p>The following switches modify the behaviour of <strong>regexp</strong></p></div>
4918 <div class="dlist"><dl>
4919 <dt class="hdlist1">
4920 <tt><strong>-nocase</strong></tt>
4921 </dt>
4922 <dd>
4924 Causes upper-case and lower-case characters to be treated as
4925 identical during the matching process.
4926 </p>
4927 </dd>
4928 <dt class="hdlist1">
4929 <tt><strong>-line</strong></tt>
4930 </dt>
4931 <dd>
4933 Use newline-sensitive matching. By default, newline
4934 is a completely ordinary character with no special meaning in
4935 either REs or strings. With this flag, <em>[<sup></em> bracket expressions
4936 and <em>.</em> never match newline, a <em></sup></em> anchor matches the null
4937 string after any newline in the string in addition to its normal
4938 function, and the <em>$</em> anchor matches the null string before any
4939 newline in the string in addition to its normal function.
4940 </p>
4941 </dd>
4942 <dt class="hdlist1">
4943 <tt><strong>-indices</strong></tt>
4944 </dt>
4945 <dd>
4947 Changes what is stored in the subMatchVars. Instead of
4948 storing the matching characters from string, each variable
4949 will contain a list of two decimal strings giving the indices
4950 in string of the first and last characters in the matching
4951 range of characters.
4952 </p>
4953 </dd>
4954 <dt class="hdlist1">
4955 <tt><strong>-start</strong> <em>offset</em></tt>
4956 </dt>
4957 <dd>
4959 Specifies a character index offset into the string at which to start
4960 matching the regular expression. If <em>-indices</em> is
4961 specified, the indices will be indexed starting from the
4962 absolute beginning of the input string. <strong>offset</strong> will be
4963 constrained to the bounds of the input string.
4964 </p>
4965 </dd>
4966 <dt class="hdlist1">
4967 <tt><strong>-all</strong></tt>
4968 </dt>
4969 <dd>
4971 Causes the regular expression to be matched as many times as possible
4972 in the string, returning the total number of matches found. If this
4973 is specified with match variables, they will contain information
4974 for the last match only.
4975 </p>
4976 </dd>
4977 <dt class="hdlist1">
4978 <tt><strong>-inline</strong></tt>
4979 </dt>
4980 <dd>
4982 Causes the command to return, as a list, the data that would otherwise
4983 be placed in match variables. When using <em>-inline</em>, match variables
4984 may not be specified. If used with <em>-all</em>, the list will be concatenated
4985 at each iteration, such that a flat list is always returned. For
4986 each match iteration, the command will append the overall match
4987 data, plus one element for each subexpression in the regular
4988 expression.
4989 </p>
4990 </dd>
4991 <dt class="hdlist1">
4992 <tt><strong>--</strong></tt>
4993 </dt>
4994 <dd>
4996 Marks the end of switches. The argument following this one will be
4997 treated as <strong>exp</strong> even if it starts with a <tt>-</tt>.
4998 </p>
4999 </dd>
5000 </dl></div>
5001 </div>
5002 <div class="sect2">
5003 <h3 id="_regsub">regsub</h3>
5004 <div class="paragraph"><p><tt><strong>regsub ?-nocase? ?-all? ?-line? ?-start</strong> <em>offset</em>? ?<strong>--</strong>? <em>exp string subSpec ?varName?</em></tt></p></div>
5005 <div class="paragraph"><p>This command matches the regular expression <strong>exp</strong> against
5006 <strong>string</strong> using the rules described in REGULAR EXPRESSIONS
5007 above.</p></div>
5008 <div class="paragraph"><p>If <strong>varName</strong> is specified, the commands stores <strong>string</strong> to <strong>varName</strong>
5009 with the substitutions detailed below, and returns the number of
5010 substitutions made (normally 1 unless <em>-all</em> is specified).
5011 This is 0 if there were no matches.</p></div>
5012 <div class="paragraph"><p>If <strong>varName</strong> is not specified, the substituted string will be returned
5013 instead.</p></div>
5014 <div class="paragraph"><p>When copying <strong>string</strong>, the portion of <strong>string</strong> that
5015 matched <strong>exp</strong> is replaced with <strong>subSpec</strong>.
5016 If <strong>subSpec</strong> contains a <em>&amp;</em> or <em>\0</em>, then it is replaced
5017 in the substitution with the portion of <strong>string</strong> that
5018 matched <strong>exp</strong>.</p></div>
5019 <div class="paragraph"><p>If <strong>subSpec</strong> contains a <em>\<strong>n</strong></em>, where <strong>n</strong> is a digit
5020 between 1 and 9, then it is replaced in the substitution with
5021 the portion of <strong>string</strong> that matched the <strong>n</strong>-th
5022 parenthesized subexpression of <strong>exp</strong>.
5023 Additional backslashes may be used in <strong>subSpec</strong> to prevent special
5024 interpretation of <em>&amp;</em> or <em>\0</em> or <em>\<strong>n</strong></em> or
5025 backslash.</p></div>
5026 <div class="paragraph"><p>The use of backslashes in <strong>subSpec</strong> tends to interact badly
5027 with the Tcl parser&#8217;s use of backslashes, so it&#8217;s generally
5028 safest to enclose <strong>subSpec</strong> in braces if it includes
5029 backslashes.</p></div>
5030 <div class="paragraph"><p>The following switches modify the behaviour of <strong>regsub</strong></p></div>
5031 <div class="dlist"><dl>
5032 <dt class="hdlist1">
5033 <tt><strong>-nocase</strong></tt>
5034 </dt>
5035 <dd>
5037 Upper-case characters in <strong>string</strong> are converted to lower-case
5038 before matching against <strong>exp</strong>; however, substitutions
5039 specified by <strong>subSpec</strong> use the original unconverted form
5040 of <strong>string</strong>.
5041 </p>
5042 </dd>
5043 <dt class="hdlist1">
5044 <tt><strong>-all</strong></tt>
5045 </dt>
5046 <dd>
5048 All ranges in <strong>string</strong> that match <strong>exp</strong> are found and substitution
5049 is performed for each of these ranges, rather than only the
5050 first. The <em>&amp;</em> and <em>\<strong>n</strong></em> sequences are handled for
5051 each substitution using the information from the corresponding
5052 match.
5053 </p>
5054 </dd>
5055 <dt class="hdlist1">
5056 <tt><strong>-line</strong></tt>
5057 </dt>
5058 <dd>
5060 Use newline-sensitive matching. By default, newline
5061 is a completely ordinary character with no special meaning in
5062 either REs or strings. With this flag, <em>[<sup></em> bracket expressions
5063 and <em>.</em> never match newline, a <em></sup></em> anchor matches the null
5064 string after any newline in the string in addition to its normal
5065 function, and the <em>$</em> anchor matches the null string before any
5066 newline in the string in addition to its normal function.
5067 </p>
5068 </dd>
5069 <dt class="hdlist1">
5070 <tt><strong>-start</strong> <em>offset</em></tt>
5071 </dt>
5072 <dd>
5074 Specifies a character index offset into the string at which to
5075 start matching the regular expression. <strong>offset</strong> will be
5076 constrained to the bounds of the input string.
5077 </p>
5078 </dd>
5079 <dt class="hdlist1">
5080 <tt><strong>--</strong></tt>
5081 </dt>
5082 <dd>
5084 Marks the end of switches. The argument following this one will be
5085 treated as <strong>exp</strong> even if it starts with a <tt>-</tt>.
5086 </p>
5087 </dd>
5088 </dl></div>
5089 </div>
5090 <div class="sect2">
5091 <h3 id="_ref">ref</h3>
5092 <div class="paragraph"><p><tt><strong>ref</strong> <em>string tag ?finalizer?</em></tt></p></div>
5093 <div class="paragraph"><p>Create a new reference containing <strong>string</strong> of type <strong>tag</strong>.
5094 If <strong>finalizer</strong> is specified, it is a command which will be invoked
5095 when the a garbage collection cycle runs and this reference is
5096 no longer accessible.</p></div>
5097 <div class="paragraph"><p>The finalizer is invoked as:</p></div>
5098 <div class="literalblock">
5099 <div class="content">
5100 <pre><tt>+finalizer 'reference string'+</tt></pre>
5101 </div></div>
5102 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5103 </div>
5104 <div class="sect2">
5105 <h3 id="_rename">rename</h3>
5106 <div class="paragraph"><p><tt><strong>rename</strong> <em>oldName newName</em></tt></p></div>
5107 <div class="paragraph"><p>Rename the command that used to be called <strong>oldName</strong> so that it
5108 is now called <strong>newName</strong>. If <strong>newName</strong> is an empty string
5109 (e.g. {}) then <strong>oldName</strong> is deleted. The <em>rename</em> command
5110 returns an empty string as result.</p></div>
5111 </div>
5112 <div class="sect2">
5113 <h3 id="_return">return</h3>
5114 <div class="paragraph"><p><tt><strong>return</strong> ?<strong>-code</strong> <em>code</em>? ?<strong>-errorinfo</strong> <em>stacktrace</em>? ?<strong>-errorcode</strong> <em>errorcode</em>? ?<strong>-level</strong> <em>n</em>? ?<em>value</em>?</tt></p></div>
5115 <div class="paragraph"><p>Return immediately from the current procedure (or top-level command
5116 or <em>source</em> command), with <strong>value</strong> as the return value. If <strong>value</strong>
5117 is not specified, an empty string will be returned as result.</p></div>
5118 <div class="paragraph"><p>If <strong>-code</strong> is specified (as either a number or ok, error, break,
5119 continue, signal, return or exit), this code will be used instead
5120 of <tt>JIM_OK</tt>. This is generally useful when implementing flow of control
5121 commands.</p></div>
5122 <div class="paragraph"><p>If <strong>-level</strong> is specified and greater than 1, it has the effect of delaying
5123 the new return code from <strong>-code</strong>. This is useful when rethrowing an error
5124 from <em>catch</em>. See the implementation of try/catch in tclcompat.tcl for
5125 an example of how this is done.</p></div>
5126 <div class="paragraph"><p>Note: The following options are only used when <strong>-code</strong> is JIM_ERR.</p></div>
5127 <div class="paragraph"><p>If <strong>-errorinfo</strong> is specified (as returned from <em>info stacktrace</em>)
5128 it is used to initialize the stacktrace.</p></div>
5129 <div class="paragraph"><p>If <strong>-errorcode</strong> is specified, it is used to set the global variable $::errorCode.</p></div>
5130 </div>
5131 <div class="sect2">
5132 <h3 id="_scan">scan</h3>
5133 <div class="paragraph"><p><tt><strong>scan</strong> <em>string format varName1 ?varName2 &#8230;?</em></tt></p></div>
5134 <div class="paragraph"><p>This command parses fields from an input string in the same fashion
5135 as the C <em>sscanf</em> procedure. <strong>String</strong> gives the input to be parsed
5136 and <strong>format</strong> indicates how to parse it, using <em>%</em> fields as in
5137 <em>sscanf</em>. All of the <em>sscanf</em> options are valid; see the <em>sscanf</em>
5138 man page for details. Each <strong>varName</strong> gives the name of a variable;
5139 when a field is scanned from <strong>string</strong>, the result is converted back
5140 into a string and assigned to the corresponding <strong>varName</strong>. The
5141 only unusual conversion is for <em>%c</em>. For <em>%c</em> conversions a single
5142 character value is converted to a decimal string, which is then
5143 assigned to the corresponding <strong>varName</strong>; no field width may be
5144 specified for this conversion.</p></div>
5145 </div>
5146 <div class="sect2">
5147 <h3 id="_seek">seek</h3>
5148 <div class="paragraph"><p><tt><strong>seek</strong> <em>fileId offset ?origin?</em></tt></p></div>
5149 <div class="paragraph"><p><tt><em>fileId</em> <strong>seek</strong> <em>offset ?origin?</em></tt></p></div>
5150 <div class="paragraph"><p>Change the current access position for <strong>fileId</strong>.
5151 The <strong>offset</strong> and <strong>origin</strong> arguments specify the position at
5152 which the next read or write will occur for <strong>fileId</strong>.
5153 <strong>offset</strong> must be a number (which may be negative) and <strong>origin</strong>
5154 must be one of the following:</p></div>
5155 <div class="dlist"><dl>
5156 <dt class="hdlist1">
5157 <tt><strong>start</strong></tt>
5158 </dt>
5159 <dd>
5161 The new access position will be <strong>offset</strong> bytes from the start
5162 of the file.
5163 </p>
5164 </dd>
5165 <dt class="hdlist1">
5166 <tt><strong>current</strong></tt>
5167 </dt>
5168 <dd>
5170 The new access position will be <strong>offset</strong> bytes from the current
5171 access position; a negative <strong>offset</strong> moves the access position
5172 backwards in the file.
5173 </p>
5174 </dd>
5175 <dt class="hdlist1">
5176 <tt><strong>end</strong></tt>
5177 </dt>
5178 <dd>
5180 The new access position will be <strong>offset</strong> bytes from the end of
5181 the file. A negative <strong>offset</strong> places the access position before
5182 the end-of-file, and a positive <strong>offset</strong> places the access position
5183 after the end-of-file.
5184 </p>
5185 </dd>
5186 </dl></div>
5187 <div class="paragraph"><p>The <strong>origin</strong> argument defaults to <em>start</em>.</p></div>
5188 <div class="paragraph"><p><strong>fileId</strong> must have been the return value from a previous call to
5189 <em>open</em>, or it may be <em>stdin</em>, <em>stdout</em>, or <em>stderr</em> to refer to one
5190 of the standard I/O channels.</p></div>
5191 <div class="paragraph"><p>This command returns an empty string.</p></div>
5192 </div>
5193 <div class="sect2">
5194 <h3 id="_set">set</h3>
5195 <div class="paragraph"><p><tt><strong>set</strong> <em>varName ?value?</em></tt></p></div>
5196 <div class="paragraph"><p>Returns the value of variable <strong>varName</strong>.</p></div>
5197 <div class="paragraph"><p>If <strong>value</strong> is specified, then set the value of <strong>varName</strong> to <strong>value</strong>,
5198 creating a new variable if one doesn&#8217;t already exist, and return
5199 its value.</p></div>
5200 <div class="paragraph"><p>If <strong>varName</strong> contains an open parenthesis and ends with a
5201 close parenthesis, then it refers to an array element: the characters
5202 before the open parenthesis are the name of the array, and the characters
5203 between the parentheses are the index within the array.
5204 Otherwise <strong>varName</strong> refers to a scalar variable.</p></div>
5205 <div class="paragraph"><p>If no procedure is active, then <strong>varName</strong> refers to a global
5206 variable.</p></div>
5207 <div class="paragraph"><p>If a procedure is active, then <strong>varName</strong> refers to a parameter
5208 or local variable of the procedure, unless the <strong>global</strong> command
5209 has been invoked to declare <strong>varName</strong> to be global.</p></div>
5210 <div class="paragraph"><p>The <em>::</em> prefix may also be used to explicitly reference a variable
5211 in the global scope.</p></div>
5212 </div>
5213 <div class="sect2">
5214 <h3 id="_setref">setref</h3>
5215 <div class="paragraph"><p><tt><strong>setref</strong> <em>reference string</em></tt></p></div>
5216 <div class="paragraph"><p>Store a new string in <strong>reference</strong>, replacing the existing string.
5217 The reference must be a valid reference create with the <em>ref</em>
5218 command.</p></div>
5219 <div class="paragraph"><p>See GARBAGE COLLECTION, REFERENCES, LAMBDA for more detail.</p></div>
5220 </div>
5221 <div class="sect2">
5222 <h3 id="_signal">signal</h3>
5223 <div class="paragraph"><p>Command for signal handling.</p></div>
5224 <div class="paragraph"><p>See <em>kill</em> for the different forms which may be used to specify signals.</p></div>
5225 <div class="paragraph"><p>Commands which return a list of signal names do so using the canonical form:
5226 "<tt>SIGINT SIGTERM</tt>".</p></div>
5227 <div class="dlist"><dl>
5228 <dt class="hdlist1">
5229 <tt><strong>signal handle</strong> ?<em>signals &#8230;</em>?</tt>
5230 </dt>
5231 <dd>
5233 If no signals are given, returns a list of all signals which are currently
5234 being handled.
5235 If signals are specified, these are added to the list of signals currently
5236 being handled.
5237 </p>
5238 </dd>
5239 <dt class="hdlist1">
5240 <tt><strong>signal ignore</strong> ?<em>signals &#8230;</em>?</tt>
5241 </dt>
5242 <dd>
5244 If no signals are given, returns a lists all signals which are currently
5245 being ignored.
5246 If signals are specified, these are added to the list of signals
5247 currently being ignored. These signals are still delivered, but
5248 are not considered by <em>catch -signal</em> or <em>try -signal</em>. Use
5249 <em>signal check</em> to determine which signals have occurred but
5250 been ignored.
5251 </p>
5252 </dd>
5253 <dt class="hdlist1">
5254 <tt><strong>signal default</strong> ?<em>signals &#8230;</em>?</tt>
5255 </dt>
5256 <dd>
5258 If no signals are given, returns a lists all signals which are currently have
5259 the default behaviour.
5260 If signals are specified, these are added to the list of signals which have
5261 the default behaviour.
5262 </p>
5263 </dd>
5264 <dt class="hdlist1">
5265 <tt><strong>signal check ?-clear?</strong> ?<em>signals &#8230;</em>?</tt>
5266 </dt>
5267 <dd>
5269 Returns a list of signals which have been delivered to the process
5270 but are <em>ignored</em>. If signals are specified, only that set of signals will
5271 be checked, otherwise all signals will be checked.
5272 If <em>-clear</em> is specified, any signals returned are removed and will not be
5273 returned by subsequent calls to <em>signal check</em> unless delivered again.
5274 </p>
5275 </dd>
5276 <dt class="hdlist1">
5277 <tt><strong>signal throw</strong> ?<em>signal</em>?</tt>
5278 </dt>
5279 <dd>
5281 Raises the given signal, which defaults to <tt>SIGINT</tt> if not specified.
5282 The behaviour is identical to:
5283 </p>
5284 <div class="literalblock">
5285 <div class="content">
5286 <pre><tt>kill signal [pid]</tt></pre>
5287 </div></div>
5288 </dd>
5289 </dl></div>
5290 <div class="paragraph"><p>Note that <em>signal handle</em> and <em>signal ignore</em> represent two forms of signal
5291 handling. <em>signal handle</em> is used in conjunction with <em>catch -signal</em> or <em>try -signal</em>
5292 to immediately abort execution when the signal is delivered. Alternatively, <em>signal ignore</em>
5293 is used in conjunction with <em>signal check</em> to handle signal synchronously. Consider the
5294 two examples below.</p></div>
5295 <div class="paragraph"><p>Prevent a processing from taking too long</p></div>
5296 <div class="literalblock">
5297 <div class="content">
5298 <pre><tt>signal handle SIGALRM
5299 alarm 20
5300 try -signal {
5301 .. possibly long running process ..
5302 alarm 0
5303 } on signal {sig} {
5304 puts stderr "Process took too long"
5305 }</tt></pre>
5306 </div></div>
5307 <div class="paragraph"><p>Handle SIGHUP to reconfigure:</p></div>
5308 <div class="literalblock">
5309 <div class="content">
5310 <pre><tt>signal ignore SIGHUP
5311 while {1} {
5312 ... handle configuration/reconfiguration ...
5313 while {[signal check -clear SIGHUP] eq ""} {
5314 ... do processing ..
5316 # Received SIGHUP, so reconfigure
5317 }</tt></pre>
5318 </div></div>
5319 </div>
5320 <div class="sect2">
5321 <h3 id="_sleep">sleep</h3>
5322 <div class="paragraph"><p><tt><strong>sleep</strong> <em>seconds</em></tt></p></div>
5323 <div class="paragraph"><p>Pauses for the given number of seconds, which may be a floating
5324 point value less than one to sleep for less than a second, or an
5325 integer to sleep for one or more seconds.</p></div>
5326 </div>
5327 <div class="sect2">
5328 <h3 id="_source">source</h3>
5329 <div class="paragraph"><p><tt><strong>source</strong> <em>fileName</em></tt></p></div>
5330 <div class="paragraph"><p>Read file <strong>fileName</strong> and pass the contents to the Tcl interpreter
5331 as a sequence of commands to execute in the normal fashion. The return
5332 value of <em>source</em> is the return value of the last command executed
5333 from the file. If an error occurs in executing the contents of the
5334 file, then the <em>source</em> command will return that error.</p></div>
5335 <div class="paragraph"><p>If a <em>return</em> command is invoked from within the file, the remainder of
5336 the file will be skipped and the <em>source</em> command will return
5337 normally with the result from the <em>return</em> command.</p></div>
5338 </div>
5339 <div class="sect2">
5340 <h3 id="_split">split</h3>
5341 <div class="paragraph"><p><tt><strong>split</strong> <em>string ?splitChars?</em></tt></p></div>
5342 <div class="paragraph"><p>Returns a list created by splitting <strong>string</strong> at each character
5343 that is in the <strong>splitChars</strong> argument.</p></div>
5344 <div class="paragraph"><p>Each element of the result list will consist of the
5345 characters from <strong>string</strong> between instances of the
5346 characters in <strong>splitChars</strong>.</p></div>
5347 <div class="paragraph"><p>Empty list elements will be generated if <strong>string</strong> contains
5348 adjacent characters in <strong>splitChars</strong>, or if the first or last
5349 character of <strong>string</strong> is in <strong>splitChars</strong>.</p></div>
5350 <div class="paragraph"><p>If <strong>splitChars</strong> is an empty string then each character of
5351 <strong>string</strong> becomes a separate element of the result list.</p></div>
5352 <div class="paragraph"><p><strong>SplitChars</strong> defaults to the standard white-space characters.
5353 For example,</p></div>
5354 <div class="literalblock">
5355 <div class="content">
5356 <pre><tt>split "comp.unix.misc" .</tt></pre>
5357 </div></div>
5358 <div class="paragraph"><p>returns <tt><em>"comp unix misc"</em></tt> and</p></div>
5359 <div class="literalblock">
5360 <div class="content">
5361 <pre><tt>split "Hello world" {}</tt></pre>
5362 </div></div>
5363 <div class="paragraph"><p>returns <tt><em>"H e l l o { } w o r l d"</em></tt>.</p></div>
5364 </div>
5365 <div class="sect2">
5366 <h3 id="_stackdump">stackdump</h3>
5367 <div class="paragraph"><p><tt><strong>stackdump</strong> <em>stacktrace</em></tt></p></div>
5368 <div class="paragraph"><p>Creates a human readable representation of a stack trace.</p></div>
5369 </div>
5370 <div class="sect2">
5371 <h3 id="_stacktrace">stacktrace</h3>
5372 <div class="paragraph"><p><tt><strong>stacktrace</strong></tt></p></div>
5373 <div class="paragraph"><p>Returns a live stack trace as a list of <tt>proc file line proc file line &#8230;</tt>.
5374 Iteratively uses <em>info frame</em> to create the stack trace. This stack trace is in the
5375 same form as produced by <em>catch</em> and <em>info stacktrace</em></p></div>
5376 <div class="paragraph"><p>See also <em>stackdump</em>.</p></div>
5377 </div>
5378 <div class="sect2">
5379 <h3 id="_string">string</h3>
5380 <div class="paragraph"><p><tt><strong>string</strong> <em>option arg ?arg &#8230;?</em></tt></p></div>
5381 <div class="paragraph"><p>Perform one of several string operations, depending on <strong>option</strong>.
5382 The legal options (which may be abbreviated) are:</p></div>
5383 <div class="dlist"><dl>
5384 <dt class="hdlist1">
5385 <tt><strong>string bytelength</strong> <em>string</em></tt>
5386 </dt>
5387 <dd>
5389 Returns the length of the string in bytes. This will return
5390 the same value as <em>string length</em> if UTF-8 support is not enabled,
5391 or if the string is composed entirely of ASCII characters.
5392 See UTF-8 AND UNICODE.
5393 </p>
5394 </dd>
5395 <dt class="hdlist1">
5396 <tt><strong>string compare ?-nocase?</strong> <em>string1 string2</em></tt>
5397 </dt>
5398 <dd>
5400 Perform a character-by-character comparison of strings <strong>string1</strong> and
5401 <strong>string2</strong> in the same way as the C <em>strcmp</em> procedure. Return
5402 -1, 0, or 1, depending on whether <strong>string1</strong> is lexicographically
5403 less than, equal to, or greater than <strong>string2</strong>.
5404 Performs a case-insensitive comparison if <em>-nocase</em> is specified.
5405 </p>
5406 </dd>
5407 <dt class="hdlist1">
5408 <tt><strong>string equal ?-nocase?</strong> <em>string1 string2</em></tt>
5409 </dt>
5410 <dd>
5412 Returns 1 if the strings are equal, or 0 otherwise.
5413 Performs a case-insensitive comparison if <em>-nocase</em> is specified.
5414 </p>
5415 </dd>
5416 <dt class="hdlist1">
5417 <tt><strong>string first</strong> <em>string1 string2 ?firstIndex?</em></tt>
5418 </dt>
5419 <dd>
5421 Search <strong>string2</strong> for a sequence of characters that exactly match
5422 the characters in <strong>string1</strong>. If found, return the index of the
5423 first character in the first such match within <strong>string2</strong>. If not
5424 found, return -1. If <strong>firstIndex</strong> is specified, matching will start
5425 from <strong>firstIndex</strong> of <strong>string1</strong>.
5426 </p>
5427 </dd>
5428 <dt class="hdlist1">
5430 </dt>
5431 <dd>
5433 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>firstIndex</strong>.
5434 </p>
5435 </dd>
5436 <dt class="hdlist1">
5437 <tt><strong>string index</strong> <em>string charIndex</em></tt>
5438 </dt>
5439 <dd>
5441 Returns the <strong>charIndex</strong>'th character of the <strong>string</strong>
5442 argument. A <strong>charIndex</strong> of 0 corresponds to the first
5443 character of the string.
5444 If <strong>charIndex</strong> is less than 0 or greater than
5445 or equal to the length of the string then an empty string is
5446 returned.
5447 </p>
5448 </dd>
5449 <dt class="hdlist1">
5451 </dt>
5452 <dd>
5454 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>charIndex</strong>.
5455 </p>
5456 </dd>
5457 <dt class="hdlist1">
5458 <tt><strong>string is</strong> <em>class</em> ?<strong>-strict</strong>? <em>string</em></tt>
5459 </dt>
5460 <dd>
5462 Returns 1 if <strong>string</strong> is a valid member of the specified character
5463 class, otherwise returns 0. If <em>-strict</em> is specified, then an
5464 empty string returns 0, otherwise an empty string will return 1
5465 on any class. The following character classes are recognized
5466 (the class name can be abbreviated):
5467 </p>
5468 <div class="dlist"><dl>
5469 <dt class="hdlist1">
5470 <tt>alnum</tt>
5471 </dt>
5472 <dd>
5474 Any alphabet or digit character.
5475 </p>
5476 </dd>
5477 <dt class="hdlist1">
5478 <tt>alpha</tt>
5479 </dt>
5480 <dd>
5482 Any alphabet character.
5483 </p>
5484 </dd>
5485 <dt class="hdlist1">
5486 <tt>ascii</tt>
5487 </dt>
5488 <dd>
5490 Any character with a value less than 128 (those that are in the 7-bit ascii range).
5491 </p>
5492 </dd>
5493 <dt class="hdlist1">
5494 <tt>control</tt>
5495 </dt>
5496 <dd>
5498 Any control character.
5499 </p>
5500 </dd>
5501 <dt class="hdlist1">
5502 <tt>digit</tt>
5503 </dt>
5504 <dd>
5506 Any digit character.
5507 </p>
5508 </dd>
5509 <dt class="hdlist1">
5510 <tt>double</tt>
5511 </dt>
5512 <dd>
5514 Any of the valid forms for a double in Tcl, with optional surrounding whitespace.
5515 In case of under/overflow in the value, 0 is returned.
5516 </p>
5517 </dd>
5518 <dt class="hdlist1">
5519 <tt>graph</tt>
5520 </dt>
5521 <dd>
5523 Any printing character, except space.
5524 </p>
5525 </dd>
5526 <dt class="hdlist1">
5527 <tt>integer</tt>
5528 </dt>
5529 <dd>
5531 Any of the valid string formats for an integer value in Tcl, with optional surrounding whitespace.
5532 </p>
5533 </dd>
5534 <dt class="hdlist1">
5535 <tt>lower</tt>
5536 </dt>
5537 <dd>
5539 Any lower case alphabet character.
5540 </p>
5541 </dd>
5542 <dt class="hdlist1">
5543 <tt>print</tt>
5544 </dt>
5545 <dd>
5547 Any printing character, including space.
5548 </p>
5549 </dd>
5550 <dt class="hdlist1">
5551 <tt>punct</tt>
5552 </dt>
5553 <dd>
5555 Any punctuation character.
5556 </p>
5557 </dd>
5558 <dt class="hdlist1">
5559 <tt>space</tt>
5560 </dt>
5561 <dd>
5563 Any space character.
5564 </p>
5565 </dd>
5566 <dt class="hdlist1">
5567 <tt>upper</tt>
5568 </dt>
5569 <dd>
5571 Any upper case alphabet character.
5572 </p>
5573 </dd>
5574 <dt class="hdlist1">
5575 <tt>xdigit</tt>
5576 </dt>
5577 <dd>
5579 Any hexadecimal digit character ([0-9A-Fa-f]).
5580 </p>
5581 </dd>
5582 </dl></div>
5583 </dd>
5584 <dt class="hdlist1">
5586 </dt>
5587 <dd>
5589 Note that string classification does <strong>not</strong> respect UTF-8. See UTF-8 AND UNICODE
5590 </p>
5591 </dd>
5592 <dt class="hdlist1">
5593 <tt><strong>string last</strong> <em>string1 string2 ?lastIndex?</em></tt>
5594 </dt>
5595 <dd>
5597 Search <strong>string2</strong> for a sequence of characters that exactly match
5598 the characters in <strong>string1</strong>. If found, return the index of the
5599 first character in the last such match within <strong>string2</strong>. If there
5600 is no match, then return -1. If <strong>lastIndex</strong> is specified, only characters
5601 up to <strong>lastIndex</strong> of <strong>string2</strong> will be considered in the match.
5602 </p>
5603 </dd>
5604 <dt class="hdlist1">
5606 </dt>
5607 <dd>
5609 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>lastIndex</strong>.
5610 </p>
5611 </dd>
5612 <dt class="hdlist1">
5613 <tt><strong>string length</strong> <em>string</em></tt>
5614 </dt>
5615 <dd>
5617 Returns a decimal string giving the number of characters in <strong>string</strong>.
5618 If UTF-8 support is enabled, this may be different than the number of bytes.
5619 See UTF-8 AND UNICODE
5620 </p>
5621 </dd>
5622 <dt class="hdlist1">
5623 <tt><strong>string match ?-nocase?</strong> <em>pattern string</em></tt>
5624 </dt>
5625 <dd>
5627 See if <strong>pattern</strong> matches <strong>string</strong>; return 1 if it does, 0
5628 if it doesn&#8217;t. Matching is done in a fashion similar to that
5629 used by the C-shell. For the two strings to match, their contents
5630 must be identical except that the following special sequences
5631 may appear in <strong>pattern</strong>:
5632 </p>
5633 <div class="dlist"><dl>
5634 <dt class="hdlist1">
5635 <tt>*</tt>
5636 </dt>
5637 <dd>
5639 Matches any sequence of characters in <strong>string</strong>,
5640 including a null string.
5641 </p>
5642 </dd>
5643 <dt class="hdlist1">
5644 <tt>?</tt>
5645 </dt>
5646 <dd>
5648 Matches any single character in <strong>string</strong>.
5649 </p>
5650 </dd>
5651 <dt class="hdlist1">
5652 <tt>[<strong>chars</strong>]</tt>
5653 </dt>
5654 <dd>
5656 Matches any character in the set given by <strong>chars</strong>.
5657 If a sequence of the form <strong>x</strong>-<strong>y</strong> appears in <strong>chars</strong>,
5658 then any character between <strong>x</strong> and <strong>y</strong>, inclusive,
5659 will match.
5660 </p>
5661 </dd>
5662 <dt class="hdlist1">
5663 <tt>\x</tt>
5664 </dt>
5665 <dd>
5667 Matches the single character <strong>x</strong>. This provides a way of
5668 avoiding the special interpretation of the characters `\*?[]\`
5669 in <strong>pattern</strong>.
5670 </p>
5671 </dd>
5672 </dl></div>
5673 </dd>
5674 <dt class="hdlist1">
5676 </dt>
5677 <dd>
5679 Performs a case-insensitive comparison if <em>-nocase</em> is specified.
5680 </p>
5681 </dd>
5682 <dt class="hdlist1">
5683 <tt><strong>string range</strong> <em>string first last</em></tt>
5684 </dt>
5685 <dd>
5687 Returns a range of consecutive characters from <strong>string</strong>, starting
5688 with the character whose index is <strong>first</strong> and ending with the
5689 character whose index is <strong>last</strong>. An index of 0 refers to the
5690 first character of the string.
5691 </p>
5692 </dd>
5693 <dt class="hdlist1">
5695 </dt>
5696 <dd>
5698 See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <strong>first</strong> and <strong>last</strong>.
5699 </p>
5700 </dd>
5701 <dt class="hdlist1">
5703 </dt>
5704 <dd>
5706 If <strong>first</strong> is less than zero then it is treated as if it were zero, and
5707 if <strong>last</strong> is greater than or equal to the length of the string then
5708 it is treated as if it were <em>end</em>. If <strong>first</strong> is greater than
5709 <strong>last</strong> then an empty string is returned.
5710 </p>
5711 </dd>
5712 <dt class="hdlist1">
5713 <tt><strong>string byterange</strong> <em>string first last</em></tt>
5714 </dt>
5715 <dd>
5717 Like <em>string range</em> except works on bytes rather than characters. These commands
5718 are identical if UTF-8 support is not enabled
5719 </p>
5720 </dd>
5721 <dt class="hdlist1">
5722 <tt><strong>string repeat</strong> <em>string count</em></tt>
5723 </dt>
5724 <dd>
5726 Returns a new string consisting of <strong>string</strong> repeated <strong>count</strong> times.
5727 </p>
5728 </dd>
5729 <dt class="hdlist1">
5730 <tt><strong>string reverse</strong> <em>string</em></tt>
5731 </dt>
5732 <dd>
5734 Returns a string that is the same length as <strong>string</strong> but
5735 with its characters in the reverse order.
5736 </p>
5737 </dd>
5738 <dt class="hdlist1">
5739 <tt><strong>string tolower</strong> <em>string</em></tt>
5740 </dt>
5741 <dd>
5743 Returns a value equal to <strong>string</strong> except that all upper case
5744 letters have been converted to lower case.
5745 </p>
5746 </dd>
5747 <dt class="hdlist1">
5748 <tt><strong>string toupper</strong> <em>string</em></tt>
5749 </dt>
5750 <dd>
5752 Returns a value equal to <strong>string</strong> except that all lower case
5753 letters have been converted to upper case.
5754 </p>
5755 </dd>
5756 <dt class="hdlist1">
5757 <tt><strong>string trim</strong> <em>string ?chars?</em></tt>
5758 </dt>
5759 <dd>
5761 Returns a value equal to <strong>string</strong> except that any leading
5762 or trailing characters from the set given by <strong>chars</strong> are
5763 removed.
5764 If <strong>chars</strong> is not specified then white space is removed
5765 (spaces, tabs, newlines, and carriage returns).
5766 </p>
5767 </dd>
5768 <dt class="hdlist1">
5769 <tt><strong>string trimleft</strong> <em>string ?chars?</em></tt>
5770 </dt>
5771 <dd>
5773 Returns a value equal to <strong>string</strong> except that any
5774 leading characters from the set given by <strong>chars</strong> are
5775 removed.
5776 If <strong>chars</strong> is not specified then white space is removed
5777 (spaces, tabs, newlines, and carriage returns).
5778 </p>
5779 </dd>
5780 <dt class="hdlist1">
5781 <tt><strong>string trimright</strong> <em>string ?chars?</em></tt>
5782 </dt>
5783 <dd>
5785 Returns a value equal to <strong>string</strong> except that any
5786 trailing characters from the set given by <strong>chars</strong> are
5787 removed.
5788 If <strong>chars</strong> is not specified then white space is removed
5789 (spaces, tabs, newlines, and carriage returns).
5790 Null characters are always removed.
5791 </p>
5792 </dd>
5793 </dl></div>
5794 </div>
5795 <div class="sect2">
5796 <h3 id="_subst">subst</h3>
5797 <div class="paragraph"><p><tt><strong>subst ?-nobackslashes? ?-nocommands? ?-novariables?</strong> <em>string</em></tt></p></div>
5798 <div class="paragraph"><p>This command performs variable substitutions, command substitutions,
5799 and backslash substitutions on its string argument and returns the
5800 fully-substituted result. The substitutions are performed in exactly
5801 the same way as for Tcl commands. As a result, the string argument
5802 is actually substituted twice, once by the Tcl parser in the usual
5803 fashion for Tcl commands, and again by the subst command.</p></div>
5804 <div class="paragraph"><p>If any of the <strong>-nobackslashes</strong>, <strong>-nocommands</strong>, or <strong>-novariables</strong> are
5805 specified, then the corresponding substitutions are not performed.
5806 For example, if <strong>-nocommands</strong> is specified, no command substitution
5807 is performed: open and close brackets are treated as ordinary
5808 characters with no special interpretation.</p></div>
5809 <div class="paragraph"><p><strong>Note</strong>: when it performs its substitutions, subst does not give any
5810 special treatment to double quotes or curly braces. For example,
5811 the following script returns <em>xyz {44}</em>, not <em>xyz {$a}</em>.</p></div>
5812 <div class="literalblock">
5813 <div class="content">
5814 <pre><tt>set a 44
5815 subst {xyz {$a}}</tt></pre>
5816 </div></div>
5817 </div>
5818 <div class="sect2">
5819 <h3 id="_switch">switch</h3>
5820 <div class="paragraph"><p><tt><strong>switch</strong> <em>?options? string pattern body ?pattern body &#8230;?</em></tt></p></div>
5821 <div class="paragraph"><p><tt><strong>switch</strong> <em>?options? string {pattern body ?pattern body &#8230;?}</em></tt></p></div>
5822 <div class="paragraph"><p>The <em>switch</em> command matches its string argument against each of
5823 the pattern arguments in order. As soon as it finds a pattern that
5824 matches string it evaluates the following body and returns the
5825 result of that evaluation. If the last pattern argument is default
5826 then it matches anything. If no pattern argument matches string and
5827 no default is given, then the switch command returns an empty string.
5828 If the initial arguments to switch start with - then they are treated
5829 as options. The following options are currently supported:</p></div>
5830 <div class="dlist"><dl>
5831 <dt class="hdlist1">
5832 <tt>-exact</tt>
5833 </dt>
5834 <dd>
5836 Use exact matching when comparing string to a
5837 pattern. This is the default.
5838 </p>
5839 </dd>
5840 <dt class="hdlist1">
5841 <tt>-glob</tt>
5842 </dt>
5843 <dd>
5845 When matching string to the patterns, use glob-style
5846 matching (i.e. the same as implemented by the string
5847 match command).
5848 </p>
5849 </dd>
5850 <dt class="hdlist1">
5851 <tt>-regexp</tt>
5852 </dt>
5853 <dd>
5855 When matching string to the patterns, use regular
5856 expression matching (i.e. the same as implemented
5857 by the regexp command).
5858 </p>
5859 </dd>
5860 <dt class="hdlist1">
5861 <tt>-command <em>commandname</em></tt>
5862 </dt>
5863 <dd>
5865 When matching string to the patterns, use the given command, which
5866 must be a single word. The command is invoked as
5867 <em>commandname pattern string</em>, or <em>commandname -nocase pattern string</em>
5868 and must return 1 if matched, or 0 if not.
5869 </p>
5870 </dd>
5871 <dt class="hdlist1">
5872 <tt>--</tt>
5873 </dt>
5874 <dd>
5876 Marks the end of options. The argument following
5877 this one will be treated as string even if it starts
5878 with a -.
5879 </p>
5880 </dd>
5881 </dl></div>
5882 <div class="paragraph"><p>Two syntaxes are provided for the pattern and body arguments. The
5883 first uses a separate argument for each of the patterns and commands;
5884 this form is convenient if substitutions are desired on some of the
5885 patterns or commands. The second form places all of the patterns
5886 and commands together into a single argument; the argument must
5887 have proper list structure, with the elements of the list being the
5888 patterns and commands. The second form makes it easy to construct
5889 multi-line switch commands, since the braces around the whole list
5890 make it unnecessary to include a backslash at the end of each line.
5891 Since the pattern arguments are in braces in the second form, no
5892 command or variable substitutions are performed on them; this makes
5893 the behaviour of the second form different than the first form in
5894 some cases.</p></div>
5895 <div class="paragraph"><p>If a body is specified as <em>-</em> it means that the body for the next
5896 pattern should also be used as the body for this pattern (if the
5897 next pattern also has a body of &#8220;-&#8221; then the body after that is
5898 used, and so on). This feature makes it possible to share a single
5899 body among several patterns.</p></div>
5900 <div class="paragraph"><p>Below are some examples of switch commands:</p></div>
5901 <div class="literalblock">
5902 <div class="content">
5903 <pre><tt>switch abc a - b {format 1} abc {format 2} default {format 3}</tt></pre>
5904 </div></div>
5905 <div class="paragraph"><p>will return 2,</p></div>
5906 <div class="literalblock">
5907 <div class="content">
5908 <pre><tt>switch -regexp aaab {
5909 ^a.*b$ -
5910 b {format 1}
5911 a* {format 2}
5912 default {format 3}
5913 }</tt></pre>
5914 </div></div>
5915 <div class="paragraph"><p>will return 1, and</p></div>
5916 <div class="literalblock">
5917 <div class="content">
5918 <pre><tt>switch xyz {
5920 b {format 1}
5921 a* {format 2}
5922 default {format 3}
5923 }</tt></pre>
5924 </div></div>
5925 <div class="paragraph"><p>will return 3.</p></div>
5926 </div>
5927 <div class="sect2">
5928 <h3 id="_tailcall">tailcall</h3>
5929 <div class="paragraph"><p><tt><strong>tailcall</strong> <em>cmd ?arg&#8230;?</em></tt></p></div>
5930 <div class="paragraph"><p>The <em>tailcall</em> command provides an optimised way of invoking a command whilst replacing
5931 the current call frame. This is similar to <em>exec</em> in Bourne Shell.</p></div>
5932 <div class="paragraph"><p>The following are identical except the first immediately replaces the current call frame.</p></div>
5933 <div class="literalblock">
5934 <div class="content">
5935 <pre><tt>tailcall a b c</tt></pre>
5936 </div></div>
5937 <div class="literalblock">
5938 <div class="content">
5939 <pre><tt>return [uplevel 1 a b c]</tt></pre>
5940 </div></div>
5941 <div class="paragraph"><p><em>tailcall</em> is useful for a dispatch mechanism:</p></div>
5942 <div class="literalblock">
5943 <div class="content">
5944 <pre><tt>proc a {cmd args} {
5945 tailcall sub_$cmd {*}$args
5947 proc sub_cmd1 ...
5948 proc sub_cmd2 ...</tt></pre>
5949 </div></div>
5950 </div>
5951 <div class="sect2">
5952 <h3 id="_tell">tell</h3>
5953 <div class="paragraph"><p><tt><strong>tell</strong> <em>fileId</em></tt></p></div>
5954 <div class="paragraph"><p><tt><em>fileId</em> <strong>tell</strong></tt></p></div>
5955 <div class="paragraph"><p>Returns a decimal string giving the current access position in
5956 <strong>fileId</strong>.</p></div>
5957 <div class="paragraph"><p><strong>fileId</strong> must have been the return value from a previous call to
5958 <em>open</em>, or it may be <em>stdin</em>, <em>stdout</em>, or <em>stderr</em> to refer to one
5959 of the standard I/O channels.</p></div>
5960 </div>
5961 <div class="sect2">
5962 <h3 id="_throw">throw</h3>
5963 <div class="paragraph"><p><tt><strong>throw</strong> <em>code ?msg?</em></tt></p></div>
5964 <div class="paragraph"><p>This command throws an exception (return) code along with an optional message.
5965 This command is mostly for convenient usage with <em>try</em>.</p></div>
5966 <div class="paragraph"><p>The command <tt>throw break</tt> is equivalent to <tt>break</tt>.
5967 The command <tt>throw 20 message</tt> can be caught with an <tt>on 20 &#8230;</tt> clause to <em>try</em>.</p></div>
5968 </div>
5969 <div class="sect2">
5970 <h3 id="_time">time</h3>
5971 <div class="paragraph"><p><tt><strong>time</strong> <em>command ?count?</em></tt></p></div>
5972 <div class="paragraph"><p>This command will call the Tcl interpreter <strong>count</strong>
5973 times to execute <strong>command</strong> (or once if <strong>count</strong> isn&#8217;t
5974 specified). It will then return a string of the form</p></div>
5975 <div class="literalblock">
5976 <div class="content">
5977 <pre><tt>503 microseconds per iteration</tt></pre>
5978 </div></div>
5979 <div class="paragraph"><p>which indicates the average amount of time required per iteration,
5980 in microseconds.</p></div>
5981 <div class="paragraph"><p>Time is measured in elapsed time, not CPU time.</p></div>
5982 </div>
5983 <div class="sect2">
5984 <h3 id="_try">try</h3>
5985 <div class="paragraph"><p><tt><strong>try</strong> <em>?catchopts? tryscript</em> ?<strong>on</strong> <em>returncodes {?resultvar? ?optsvar?} handlerscript &#8230;</em>? ?<strong>finally</strong> <em>finalscript</em>?</tt></p></div>
5986 <div class="paragraph"><p>The <em>try</em> command is provided as a convenience for exception handling.</p></div>
5987 <div class="paragraph"><p>This interpeter first evaluates <strong>tryscript</strong> under the effect of the catch
5988 options <strong>catchopts</strong> (e.g. <tt>-signal -noexit --</tt>, see <em>catch</em>).</p></div>
5989 <div class="paragraph"><p>It then evaluates the script for the first matching <em>on</em> handler
5990 (there many be zero or more) based on the return code from the <em>try</em>
5991 section. For example a normal <tt>JIM_ERR</tt> error will be matched by
5992 an <em>on error</em> handler.</p></div>
5993 <div class="paragraph"><p>Finally, any <strong>finalscript</strong> is evaluated.</p></div>
5994 <div class="paragraph"><p>The result of this command is the result of <strong>tryscript</strong>, except in the
5995 case where an exception occurs in a matching <em>on</em> handler script or the <em>finally</em> script,
5996 in which case the result is this new exception.</p></div>
5997 <div class="paragraph"><p>The specified <strong>returncodes</strong> is a list of return codes either as names (<em>ok</em>, <em>error</em>, <em>break</em>, etc.)
5998 or as integers.</p></div>
5999 <div class="paragraph"><p>If <strong>resultvar</strong> and <strong>optsvar</strong> are specified, they are set as for <em>catch</em> before evaluating
6000 the matching handler.</p></div>
6001 <div class="paragraph"><p>For example:</p></div>
6002 <div class="literalblock">
6003 <div class="content">
6004 <pre><tt>set f [open input]
6005 try -signal {
6006 process $f
6007 } on {continue break} {} {
6008 error "Unexpected break/continue"
6009 } on error {msg opts} {
6010 puts "Dealing with error"
6011 return {*}$opts $msg
6012 } on signal sig {
6013 puts "Got signal: $sig"
6014 } finally {
6015 $f close
6016 }</tt></pre>
6017 </div></div>
6018 <div class="paragraph"><p>If break, continue or error are raised, they are dealt with by the matching
6019 handler.</p></div>
6020 <div class="paragraph"><p>In any case, the file will be closed via the <em>finally</em> clause.</p></div>
6021 <div class="paragraph"><p>See also <em>throw</em>, <em>catch</em>, <em>return</em>, <em>error</em>.</p></div>
6022 </div>
6023 <div class="sect2">
6024 <h3 id="_unknown">unknown</h3>
6025 <div class="paragraph"><p><tt><strong>unknown</strong> <em>cmdName ?arg arg &#8230;?</em></tt></p></div>
6026 <div class="paragraph"><p>This command doesn&#8217;t actually exist as part of Tcl, but Tcl will
6027 invoke it if it does exist.</p></div>
6028 <div class="paragraph"><p>If the Tcl interpreter encounters a command name for which there
6029 is not a defined command, then Tcl checks for the existence of
6030 a command named <em>unknown</em>.</p></div>
6031 <div class="paragraph"><p>If there is no such command, then the interpreter returns an
6032 error.</p></div>
6033 <div class="paragraph"><p>If the <em>unknown</em> command exists, then it is invoked with
6034 arguments consisting of the fully-substituted name and arguments
6035 for the original non-existent command.</p></div>
6036 <div class="paragraph"><p>The <em>unknown</em> command typically does things like searching
6037 through library directories for a command procedure with the name
6038 <strong>cmdName</strong>, or expanding abbreviated command names to full-length,
6039 or automatically executing unknown commands as UNIX sub-processes.</p></div>
6040 <div class="paragraph"><p>In some cases (such as expanding abbreviations) <em>unknown</em> will
6041 change the original command slightly and then (re-)execute it.
6042 The result of the <em>unknown</em> command is used as the result for
6043 the original non-existent command.</p></div>
6044 </div>
6045 <div class="sect2">
6046 <h3 id="_unset">unset</h3>
6047 <div class="paragraph"><p><tt><strong>unset ?-nocomplain? ?--?</strong> <em>?name name &#8230;?</em></tt></p></div>
6048 <div class="paragraph"><p>Remove variables.
6049 Each <strong>name</strong> is a variable name, specified in any of the
6050 ways acceptable to the <em>set</em> command.</p></div>
6051 <div class="paragraph"><p>If a <strong>name</strong> refers to an element of an array, then that
6052 element is removed without affecting the rest of the array.</p></div>
6053 <div class="paragraph"><p>If a <strong>name</strong> consists of an array name with no parenthesized
6054 index, then the entire array is deleted.</p></div>
6055 <div class="paragraph"><p>The <em>unset</em> command returns an empty string as result.</p></div>
6056 <div class="paragraph"><p>An error occurs if any of the variables doesn&#8217;t exist, unless <em>-nocomplain</em>
6057 is specified. The <em>--</em> argument may be specified to stop option processing
6058 in case the variable name may be <em>-nocomplain</em>.</p></div>
6059 </div>
6060 <div class="sect2">
6061 <h3 id="_upcall">upcall</h3>
6062 <div class="paragraph"><p><tt><strong>upcall</strong> <em>command ?args &#8230;?</em></tt></p></div>
6063 <div class="paragraph"><p>May be used from within a proc defined as <tt>local proc</tt> in order to call
6064 the previous, hidden version of the same command.</p></div>
6065 <div class="paragraph"><p>If there is no previous definition of the command, an error is returned.</p></div>
6066 </div>
6067 <div class="sect2">
6068 <h3 id="_uplevel">uplevel</h3>
6069 <div class="paragraph"><p><tt><strong>uplevel</strong> <em>?level? command ?command &#8230;?</em></tt></p></div>
6070 <div class="paragraph"><p>All of the <strong>command</strong> arguments are concatenated as if they had
6071 been passed to <em>concat</em>; the result is then evaluated in the
6072 variable context indicated by <strong>level</strong>. <em>Uplevel</em> returns
6073 the result of that evaluation. If <strong>level</strong> is an integer, then
6074 it gives a distance (up the procedure calling stack) to move before
6075 executing the command. If <strong>level</strong> consists of <em>#</em> followed by
6076 a number then the number gives an absolute level number. If <strong>level</strong>
6077 is omitted then it defaults to <em>1</em>. <strong>Level</strong> cannot be
6078 defaulted if the first <strong>command</strong> argument starts with a digit or <em>#</em>.</p></div>
6079 <div class="paragraph"><p>For example, suppose that procedure <em>a</em> was invoked
6080 from top-level, and that it called <em>b</em>, and that <em>b</em> called <em>c</em>.
6081 Suppose that <em>c</em> invokes the <em>uplevel</em> command. If <strong>level</strong>
6082 is <em>1</em> or <em>#2</em> or omitted, then the command will be executed
6083 in the variable context of <em>b</em>. If <strong>level</strong> is <em>2</em> or <em>#1</em>
6084 then the command will be executed in the variable context of <em>a</em>.</p></div>
6085 <div class="paragraph"><p>If <strong>level</strong> is <em>3</em> or <em>#0</em> then the command will be executed
6086 at top-level (only global variables will be visible).
6087 The <em>uplevel</em> command causes the invoking procedure to disappear
6088 from the procedure calling stack while the command is being executed.
6089 In the above example, suppose <em>c</em> invokes the command</p></div>
6090 <div class="literalblock">
6091 <div class="content">
6092 <pre><tt>uplevel 1 {set x 43; d}</tt></pre>
6093 </div></div>
6094 <div class="paragraph"><p>where <em>d</em> is another Tcl procedure. The <em>set</em> command will
6095 modify the variable <em>x</em> in <em>b&#8217;s context, and 'd</em> will execute
6096 at level 3, as if called from <em>b</em>. If it in turn executes
6097 the command</p></div>
6098 <div class="literalblock">
6099 <div class="content">
6100 <pre><tt>uplevel {set x 42}</tt></pre>
6101 </div></div>
6102 <div class="paragraph"><p>then the <em>set</em> command will modify the same variable <em>x</em> in <em>b&#8217;s
6103 context: the procedure 'c</em> does not appear to be on the call stack
6104 when <em>d</em> is executing. The command <em>info level</em> may
6105 be used to obtain the level of the current procedure.</p></div>
6106 <div class="paragraph"><p><em>Uplevel</em> makes it possible to implement new control
6107 constructs as Tcl procedures (for example, <em>uplevel</em> could
6108 be used to implement the <em>while</em> construct as a Tcl procedure).</p></div>
6109 </div>
6110 <div class="sect2">
6111 <h3 id="_upvar">upvar</h3>
6112 <div class="paragraph"><p><tt><strong>upvar</strong> <em>?level? otherVar myVar ?otherVar myVar &#8230;?</em></tt></p></div>
6113 <div class="paragraph"><p>This command arranges for one or more local variables in the current
6114 procedure to refer to variables in an enclosing procedure call or
6115 to global variables.</p></div>
6116 <div class="paragraph"><p><strong>Level</strong> may have any of the forms permitted for the <em>uplevel</em>
6117 command, and may be omitted if the first letter of the first <strong>otherVar</strong>
6118 isn&#8217;t <em>#</em> or a digit (it defaults to <em>1</em>).</p></div>
6119 <div class="paragraph"><p>For each <strong>otherVar</strong> argument, <em>upvar</em> makes the variable
6120 by that name in the procedure frame given by <strong>level</strong> (or at
6121 global level, if <strong>level</strong> is <em>#0</em>) accessible
6122 in the current procedure by the name given in the corresponding
6123 <strong>myVar</strong> argument.</p></div>
6124 <div class="paragraph"><p>The variable named by <strong>otherVar</strong> need not exist at the time of the
6125 call; it will be created the first time <strong>myVar</strong> is referenced, just like
6126 an ordinary variable.</p></div>
6127 <div class="paragraph"><p><em>Upvar</em> may only be invoked from within procedures.</p></div>
6128 <div class="paragraph"><p><em>Upvar</em> returns an empty string.</p></div>
6129 <div class="paragraph"><p>The <em>upvar</em> command simplifies the implementation of call-by-name
6130 procedure calling and also makes it easier to build new control constructs
6131 as Tcl procedures.
6132 For example, consider the following procedure:</p></div>
6133 <div class="literalblock">
6134 <div class="content">
6135 <pre><tt>proc add2 name {
6136 upvar $name x
6137 set x [expr $x+2]
6138 }</tt></pre>
6139 </div></div>
6140 <div class="paragraph"><p><em>Add2</em> is invoked with an argument giving the name of a variable,
6141 and it adds two to the value of that variable.
6142 Although <em>add2</em> could have been implemented using <em>uplevel</em>
6143 instead of <em>upvar</em>, <em>upvar</em> makes it simpler for <em>add2</em>
6144 to access the variable in the caller&#8217;s procedure frame.</p></div>
6145 </div>
6146 <div class="sect2">
6147 <h3 id="_while">while</h3>
6148 <div class="paragraph"><p><tt><strong>while</strong> <em>test body</em></tt></p></div>
6149 <div class="paragraph"><p>The <strong>while</strong> command evaluates <strong>test</strong> as an expression
6150 (in the same way that <em>expr</em> evaluates its argument).
6151 The value of the expression must be numeric; if it is non-zero
6152 then <strong>body</strong> is executed by passing it to the Tcl interpreter.</p></div>
6153 <div class="paragraph"><p>Once <strong>body</strong> has been executed then <strong>test</strong> is evaluated
6154 again, and the process repeats until eventually <strong>test</strong>
6155 evaluates to a zero numeric value. <em>Continue</em>
6156 commands may be executed inside <strong>body</strong> to terminate the current
6157 iteration of the loop, and <em>break</em>
6158 commands may be executed inside <strong>body</strong> to cause immediate
6159 termination of the <em>while</em> command.</p></div>
6160 <div class="paragraph"><p>The <em>while</em> command always returns an empty string.</p></div>
6161 </div>
6162 </div>
6163 </div>
6164 <div class="sect1">
6165 <h2 id="_optional_extensions">OPTIONAL-EXTENSIONS</h2>
6166 <div class="sectionbody">
6167 <div class="paragraph"><p>The following extensions may or may not be available depending upon
6168 what options were selected when Jim Tcl was built.</p></div>
6169 <div class="sect2">
6170 <h3 id="cmd_1">posix: os.fork, os.wait, os.gethostname, os.getids, os.uptime</h3>
6171 <div class="dlist"><dl>
6172 <dt class="hdlist1">
6173 <tt><strong>os.fork</strong></tt>
6174 </dt>
6175 <dd>
6177 Invokes <em>fork(2)</em> and returns the result.
6178 </p>
6179 </dd>
6180 <dt class="hdlist1">
6181 <tt><strong>os.wait -nohang</strong> <em>pid</em></tt>
6182 </dt>
6183 <dd>
6185 Invokes waitpid(2), with WNOHANG if <strong>-nohang</strong> is specified.
6186 Returns a list of 3 elements.
6187 </p>
6188 <div class="literalblock">
6189 <div class="content">
6190 <pre><tt>{0 none 0} if -nohang is specified, and the process is still alive.</tt></pre>
6191 </div></div>
6192 <div class="literalblock">
6193 <div class="content">
6194 <pre><tt>{-1 error &lt;error-description&gt;} if the process does not exist or has already been waited for.</tt></pre>
6195 </div></div>
6196 <div class="literalblock">
6197 <div class="content">
6198 <pre><tt>{&lt;pid&gt; exit &lt;exit-status&gt;} if the process exited normally.</tt></pre>
6199 </div></div>
6200 <div class="literalblock">
6201 <div class="content">
6202 <pre><tt>{&lt;pid&gt; signal &lt;signal-number&gt;} if the process terminated on a signal.</tt></pre>
6203 </div></div>
6204 <div class="literalblock">
6205 <div class="content">
6206 <pre><tt>{&lt;pid&gt; other 0} otherwise (core dump, stopped, continued, etc.)</tt></pre>
6207 </div></div>
6208 </dd>
6209 <dt class="hdlist1">
6210 <tt><strong>os.gethostname</strong></tt>
6211 </dt>
6212 <dd>
6214 Invokes <em>gethostname(3)</em> and returns the result.
6215 </p>
6216 </dd>
6217 <dt class="hdlist1">
6218 <tt><strong>os.getids</strong></tt>
6219 </dt>
6220 <dd>
6222 Returns the various user/group ids for the current process.
6223 </p>
6224 <div class="literalblock">
6225 <div class="content">
6226 <pre><tt>jim&gt; os.getids
6227 uid 1000 euid 1000 gid 100 egid 100</tt></pre>
6228 </div></div>
6229 </dd>
6230 <dt class="hdlist1">
6231 <tt><strong>os.uptime</strong></tt>
6232 </dt>
6233 <dd>
6235 Returns the number of seconds since system boot. See description of <em>uptime</em> in <em>sysinfo(2)</em>.
6236 </p>
6237 </dd>
6238 </dl></div>
6239 </div>
6240 </div>
6241 </div>
6242 <div class="sect1">
6243 <h2 id="_ansi_i_o_aio_and_eventloop_api">ANSI I/O (aio) and EVENTLOOP API</h2>
6244 <div class="sectionbody">
6245 <div class="paragraph"><p>Jim provides an alternative object-based API for I/O.</p></div>
6246 <div class="paragraph"><p>See <em><a href="#_open">open</a></em> and <em><a href="#_socket">socket</a></em> for commands which return an I/O handle.</p></div>
6247 <div class="sect2">
6248 <h3 id="_aio">aio</h3>
6249 <div class="dlist"><dl>
6250 <dt class="hdlist1">
6251 <tt>$handle <strong>read ?-nonewline?</strong> <em>?len?</em></tt>
6252 </dt>
6253 <dd>
6255 Read and return bytes from the stream. To eof if no len.
6256 </p>
6257 </dd>
6258 <dt class="hdlist1">
6259 <tt>$handle <strong>gets</strong> <em>?var?</em></tt>
6260 </dt>
6261 <dd>
6263 Read one line and return it or store it in the var
6264 </p>
6265 </dd>
6266 <dt class="hdlist1">
6267 <tt>$handle <strong>puts ?-nonewline?</strong> <em>str</em></tt>
6268 </dt>
6269 <dd>
6271 Write the string, with newline unless -nonewline
6272 </p>
6273 </dd>
6274 <dt class="hdlist1">
6275 <tt>$handle <strong>copyto</strong> <em>tofd ?size?</em></tt>
6276 </dt>
6277 <dd>
6279 Copy bytes to the file descriptor <strong>tofd</strong>. If <strong>size</strong> is specified, at most
6280 that many bytes will be copied. Otherwise copying continues until the end
6281 of the input file. Returns the number of bytes actually copied.
6282 </p>
6283 </dd>
6284 <dt class="hdlist1">
6285 <tt>$handle <strong>flush</strong></tt>
6286 </dt>
6287 <dd>
6289 Flush the stream
6290 </p>
6291 </dd>
6292 <dt class="hdlist1">
6293 <tt>$handle <strong>filename</strong></tt>
6294 </dt>
6295 <dd>
6297 Returns the original filename associated with the handle.
6298 Handles returned by <em>socket</em> give the socket type instead of a filename.
6299 </p>
6300 </dd>
6301 <dt class="hdlist1">
6302 <tt>$handle <strong>eof</strong></tt>
6303 </dt>
6304 <dd>
6306 Returns 1 if stream is at eof
6307 </p>
6308 </dd>
6309 <dt class="hdlist1">
6310 <tt>$handle <strong>close</strong></tt>
6311 </dt>
6312 <dd>
6314 Closes the stream
6315 </p>
6316 </dd>
6317 <dt class="hdlist1">
6318 <tt>$handle <strong>seek</strong> <em>offset</em> <strong>?start|current|end?</strong></tt>
6319 </dt>
6320 <dd>
6322 Seeks in the stream (default <em>current</em>)
6323 </p>
6324 </dd>
6325 <dt class="hdlist1">
6326 <tt>$handle <strong>tell</strong></tt>
6327 </dt>
6328 <dd>
6330 Returns the current seek position
6331 </p>
6332 </dd>
6333 <dt class="hdlist1">
6334 <tt>$handle <strong>filename</strong></tt>
6335 </dt>
6336 <dd>
6338 Returns the original filename used when opening the file.
6339 If the handle was returned from <em>socket</em>, the type of the
6340 handle is returned instead.
6341 </p>
6342 </dd>
6343 <dt class="hdlist1">
6344 <tt>$handle <strong>ndelay ?0|1?</strong></tt>
6345 </dt>
6346 <dd>
6348 Set O_NDELAY (if arg). Returns current/new setting.
6349 Note that in general ANSI I/O interacts badly with non-blocking I/O.
6350 Use with care.
6351 </p>
6352 </dd>
6353 <dt class="hdlist1">
6354 <tt>$handle <strong>buffering none|line|full</strong></tt>
6355 </dt>
6356 <dd>
6358 Sets the buffering mode of the stream.
6359 </p>
6360 </dd>
6361 <dt class="hdlist1">
6362 <tt>$handle <strong>accept</strong></tt>
6363 </dt>
6364 <dd>
6366 Server socket only: Accept a connection and return stream
6367 </p>
6368 </dd>
6369 <dt class="hdlist1">
6370 <tt>$handle <strong>sendto</strong> <em>str ?hostname:?port</em></tt>
6371 </dt>
6372 <dd>
6374 Sends the string, <strong>str</strong>, to the given address via the socket using sendto(2).
6375 This is intended for udp sockets and may give an error or behave in unintended
6376 ways for other handle types.
6377 Returns the number of bytes written.
6378 </p>
6379 </dd>
6380 <dt class="hdlist1">
6381 <tt>$handle <strong>recvfrom</strong> <em>maxlen ?addrvar?</em></tt>
6382 </dt>
6383 <dd>
6385 Receives a message from the handle via recvfrom(2) and returns it.
6386 At most <strong>maxlen</strong> bytes are read.
6387 If <strong>addrvar</strong> is specified, the sending address of the message is stored in
6388 the named variable in the form <em>addr:port</em>. See <em>socket</em> for details.
6389 </p>
6390 </dd>
6391 </dl></div>
6392 </div>
6393 <div class="sect2">
6394 <h3 id="cmd_2">eventloop: after, vwait, update</h3>
6395 <div class="paragraph"><p>The following commands allow a script to be invoked when the given condition occurs.
6396 If no script is given, returns the current script. If the given script is the empty, the
6397 handler is removed.</p></div>
6398 <div class="dlist"><dl>
6399 <dt class="hdlist1">
6400 <tt>$handle <strong>readable</strong> <em>?readable-script?</em></tt>
6401 </dt>
6402 <dd>
6404 Sets or returns the script for when the socket is readable.
6405 </p>
6406 </dd>
6407 <dt class="hdlist1">
6408 <tt>$handle <strong>writable</strong> <em>?writable-script?</em></tt>
6409 </dt>
6410 <dd>
6412 Sets or returns the script for when the socket is writable.
6413 </p>
6414 </dd>
6415 <dt class="hdlist1">
6416 <tt>$handle <strong>onexception</strong> <em>?exception-script?</em></tt>
6417 </dt>
6418 <dd>
6420 Sets or returns the script for when when oob data received.
6421 </p>
6422 </dd>
6423 </dl></div>
6424 <div class="paragraph"><p>For compatibility with <em>Tcl</em>, these may be prefixed with <em>fileevent</em>. e.g.</p></div>
6425 <div class="dlist"><dl>
6426 <dt class="hdlist1">
6428 </dt>
6429 <dd>
6431 <tt>fileevent $handle <strong>readable</strong> <em>&#8230;</em></tt>
6432 </p>
6433 </dd>
6434 </dl></div>
6435 <div class="paragraph"><p>Time-based execution is also available via the eventloop API.</p></div>
6436 <div class="dlist"><dl>
6437 <dt class="hdlist1">
6438 <tt><strong>after</strong> <em>ms</em></tt>
6439 </dt>
6440 <dd>
6442 Sleeps for the given number of milliseconds. No events are
6443 processed during this time.
6444 </p>
6445 </dd>
6446 <dt class="hdlist1">
6447 <tt><strong>after</strong> <em>ms|<strong>idle</strong> script ?script &#8230;?</em></tt>
6448 </dt>
6449 <dd>
6451 The scripts are concatenated and executed after the given
6452 number of milliseconds have elapsed. If <em>idle</em> is specified,
6453 the script will run the next time the event loop is processed
6454 with <em>vwait</em> or <em>update</em>. The script is only run once and
6455 then removed. Returns an event id.
6456 </p>
6457 </dd>
6458 <dt class="hdlist1">
6459 <tt><strong>after cancel</strong> <em>id|command</em></tt>
6460 </dt>
6461 <dd>
6463 Cancels an <em>after</em> event with the given event id or matching
6464 command (script). Returns the number of milliseconds
6465 remaining until the event would have fired. Returns the
6466 empty string if no matching event is found.
6467 </p>
6468 </dd>
6469 <dt class="hdlist1">
6470 <tt><strong>after info</strong> <em>?id?</em></tt>
6471 </dt>
6472 <dd>
6474 If <strong>id</strong> is not given, returns a list of current <em>after</em>
6475 events. If <strong>id</strong> is given, returns a list containing the
6476 associated script and either <em>timer</em> or <em>idle</em> to indicated
6477 the type of the event. An error occurs if <strong>id</strong> does not
6478 match an event.
6479 </p>
6480 </dd>
6481 <dt class="hdlist1">
6482 <tt><strong>vwait</strong> <em>variable</em></tt>
6483 </dt>
6484 <dd>
6486 A call to <em>vwait</em> is enters the eventloop. <em>vwait</em> processes
6487 events until the named (global) variable changes or all
6488 event handlers are removed. The variable need not exist
6489 beforehand. If there are no event handlers defined, <em>vwait</em>
6490 returns immediately.
6491 </p>
6492 </dd>
6493 <dt class="hdlist1">
6494 <tt><strong>update ?idletasks?</strong></tt>
6495 </dt>
6496 <dd>
6498 A call to <em>update</em> enters the eventloop to process expired events, but
6499 no new events. If <em>idletasks</em> is specified, only expired time events are handled,
6500 not file events.
6501 Returns once handlers have been run for all expired events.
6502 </p>
6503 </dd>
6504 </dl></div>
6505 <div class="paragraph"><p>Scripts are executed at the global scope. If an error occurs during a handler script,
6506 an attempt is made to call (the user-defined command) <em>bgerror</em> with the details of the error.
6507 If the <em>bgerror</em> commands does not exist, it is printed to stderr instead.</p></div>
6508 <div class="paragraph"><p>If a file event handler script generates an error, the handler is automatically removed
6509 to prevent infinite errors. (A time event handler is always removed after execution).</p></div>
6510 <div class="dlist"><dl>
6511 <dt class="hdlist1">
6512 <tt><strong>bgerror</strong> <em>error</em></tt>
6513 </dt>
6514 <dd>
6516 Called when an event handler script generates an error.
6517 </p>
6518 </dd>
6519 </dl></div>
6520 </div>
6521 <div class="sect2">
6522 <h3 id="_socket">socket</h3>
6523 <div class="paragraph"><p>Various socket types may be created.</p></div>
6524 <div class="dlist"><dl>
6525 <dt class="hdlist1">
6526 <tt><strong>socket unix</strong> <em>path</em></tt>
6527 </dt>
6528 <dd>
6530 A unix domain socket client.
6531 </p>
6532 </dd>
6533 <dt class="hdlist1">
6534 <tt><strong>socket unix.server</strong> <em>path</em></tt>
6535 </dt>
6536 <dd>
6538 A unix domain socket server.
6539 </p>
6540 </dd>
6541 <dt class="hdlist1">
6542 <tt><strong>socket ?-ipv6? stream</strong> <em>addr:port</em></tt>
6543 </dt>
6544 <dd>
6546 A TCP socket client.
6547 </p>
6548 </dd>
6549 <dt class="hdlist1">
6550 <tt><strong>socket ?-ipv6? stream.server</strong> <em>?addr:?port</em></tt>
6551 </dt>
6552 <dd>
6554 A TCP socket server (<strong>addr</strong> defaults to <tt>0.0.0.0</tt> for IPv4 or <tt>[::]</tt> for IPv6).
6555 </p>
6556 </dd>
6557 <dt class="hdlist1">
6558 <tt><strong>socket ?-ipv6? dgram</strong> ?<em>addr:port</em>?</tt>
6559 </dt>
6560 <dd>
6562 A UDP socket client. If the address is not specified,
6563 the client socket will be unbound and <em>sendto</em> must be used
6564 to indicated the destination.
6565 </p>
6566 </dd>
6567 <dt class="hdlist1">
6568 <tt><strong>socket ?-ipv6? dgram.server</strong> <em>addr:port</em></tt>
6569 </dt>
6570 <dd>
6572 A UDP socket server.
6573 </p>
6574 </dd>
6575 <dt class="hdlist1">
6576 <tt><strong>socket pipe</strong></tt>
6577 </dt>
6578 <dd>
6580 A pipe. Note that unlike all other socket types, this command returns
6581 a list of two channels: {read write}
6582 </p>
6583 </dd>
6584 </dl></div>
6585 <div class="paragraph"><p>This command creates a socket connected (client) or bound (server) to the given
6586 address.</p></div>
6587 <div class="paragraph"><p>The returned value is channel and may generally be used with the various file I/O
6588 commands (gets, puts, read, etc.), either as object-based syntax or Tcl-compatible syntax.</p></div>
6589 <div class="literalblock">
6590 <div class="content">
6591 <pre><tt>set f [socket stream www.google.com:80]
6592 aio.sockstream1
6593 $f puts -nonewline "GET / HTTP/1.0\r\n\r\n"
6594 $f gets
6595 HTTP/1.0 302 Found
6596 $f close</tt></pre>
6597 </div></div>
6598 <div class="paragraph"><p>Server sockets, however support only <em>accept</em>, which is most useful in conjunction with
6599 the EVENTLOOP API.</p></div>
6600 <div class="literalblock">
6601 <div class="content">
6602 <pre><tt>set f [socket stream.server 80]
6603 $f readable {
6604 set client [$f accept]
6605 $client gets $buf
6607 $client puts -nonewline "HTTP/1.1 404 Not found\r\n"
6608 $client close
6610 vwait done</tt></pre>
6611 </div></div>
6612 <div class="paragraph"><p>The address, <strong>addr</strong>, can be given in one of the following forms:</p></div>
6613 <div class="olist arabic"><ol class="arabic">
6614 <li>
6616 For IPv4 socket types, an IPv4 address such as 192.168.1.1
6617 </p>
6618 </li>
6619 <li>
6621 For IPv6 socket types, an IPv6 address such as [fe80::1234] or [::]
6622 </p>
6623 </li>
6624 <li>
6626 A hostname
6627 </p>
6628 </li>
6629 </ol></div>
6630 <div class="paragraph"><p>Note that on many systems, listening on an IPv6 address such as [::] will
6631 also accept requests via IPv4.</p></div>
6632 <div class="paragraph"><p>Where a hostname is specified, the <strong>first</strong> returned address is used
6633 which matches the socket type is used.</p></div>
6634 <div class="paragraph"><p>The special type <em>pipe</em> isn&#8217;t really a socket.</p></div>
6635 <div class="literalblock">
6636 <div class="content">
6637 <pre><tt>lassign [socket pipe] r w</tt></pre>
6638 </div></div>
6639 <div class="literalblock">
6640 <div class="content">
6641 <pre><tt># Must close $w after exec
6642 exec ps &gt;@$w &amp;
6643 $w close</tt></pre>
6644 </div></div>
6645 <div class="literalblock">
6646 <div class="content">
6647 <pre><tt>$r readable ...</tt></pre>
6648 </div></div>
6649 </div>
6650 <div class="sect2">
6651 <h3 id="_syslog">syslog</h3>
6652 <div class="paragraph"><p><tt><strong>syslog</strong> <em>?options? ?priority? message</em></tt></p></div>
6653 <div class="paragraph"><p>This command sends message to system syslog facility with given
6654 priority. Valid priorities are:</p></div>
6655 <div class="literalblock">
6656 <div class="content">
6657 <pre><tt>emerg, alert, crit, err, error, warning, notice, info, debug</tt></pre>
6658 </div></div>
6659 <div class="paragraph"><p>If a message is specified, but no priority is specified, then a
6660 priority of info is used.</p></div>
6661 <div class="paragraph"><p>By default, facility user is used and the value of global tcl variable
6662 argv0 is used as ident string. However, any of the following options
6663 may be specified before priority to control these parameters:</p></div>
6664 <div class="dlist"><dl>
6665 <dt class="hdlist1">
6666 <tt><strong>-facility</strong> <em>value</em></tt>
6667 </dt>
6668 <dd>
6670 Use specified facility instead of user. The following
6671 values for facility are recognized:
6672 </p>
6673 <div class="literalblock">
6674 <div class="content">
6675 <pre><tt>authpriv, cron, daemon, kernel, lpr, mail, news, syslog, user,
6676 uucp, local0-local7</tt></pre>
6677 </div></div>
6678 </dd>
6679 <dt class="hdlist1">
6680 <tt><strong>-ident</strong> <em>string</em></tt>
6681 </dt>
6682 <dd>
6684 Use given string instead of argv0 variable for ident string.
6685 </p>
6686 </dd>
6687 <dt class="hdlist1">
6688 <tt><strong>-options</strong> <em>integer</em></tt>
6689 </dt>
6690 <dd>
6692 Set syslog options such as <tt>LOG_CONS</tt>, <tt>LOG_NDELAY</tt>. You should
6693 use numeric values of those from your system syslog.h file,
6694 because I haven&#8217;t got time to implement yet another hash
6695 table.
6696 </p>
6697 </dd>
6698 </dl></div>
6699 </div>
6700 </div>
6701 </div>
6702 <div class="sect1">
6703 <h2 id="BuiltinVariables">BUILT-IN VARIABLES</h2>
6704 <div class="sectionbody">
6705 <div class="paragraph"><p>The following global variables are created automatically
6706 by the Tcl library.</p></div>
6707 <div class="dlist"><dl>
6708 <dt class="hdlist1">
6709 <tt><strong>env</strong></tt>
6710 </dt>
6711 <dd>
6713 This variable is set by Jim as an array
6714 whose elements are the environment variables for the process.
6715 Reading an element will return the value of the corresponding
6716 environment variable.
6717 This array is initialised at startup from the <em>env</em> command.
6718 It may be modified and will affect the environment passed to
6719 commands invoked with <em>exec</em>.
6720 </p>
6721 </dd>
6722 <dt class="hdlist1">
6723 <tt><strong>platform_tcl</strong></tt>
6724 </dt>
6725 <dd>
6727 This variable is set by Jim as an array containing information
6728 about the platform on which Jim was built. Currently this includes
6729 <em>os</em> and <em>platform</em>.
6730 </p>
6731 </dd>
6732 <dt class="hdlist1">
6733 <tt><strong>auto_path</strong></tt>
6734 </dt>
6735 <dd>
6737 This variable contains a list of paths to search for packages.
6738 It defaults to a location based on where jim is installed
6739 (e.g. <tt>/usr/local/lib/jim</tt>), but may be changed by <tt>jimsh</tt>
6740 or the embedding application. Note that <tt>jimsh</tt> will consider
6741 the environment variable <tt>$JIMLIB</tt> to be a list of colon-separated
6742 list of paths to add to <strong>auto_path</strong>.
6743 </p>
6744 </dd>
6745 <dt class="hdlist1">
6746 <tt><strong>errorCode</strong></tt>
6747 </dt>
6748 <dd>
6750 This variable holds the value of the -errorcode return
6751 option set by the most recent error that occurred in this
6752 interpreter. This list value represents additional information
6753 about the error in a form that is easy to process with
6754 programs. The first element of the list identifies a general
6755 class of errors, and determines the format of the rest of
6756 the list. The following formats for -errorcode return options
6757 are used by the Tcl core; individual applications may define
6758 additional formats. Currently only <em>exec</em> sets this variable.
6759 Otherwise it will be <strong>NONE</strong>.
6760 </p>
6761 </dd>
6762 </dl></div>
6763 <div class="paragraph"><p>The following global variables are set by jimsh.</p></div>
6764 <div class="dlist"><dl>
6765 <dt class="hdlist1">
6766 <tt><strong>tcl_interactive</strong></tt>
6767 </dt>
6768 <dd>
6770 This variable is set to 1 if jimsh is started in interactive mode
6771 or 0 otherwise.
6772 </p>
6773 </dd>
6774 <dt class="hdlist1">
6775 <tt><strong>tcl_platform</strong></tt>
6776 </dt>
6777 <dd>
6779 This variable is set by Jim as an array containing information
6780 about the platform upon which Jim was built. The following is an
6781 example of the contents of this array.
6782 </p>
6783 <div class="literalblock">
6784 <div class="content">
6785 <pre><tt>tcl_platform(byteOrder) = littleEndian
6786 tcl_platform(os) = Darwin
6787 tcl_platform(platform) = unix
6788 tcl_platform(pointerSize) = 8
6789 tcl_platform(threaded) = 0
6790 tcl_platform(wordSize) = 8
6791 tcl_platform(pathSeparator) = :</tt></pre>
6792 </div></div>
6793 </dd>
6794 <dt class="hdlist1">
6795 <tt><strong>argv0</strong></tt>
6796 </dt>
6797 <dd>
6799 If jimsh is invoked to run a script, this variable contains the name
6800 of the script.
6801 </p>
6802 </dd>
6803 <dt class="hdlist1">
6804 <tt><strong>argv</strong></tt>
6805 </dt>
6806 <dd>
6808 If jimsh is invoked to run a script, this variable contains a list
6809 of any arguments supplied to the script.
6810 </p>
6811 </dd>
6812 <dt class="hdlist1">
6813 <tt><strong>argc</strong></tt>
6814 </dt>
6815 <dd>
6817 If jimsh is invoked to run a script, this variable contains the number
6818 of arguments supplied to the script.
6819 </p>
6820 </dd>
6821 <dt class="hdlist1">
6822 <tt><strong>jim_argv0</strong></tt>
6823 </dt>
6824 <dd>
6826 The value of argv[0] when jimsh was invoked.
6827 </p>
6828 </dd>
6829 </dl></div>
6830 </div>
6831 </div>
6832 <div class="sect1">
6833 <h2 id="_changes_in_previous_releases">CHANGES IN PREVIOUS RELEASES</h2>
6834 <div class="sectionbody">
6835 <div class="sect2">
6836 <h3 id="_in_v0_63">In v0.63</h3>
6837 <div class="olist arabic"><ol class="arabic">
6838 <li>
6840 <em>source</em> now checks that a script is complete (.i.e. not missing a brace)
6841 </p>
6842 </li>
6843 <li>
6845 <em>info complete</em> now uses the real parser and so is 100% accurate
6846 </p>
6847 </li>
6848 <li>
6850 Better access to live stack frames with <em>info frame</em>, <em>stacktrace</em> and <em>stackdump</em>
6851 </p>
6852 </li>
6853 <li>
6855 <em>tailcall</em> no longer loses stack trace information
6856 </p>
6857 </li>
6858 <li>
6860 Add <em>alias</em> and <em>curry</em>
6861 </p>
6862 </li>
6863 <li>
6865 <em>lambda</em>, <em>alias</em> and <em>curry</em> are implemented via <em>tailcall</em> for efficiency
6866 </p>
6867 </li>
6868 <li>
6870 <em>local</em> allows procedures to be deleted automatically at the end of the current procedure
6871 </p>
6872 </li>
6873 <li>
6875 udp sockets are now supported for both clients and servers.
6876 </p>
6877 </li>
6878 <li>
6880 vfork-based exec is now working correctly
6881 </p>
6882 </li>
6883 <li>
6885 Add <em>file tempfile</em>
6886 </p>
6887 </li>
6888 <li>
6890 Add <em>socket pipe</em>
6891 </p>
6892 </li>
6893 <li>
6895 Enhance <em>try &#8230; on &#8230; finally</em> to be more Tcl 8.6 compatible
6896 </p>
6897 </li>
6898 <li>
6900 It is now possible to <em>return</em> from within <em>try</em>
6901 </p>
6902 </li>
6903 <li>
6905 IPv6 support is now included
6906 </p>
6907 </li>
6908 <li>
6910 Add <em>string is</em>
6911 </p>
6912 </li>
6913 <li>
6915 Event handlers works better if an error occurs. eof handler has been removed.
6916 </p>
6917 </li>
6918 <li>
6920 <em>exec</em> now sets $::errorCode, and catch sets opts(-errorcode) for exit status
6921 </p>
6922 </li>
6923 <li>
6925 Command pipelines via open "|&#8230;" are now supported
6926 </p>
6927 </li>
6928 <li>
6930 <em>pid</em> can now return pids of a command pipeline
6931 </p>
6932 </li>
6933 <li>
6935 Add <em>info references</em>
6936 </p>
6937 </li>
6938 <li>
6940 Add support for <em>after <strong>ms</strong></em>, <em>after idle</em>, <em>after info</em>, <em>update</em>
6941 </p>
6942 </li>
6943 <li>
6945 <em>exec</em> now sets environment based on $::env
6946 </p>
6947 </li>
6948 <li>
6950 Add <em>dict keys</em>
6951 </p>
6952 </li>
6953 <li>
6955 Add support for <em>lsort -index</em>
6956 </p>
6957 </li>
6958 </ol></div>
6959 </div>
6960 <div class="sect2">
6961 <h3 id="_in_v0_62">In v0.62</h3>
6962 <div class="olist arabic"><ol class="arabic">
6963 <li>
6965 Add support to <em>exec</em> for <em>&gt;&amp;</em>, <em>&gt;&gt;&amp;</em>, <em>|&amp;</em>, <em>2&gt;@1</em>
6966 </p>
6967 </li>
6968 <li>
6970 Fix <em>exec</em> error messages when special token (e.g. <em>&gt;</em>) is the last token
6971 </p>
6972 </li>
6973 <li>
6975 Fix <em>subst</em> handling of backslash escapes.
6976 </p>
6977 </li>
6978 <li>
6980 Allow abbreviated options for <em>subst</em>
6981 </p>
6982 </li>
6983 <li>
6985 Add support for <em>return</em>, <em>break</em>, <em>continue</em> in subst
6986 </p>
6987 </li>
6988 <li>
6990 Many <em>expr</em> bug fixes
6991 </p>
6992 </li>
6993 <li>
6995 Add support for functions in <em>expr</em> (e.g. int(), abs()), and also <em>in</em>, <em>ni</em> list operations
6996 </p>
6997 </li>
6998 <li>
7000 The variable name argument to <em>regsub</em> is now optional
7001 </p>
7002 </li>
7003 <li>
7005 Add support for <em>unset -nocomplain</em>
7006 </p>
7007 </li>
7008 <li>
7010 Add support for list commands: <em>lassign</em>, <em>lrepeat</em>
7011 </p>
7012 </li>
7013 <li>
7015 Fully-functional <em>lsearch</em> is now implemented
7016 </p>
7017 </li>
7018 <li>
7020 Add <em>info nameofexecutable</em> and <em>info returncodes</em>
7021 </p>
7022 </li>
7023 <li>
7025 Allow <em>catch</em> to determine what return codes are caught
7026 </p>
7027 </li>
7028 <li>
7030 Allow <em>incr</em> to increment an unset variable by first setting to 0
7031 </p>
7032 </li>
7033 <li>
7035 Allow <em>args</em> and optional arguments to the left or required arguments in <em>proc</em>
7036 </p>
7037 </li>
7038 <li>
7040 Add <em>file copy</em>
7041 </p>
7042 </li>
7043 <li>
7045 Add <em>try &#8230; finally</em> command
7046 </p>
7047 </li>
7048 </ol></div>
7049 </div>
7050 </div>
7051 </div>
7052 <div class="sect1">
7053 <h2 id="_licence">LICENCE</h2>
7054 <div class="sectionbody">
7055 <div class="literalblock">
7056 <div class="content">
7057 <pre><tt>Copyright 2005 Salvatore Sanfilippo &lt;antirez@invece.org&gt;
7058 Copyright 2005 Clemens Hintze &lt;c.hintze@gmx.net&gt;
7059 Copyright 2005 patthoyts - Pat Thoyts &lt;patthoyts@users.sf.net&gt;
7060 Copyright 2008 oharboe - Oyvind Harboe - oyvind.harboe@zylin.com
7061 Copyright 2008 Andrew Lunn &lt;andrew@lunn.ch&gt;
7062 Copyright 2008 Duane Ellis &lt;openocd@duaneellis.com&gt;
7063 Copyright 2008 Uwe Klein &lt;uklein@klein-messgeraete.de&gt;
7064 Copyright 2009 Steve Bennett &lt;steveb@workware.net.au&gt;</tt></pre>
7065 </div></div>
7066 <div class="literalblock">
7067 <div class="content">
7068 <pre><tt>Redistribution and use in source and binary forms, with or without
7069 modification, are permitted provided that the following conditions
7070 are met:
7071 1. Redistributions of source code must retain the above copyright
7072 notice, this list of conditions and the following disclaimer.
7073 2. Redistributions in binary form must reproduce the above
7074 copyright notice, this list of conditions and the following
7075 disclaimer in the documentation and/or other materials
7076 provided with the distribution.</tt></pre>
7077 </div></div>
7078 <div class="literalblock">
7079 <div class="content">
7080 <pre><tt>THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
7081 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
7082 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
7083 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
7084 JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
7085 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7086 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
7087 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7088 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
7089 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
7090 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
7091 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</tt></pre>
7092 </div></div>
7093 <div class="literalblock">
7094 <div class="content">
7095 <pre><tt>The views and conclusions contained in the software and documentation
7096 are those of the authors and should not be interpreted as representing
7097 official policies, either expressed or implied, of the Jim Tcl Project.</tt></pre>
7098 </div></div>
7099 </div>
7100 </div>
7101 </div>
7102 <div id="footnotes"><hr /></div>
7103 <div id="footer">
7104 <div id="footer-text">
7105 Last updated 2011-07-18 16:09:46 EST
7106 </div>
7107 </div>
7108 </body>
7109 </html>