home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tc-tcl93.tex < prev    next >
LaTeX Document  |  1993-06-16  |  64.0 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Corel 10 Texture (image/corel10Texture) ext Unsupported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: Plain text[LF] default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 64 6f 63 75 6d 65 6e | 74 73 74 79 6c 65 5b 74 |\documen|tstyle[t|
|00000010| 77 6f 63 6f 6c 75 6d 6e | 5d 7b 61 72 74 69 63 6c |wocolumn|]{articl|
|00000020| 65 7d 20 0a 0a 5c 74 65 | 78 74 77 69 64 74 68 20 |e} ..\te|xtwidth |
|00000030| 3d 20 36 2e 37 35 69 6e | 0a 5c 6f 64 64 73 69 64 |= 6.75in|.\oddsid|
|00000040| 65 6d 61 72 67 69 6e 20 | 3d 20 30 20 69 6e 0a 5c |emargin |= 0 in.\|
|00000050| 65 76 65 6e 73 69 64 65 | 6d 61 72 67 69 6e 20 3d |evenside|margin =|
|00000060| 20 2d 30 2e 32 35 20 69 | 6e 0a 5c 74 6f 70 6d 61 | -0.25 i|n.\topma|
|00000070| 72 67 69 6e 20 3d 20 2d | 30 2e 32 35 20 69 6e 0a |rgin = -|0.25 in.|
|00000080| 5c 74 65 78 74 68 65 69 | 67 68 74 20 3d 20 39 2e |\texthei|ght = 9.|
|00000090| 35 20 69 6e 0a 25 5c 66 | 6f 6f 74 73 6b 69 70 20 |5 in.%\f|ootskip |
|000000a0| 3d 20 30 2e 35 20 69 6e | 0a 0a 25 5c 70 61 72 69 |= 0.5 in|..%\pari|
|000000b0| 6e 64 65 6e 74 20 3d 20 | 30 20 69 6e 0a 25 5c 70 |ndent = |0 in.%\p|
|000000c0| 61 72 73 6b 69 70 20 3d | 20 31 30 20 70 74 0a 0a |arskip =| 10 pt..|
|000000d0| 5c 62 65 67 69 6e 7b 64 | 6f 63 75 6d 65 6e 74 7d |\begin{d|ocument}|
|000000e0| 0a 5c 62 69 62 6c 69 6f | 67 72 61 70 68 79 73 74 |.\biblio|graphyst|
|000000f0| 79 6c 65 7b 61 6c 70 68 | 61 7d 0a 0a 5c 74 69 74 |yle{alph|a}..\tit|
|00000100| 6c 65 20 7b 0a 09 09 09 | 41 20 43 6f 6d 70 69 6c |le {....|A Compil|
|00000110| 65 72 20 66 6f 72 20 74 | 68 65 20 54 63 6c 20 4c |er for t|he Tcl L|
|00000120| 61 6e 67 75 61 67 65 0a | 7d 0a 0a 5c 61 75 74 68 |anguage.|}..\auth|
|00000130| 6f 72 20 7b 41 64 61 6d | 20 53 61 68 20 61 6e 64 |or {Adam| Sah and|
|00000140| 20 4a 6f 6e 20 42 6c 6f | 77 20 5c 5c 0a 5c 5c 20 | Jon Blo|w \\.\\ |
|00000150| 25 73 6b 69 70 20 73 6f | 6d 65 20 73 70 61 63 65 |%skip so|me space|
|00000160| 0a 43 6f 6d 70 75 74 65 | 72 20 53 63 69 65 6e 63 |.Compute|r Scienc|
|00000170| 65 20 44 69 76 69 73 69 | 6f 6e 20 5c 5c 0a 45 6c |e Divisi|on \\.El|
|00000180| 65 63 74 72 69 63 61 6c | 20 45 6e 67 69 6e 65 65 |ectrical| Enginee|
|00000190| 72 69 6e 67 20 61 6e 64 | 20 43 6f 6d 70 75 74 65 |ring and| Compute|
|000001a0| 72 20 53 63 69 65 6e 63 | 65 73 20 5c 5c 0a 55 6e |r Scienc|es \\.Un|
|000001b0| 69 76 65 72 73 69 74 79 | 20 6f 66 20 43 61 6c 69 |iversity| of Cali|
|000001c0| 66 6f 72 6e 69 61 20 5c | 5c 0a 42 65 72 6b 65 6c |fornia \|\.Berkel|
|000001d0| 65 79 2c 20 43 41 20 39 | 34 37 32 30 20 5c 5c 0a |ey, CA 9|4720 \\.|
|000001e0| 28 61 73 61 68 40 63 73 | 2e 42 65 72 6b 65 6c 65 |(asah@cs|.Berkele|
|000001f0| 79 2e 45 44 55 2c 20 62 | 6c 6f 6a 6f 40 78 63 66 |y.EDU, b|lojo@xcf|
|00000200| 2e 42 65 72 6b 65 6c 65 | 79 2e 45 44 55 29 0a 7d |.Berkele|y.EDU).}|
|00000210| 0a 5c 64 61 74 65 20 7b | 4d 61 79 20 32 34 2c 20 |.\date {|May 24, |
|00000220| 31 39 39 33 7d 0a 0a 5c | 6d 61 6b 65 74 69 74 6c |1993}..\|maketitl|
|00000230| 65 0a 5c 62 65 67 69 6e | 7b 61 62 73 74 72 61 63 |e.\begin|{abstrac|
|00000240| 74 7d 0a 0a 54 63 6c 20 | 69 73 20 61 20 68 69 67 |t}..Tcl |is a hig|
|00000250| 68 6c 79 20 64 79 6e 61 | 6d 69 63 20 6c 61 6e 67 |hly dyna|mic lang|
|00000260| 75 61 67 65 20 74 68 61 | 74 20 69 73 20 65 73 70 |uage tha|t is esp|
|00000270| 65 63 69 61 6c 6c 79 20 | 63 68 61 6c 6c 65 6e 67 |ecially |challeng|
|00000280| 69 6e 67 20 74 6f 20 65 | 78 65 63 75 74 65 0a 20 |ing to e|xecute. |
|00000290| 20 65 66 66 69 63 69 65 | 6e 74 6c 79 2e 20 20 54 | efficie|ntly. T|
|000002a0| 68 65 20 64 75 61 6c 2d | 6c 61 6e 67 75 61 67 65 |he dual-|language|
|000002b0| 20 6e 61 74 75 72 65 20 | 6f 66 20 74 68 65 20 73 | nature |of the s|
|000002c0| 79 73 74 65 6d 20 65 6e | 66 6f 72 63 65 64 20 62 |ystem en|forced b|
|000002d0| 79 20 74 68 65 20 43 0a | 20 20 63 61 6c 6c 62 61 |y the C.| callba|
|000002e0| 63 6b 20 6d 65 63 68 61 | 6e 69 73 6d 20 6d 61 6b |ck mecha|nism mak|
|000002f0| 65 73 20 74 72 61 64 69 | 74 69 6f 6e 61 6c 20 63 |es tradi|tional c|
|00000300| 6f 6d 70 69 6c 61 74 69 | 6f 6e 20 61 6e 64 20 6f |ompilati|on and o|
|00000310| 70 74 69 6d 69 7a 61 74 | 69 6f 6e 0a 20 20 75 6e |ptimizat|ion. un|
|00000320| 72 65 61 6c 69 73 74 69 | 63 2e 20 20 49 6e 20 61 |realisti|c. In a|
|00000330| 64 64 69 74 69 6f 6e 2c | 20 74 68 65 20 6c 61 63 |ddition,| the lac|
|00000340| 6b 20 6f 66 20 66 6f 72 | 6d 61 6c 20 64 61 74 61 |k of for|mal data|
|00000350| 20 74 79 70 65 73 20 28 | 61 6e 64 20 74 68 65 72 | types (|and ther|
|00000360| 65 66 6f 72 65 0a 20 20 | 74 79 70 65 20 63 68 65 |efore. |type che|
|00000370| 63 6b 69 6e 67 29 20 70 | 6c 61 63 65 73 20 73 65 |cking) p|laces se|
|00000380| 76 65 72 65 20 6c 69 6d | 69 74 73 20 6f 6e 20 74 |vere lim|its on t|
|00000390| 68 65 20 61 62 69 6c 69 | 74 79 20 74 6f 20 70 72 |he abili|ty to pr|
|000003a0| 6f 76 69 64 65 20 66 6f | 72 0a 20 20 65 66 66 69 |ovide fo|r. effi|
|000003b0| 63 69 65 6e 74 20 64 61 | 74 61 20 73 74 6f 72 61 |cient da|ta stora|
|000003c0| 67 65 20 61 74 20 63 6f | 6d 70 69 6c 65 20 74 69 |ge at co|mpile ti|
|000003d0| 6d 65 2e 20 20 49 6e 20 | 74 68 69 73 20 70 61 70 |me. In |this pap|
|000003e0| 65 72 2c 20 77 65 20 64 | 69 73 63 75 73 73 20 74 |er, we d|iscuss t|
|000003f0| 68 65 0a 20 20 6d 61 6e | 79 20 69 73 73 75 65 73 |he. man|y issues|
|00000400| 20 69 6e 76 6f 6c 76 65 | 64 20 77 69 74 68 20 63 | involve|d with c|
|00000410| 6f 6d 70 69 6c 69 6e 67 | 20 54 63 6c 2c 20 61 6e |ompiling| Tcl, an|
|00000420| 64 20 70 72 65 73 65 6e | 74 20 61 20 64 65 73 69 |d presen|t a desi|
|00000430| 67 6e 20 66 6f 72 20 73 | 75 63 68 20 61 0a 20 20 |gn for s|uch a. |
|00000440| 73 79 73 74 65 6d 2c 20 | 69 6e 63 6c 75 64 69 6e |system, |includin|
|00000450| 67 20 74 68 65 20 6d 65 | 63 68 61 6e 69 73 6d 20 |g the me|chanism |
|00000460| 66 6f 72 20 65 6d 62 65 | 64 64 69 6e 67 20 61 20 |for embe|dding a |
|00000470| 54 63 6c 20 73 63 72 69 | 70 74 20 69 6e 74 6f 20 |Tcl scri|pt into |
|00000480| 74 68 65 0a 20 20 63 6f | 6d 70 69 6c 65 72 20 69 |the. co|mpiler i|
|00000490| 74 73 65 6c 66 20 69 6e | 20 6f 72 64 65 72 20 74 |tself in| order t|
|000004a0| 6f 20 70 72 6f 76 69 64 | 65 20 75 73 65 72 20 65 |o provid|e user e|
|000004b0| 78 74 65 6e 73 69 62 69 | 6c 69 74 79 2e 20 20 54 |xtensibi|lity. T|
|000004c0| 68 65 20 63 75 72 72 65 | 6e 74 0a 20 20 69 6d 70 |he curre|nt. imp|
|000004d0| 6c 65 6d 65 6e 74 61 74 | 69 6f 6e 20 69 73 20 70 |lementat|ion is p|
|000004e0| 72 65 73 65 6e 74 65 64 | 20 61 6c 6f 6e 67 20 77 |resented| along w|
|000004f0| 69 74 68 20 72 65 73 75 | 6c 74 73 20 73 68 6f 77 |ith resu|lts show|
|00000500| 69 6e 67 20 61 70 70 72 | 6f 78 69 6d 61 74 65 6c |ing appr|oximatel|
|00000510| 79 20 74 65 6e 0a 20 20 | 74 69 6d 65 73 20 74 68 |y ten. |times th|
|00000520| 65 20 70 65 72 66 6f 72 | 6d 61 6e 63 65 20 6f 66 |e perfor|mance of|
|00000530| 20 74 68 65 20 65 78 69 | 73 74 69 6e 67 20 54 63 | the exi|sting Tc|
|00000540| 6c 20 69 6e 74 65 72 70 | 72 65 74 65 72 2e 0a 0a |l interp|reter...|
|00000550| 5c 65 6e 64 7b 61 62 73 | 74 72 61 63 74 7d 0a 0a |\end{abs|tract}..|
|00000560| 5c 6e 65 77 63 6f 6d 6d | 61 6e 64 7b 5c 54 7d 7b |\newcomm|and{\T}{|
|00000570| 5c 68 73 70 61 63 65 7b | 2e 32 69 6e 7d 7d 0a 0a |\hspace{|.2in}}..|
|00000580| 5c 6e 65 77 6c 65 6e 67 | 74 68 7b 5c 78 77 69 64 |\newleng|th{\xwid|
|00000590| 74 68 7d 0a 5c 6e 65 77 | 6c 65 6e 67 74 68 7b 5c |th}.\new|length{\|
|000005a0| 73 65 63 77 69 64 74 68 | 7d 0a 5c 73 65 74 74 6f |secwidth|}.\setto|
|000005b0| 77 69 64 74 68 7b 5c 78 | 77 69 64 74 68 7d 7b 5c |width{\x|width}{\|
|000005c0| 73 63 20 78 7d 0a 5c 73 | 65 74 74 6f 77 69 64 74 |sc x}.\s|ettowidt|
|000005d0| 68 7b 5c 73 65 63 77 69 | 64 74 68 7d 7b 5c 73 66 |h{\secwi|dth}{\sf|
|000005e0| 20 24 20 6d 75 24 73 65 | 63 7d 0a 5c 61 64 64 74 | $ mu$se|c}.\addt|
|000005f0| 6f 6c 65 6e 67 74 68 7b | 5c 73 65 63 77 69 64 74 |olength{|\secwidt|
|00000600| 68 7d 7b 2d 5c 78 77 69 | 64 74 68 7d 0a 0a 5c 73 |h}{-\xwi|dth}..\s|
|00000610| 65 63 74 69 6f 6e 7b 49 | 6e 74 72 6f 64 75 63 74 |ection{I|ntroduct|
|00000620| 69 6f 6e 7d 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |ion}..\s|ubsectio|
|00000630| 6e 7b 4f 76 65 72 76 69 | 65 77 20 6f 66 20 74 68 |n{Overvi|ew of th|
|00000640| 65 20 54 63 6c 20 4c 61 | 6e 67 75 61 67 65 7d 0a |e Tcl La|nguage}.|
|00000650| 0a 54 63 6c 5c 63 69 74 | 65 7b 74 63 6c 7d 20 69 |.Tcl\cit|e{tcl} i|
|00000660| 73 20 64 65 73 69 67 6e | 65 64 20 74 6f 20 61 64 |s design|ed to ad|
|00000670| 64 72 65 73 73 20 74 68 | 65 20 6e 65 65 64 20 66 |dress th|e need f|
|00000680| 6f 72 20 61 20 60 60 73 | 63 72 69 70 74 69 6e 67 |or a ``s|cripting|
|00000690| 27 27 20 6c 61 6e 67 75 | 61 67 65 2c 0a 20 20 70 |'' langu|age,. p|
|000006a0| 72 6f 76 69 64 69 6e 67 | 20 68 69 67 68 2d 6c 65 |roviding| high-le|
|000006b0| 76 65 6c 20 63 6f 6e 74 | 72 6f 6c 20 6f 76 65 72 |vel cont|rol over|
|000006c0| 20 61 20 70 72 6f 67 72 | 61 6d 2e 20 20 54 68 65 | a progr|am. The|
|000006d0| 20 69 6e 74 65 72 66 61 | 63 65 20 62 65 74 77 65 | interfa|ce betwe|
|000006e0| 65 6e 20 54 63 6c 0a 20 | 20 61 6e 64 20 74 68 65 |en Tcl. | and the|
|000006f0| 20 72 75 6e 6e 69 6e 67 | 20 70 72 6f 67 72 61 6d | running| program|
|00000700| 20 63 6f 6e 73 69 73 74 | 73 20 6f 66 20 74 68 65 | consist|s of the|
|00000710| 20 54 63 6c 20 72 75 6e | 74 69 6d 65 20 6c 69 62 | Tcl run|time lib|
|00000720| 72 61 72 79 2c 20 77 68 | 69 63 68 20 69 73 0a 20 |rary, wh|ich is. |
|00000730| 20 65 6d 62 65 64 64 65 | 64 20 69 6e 74 6f 20 74 | embedde|d into t|
|00000740| 68 65 20 43 20 61 70 70 | 6c 69 63 61 74 69 6f 6e |he C app|lication|
|00000750| 20 63 6f 64 65 2e 0a 0a | 54 63 6c 20 61 70 70 65 | code...|Tcl appe|
|00000760| 61 72 73 20 74 6f 20 74 | 68 65 20 70 72 6f 67 72 |ars to t|he progr|
|00000770| 61 6d 6d 65 72 20 61 73 | 20 61 20 73 79 6e 74 61 |ammer as| a synta|
|00000780| 63 74 69 63 61 6c 6c 79 | 20 73 69 6d 70 6c 65 20 |ctically| simple |
|00000790| 63 6f 6d 62 69 6e 61 74 | 69 6f 6e 20 6f 66 20 4c |combinat|ion of L|
|000007a0| 69 73 70 0a 20 20 5c 63 | 69 74 65 7b 6c 69 73 70 |isp. \c|ite{lisp|
|000007b0| 63 72 61 66 74 7d 2c 20 | 50 65 72 6c 20 5c 63 69 |craft}, |Perl \ci|
|000007c0| 74 65 7b 70 65 72 6c 7d | 20 61 6e 64 20 74 68 65 |te{perl}| and the|
|000007d0| 20 55 6e 69 78 20 53 68 | 65 6c 6c 20 6c 61 6e 67 | Unix Sh|ell lang|
|000007e0| 75 61 67 65 20 5c 63 69 | 74 65 7b 73 68 7d 2e 0a |uage \ci|te{sh}..|
|000007f0| 20 20 4c 69 6b 65 20 74 | 68 65 20 55 6e 69 78 20 | Like t|he Unix |
|00000800| 53 68 65 6c 6c 2c 20 69 | 74 20 73 75 70 70 6f 72 |Shell, i|t suppor|
|00000810| 74 73 20 6e 65 73 74 65 | 64 20 63 6f 6d 6d 61 6e |ts neste|d comman|
|00000820| 64 73 2c 20 61 75 74 6f | 6d 61 74 69 63 0a 20 20 |ds, auto|matic. |
|00000830| 63 6f 6e 63 61 74 65 6e | 61 74 69 6f 6e 2c 20 61 |concaten|ation, a|
|00000840| 6e 64 20 6e 65 77 6c 69 | 6e 65 2d 63 6f 6d 6d 61 |nd newli|ne-comma|
|00000850| 6e 64 2d 74 65 72 6d 69 | 6e 61 74 69 6f 6e 2e 20 |nd-termi|nation. |
|00000860| 20 46 72 6f 6d 20 4c 69 | 73 70 2c 20 69 74 20 62 | From Li|sp, it b|
|00000870| 6f 72 72 6f 77 73 0a 20 | 20 60 64 65 66 75 6e 27 |orrows. | `defun'|
|00000880| 2d 6c 69 6b 65 20 73 79 | 6e 74 61 78 2c 20 64 65 |-like sy|ntax, de|
|00000890| 66 61 75 6c 74 20 70 72 | 6f 63 65 64 75 72 65 20 |fault pr|ocedure |
|000008a0| 61 72 67 75 6d 65 6e 74 | 73 2c 20 61 6e 64 20 65 |argument|s, and e|
|000008b0| 76 61 6c 28 29 2e 20 20 | 4c 69 6b 65 20 50 65 72 |val(). |Like Per|
|000008c0| 6c 2c 0a 20 20 54 63 6c | 27 73 20 6f 6e 6c 79 20 |l,. Tcl|'s only |
|000008d0| 64 61 74 61 20 74 79 70 | 65 20 69 73 20 74 68 65 |data typ|e is the|
|000008e0| 20 73 74 72 69 6e 67 2e | 0a 0a 49 6e 20 54 63 6c | string.|..In Tcl|
|000008f0| 2c 20 65 76 65 72 79 20 | 73 74 61 74 65 6d 65 6e |, every |statemen|
|00000900| 74 20 63 61 6e 20 62 65 | 20 74 68 6f 75 67 68 74 |t can be| thought|
|00000910| 20 6f 66 20 61 73 20 61 | 20 66 75 6e 63 74 69 6f | of as a| functio|
|00000920| 6e 20 63 61 6c 6c 2c 20 | 69 6e 20 74 68 65 20 66 |n call, |in the f|
|00000930| 6f 72 6d 0a 20 20 6f 66 | 20 60 60 63 6d 64 20 61 |orm. of| ``cmd a|
|00000940| 72 67 20 61 72 67 20 61 | 72 67 27 27 2c 20 77 68 |rg arg a|rg'', wh|
|00000950| 65 72 65 20 74 68 65 20 | 60 63 6d 64 27 20 70 73 |ere the |`cmd' ps|
|00000960| 65 75 64 6f 2d 66 75 6e | 63 74 69 6f 6e 20 69 73 |eudo-fun|ction is|
|00000970| 20 74 68 65 20 66 69 72 | 73 74 0a 20 20 77 68 69 | the fir|st. whi|
|00000980| 74 65 73 70 61 63 65 2d | 73 65 70 61 72 61 74 65 |tespace-|separate|
|00000990| 64 20 61 72 67 75 6d 65 | 6e 74 20 61 6e 64 20 74 |d argume|nt and t|
|000009a0| 68 65 20 61 72 67 73 20 | 61 72 65 20 74 68 65 20 |he args |are the |
|000009b0| 76 61 72 69 6f 75 73 0a | 20 20 77 68 69 74 65 73 |various.| whites|
|000009c0| 70 61 63 65 2d 73 65 70 | 61 72 61 74 65 64 20 69 |pace-sep|arated i|
|000009d0| 74 65 6d 73 20 74 68 61 | 74 20 66 6f 6c 6c 6f 77 |tems tha|t follow|
|000009e0| 20 69 74 2e 20 20 53 71 | 75 61 72 65 2d 62 72 61 | it. Sq|uare-bra|
|000009f0| 63 6b 65 74 73 20 64 65 | 6e 6f 74 65 20 6e 65 73 |ckets de|note nes|
|00000a00| 74 65 64 0a 20 20 63 6f | 6d 6d 61 6e 64 73 3b 20 |ted. co|mmands; |
|00000a10| 64 6f 6c 6c 61 72 2d 73 | 69 67 6e 73 20 69 6e 64 |dollar-s|igns ind|
|00000a20| 69 63 61 74 65 20 76 61 | 72 69 61 62 6c 65 20 73 |icate va|riable s|
|00000a30| 75 62 73 74 69 74 75 74 | 69 6f 6e 3b 20 63 75 72 |ubstitut|ion; cur|
|00000a40| 6c 79 2d 62 72 61 63 65 | 73 20 73 65 72 76 65 0a |ly-brace|s serve.|
|00000a50| 20 20 74 6f 20 67 72 6f | 75 70 20 74 65 78 74 20 | to gro|up text |
|00000a60| 69 6e 74 6f 20 61 20 73 | 69 6e 67 6c 65 20 61 72 |into a s|ingle ar|
|00000a70| 67 75 6d 65 6e 74 2c 20 | 77 69 74 68 6f 75 74 20 |gument, |without |
|00000a80| 70 65 72 66 6f 72 6d 69 | 6e 67 20 73 75 62 73 74 |performi|ng subst|
|00000a90| 69 74 75 74 69 6f 6e 2e | 0a 0a 41 6e 20 65 78 61 |itution.|..An exa|
|00000aa0| 6d 70 6c 65 20 66 6f 6c | 6c 6f 77 73 3a 0a 5c 62 |mple fol|lows:.\b|
|00000ab0| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0a 23 |egin{ver|batim}.#|
|00000ac0| 20 63 6f 6d 6d 65 6e 74 | 73 20 73 74 61 72 74 20 | comment|s start |
|00000ad0| 77 69 74 68 20 61 20 27 | 23 27 20 63 68 61 72 61 |with a '|#' chara|
|00000ae0| 63 74 65 72 2e 0a 23 20 | 73 65 74 73 20 76 61 72 |cter..# |sets var|
|00000af0| 69 61 62 6c 65 20 61 20 | 74 6f 20 76 61 6c 75 65 |iable a |to value|
|00000b00| 20 22 35 22 0a 23 20 20 | 20 28 74 68 65 20 73 74 | "5".# | (the st|
|00000b10| 72 69 6e 67 2c 20 6e 6f | 74 20 74 68 65 20 6e 75 |ring, no|t the nu|
|00000b20| 6d 62 65 72 21 29 0a 73 | 65 74 20 61 20 35 0a 20 |mber!).s|et a 5. |
|00000b30| 20 0a 23 20 73 65 74 73 | 20 62 20 74 6f 20 74 68 | .# sets| b to th|
|00000b40| 65 20 73 74 72 69 6e 67 | 20 22 31 30 22 2e 0a 23 |e string| "10"..#|
|00000b50| 20 54 68 65 20 27 65 78 | 70 72 27 20 63 6f 6d 6d | The 'ex|pr' comm|
|00000b60| 61 6e 64 20 63 6f 6e 76 | 65 72 74 73 20 74 68 65 |and conv|erts the|
|00000b70| 20 73 74 72 69 6e 67 0a | 23 20 20 20 22 35 22 20 | string.|# "5" |
|00000b80| 74 6f 20 74 68 65 20 6e | 75 6d 62 65 72 20 35 2c |to the n|umber 5,|
|00000b90| 20 28 69 74 20 69 73 20 | 6e 6f 74 0a 23 20 20 20 | (it is |not.# |
|00000ba0| 70 65 72 66 6f 72 6d 65 | 64 20 62 79 20 74 68 65 |performe|d by the|
|00000bb0| 20 69 6e 74 65 72 70 65 | 74 65 72 29 0a 73 65 74 | interpe|ter).set|
|00000bc0| 20 62 20 5b 65 78 70 72 | 20 24 61 2b 35 5d 0a 20 | b [expr| $a+5]. |
|00000bd0| 20 0a 23 20 73 65 74 73 | 20 63 20 74 6f 20 22 35 | .# sets| c to "5|
|00000be0| 2e 35 31 30 22 0a 73 65 | 74 20 63 20 24 61 2e 24 |.510".se|t c $a.$|
|00000bf0| 61 24 62 0a 20 20 0a 23 | 20 6f 75 74 70 75 74 73 |a$b. .#| outputs|
|00000c00| 20 74 68 65 20 73 74 72 | 69 6e 67 20 22 35 22 2e | the str|ing "5".|
|00000c10| 0a 70 75 74 73 20 73 74 | 64 6f 75 74 20 24 61 0a |.puts st|dout $a.|
|00000c20| 20 20 0a 23 20 64 65 66 | 69 6e 65 20 61 20 6e 65 | .# def|ine a ne|
|00000c30| 77 20 66 75 6e 63 74 69 | 6f 6e 0a 23 20 20 6e 6f |w functi|on.# no|
|00000c40| 74 65 20 64 65 66 61 75 | 6c 74 20 61 72 67 75 6d |te defau|lt argum|
|00000c50| 65 6e 74 20 6f 66 20 27 | 31 27 2e 0a 23 20 27 70 |ent of '|1'..# 'p|
|00000c60| 72 6f 63 27 20 69 73 20 | 61 20 63 6f 6d 6d 61 6e |roc' is |a comman|
|00000c70| 64 20 74 61 6b 69 6e 67 | 20 22 66 61 63 74 22 2c |d taking| "fact",|
|00000c80| 20 0a 23 20 20 22 7b 6e | 20 31 7d 22 20 61 6e 64 | .# "{n| 1}" and|
|00000c90| 20 22 69 66 20 2e 2e 2e | 20 22 20 61 73 20 61 72 | "if ...| " as ar|
|00000ca0| 67 75 6d 65 6e 74 73 0a | 23 20 20 28 63 75 72 6c |guments.|# (curl|
|00000cb0| 69 65 73 20 61 72 65 20 | 73 74 72 69 70 70 65 64 |ies are |stripped|
|00000cc0| 20 62 79 20 74 68 65 20 | 69 6e 74 65 72 70 72 65 | by the |interpre|
|00000cd0| 74 65 72 29 2e 0a 70 72 | 6f 63 20 66 61 63 74 20 |ter)..pr|oc fact |
|00000ce0| 7b 20 7b 6e 20 31 7d 20 | 7d 20 7b 0a 20 20 69 66 |{ {n 1} |} {. if|
|00000cf0| 20 7b 24 6e 20 3c 3d 20 | 31 7d 20 7b 0a 20 20 20 | {$n <= |1} {. |
|00000d00| 20 72 65 74 75 72 6e 20 | 31 3b 0a 20 20 7d 20 65 | return |1;. } e|
|00000d10| 6c 73 65 20 7b 0a 20 20 | 20 20 72 65 74 75 72 6e |lse {. | return|
|00000d20| 20 5b 65 78 70 72 20 24 | 6e 2a 5b 66 61 63 74 20 | [expr $|n*[fact |
|00000d30| 5b 65 78 70 72 20 24 6e | 2d 31 5d 5d 5d 3b 0a 20 |[expr $n|-1]]];. |
|00000d40| 20 7d 0a 7d 0a 20 20 0a | 23 20 22 66 6f 6f 22 20 | }.}. .|# "foo" |
|00000d50| 69 73 20 63 61 6c 6c 65 | 64 20 77 69 74 68 20 61 |is calle|d with a|
|00000d60| 72 67 73 20 22 62 61 72 | 22 2c 20 22 37 22 0a 66 |rgs "bar|", "7".f|
|00000d70| 6f 6f 20 62 61 72 20 37 | 0a 5c 65 6e 64 7b 76 65 |oo bar 7|.\end{ve|
|00000d80| 72 62 61 74 69 6d 7d 0a | 0a 4f 6e 65 20 6f 66 20 |rbatim}.|.One of |
|00000d90| 74 68 65 20 6d 6f 73 74 | 20 69 6e 74 65 72 65 73 |the most| interes|
|00000da0| 74 69 6e 67 20 66 65 61 | 74 75 72 65 73 20 6f 66 |ting fea|tures of|
|00000db0| 20 54 63 6c 20 69 73 20 | 69 74 73 20 61 62 69 6c | Tcl is |its abil|
|00000dc0| 69 74 79 20 74 6f 20 62 | 65 20 65 6d 62 65 64 64 |ity to b|e embedd|
|00000dd0| 65 64 0a 20 20 61 6e 64 | 20 65 78 74 65 6e 64 65 |ed. and| extende|
|00000de0| 64 20 74 68 72 6f 75 67 | 68 20 69 74 73 20 43 20 |d throug|h its C |
|00000df0| 6c 61 6e 67 75 61 67 65 | 20 6c 69 62 72 61 72 79 |language| library|
|00000e00| 2e 20 20 46 72 6f 6d 20 | 74 68 65 20 43 20 70 72 |. From |the C pr|
|00000e10| 6f 67 72 61 6d 6d 65 72 | 27 73 0a 20 20 70 65 72 |ogrammer|'s. per|
|00000e20| 73 70 65 63 74 69 76 65 | 2c 20 74 68 65 20 54 63 |spective|, the Tc|
|00000e30| 6c 20 69 6e 74 65 72 70 | 72 65 74 65 72 20 69 73 |l interp|reter is|
|00000e40| 20 74 72 65 61 74 65 64 | 20 61 73 20 61 6e 20 69 | treated| as an i|
|00000e50| 6e 73 74 61 6e 74 69 61 | 62 6c 65 20 6f 62 6a 65 |nstantia|ble obje|
|00000e60| 63 74 0a 20 20 28 65 6d | 62 65 64 64 65 64 29 2c |ct. (em|bedded),|
|00000e70| 20 77 68 69 63 68 20 69 | 73 20 70 61 73 73 65 64 | which i|s passed|
|00000e80| 20 74 68 65 20 63 6f 6e | 74 65 6e 74 73 20 6f 66 | the con|tents of|
|00000e90| 20 74 68 65 20 73 63 72 | 69 70 74 20 74 6f 20 62 | the scr|ipt to b|
|00000ea0| 65 20 72 75 6e 2e 20 20 | 54 68 69 73 0a 20 20 6f |e run. |This. o|
|00000eb0| 62 6a 65 63 74 20 65 78 | 69 73 74 73 20 61 73 20 |bject ex|ists as |
|00000ec0| 61 20 64 61 74 61 20 73 | 74 72 75 63 74 75 72 65 |a data s|tructure|
|00000ed0| 20 69 6e 20 43 20 77 6f | 72 6b 69 6e 67 20 69 6e | in C wo|rking in|
|00000ee0| 20 74 61 6e 64 65 6d 20 | 77 69 74 68 20 61 20 43 | tandem |with a C|
|00000ef0| 0a 20 20 66 75 6e 63 74 | 69 6f 6e 20 6c 69 62 72 |. funct|ion libr|
|00000f00| 61 72 79 2e 20 20 54 68 | 65 20 54 63 6c 20 72 75 |ary. Th|e Tcl ru|
|00000f10| 6e 74 69 6d 65 20 6c 69 | 62 72 61 72 79 20 65 78 |ntime li|brary ex|
|00000f20| 70 6f 73 65 73 20 61 6c | 6c 20 6f 66 20 74 68 65 |poses al|l of the|
|00000f30| 20 63 6f 72 65 0a 20 20 | 63 6f 6d 6d 61 6e 64 73 | core. |commands|
|00000f40| 20 74 6f 20 74 68 65 20 | 43 20 70 72 6f 67 72 61 | to the |C progra|
|00000f50| 6d 6d 65 72 20 64 69 72 | 65 63 74 6c 79 2c 20 73 |mmer dir|ectly, s|
|00000f60| 6f 20 54 63 6c 20 73 74 | 61 74 65 6d 65 6e 74 73 |o Tcl st|atements|
|00000f70| 20 6d 61 79 20 62 65 20 | 65 78 65 63 75 74 65 64 | may be |executed|
|00000f80| 0a 20 20 61 73 20 43 20 | 66 75 6e 63 74 69 6f 6e |. as C |function|
|00000f90| 20 63 61 6c 6c 73 20 74 | 6f 20 72 6f 75 74 69 6e | calls t|o routin|
|00000fa0| 65 73 20 70 72 6f 76 69 | 64 65 64 20 62 79 20 74 |es provi|ded by t|
|00000fb0| 68 65 20 6c 69 62 72 61 | 72 79 2e 20 20 54 68 69 |he libra|ry. Thi|
|00000fc0| 73 20 6c 69 62 72 61 72 | 79 20 69 73 0a 20 20 69 |s librar|y is. i|
|00000fd0| 64 65 6e 74 69 63 61 6c | 20 74 6f 20 74 68 65 20 |dentical| to the |
|00000fe0| 6f 6e 65 20 74 68 61 74 | 20 54 63 6c 20 75 73 65 |one that| Tcl use|
|00000ff0| 73 20 74 6f 20 65 76 61 | 6c 75 61 74 65 20 73 74 |s to eva|luate st|
|00001000| 61 74 65 6d 65 6e 74 73 | 20 69 6e 20 61 20 73 63 |atements| in a sc|
|00001010| 72 69 70 74 2e 0a 20 20 | 54 68 75 73 2c 20 70 72 |ript.. |Thus, pr|
|00001020| 6f 67 72 61 6d 73 20 6c | 69 6b 65 20 7b 5c 74 74 |ograms l|ike {\tt|
|00001030| 20 77 69 73 68 7d 20 61 | 72 65 20 6e 6f 74 68 69 | wish} a|re nothi|
|00001040| 6e 67 20 6d 6f 72 65 20 | 74 68 61 6e 20 6d 61 69 |ng more |than mai|
|00001050| 6e 20 6c 6f 6f 70 73 20 | 77 68 69 63 68 0a 20 20 |n loops |which. |
|00001060| 63 6f 6c 6c 65 63 74 20 | 75 73 65 72 20 69 6e 70 |collect |user inp|
|00001070| 75 74 20 61 6e 64 20 70 | 61 73 73 20 69 74 20 6f |ut and p|ass it o|
|00001080| 6e 65 20 73 74 61 74 65 | 6d 65 6e 74 20 61 74 20 |ne state|ment at |
|00001090| 61 20 74 69 6d 65 20 74 | 6f 20 61 20 72 6f 75 74 |a time t|o a rout|
|000010a0| 69 6e 65 0a 20 20 63 61 | 6c 6c 65 64 20 54 63 6c |ine. ca|lled Tcl|
|000010b0| 5c 5f 45 76 61 6c 28 29 | 2e 0a 0a 54 63 6c 20 63 |\_Eval()|...Tcl c|
|000010c0| 61 6e 20 61 6c 73 6f 20 | 62 65 20 65 78 74 65 6e |an also |be exten|
|000010d0| 64 65 64 20 66 72 6f 6d | 20 74 68 65 20 43 20 70 |ded from| the C p|
|000010e0| 72 6f 67 72 61 6d 20 62 | 79 20 72 65 67 69 73 74 |rogram b|y regist|
|000010f0| 65 72 69 6e 67 20 63 6f | 6d 6d 61 6e 64 73 20 77 |ering co|mmands w|
|00001100| 69 74 68 0a 20 20 74 68 | 65 20 54 63 6c 20 69 6e |ith. th|e Tcl in|
|00001110| 74 65 72 70 72 65 74 65 | 72 2e 20 20 54 68 65 20 |terprete|r. The |
|00001120| 69 6e 74 65 72 70 72 65 | 74 65 72 20 77 69 6c 6c |interpre|ter will|
|00001130| 20 63 61 6c 6c 20 62 61 | 63 6b 20 74 6f 20 79 6f | call ba|ck to yo|
|00001140| 75 72 20 43 20 63 6f 64 | 65 20 77 68 65 6e 0a 20 |ur C cod|e when. |
|00001150| 20 61 6e 64 20 69 66 20 | 74 68 61 74 20 54 63 6c | and if |that Tcl|
|00001160| 20 63 6f 6d 6d 61 6e 64 | 20 69 73 20 65 78 65 63 | command| is exec|
|00001170| 75 74 65 64 2e 20 20 49 | 6e 20 66 61 63 74 2c 20 |uted. I|n fact, |
|00001180| 74 68 69 73 20 69 73 20 | 68 6f 77 20 61 6c 6c 20 |this is |how all |
|00001190| 6f 66 20 74 68 65 0a 20 | 20 63 6f 72 65 20 6c 61 |of the. | core la|
|000011a0| 6e 67 75 61 67 65 20 63 | 6f 6d 6d 61 6e 64 73 20 |nguage c|ommands |
|000011b0| 61 72 65 20 69 6d 70 6c | 65 6d 65 6e 74 65 64 2e |are impl|emented.|
|000011c0| 20 20 49 6e 20 74 68 65 | 20 61 62 6f 76 65 20 65 | In the| above e|
|000011d0| 78 61 6d 70 6c 65 2c 20 | 74 68 65 20 7b 5c 74 74 |xample, |the {\tt|
|000011e0| 0a 20 20 73 65 74 7d 20 | 63 6f 6d 6d 61 6e 64 20 |. set} |command |
|000011f0| 69 73 20 6e 6f 74 68 69 | 6e 67 20 6d 6f 72 65 20 |is nothi|ng more |
|00001200| 74 68 61 6e 20 61 20 72 | 65 67 69 73 74 65 72 65 |than a r|egistere|
|00001210| 64 20 63 61 6c 6c 62 61 | 63 6b 20 77 68 6f 73 65 |d callba|ck whose|
|00001220| 20 66 75 6e 63 74 69 6f | 6e 0a 20 20 70 6f 69 6e | functio|n. poin|
|00001230| 74 65 72 20 69 73 20 74 | 68 65 20 6c 69 62 72 61 |ter is t|he libra|
|00001240| 72 79 20 66 75 6e 63 74 | 69 6f 6e 20 77 68 69 63 |ry funct|ion whic|
|00001250| 68 20 68 61 6e 64 6c 65 | 73 20 73 65 74 20 2d 20 |h handle|s set - |
|00001260| 74 68 65 20 76 65 72 79 | 20 73 61 6d 65 20 6f 6e |the very| same on|
|00001270| 65 0a 20 20 77 68 69 63 | 68 20 69 73 20 61 76 61 |e. whic|h is ava|
|00001280| 69 6c 61 62 6c 65 20 74 | 6f 20 74 68 65 20 43 20 |ilable t|o the C |
|00001290| 6c 61 6e 67 75 61 67 65 | 20 70 72 6f 67 72 61 6d |language| program|
|000012a0| 6d 65 72 20 64 69 72 65 | 63 74 6c 79 21 20 20 54 |mer dire|ctly! T|
|000012b0| 68 65 20 6c 61 73 74 0a | 20 20 73 74 61 74 65 6d |he last.| statem|
|000012c0| 65 6e 74 20 69 6e 20 74 | 68 65 20 65 78 61 6d 70 |ent in t|he examp|
|000012d0| 6c 65 2c 20 60 60 66 6f | 6f 27 27 20 64 6f 65 73 |le, ``fo|o'' does|
|000012e0| 6e 27 74 20 65 78 69 73 | 74 20 69 6e 20 74 68 65 |n't exis|t in the|
|000012f0| 20 64 65 66 61 75 6c 74 | 20 54 63 6c 0a 20 20 6c | default| Tcl. l|
|00001300| 61 6e 67 75 61 67 65 20 | 2d 20 69 74 20 69 73 20 |anguage |- it is |
|00001310| 65 69 74 68 65 72 20 61 | 20 63 61 6c 6c 20 74 6f |either a| call to|
|00001320| 20 61 20 70 72 6f 63 65 | 64 75 72 65 20 64 65 66 | a proce|dure def|
|00001330| 69 6e 65 64 20 69 6e 20 | 54 63 6c 20 69 74 73 65 |ined in |Tcl itse|
|00001340| 6c 66 20 75 73 69 6e 67 | 0a 20 20 74 68 65 20 7b |lf using|. the {|
|00001350| 5c 74 74 20 70 72 6f 63 | 7d 20 6d 65 63 68 61 6e |\tt proc|} mechan|
|00001360| 69 73 6d 2c 20 6f 72 20 | 61 20 63 61 6c 6c 62 61 |ism, or |a callba|
|00001370| 63 6b 20 74 6f 20 61 20 | 43 20 66 75 6e 63 74 69 |ck to a |C functi|
|00001380| 6f 6e 20 64 65 66 69 6e | 65 64 20 62 79 20 74 68 |on defin|ed by th|
|00001390| 65 0a 20 20 75 73 65 72 | 2c 20 77 68 65 72 65 20 |e. user|, where |
|000013a0| 74 68 65 20 61 72 67 75 | 6d 65 6e 74 73 20 60 60 |the argu|ments ``|
|000013b0| 62 61 72 27 27 20 61 6e | 64 20 60 60 37 27 27 20 |bar'' an|d ``7'' |
|000013c0| 61 72 65 20 70 61 73 73 | 65 64 20 74 6f 20 69 74 |are pass|ed to it|
|000013d0| 2c 20 69 6e 20 74 68 65 | 69 72 0a 20 20 73 74 72 |, in the|ir. str|
|000013e0| 69 6e 67 20 66 6f 72 6d | 73 2e 0a 0a 5c 73 75 62 |ing form|s...\sub|
|000013f0| 73 65 63 74 69 6f 6e 7b | 57 68 79 20 44 6f 20 57 |section{|Why Do W|
|00001400| 65 20 4e 65 65 64 20 74 | 6f 20 43 6f 6d 70 69 6c |e Need t|o Compil|
|00001410| 65 20 49 74 3f 7d 0a 0a | 4d 6f 73 74 20 54 63 6c |e It?}..|Most Tcl|
|00001420| 20 73 63 72 69 70 74 73 | 20 61 6e 64 20 63 6f 6d | scripts| and com|
|00001430| 6d 61 6e 64 73 20 61 72 | 65 20 64 65 73 69 67 6e |mands ar|e design|
|00001440| 65 64 20 74 6f 20 6f 70 | 65 72 61 74 65 20 6f 76 |ed to op|erate ov|
|00001450| 65 72 20 68 69 67 68 20 | 6c 65 76 65 6c 2c 0a 20 |er high |level,. |
|00001460| 20 65 78 70 65 6e 73 69 | 76 65 20 63 6f 6e 73 74 | expensi|ve const|
|00001470| 72 75 63 74 73 2c 20 77 | 68 65 72 65 20 73 70 65 |ructs, w|here spe|
|00001480| 65 64 20 69 73 20 6e 6f | 74 20 74 68 65 20 70 72 |ed is no|t the pr|
|00001490| 69 6d 61 72 79 20 63 6f | 6e 73 69 64 65 72 61 74 |imary co|nsiderat|
|000014a0| 69 6f 6e 2e 20 20 49 6e | 0a 20 20 74 68 65 73 65 |ion. In|. these|
|000014b0| 20 63 61 73 65 73 2c 20 | 74 68 65 20 63 6f 73 74 | cases, |the cost|
|000014c0| 20 6f 66 20 74 68 65 20 | 69 6e 74 65 72 70 72 65 | of the |interpre|
|000014d0| 74 61 74 69 6f 6e 20 69 | 73 20 6e 65 67 6c 69 67 |tation i|s neglig|
|000014e0| 69 62 6c 65 20 63 6f 6d | 70 61 72 65 64 20 74 6f |ible com|pared to|
|000014f0| 20 74 68 65 0a 20 20 6f | 76 65 72 68 65 61 64 20 | the. o|verhead |
|00001500| 77 69 74 68 69 6e 20 69 | 6e 64 69 76 69 64 75 61 |within i|ndividua|
|00001510| 6c 20 63 61 6c 6c 62 61 | 63 6b 20 66 75 6e 63 74 |l callba|ck funct|
|00001520| 69 6f 6e 73 2e 20 20 46 | 6f 72 20 65 78 61 6d 70 |ions. F|or examp|
|00001530| 6c 65 2c 20 6f 6e 20 61 | 20 53 75 6e 0a 20 20 53 |le, on a| Sun. S|
|00001540| 70 61 72 63 32 2c 20 74 | 68 65 20 7b 5c 74 74 20 |parc2, t|he {\tt |
|00001550| 73 65 74 7d 20 63 6f 6d | 6d 61 6e 64 20 74 61 6b |set} com|mand tak|
|00001560| 65 73 20 75 6e 64 65 72 | 20 37 35 20 6d 69 63 72 |es under| 75 micr|
|00001570| 6f 73 65 63 6f 6e 64 73 | 2e 20 20 42 79 0a 20 20 |oseconds|. By. |
|00001580| 63 6f 6d 70 61 72 69 73 | 6f 6e 2c 20 63 72 65 61 |comparis|on, crea|
|00001590| 74 69 6e 67 20 61 20 6e | 65 77 20 77 69 6e 64 6f |ting a n|ew windo|
|000015a0| 77 20 69 6e 20 58 20 57 | 69 6e 64 6f 77 73 20 63 |w in X W|indows c|
|000015b0| 61 6e 20 74 61 6b 65 20 | 61 0a 20 20 68 75 6d 61 |an take |a. huma|
|000015c0| 6e 2d 6e 6f 74 69 63 65 | 61 62 6c 65 20 61 6d 6f |n-notice|able amo|
|000015d0| 75 6e 74 20 6f 66 20 74 | 69 6d 65 2c 20 65 76 65 |unt of t|ime, eve|
|000015e0| 6e 20 6f 6e 20 66 61 73 | 74 65 72 20 77 6f 72 6b |n on fas|ter work|
|000015f0| 73 74 61 74 69 6f 6e 73 | 2e 20 20 55 73 69 6e 67 |stations|. Using|
|00001600| 20 54 63 6c 0a 20 20 61 | 73 20 61 20 68 65 61 76 | Tcl. a|s a heav|
|00001610| 79 77 65 69 67 68 74 20 | 69 6e 74 65 67 72 61 74 |yweight |integrat|
|00001620| 69 6f 6e 20 74 6f 6f 6c | 20 67 65 6e 65 72 61 6c |ion tool| general|
|00001630| 6c 79 20 64 6f 65 73 20 | 6e 6f 74 20 69 6d 70 61 |ly does |not impa|
|00001640| 63 74 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 0a 20 |ct appli|cation. |
|00001650| 20 70 65 72 66 6f 72 6d | 61 6e 63 65 2e 20 20 45 | perform|ance. E|
|00001660| 76 65 6e 20 69 6e 20 63 | 61 73 65 73 20 77 68 65 |ven in c|ases whe|
|00001670| 72 65 20 69 74 20 64 6f | 65 73 2c 20 70 65 72 66 |re it do|es, perf|
|00001680| 6f 72 6d 61 6e 63 65 20 | 62 6f 74 74 6c 65 6e 65 |ormance |bottlene|
|00001690| 63 6b 73 20 69 6e 20 54 | 63 6c 0a 20 20 63 61 6e |cks in T|cl. can|
|000016a0| 20 65 61 73 69 6c 79 20 | 62 65 20 69 73 6f 6c 61 | easily |be isola|
|000016b0| 74 65 64 20 61 6e 64 20 | 72 65 77 72 69 74 74 65 |ted and |rewritte|
|000016c0| 6e 20 69 6e 20 43 2c 20 | 69 6e 20 74 68 65 20 66 |n in C, |in the f|
|000016d0| 6f 72 6d 20 6f 66 20 63 | 61 6c 6c 62 61 63 6b 73 |orm of c|allbacks|
|000016e0| 2e 0a 0a 48 6f 77 65 76 | 65 72 2c 20 74 68 69 73 |...Howev|er, this|
|000016f0| 20 72 65 63 6f 64 69 6e | 67 20 69 73 20 61 6e 6e | recodin|g is ann|
|00001700| 6f 79 69 6e 67 20 61 6e | 64 20 69 6e 62 69 68 69 |oying an|d inbihi|
|00001710| 74 73 20 74 68 65 20 63 | 6f 6e 66 69 67 75 72 61 |ts the c|onfigura|
|00001720| 62 69 6c 69 74 79 20 74 | 68 61 74 0a 20 20 54 63 |bility t|hat. Tc|
|00001730| 6c 20 6f 66 66 65 72 73 | 3b 20 69 74 20 63 61 6e |l offers|; it can|
|00001740| 20 61 6c 73 6f 20 72 65 | 6d 6f 76 65 20 73 6f 6d | also re|move som|
|00001750| 65 20 6f 66 20 74 68 65 | 20 6d 6f 64 75 6c 61 72 |e of the| modular|
|00001760| 69 74 79 20 6f 66 20 61 | 20 77 65 6c 6c 2d 77 72 |ity of a| well-wr|
|00001770| 69 74 74 65 6e 0a 20 20 | 54 63 6c 2d 62 61 73 65 |itten. |Tcl-base|
|00001780| 64 20 70 72 6f 67 72 61 | 6d 2e 20 20 46 6f 72 20 |d progra|m. For |
|00001790| 65 78 61 6d 70 6c 65 2c | 20 69 66 20 79 6f 75 20 |example,| if you |
|000017a0| 64 69 73 63 6f 76 65 72 | 20 74 68 61 74 20 61 20 |discover| that a |
|000017b0| 6c 6f 6f 70 0a 20 20 77 | 72 69 74 74 65 6e 20 69 |loop. w|ritten i|
|000017c0| 6e 20 54 63 6c 20 69 73 | 20 61 20 70 65 72 66 6f |n Tcl is| a perfo|
|000017d0| 72 6d 61 6e 63 65 20 62 | 6f 74 74 6c 65 6e 65 63 |rmance b|ottlenec|
|000017e0| 6b 2c 20 69 74 20 77 6f | 75 6c 64 20 62 65 20 72 |k, it wo|uld be r|
|000017f0| 65 77 72 69 74 74 65 6e | 20 69 6e 20 43 2c 0a 20 |ewritten| in C,. |
|00001800| 20 61 6e 64 20 61 20 6e | 65 77 20 63 6f 6d 6d 61 | and a n|ew comma|
|00001810| 6e 64 20 72 65 67 69 73 | 74 65 72 65 64 20 77 69 |nd regis|tered wi|
|00001820| 74 68 20 74 68 65 20 54 | 63 6c 20 69 6e 74 65 72 |th the T|cl inter|
|00001830| 70 72 65 74 65 72 2e 20 | 20 4f 6e 63 65 20 74 68 |preter. | Once th|
|00001840| 69 73 20 68 61 73 0a 20 | 20 62 65 65 6e 20 64 6f |is has. | been do|
|00001850| 6e 65 2c 20 61 6e 79 20 | 63 6f 6d 6d 61 6e 64 73 |ne, any |commands|
|00001860| 20 69 6e 20 74 68 65 20 | 6c 6f 6f 70 20 61 72 65 | in the |loop are|
|00001870| 20 6e 6f 77 20 68 61 72 | 64 2d 63 6f 64 65 64 20 | now har|d-coded |
|00001880| 72 65 6c 61 74 69 76 65 | 20 74 6f 0a 20 20 74 68 |relative| to. th|
|00001890| 65 20 68 69 67 68 20 64 | 65 67 72 65 65 20 6f 66 |e high d|egree of|
|000018a0| 20 63 6f 6e 66 69 67 75 | 72 61 62 69 6c 69 74 79 | configu|rability|
|000018b0| 20 74 68 61 74 20 54 63 | 6c 20 6f 66 66 65 72 73 | that Tc|l offers|
|000018c0| 2e 0a 0a 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 53 |...\subs|ection{S|
|000018d0| 75 6d 6d 61 72 79 7d 0a | 49 6e 20 74 68 65 20 72 |ummary}.|In the r|
|000018e0| 65 6d 61 69 6e 64 65 72 | 20 6f 66 20 74 68 65 20 |emainder| of the |
|000018f0| 70 61 70 65 72 2c 20 77 | 65 20 64 69 73 63 75 73 |paper, w|e discus|
|00001900| 73 20 74 68 65 20 64 65 | 73 69 67 6e 20 61 6e 64 |s the de|sign and|
|00001910| 20 69 6d 70 6c 65 6d 65 | 6e 74 61 74 69 6f 6e 20 | impleme|ntation |
|00001920| 6f 66 0a 20 20 74 68 65 | 20 63 6f 6d 70 69 6c 65 |of. the| compile|
|00001930| 72 20 69 6e 20 64 65 70 | 74 68 2e 20 20 53 65 63 |r in dep|th. Sec|
|00001940| 74 69 6f 6e 20 32 20 64 | 65 73 63 72 69 62 65 73 |tion 2 d|escribes|
|00001950| 20 74 68 65 20 63 6f 6d | 70 69 6c 65 72 20 69 6e | the com|piler in|
|00001960| 74 65 72 66 61 63 65 2c | 20 61 6e 0a 20 20 6f 76 |terface,| an. ov|
|00001970| 65 72 76 69 65 77 20 6f | 66 20 74 68 65 20 75 73 |erview o|f the us|
|00001980| 65 72 27 73 20 76 69 65 | 77 20 6f 66 20 74 68 65 |er's vie|w of the|
|00001990| 20 63 6f 6d 70 69 6c 61 | 74 69 6f 6e 20 73 79 73 | compila|tion sys|
|000019a0| 74 65 6d 2e 20 20 53 65 | 63 74 69 6f 6e 20 33 0a |tem. Se|ction 3.|
|000019b0| 20 20 64 69 73 63 75 73 | 73 65 73 20 74 68 65 20 | discus|ses the |
|000019c0| 68 69 67 68 2d 6c 65 76 | 65 6c 20 64 65 73 69 67 |high-lev|el desig|
|000019d0| 6e 20 64 65 63 69 73 69 | 6f 6e 73 20 69 6e 76 6f |n decisi|ons invo|
|000019e0| 6c 76 65 64 20 77 69 74 | 68 20 74 68 65 20 65 66 |lved wit|h the ef|
|000019f0| 66 69 63 69 65 6e 74 0a | 20 20 65 78 65 63 75 74 |ficient.| execut|
|00001a00| 69 6f 6e 20 6f 66 20 54 | 63 6c 2e 20 20 49 6e 20 |ion of T|cl. In |
|00001a10| 53 65 63 74 69 6f 6e 73 | 20 34 20 61 6e 64 20 35 |Sections| 4 and 5|
|00001a20| 2c 20 74 68 65 20 67 69 | 76 65 6e 20 69 6d 70 6c |, the gi|ven impl|
|00001a30| 65 6d 65 6e 74 61 74 69 | 6f 6e 20 69 73 0a 20 20 |ementati|on is. |
|00001a40| 70 72 65 73 65 6e 74 65 | 64 2c 20 66 69 72 73 74 |presente|d, first|
|00001a50| 20 69 6e 20 74 65 72 6d | 73 20 6f 66 20 74 68 65 | in term|s of the|
|00001a60| 20 63 6f 6d 70 69 6c 65 | 72 2c 20 61 6e 64 20 74 | compile|r, and t|
|00001a70| 68 65 6e 20 69 6e 20 74 | 65 72 6d 73 20 6f 66 20 |hen in t|erms of |
|00001a80| 74 68 65 20 72 75 6e 74 | 69 6d 65 2e 0a 20 20 53 |the runt|ime.. S|
|00001a90| 65 63 74 69 6f 6e 20 36 | 20 70 72 65 73 65 6e 74 |ection 6| present|
|00001aa0| 73 20 74 68 65 20 72 65 | 73 75 6c 74 73 20 6f 66 |s the re|sults of|
|00001ab0| 20 74 68 69 73 20 69 6d | 70 6c 65 6d 65 6e 74 61 | this im|plementa|
|00001ac0| 74 69 6f 6e 20 74 68 72 | 6f 75 67 68 20 61 20 73 |tion thr|ough a s|
|00001ad0| 65 72 69 65 73 20 6f 66 | 0a 20 20 73 6d 61 6c 6c |eries of|. small|
|00001ae0| 20 62 65 6e 63 68 6d 61 | 72 6b 73 2c 20 61 6e 64 | benchma|rks, and|
|00001af0| 20 53 65 63 74 69 6f 6e | 20 37 20 73 75 6d 6d 61 | Section| 7 summa|
|00001b00| 72 69 7a 65 73 20 6f 75 | 72 20 65 66 66 6f 72 74 |rizes ou|r effort|
|00001b10| 73 20 61 6e 64 20 70 72 | 6f 70 6f 73 65 73 20 66 |s and pr|oposes f|
|00001b20| 75 74 75 72 65 0a 20 20 | 77 6f 72 6b 2e 0a 0a 5c |uture. |work...\|
|00001b30| 73 65 63 74 69 6f 6e 7b | 54 68 65 20 43 6f 6d 70 |section{|The Comp|
|00001b40| 69 6c 65 72 20 49 6e 74 | 65 72 66 61 63 65 7d 0a |iler Int|erface}.|
|00001b50| 0a 5c 73 75 62 73 65 63 | 74 69 6f 6e 7b 50 72 65 |.\subsec|tion{Pre|
|00001b60| 76 69 6f 75 73 20 57 6f | 72 6b 7d 0a 5c 73 75 62 |vious Wo|rk}.\sub|
|00001b70| 73 75 62 73 65 63 74 69 | 6f 6e 7b 45 6d 61 63 73 |subsecti|on{Emacs|
|00001b80| 20 4c 69 73 70 7d 0a 0a | 45 6d 61 63 73 20 69 73 | Lisp}..|Emacs is|
|00001b90| 20 61 20 70 72 6f 67 72 | 61 6d 6d 61 62 6c 65 20 | a progr|ammable |
|00001ba0| 65 64 69 74 6f 72 20 77 | 68 6f 73 65 20 75 6e 64 |editor w|hose und|
|00001bb0| 65 72 6c 79 69 6e 67 20 | 6c 61 6e 67 75 61 67 65 |erlying |language|
|00001bc0| 20 69 73 20 61 20 76 61 | 72 69 61 6e 74 20 6f 66 | is a va|riant of|
|00001bd0| 0a 20 20 4d 6f 63 6b 4c | 69 73 70 20 63 61 6c 6c |. MockL|isp call|
|00001be0| 65 64 20 45 6d 61 63 73 | 20 4c 69 73 70 5c 63 69 |ed Emacs| Lisp\ci|
|00001bf0| 74 65 7b 65 6c 69 73 70 | 7d 20 28 6f 72 20 65 6c |te{elisp|} (or el|
|00001c00| 69 73 70 20 66 6f 72 20 | 73 68 6f 72 74 29 2e 20 |isp for |short). |
|00001c10| 20 49 6e 63 6c 75 64 65 | 64 20 69 6e 0a 20 20 74 | Include|d in. t|
|00001c20| 68 69 73 20 73 79 73 74 | 65 6d 20 69 73 20 61 20 |his syst|em is a |
|00001c30| 60 60 62 79 74 65 2d 63 | 6f 6d 70 69 6c 65 72 27 |``byte-c|ompiler'|
|00001c40| 27 20 77 68 69 63 68 20 | 70 72 65 70 61 72 73 65 |' which |preparse|
|00001c50| 73 20 74 68 65 20 63 6f | 64 65 20 74 6f 20 61 20 |s the co|de to a |
|00001c60| 62 69 6e 61 72 79 0a 20 | 20 66 6f 72 6d 61 74 2e |binary. | format.|
|00001c70| 20 20 41 6c 6c 20 6f 66 | 20 74 68 65 20 65 6c 69 | All of| the eli|
|00001c80| 73 70 20 73 6f 75 72 63 | 65 20 66 69 6c 65 73 20 |sp sourc|e files |
|00001c90| 61 72 65 20 73 74 6f 72 | 65 64 20 69 6e 20 61 20 |are stor|ed in a |
|00001ca0| 73 69 6e 67 6c 65 20 64 | 69 72 65 63 74 6f 72 79 |single d|irectory|
|00001cb0| 2c 0a 20 20 77 69 74 68 | 20 6e 61 6d 65 73 20 65 |,. with| names e|
|00001cc0| 6e 64 69 6e 67 20 69 6e | 20 60 60 2e 65 6c 27 27 |nding in| ``.el''|
|00001cd0| 2e 20 20 42 79 74 65 2d | 63 6f 6d 70 69 6c 61 74 |. Byte-|compilat|
|00001ce0| 69 6f 6e 20 6f 66 20 61 | 20 73 6f 75 72 63 65 20 |ion of a| source |
|00001cf0| 66 69 6c 65 20 69 73 0a | 20 20 6f 75 74 70 75 74 |file is.| output|
|00001d00| 20 74 6f 20 74 68 65 20 | 73 61 6d 65 20 66 69 6c | to the |same fil|
|00001d10| 65 6e 61 6d 65 20 77 69 | 74 68 20 74 68 65 20 65 |ename wi|th the e|
|00001d20| 78 74 65 6e 73 69 6f 6e | 20 60 60 2e 65 6c 63 27 |xtension| ``.elc'|
|00001d30| 27 2e 20 20 57 68 65 6e | 20 74 68 69 73 0a 20 20 |'. When| this. |
|00001d40| 73 6f 75 72 63 65 20 66 | 69 6c 65 20 77 6f 75 6c |source f|ile woul|
|00001d50| 64 20 6f 74 68 65 72 77 | 69 73 65 20 62 65 20 6c |d otherw|ise be l|
|00001d60| 6f 61 64 65 64 2c 20 74 | 68 65 20 73 79 73 74 65 |oaded, t|he syste|
|00001d70| 6d 20 61 75 74 6f 6d 61 | 74 69 63 61 6c 6c 79 20 |m automa|tically |
|00001d80| 6c 6f 6f 6b 73 20 66 6f | 72 0a 20 20 61 20 63 6f |looks fo|r. a co|
|00001d90| 6d 70 69 6c 65 64 20 76 | 65 72 73 69 6f 6e 20 6f |mpiled v|ersion o|
|00001da0| 66 20 69 74 20 61 6e 64 | 20 77 69 6c 6c 20 6c 6f |f it and| will lo|
|00001db0| 61 64 20 74 68 61 74 20 | 69 6e 20 74 68 65 20 70 |ad that |in the p|
|00001dc0| 6c 61 63 65 20 6f 66 20 | 61 6e 20 6f 72 69 67 69 |lace of |an origi|
|00001dd0| 6e 61 6c 0a 20 20 73 6f | 75 72 63 65 20 66 69 6c |nal. so|urce fil|
|00001de0| 65 2e 0a 0a 54 68 65 20 | 62 79 74 65 2d 63 6f 6d |e...The |byte-com|
|00001df0| 70 69 6c 65 72 27 73 20 | 6f 75 74 70 75 74 20 69 |piler's |output i|
|00001e00| 73 20 68 69 67 68 6c 79 | 20 70 6f 72 74 61 62 6c |s highly| portabl|
|00001e10| 65 2e 20 20 54 68 69 73 | 20 6d 65 61 6e 73 20 74 |e. This| means t|
|00001e20| 68 61 74 0a 20 20 63 6f | 6d 70 69 6c 65 64 20 65 |hat. co|mpiled e|
|00001e30| 6c 69 73 70 20 66 69 6c | 65 73 20 63 61 6e 20 62 |lisp fil|es can b|
|00001e40| 65 20 70 6c 61 63 65 64 | 20 6f 6e 20 73 65 72 76 |e placed| on serv|
|00001e50| 65 72 73 2c 20 73 69 64 | 65 20 62 79 20 73 69 64 |ers, sid|e by sid|
|00001e60| 65 20 77 69 74 68 20 74 | 68 65 0a 20 20 6f 72 69 |e with t|he. ori|
|00001e70| 67 69 6e 61 6c 20 73 6f | 75 72 63 65 20 63 6f 64 |ginal so|urce cod|
|00001e80| 65 2c 20 69 6e 73 74 65 | 61 64 20 6f 66 20 72 65 |e, inste|ad of re|
|00001e90| 71 75 69 72 69 6e 67 20 | 61 20 73 65 70 61 72 61 |quiring |a separa|
|00001ea0| 74 65 20 73 65 74 20 66 | 6f 72 20 65 61 63 68 0a |te set f|or each.|
|00001eb0| 20 20 61 72 63 68 69 74 | 65 63 74 75 72 65 2e 0a | archit|ecture..|
|00001ec0| 0a 5c 73 75 62 73 75 62 | 73 65 63 74 69 6f 6e 7b |.\subsub|section{|
|00001ed0| 50 65 72 6c 7d 0a 0a 50 | 65 72 6c 5c 63 69 74 65 |Perl}..P|erl\cite|
|00001ee0| 7b 70 65 72 6c 7d 20 69 | 73 20 61 20 73 63 72 69 |{perl} i|s a scri|
|00001ef0| 70 74 69 6e 67 20 6c 61 | 6e 67 75 61 67 65 20 77 |pting la|nguage w|
|00001f00| 69 74 68 20 6d 61 6e 79 | 20 63 68 61 72 61 63 74 |ith many| charact|
|00001f10| 65 72 69 73 74 69 63 73 | 20 6f 66 20 54 63 6c 3a |eristics| of Tcl:|
|00001f20| 0a 20 20 69 74 20 69 73 | 20 64 65 73 69 67 6e 65 |. it is| designe|
|00001f30| 64 20 66 6f 72 20 68 69 | 67 68 2d 6c 65 76 65 6c |d for hi|gh-level|
|00001f40| 20 63 6f 6e 74 72 6f 6c | 20 6f 76 65 72 20 61 72 | control| over ar|
|00001f50| 62 69 74 72 61 72 79 20 | 69 6e 70 75 74 2c 20 69 |bitrary |input, i|
|00001f60| 74 73 20 73 79 6e 74 61 | 78 20 69 73 0a 20 20 64 |ts synta|x is. d|
|00001f70| 65 73 69 67 6e 65 64 20 | 61 72 6f 75 6e 64 20 74 |esigned |around t|
|00001f80| 68 65 20 73 74 72 69 6e | 67 20 64 61 74 61 20 74 |he strin|g data t|
|00001f90| 79 70 65 2c 20 61 6e 64 | 20 69 74 73 20 73 75 70 |ype, and| its sup|
|00001fa0| 70 6f 72 74 20 66 6f 72 | 20 64 61 74 61 20 74 79 |port for| data ty|
|00001fb0| 70 65 73 20 69 73 0a 20 | 20 6e 65 61 72 6c 79 20 |pes is. | nearly |
|00001fc0| 69 64 65 6e 74 69 63 61 | 6c 2d 20 61 73 73 6f 63 |identica|l- assoc|
|00001fd0| 69 61 74 69 76 65 20 61 | 72 72 61 79 73 2c 20 73 |iative a|rrays, s|
|00001fe0| 63 61 6c 61 72 20 76 61 | 72 69 61 62 6c 65 73 2c |calar va|riables,|
|00001ff0| 20 61 6e 64 20 61 72 72 | 61 79 73 20 6f 66 0a 20 | and arr|ays of. |
|00002000| 20 73 63 61 6c 61 72 73 | 20 28 77 68 69 63 68 20 | scalars| (which |
|00002010| 61 72 65 20 73 69 6d 69 | 6c 61 72 20 74 6f 20 54 |are simi|lar to T|
|00002020| 63 6c 20 6c 69 73 74 73 | 29 2e 0a 0a 50 65 72 6c |cl lists|)...Perl|
|00002030| 20 6c 61 63 6b 73 20 65 | 6d 62 65 64 64 61 62 69 | lacks e|mbeddabi|
|00002040| 6c 69 74 79 2c 20 61 6e | 64 20 73 6f 20 66 61 69 |lity, an|d so fai|
|00002050| 6c 73 20 74 6f 20 61 20 | 6c 61 72 67 65 20 64 65 |ls to a |large de|
|00002060| 67 72 65 65 20 74 6f 20 | 73 65 72 76 65 20 61 73 |gree to |serve as|
|00002070| 20 61 0a 20 20 68 69 67 | 68 2d 6c 65 76 65 6c 20 | a. hig|h-level |
|00002080| 63 6f 6e 74 72 6f 6c 20 | 6c 61 6e 67 75 61 67 65 |control |language|
|00002090| 2e 20 20 4e 6f 74 65 2c | 20 68 6f 77 65 76 65 72 |. Note,| however|
|000020a0| 2c 20 74 68 61 74 20 50 | 65 72 6c 20 64 6f 65 73 |, that P|erl does|
|000020b0| 20 73 75 70 70 6f 72 74 | 0a 20 20 61 72 62 69 74 | support|. arbit|
|000020c0| 72 61 72 79 20 69 6e 74 | 65 72 2d 70 72 6f 63 65 |rary int|er-proce|
|000020d0| 73 73 20 63 6f 6d 6d 75 | 6e 69 63 61 74 69 6f 6e |ss commu|nication|
|000020e0| 20 28 49 50 43 29 2c 20 | 73 6f 20 61 70 70 6c 69 | (IPC), |so appli|
|000020f0| 63 61 74 69 6f 6e 73 20 | 77 68 69 63 68 20 63 61 |cations |which ca|
|00002100| 6e 0a 20 20 74 61 6c 6b | 20 69 6e 20 74 68 69 73 |n. talk| in this|
|00002110| 20 77 61 79 20 63 61 6e | 20 69 6e 74 65 72 66 61 | way can| interfa|
|00002120| 63 65 20 77 69 74 68 20 | 50 65 72 6c 20 75 73 69 |ce with |Perl usi|
|00002130| 6e 67 20 74 68 69 73 20 | 66 61 63 69 6c 69 74 79 |ng this |facility|
|00002140| 2e 0a 0a 50 65 72 6c 20 | 69 73 20 63 6f 6d 70 69 |...Perl |is compi|
|00002150| 6c 65 64 20 6f 6e 20 64 | 65 6d 61 6e 64 20 65 61 |led on d|emand ea|
|00002160| 63 68 20 74 69 6d 65 20 | 74 68 65 20 73 63 72 69 |ch time |the scri|
|00002170| 70 74 20 69 73 20 6c 6f | 61 64 65 64 2e 0a 0a 5c |pt is lo|aded...\|
|00002180| 73 75 62 73 65 63 74 69 | 6f 6e 7b 54 68 65 20 55 |subsecti|on{The U|
|00002190| 73 65 72 20 49 6e 74 65 | 72 66 61 63 65 7d 0a 0a |ser Inte|rface}..|
|000021a0| 54 68 65 20 54 63 6c 20 | 43 6f 6d 70 69 6c 65 72 |The Tcl |Compiler|
|000021b0| 20 28 54 43 29 20 6f 70 | 65 72 61 74 65 73 20 6d | (TC) op|erates m|
|000021c0| 75 63 68 20 6c 69 6b 65 | 20 74 68 65 20 65 6c 69 |uch like| the eli|
|000021d0| 73 70 20 62 79 74 65 20 | 63 6f 6d 70 69 6c 65 72 |sp byte |compiler|
|000021e0| 3a 20 69 74 0a 20 20 70 | 72 6f 64 75 63 65 73 20 |: it. p|roduces |
|000021f0| 62 69 6e 61 72 79 20 66 | 69 6c 65 73 20 77 68 69 |binary f|iles whi|
|00002200| 63 68 20 74 68 65 20 72 | 75 6e 74 69 6d 65 20 73 |ch the r|untime s|
|00002210| 79 73 74 65 6d 20 6b 6e | 6f 77 73 20 74 6f 20 6c |ystem kn|ows to l|
|00002220| 6f 6f 6b 20 66 6f 72 2c | 20 61 6e 64 20 69 66 0a |ook for,| and if.|
|00002230| 20 20 66 6f 75 6e 64 2c | 20 77 69 6c 6c 20 75 73 | found,| will us|
|00002240| 65 20 69 6e 20 74 68 65 | 20 70 6c 61 63 65 20 6f |e in the| place o|
|00002250| 66 20 74 68 65 20 72 61 | 77 20 73 6f 75 72 63 65 |f the ra|w source|
|00002260| 20 77 68 65 6e 20 65 78 | 65 63 75 74 69 6e 67 2e | when ex|ecuting.|
|00002270| 20 20 54 68 69 73 0a 20 | 20 72 75 6e 74 69 6d 65 | This. | runtime|
|00002280| 20 69 73 20 65 73 73 65 | 6e 74 69 61 6c 6c 79 20 | is esse|ntially |
|00002290| 61 20 72 65 70 6c 61 63 | 65 6d 65 6e 74 20 54 63 |a replac|ement Tc|
|000022a0| 6c 20 69 6e 74 65 72 70 | 72 65 74 65 72 2c 20 77 |l interp|reter, w|
|000022b0| 68 69 63 68 20 74 61 6b | 65 73 20 61 73 0a 20 20 |hich tak|es as. |
|000022c0| 69 6e 70 75 74 20 62 69 | 6e 61 72 79 20 64 61 74 |input bi|nary dat|
|000022d0| 61 20 66 72 6f 6d 20 61 | 20 66 69 6c 65 2c 20 69 |a from a| file, i|
|000022e0| 6e 73 74 65 61 64 20 6f | 66 20 74 65 78 74 75 61 |nstead o|f textua|
|000022f0| 6c 20 64 61 74 61 2e 20 | 20 4c 69 6b 65 20 65 6c |l data. | Like el|
|00002300| 69 73 70 2c 20 54 43 27 | 73 0a 20 20 6f 75 74 70 |isp, TC'|s. outp|
|00002310| 75 74 20 66 69 6c 65 73 | 20 61 72 65 20 70 6f 72 |ut files| are por|
|00002320| 74 61 62 6c 65 2c 20 61 | 6e 64 20 73 6f 20 63 61 |table, a|nd so ca|
|00002330| 6e 20 62 65 20 70 6c 61 | 63 65 64 20 6f 6e 20 73 |n be pla|ced on s|
|00002340| 65 72 76 65 72 73 2e 0a | 0a 54 68 65 20 72 65 61 |ervers..|.The rea|
|00002350| 73 6f 6e 20 77 65 20 63 | 68 6f 73 65 20 74 68 69 |son we c|hose thi|
|00002360| 73 20 6d 6f 64 65 6c 20 | 69 73 20 74 68 61 74 20 |s model |is that |
|00002370| 54 63 6c 20 63 61 6e 6e | 6f 74 20 62 65 20 63 6f |Tcl cann|ot be co|
|00002380| 6d 70 69 6c 65 64 20 69 | 6e 74 6f 0a 20 20 70 75 |mpiled i|nto. pu|
|00002390| 72 65 20 6d 61 63 68 69 | 6e 65 20 63 6f 64 65 20 |re machi|ne code |
|000023a0| 77 69 74 68 6f 75 74 20 | 74 68 65 20 73 75 70 70 |without |the supp|
|000023b0| 6f 72 74 20 6f 66 20 61 | 20 6c 61 72 67 65 20 72 |ort of a| large r|
|000023c0| 75 6e 74 69 6d 65 20 6c | 69 62 72 61 72 79 2e 20 |untime l|ibrary. |
|000023d0| 20 54 68 69 73 0a 20 20 | 69 73 20 64 75 65 20 74 | This. |is due t|
|000023e0| 6f 20 74 68 65 20 75 73 | 65 72 2d 65 78 74 65 6e |o the us|er-exten|
|000023f0| 73 69 62 69 6c 69 74 79 | 20 73 79 73 74 65 6d 2c |sibility| system,|
|00002400| 20 77 68 65 72 65 20 62 | 75 69 6c 74 69 6e 20 63 | where b|uiltin c|
|00002410| 6f 6d 6d 61 6e 64 73 20 | 63 61 6e 20 62 65 0a 20 |ommands |can be. |
|00002420| 20 6f 76 65 72 6c 6f 61 | 64 65 64 2c 20 72 65 6d | overloa|ded, rem|
|00002430| 6f 76 65 64 2c 20 61 64 | 64 65 64 2c 20 65 74 63 |oved, ad|ded, etc|
|00002440| 2e 20 20 45 76 65 6e 20 | 73 69 6d 70 6c 65 20 73 |. Even |simple s|
|00002450| 74 61 74 65 6d 65 6e 74 | 73 20 6d 61 79 20 68 61 |tatement|s may ha|
|00002460| 76 65 0a 20 20 63 6f 6d | 70 6c 65 74 65 6c 79 20 |ve. com|pletely |
|00002470| 64 69 66 66 65 72 65 6e | 74 20 62 65 68 61 76 69 |differen|t behavi|
|00002480| 6f 72 73 20 64 65 70 65 | 6e 64 65 6e 74 20 6f 6e |ors depe|ndent on|
|00002490| 20 73 6f 6d 65 20 70 6f | 72 74 69 6f 6e 20 6f 66 | some po|rtion of|
|000024a0| 20 63 6f 64 65 20 74 68 | 61 74 20 74 68 65 0a 20 | code th|at the. |
|000024b0| 20 63 6f 6d 70 69 6c 65 | 72 20 64 6f 65 73 20 6e | compile|r does n|
|000024c0| 6f 74 20 68 61 76 65 20 | 61 63 63 65 73 73 20 74 |ot have |access t|
|000024d0| 6f 2e 20 20 54 68 69 73 | 20 70 72 6f 70 65 72 74 |o. This| propert|
|000024e0| 79 20 69 73 20 64 65 73 | 63 72 69 62 65 64 20 69 |y is des|cribed i|
|000024f0| 6e 20 66 75 72 74 68 65 | 72 0a 20 20 64 65 74 61 |n furthe|r. deta|
|00002500| 69 6c 20 62 65 6c 6f 77 | 2e 0a 0a 4f 6e 65 20 61 |il below|...One a|
|00002510| 6c 74 65 72 6e 61 74 69 | 76 65 20 77 6f 75 6c 64 |lternati|ve would|
|00002520| 20 68 61 76 65 20 62 65 | 65 6e 20 74 6f 20 66 6f | have be|en to fo|
|00002530| 6c 6c 6f 77 20 50 65 72 | 6c 27 73 20 6d 6f 64 65 |llow Per|l's mode|
|00002540| 6c 2c 20 77 68 65 72 65 | 20 74 68 65 20 73 6f 75 |l, where| the sou|
|00002550| 72 63 65 0a 20 20 63 6f | 64 65 20 69 73 20 72 65 |rce. co|de is re|
|00002560| 61 64 20 61 74 20 72 75 | 6e 74 69 6d 65 20 61 6e |ad at ru|ntime an|
|00002570| 64 20 63 6f 6d 70 69 6c | 65 64 20 6f 6e 2d 74 68 |d compil|ed on-th|
|00002580| 65 2d 66 6c 79 20 62 65 | 66 6f 72 65 20 65 61 63 |e-fly be|fore eac|
|00002590| 68 20 65 78 65 63 75 74 | 69 6f 6e 2e 0a 20 20 48 |h execut|ion.. H|
|000025a0| 6f 77 65 76 65 72 2c 20 | 54 63 6c 20 68 61 73 20 |owever, |Tcl has |
|000025b0| 61 20 68 69 67 68 20 70 | 61 72 73 69 6e 67 20 63 |a high p|arsing c|
|000025c0| 6f 73 74 2c 20 73 6f 20 | 69 74 20 69 73 20 64 65 |ost, so |it is de|
|000025d0| 73 69 72 65 61 62 6c 65 | 20 74 6f 20 70 72 65 70 |sireable| to prep|
|000025e0| 61 72 73 65 0a 20 20 73 | 6f 75 72 63 65 20 63 6f |arse. s|ource co|
|000025f0| 64 65 20 70 72 69 6f 72 | 20 74 6f 20 65 78 65 63 |de prior| to exec|
|00002600| 75 74 69 6f 6e 2e 20 20 | 41 64 64 69 74 69 6f 6e |ution. |Addition|
|00002610| 61 6c 6c 79 2c 20 54 63 | 6c 20 69 73 20 75 73 65 |ally, Tc|l is use|
|00002620| 64 20 66 6f 72 20 6c 61 | 72 67 65 0a 20 20 61 70 |d for la|rge. ap|
|00002630| 70 6c 69 63 61 74 69 6f | 6e 73 2c 20 73 6f 6d 65 |plicatio|ns, some|
|00002640| 20 6f 66 20 77 68 69 63 | 68 20 61 72 65 20 31 30 | of whic|h are 10|
|00002650| 2c 30 30 30 20 6c 69 6e | 65 73 20 6c 6f 6e 67 2e |,000 lin|es long.|
|00002660| 20 20 54 68 65 73 65 20 | 70 72 6f 67 72 61 6d 73 | These |programs|
|00002670| 20 6d 75 73 74 0a 20 20 | 62 65 20 63 6f 6d 70 69 | must. |be compi|
|00002680| 6c 65 64 20 70 72 69 6f | 72 20 74 6f 20 65 78 65 |led prio|r to exe|
|00002690| 63 75 74 69 6f 6e 2e 0a | 0a 5c 73 65 63 74 69 6f |cution..|.\sectio|
|000026a0| 6e 7b 44 69 66 66 69 63 | 75 6c 74 69 65 73 20 77 |n{Diffic|ulties w|
|000026b0| 69 74 68 20 43 6f 6d 70 | 69 6c 69 6e 67 7d 0a 0a |ith Comp|iling}..|
|000026c0| 5c 73 75 62 73 65 63 74 | 69 6f 6e 7b 53 6f 6d 65 |\subsect|ion{Some|
|000026d0| 20 54 65 72 6d 73 7d 0a | 54 6f 20 73 69 6d 70 6c | Terms}.|To simpl|
|000026e0| 69 66 79 20 74 68 69 73 | 20 70 61 70 65 72 2c 20 |ify this| paper, |
|000026f0| 73 6f 6d 65 20 74 65 72 | 6d 73 20 61 72 65 20 65 |some ter|ms are e|
|00002700| 78 70 6c 69 63 69 74 6c | 79 20 64 65 66 69 6e 65 |xplicitl|y define|
|00002710| 64 2e 20 20 41 20 60 60 | 73 74 61 74 65 6d 65 6e |d. A ``|statemen|
|00002720| 74 27 27 0a 20 20 72 65 | 66 65 72 73 20 74 6f 20 |t''. re|fers to |
|00002730| 61 6e 20 69 6e 64 69 76 | 69 64 75 61 6c 20 6c 69 |an indiv|idual li|
|00002740| 6e 65 20 6f 66 20 54 63 | 6c 20 63 6f 64 65 2c 20 |ne of Tc|l code, |
|00002750| 69 6e 63 6c 75 64 69 6e | 67 20 61 6c 6c 20 61 72 |includin|g all ar|
|00002760| 67 75 6d 65 6e 74 73 2e | 20 20 54 68 65 0a 20 20 |guments.| The. |
|00002770| 66 69 72 73 74 20 61 72 | 67 75 6d 65 6e 74 20 69 |first ar|gument i|
|00002780| 73 20 63 61 6c 6c 65 64 | 20 74 68 65 20 60 60 63 |s called| the ``c|
|00002790| 6f 6d 6d 61 6e 64 27 27 | 3b 20 61 6c 6c 20 73 75 |ommand''|; all su|
|000027a0| 62 73 65 71 75 65 6e 74 | 0a 20 20 77 68 69 74 65 |bsequent|. white|
|000027b0| 73 70 61 63 65 2d 73 65 | 70 61 72 61 74 65 64 20 |space-se|parated |
|000027c0| 61 72 67 75 6d 65 6e 74 | 73 20 61 72 65 20 63 61 |argument|s are ca|
|000027d0| 6c 6c 65 64 20 60 60 61 | 72 67 75 6d 65 6e 74 73 |lled ``a|rguments|
|000027e0| 27 27 20 6f 72 20 60 60 | 61 72 67 73 27 27 2e 20 |'' or ``|args''. |
|000027f0| 20 49 66 0a 20 20 61 20 | 63 6f 6d 6d 61 6e 64 20 | If. a |command |
|00002800| 77 61 73 20 6e 6f 74 20 | 64 65 66 69 6e 65 64 20 |was not |defined |
|00002810| 62 79 20 7b 5c 74 74 20 | 70 72 6f 63 7d 2c 20 62 |by {\tt |proc}, b|
|00002820| 75 74 20 65 78 69 73 74 | 73 20 69 6e 20 74 68 65 |ut exist|s in the|
|00002830| 20 69 6e 74 65 72 70 72 | 65 74 65 72 0a 20 20 28 | interpr|eter. (|
|00002840| 65 67 2e 20 20 69 74 20 | 69 73 20 61 20 72 65 67 |eg. it |is a reg|
|00002850| 69 73 74 65 72 65 64 20 | 43 20 63 61 6c 6c 62 61 |istered |C callba|
|00002860| 63 6b 20 66 75 6e 63 74 | 69 6f 6e 29 2c 20 69 74 |ck funct|ion), it|
|00002870| 20 69 73 20 63 61 6c 6c | 65 64 20 61 0a 20 20 60 | is call|ed a. `|
|00002880| 60 62 75 69 6c 74 69 6e | 27 27 2e 20 20 4e 6f 74 |`builtin|''. Not|
|00002890| 65 20 74 68 61 74 20 74 | 68 65 20 65 6e 74 69 72 |e that t|he entir|
|000028a0| 65 20 54 63 6c 20 63 6f | 72 65 20 63 6f 6d 6d 61 |e Tcl co|re comma|
|000028b0| 6e 64 20 73 65 74 20 69 | 73 20 69 6d 70 6c 65 6d |nd set i|s implem|
|000028c0| 65 6e 74 65 64 20 61 73 | 0a 20 20 62 75 69 6c 74 |ented as|. built|
|000028d0| 69 6e 73 2e 0a 0a 5c 73 | 75 62 73 65 63 74 69 6f |ins...\s|ubsectio|
|000028e0| 6e 7b 4f 76 65 72 76 69 | 65 77 7d 0a 0a 49 74 20 |n{Overvi|ew}..It |
|000028f0| 69 73 20 74 65 6d 70 74 | 69 6e 67 20 74 6f 20 6e |is tempt|ing to n|
|00002900| 61 69 76 65 6c 79 20 64 | 65 73 69 67 6e 20 61 20 |aively d|esign a |
|00002910| 74 72 61 64 69 74 69 6f | 6e 61 6c 20 63 6f 6d 70 |traditio|nal comp|
|00002920| 69 6c 65 72 20 66 6f 72 | 20 54 63 6c 2c 20 77 68 |iler for| Tcl, wh|
|00002930| 69 63 68 0a 20 20 6f 75 | 74 70 75 74 73 20 70 75 |ich. ou|tputs pu|
|00002940| 72 65 20 65 78 65 63 75 | 74 61 62 6c 65 20 63 6f |re execu|table co|
|00002950| 64 65 2e 20 20 48 6f 77 | 65 76 65 72 2c 20 74 68 |de. How|ever, th|
|00002960| 65 72 65 20 61 72 65 20 | 6e 75 6d 65 72 6f 75 73 |ere are |numerous|
|00002970| 20 70 72 6f 62 6c 65 6d | 73 20 77 69 74 68 0a 20 | problem|s with. |
|00002980| 20 74 68 69 73 2e 20 20 | 46 69 72 73 74 2c 20 54 | this. |First, T|
|00002990| 63 6c 20 69 73 20 68 69 | 67 68 6c 79 20 64 79 6e |cl is hi|ghly dyn|
|000029a0| 61 6d 69 63 20 69 6e 20 | 6e 61 74 75 72 65 2e 20 |amic in |nature. |
|000029b0| 20 43 6f 6d 6d 61 6e 64 | 73 20 28 66 75 6e 63 74 | Command|s (funct|
|000029c0| 69 6f 6e 73 20 69 6e 0a | 20 20 74 68 65 20 43 20 |ions in.| the C |
|000029d0| 6d 6f 64 65 6c 29 20 63 | 61 6e 20 62 65 20 63 61 |model) c|an be ca|
|000029e0| 6c 6c 65 64 20 62 79 20 | 74 68 65 69 72 20 73 74 |lled by |their st|
|000029f0| 72 69 6e 67 20 6e 61 6d | 65 73 20 6f 72 20 72 65 |ring nam|es or re|
|00002a00| 62 6f 75 6e 64 20 61 74 | 20 61 6e 79 20 70 6f 69 |bound at| any poi|
|00002a10| 6e 74 0a 20 20 74 68 72 | 6f 75 67 68 20 74 68 65 |nt. thr|ough the|
|00002a20| 20 7b 5c 74 74 20 72 65 | 6e 61 6d 65 7d 20 63 6f | {\tt re|name} co|
|00002a30| 6d 6d 61 6e 64 2e 20 20 | 53 69 6d 69 6c 61 72 6c |mmand. |Similarl|
|00002a40| 79 2c 20 76 61 72 69 61 | 62 6c 65 73 20 63 61 6e |y, varia|bles can|
|00002a50| 20 62 65 20 7b 5c 74 74 | 0a 20 20 75 6e 73 65 74 | be {\tt|. unset|
|00002a60| 7d 2c 20 63 6f 6d 6d 61 | 6e 64 73 20 6d 61 79 20 |}, comma|nds may |
|00002a70| 6e 6f 74 20 65 78 69 73 | 74 20 28 61 6e 64 20 68 |not exis|t (and h|
|00002a80| 65 6e 63 65 20 74 72 69 | 67 67 65 72 20 7b 5c 74 |ence tri|gger {\t|
|00002a90| 74 20 75 6e 6b 6e 6f 77 | 6e 7d 20 74 6f 20 62 65 |t unknow|n} to be|
|00002aa0| 0a 20 20 63 61 6c 6c 65 | 64 29 2c 20 74 72 61 63 |. calle|d), trac|
|00002ab0| 65 73 20 63 61 6e 20 62 | 65 20 70 6c 61 63 65 64 |es can b|e placed|
|00002ac0| 20 6f 6e 20 61 6c 6c 20 | 64 61 74 61 20 6f 62 6a | on all |data obj|
|00002ad0| 65 63 74 73 2c 20 61 6e | 64 20 73 6f 20 6f 6e 2e |ects, an|d so on.|
|00002ae0| 20 20 54 6f 0a 20 20 69 | 6d 70 6c 65 6d 65 6e 74 | To. i|mplement|
|00002af0| 20 61 6c 6c 20 6f 66 20 | 74 68 65 73 65 20 66 65 | all of |these fe|
|00002b00| 61 74 75 72 65 73 20 77 | 6f 75 6c 64 20 72 65 71 |atures w|ould req|
|00002b10| 75 69 72 65 20 62 6f 74 | 68 20 61 20 6c 61 72 67 |uire bot|h a larg|
|00002b20| 65 20 72 75 6e 74 69 6d | 65 0a 20 20 6c 69 62 72 |e runtim|e. libr|
|00002b30| 61 72 79 20 61 6e 64 20 | 65 6e 6f 72 6d 6f 75 73 |ary and |enormous|
|00002b40| 20 6f 76 65 72 68 65 61 | 64 20 69 6e 20 65 61 63 | overhea|d in eac|
|00002b50| 68 20 75 73 61 67 65 2c | 20 6e 6f 74 20 64 69 73 |h usage,| not dis|
|00002b60| 73 69 6d 69 6c 61 72 20 | 66 72 6f 6d 20 74 68 65 |similar |from the|
|00002b70| 20 73 61 6d 65 0a 20 20 | 6f 76 65 72 68 65 61 64 | same. |overhead|
|00002b80| 20 74 68 61 74 20 74 68 | 65 20 65 78 69 73 74 69 | that th|e existi|
|00002b90| 6e 67 20 69 6e 74 65 72 | 70 72 65 74 65 72 20 69 |ng inter|preter i|
|00002ba0| 6e 63 75 72 73 2e 0a 0a | 53 65 63 6f 6e 64 2c 20 |ncurs...|Second, |
|00002bb0| 69 74 20 69 73 20 75 6e | 63 6c 65 61 72 20 68 6f |it is un|clear ho|
|00002bc0| 77 20 74 6f 20 65 66 66 | 69 63 69 65 6e 74 6c 79 |w to eff|iciently|
|00002bd0| 20 73 74 6f 72 65 20 64 | 61 74 61 20 66 6f 72 20 | store d|ata for |
|00002be0| 54 63 6c 2e 20 20 53 69 | 6e 63 65 20 74 68 65 72 |Tcl. Si|nce ther|
|00002bf0| 65 0a 20 20 61 72 65 20 | 6e 6f 20 74 79 70 65 73 |e. are |no types|
|00002c00| 20 69 6e 20 74 68 65 20 | 6c 61 6e 67 75 61 67 65 | in the |language|
|00002c10| 2c 20 74 68 65 72 65 20 | 69 73 20 6e 6f 20 6f 62 |, there |is no ob|
|00002c20| 76 69 6f 75 73 20 64 61 | 74 61 20 6c 61 79 6f 75 |vious da|ta layou|
|00002c30| 74 20 6d 65 74 68 6f 64 | 20 6f 6e 65 0a 20 20 63 |t method| one. c|
|00002c40| 61 6e 20 75 73 65 20 62 | 65 73 69 64 65 73 20 73 |an use b|esides s|
|00002c50| 74 72 69 6e 67 73 2e 20 | 20 41 67 61 69 6e 2c 20 |trings. | Again, |
|00002c60| 74 68 69 73 20 69 73 20 | 77 68 61 74 20 74 68 65 |this is |what the|
|00002c70| 20 63 75 72 72 65 6e 74 | 20 69 6e 74 65 72 70 72 | current| interpr|
|00002c80| 65 74 65 72 0a 20 20 64 | 6f 65 73 2e 0a 0a 4c 61 |eter. d|oes...La|
|00002c90| 73 74 6c 79 2c 20 54 63 | 6c 20 75 73 65 73 20 43 |stly, Tc|l uses C|
|00002ca0| 20 63 61 6c 6c 62 61 63 | 6b 73 20 28 60 60 62 75 | callbac|ks (``bu|
|00002cb0| 69 6c 74 69 6e 73 27 27 | 29 20 61 73 20 66 69 72 |iltins''|) as fir|
|00002cc0| 73 74 2d 63 6c 61 73 73 | 20 66 75 6e 63 74 69 6f |st-class| functio|
|00002cd0| 6e 73 2c 20 77 68 65 72 | 65 0a 20 20 74 68 65 20 |ns, wher|e. the |
|00002ce0| 63 61 6c 6c 62 61 63 6b | 73 20 68 61 76 65 20 64 |callback|s have d|
|00002cf0| 69 72 65 63 74 20 61 63 | 63 65 73 73 20 74 6f 20 |irect ac|cess to |
|00002d00| 74 68 65 20 69 6e 74 65 | 72 70 72 65 74 65 72 20 |the inte|rpreter |
|00002d10| 73 74 61 74 65 2e 20 20 | 43 61 6c 6c 62 61 63 6b |state. |Callback|
|00002d20| 0a 20 20 66 75 6e 63 74 | 69 6f 6e 73 20 61 72 65 |. funct|ions are|
|00002d30| 20 66 72 65 65 20 74 6f | 20 6d 61 6b 65 20 63 68 | free to| make ch|
|00002d40| 61 6e 67 65 73 20 74 6f | 2c 20 6f 72 20 64 65 70 |anges to|, or dep|
|00002d50| 65 6e 64 20 6f 6e 2c 20 | 74 68 65 20 73 74 61 74 |end on, |the stat|
|00002d60| 65 20 6f 66 20 74 68 65 | 0a 20 20 76 69 72 74 75 |e of the|. virtu|
|00002d70| 61 6c 20 6d 61 63 68 69 | 6e 65 3b 20 74 68 65 73 |al machi|ne; thes|
|00002d80| 65 20 61 72 65 20 63 61 | 6c 6c 65 64 20 60 60 73 |e are ca|lled ``s|
|00002d90| 69 64 65 20 65 66 66 65 | 63 74 73 27 27 20 69 6e |ide effe|cts'' in|
|00002da0| 20 63 6f 6d 70 69 6c 65 | 72 20 70 61 72 6c 61 6e | compile|r parlan|
|00002db0| 63 65 2e 0a 20 20 54 68 | 65 20 64 69 66 66 69 63 |ce.. Th|e diffic|
|00002dc0| 75 6c 74 79 20 77 69 74 | 68 20 74 68 65 73 65 20 |ulty wit|h these |
|00002dd0| 73 69 64 65 20 65 66 66 | 65 63 74 73 20 69 6e 20 |side eff|ects in |
|00002de0| 74 68 65 20 54 63 6c 2f | 43 20 6d 6f 64 65 6c 20 |the Tcl/|C model |
|00002df0| 69 73 20 74 68 61 74 20 | 74 68 65 79 0a 20 20 61 |is that |they. a|
|00002e00| 72 65 20 69 6d 70 6f 73 | 73 69 62 6c 65 20 74 6f |re impos|sible to|
|00002e10| 20 70 72 65 64 69 63 74 | 2e 20 20 57 69 74 68 6f | predict|. Witho|
|00002e20| 75 74 20 74 68 69 73 20 | 6b 6e 6f 77 6c 65 64 67 |ut this |knowledg|
|00002e30| 65 2c 20 74 68 65 20 63 | 6f 6d 70 69 6c 65 72 20 |e, the c|ompiler |
|00002e40| 63 61 6e 6e 6f 74 0a 20 | 20 62 65 20 73 75 72 65 |cannot. | be sure|
|00002e50| 20 74 68 61 74 20 61 6e | 79 20 67 69 76 65 6e 20 | that an|y given |
|00002e60| 73 74 61 74 65 6d 65 6e | 74 20 77 6f 6e 27 74 20 |statemen|t won't |
|00002e70| 63 61 75 73 65 20 61 20 | 7b 5c 74 74 20 72 65 6e |cause a |{\tt ren|
|00002e80| 61 6d 65 7d 2c 20 7b 5c | 74 74 20 75 6e 73 65 74 |ame}, {\|tt unset|
|00002e90| 7d 0a 20 20 6f 72 20 73 | 6f 6d 65 20 6f 74 68 65 |}. or s|ome othe|
|00002ea0| 72 20 73 74 61 74 65 20 | 63 68 61 6e 67 65 20 69 |r state |change i|
|00002eb0| 6e 20 74 68 65 20 76 69 | 72 74 75 61 6c 20 6d 61 |n the vi|rtual ma|
|00002ec0| 63 68 69 6e 65 2e 0a 0a | 5c 73 75 62 73 65 63 74 |chine...|\subsect|
|00002ed0| 69 6f 6e 7b 50 72 65 70 | 61 72 73 69 6e 67 7d 0a |ion{Prep|arsing}.|
|00002ee0| 0a 41 20 6d 6f 72 65 20 | 68 75 6d 62 6c 65 20 61 |.A more |humble a|
|00002ef0| 70 70 72 6f 61 63 68 20 | 69 73 20 6e 65 65 64 65 |pproach |is neede|
|00002f00| 64 2e 20 20 49 6e 20 74 | 68 69 73 20 76 65 69 6e |d. In t|his vein|
|00002f10| 2c 20 6f 6e 65 20 63 61 | 6e 20 73 74 61 72 74 20 |, one ca|n start |
|00002f20| 62 79 20 6e 6f 74 69 6e | 67 0a 20 20 74 68 61 74 |by notin|g. that|
|00002f30| 20 54 63 6c 27 73 20 60 | 60 63 6d 64 20 61 72 67 | Tcl's `|`cmd arg|
|00002f40| 20 61 72 67 20 61 72 67 | 27 27 20 73 74 79 6c 65 | arg arg|'' style|
|00002f50| 20 73 74 61 74 65 6d 65 | 6e 74 73 20 6c 65 6e 64 | stateme|nts lend|
|00002f60| 20 74 68 65 6d 73 65 6c | 76 65 73 20 74 6f 0a 20 | themsel|ves to. |
|00002f70| 20 70 72 65 70 61 72 73 | 69 6e 67 2e 20 20 54 68 | prepars|ing. Th|
|00002f80| 69 73 20 69 73 20 62 65 | 63 61 75 73 65 20 69 74 |is is be|cause it|
|00002f90| 20 69 73 20 61 6c 77 61 | 79 73 20 70 6f 73 73 69 | is alwa|ys possi|
|00002fa0| 62 6c 65 20 74 6f 20 64 | 65 74 65 72 6d 69 6e 65 |ble to d|etermine|
|00002fb0| 20 74 68 65 0a 20 20 61 | 72 67 75 6d 65 6e 74 73 | the. a|rguments|
|00002fc0| 20 74 6f 20 61 20 67 69 | 76 65 6e 20 63 6f 6d 6d | to a gi|ven comm|
|00002fd0| 61 6e 64 2e 20 20 41 74 | 20 74 68 65 20 76 65 72 |and. At| the ver|
|00002fe0| 79 20 6c 65 61 73 74 2c | 20 74 68 65 20 63 6f 6d |y least,| the com|
|00002ff0| 70 69 6c 65 72 20 63 61 | 6e 20 62 72 65 61 6b 0a |piler ca|n break.|
|00003000| 20 20 75 70 20 74 68 65 | 20 73 74 61 74 65 6d 65 | up the| stateme|
|00003010| 6e 74 20 69 6e 74 6f 20 | 73 74 72 69 6e 67 20 61 |nt into |string a|
|00003020| 72 67 75 6d 65 6e 74 73 | 2c 20 77 68 69 63 68 20 |rguments|, which |
|00003030| 77 69 6c 6c 20 73 61 76 | 65 20 73 6f 6d 65 20 61 |will sav|e some a|
|00003040| 6d 6f 75 6e 74 20 6f 66 | 0a 20 20 70 61 72 73 69 |mount of|. parsi|
|00003050| 6e 67 20 65 66 66 6f 72 | 74 20 6e 6f 72 6d 61 6c |ng effor|t normal|
|00003060| 6c 79 20 65 78 70 65 6e | 64 65 64 20 61 74 20 72 |ly expen|ded at r|
|00003070| 75 6e 74 69 6d 65 2e 20 | 20 50 72 65 70 61 72 73 |untime. | Prepars|
|00003080| 69 6e 67 20 69 73 20 76 | 65 72 79 20 76 61 6c 75 |ing is v|ery valu|
|00003090| 61 62 6c 65 0a 20 20 69 | 6e 20 54 63 6c 3b 20 61 |able. i|n Tcl; a|
|000030a0| 20 74 79 70 69 63 61 6c | 20 54 63 6c 20 73 63 72 | typical| Tcl scr|
|000030b0| 69 70 74 20 73 70 65 6e | 64 73 20 6d 6f 73 74 20 |ipt spen|ds most |
|000030c0| 6f 66 20 69 74 73 20 6e | 6f 6e 2d 77 6f 72 6b 2d |of its n|on-work-|
|000030d0| 72 65 6c 61 74 65 64 0a | 20 20 65 78 65 63 75 74 |related.| execut|
|000030e0| 69 6f 6e 20 74 69 6d 65 | 20 73 63 61 6e 6e 69 6e |ion time| scannin|
|000030f0| 67 20 61 6e 64 20 70 61 | 72 73 69 6e 67 20 73 74 |g and pa|rsing st|
|00003100| 61 74 65 6d 65 6e 74 73 | 2e 0a 0a 48 6f 77 65 76 |atements|...Howev|
|00003110| 65 72 2c 20 70 72 65 70 | 61 72 73 69 6e 67 20 73 |er, prep|arsing s|
|00003120| 74 61 74 65 6d 65 6e 74 | 73 20 69 6e 74 6f 20 61 |tatement|s into a|
|00003130| 72 67 20 6c 69 73 74 73 | 20 69 73 20 6e 6f 74 20 |rg lists| is not |
|00003140| 61 20 70 61 6e 61 63 65 | 61 2e 20 20 4d 61 6e 79 |a panace|a. Many|
|00003150| 0a 20 20 69 6d 70 6f 72 | 74 61 6e 74 20 63 6f 6d |. impor|tant com|
|00003160| 6d 61 6e 64 73 20 74 61 | 6b 65 20 61 72 67 75 6d |mands ta|ke argum|
|00003170| 65 6e 74 73 20 63 6f 6e | 74 61 69 6e 69 6e 67 20 |ents con|taining |
|00003180| 6c 61 72 67 65 20 61 6d | 6f 75 6e 74 73 20 6f 66 |large am|ounts of|
|00003190| 20 64 61 74 61 2e 20 20 | 46 6f 72 0a 20 20 65 78 | data. |For. ex|
|000031a0| 61 6d 70 6c 65 2c 20 7b | 5c 74 74 20 69 66 7d 2c |ample, {|\tt if},|
|000031b0| 20 7b 5c 74 74 20 77 68 | 69 6c 65 7d 2c 20 7b 5c | {\tt wh|ile}, {\|
|000031c0| 74 74 20 70 72 6f 63 7d | 2c 20 7b 5c 74 74 20 66 |tt proc}|, {\tt f|
|000031d0| 6f 72 7d 2c 20 61 6e 64 | 20 6f 74 68 65 72 20 63 |or}, and| other c|
|000031e0| 6f 6d 6d 61 6e 64 73 0a | 20 20 61 6c 6c 20 74 61 |ommands.| all ta|
|000031f0| 6b 65 20 60 60 63 6f 6d | 6d 61 6e 64 20 6c 69 73 |ke ``com|mand lis|
|00003200| 74 73 27 27 20 69 6e 20 | 6f 6e 65 20 6f 72 20 6d |ts'' in |one or m|
|00003210| 6f 72 65 20 61 72 67 75 | 6d 65 6e 74 73 2e 20 20 |ore argu|ments. |
|00003220| 54 68 65 73 65 20 63 6d | 64 6c 69 73 74 73 20 61 |These cm|dlists a|
|00003230| 72 65 0a 20 20 6f 66 74 | 65 6e 20 68 75 6e 64 72 |re. oft|en hundr|
|00003240| 65 64 73 20 6f 66 20 62 | 79 74 65 73 20 6c 6f 6e |eds of b|ytes lon|
|00003250| 67 3b 20 74 68 65 79 20 | 65 66 66 65 63 74 69 76 |g; they |effectiv|
|00003260| 65 6c 79 20 63 61 6e 20 | 63 6f 6e 74 61 69 6e 20 |ely can |contain |
|00003270| 65 6e 74 69 72 65 20 73 | 63 72 69 70 74 73 0a 20 |entire s|cripts. |
|00003280| 20 77 69 74 68 69 6e 20 | 74 68 65 6d 2e 20 20 43 | within |them. C|
|00003290| 6c 65 61 72 6c 79 2c 20 | 6f 6e 65 20 77 6f 75 6c |learly, |one woul|
|000032a0| 64 20 6c 69 6b 65 20 74 | 6f 20 70 61 72 73 65 20 |d like t|o parse |
|000032b0| 74 68 65 73 65 20 69 6e | 74 65 72 6e 61 6c 6c 79 |these in|ternally|
|000032c0| 20 61 73 20 77 65 6c 6c | 2e 0a 20 20 42 79 20 74 | as well|.. By t|
|000032d0| 68 65 20 73 61 6d 65 20 | 74 6f 6b 65 6e 2c 20 77 |he same |token, w|
|000032e0| 65 20 77 6f 75 6c 64 20 | 6c 69 6b 65 20 74 6f 20 |e would |like to |
|000032f0| 61 6c 73 6f 20 70 72 65 | 70 61 72 73 65 20 74 68 |also pre|parse th|
|00003300| 65 20 62 6f 6f 6c 65 61 | 6e 20 65 78 70 72 65 73 |e boolea|n expres|
|00003310| 73 69 6f 6e 73 0a 20 20 | 61 73 73 6f 63 69 61 74 |sions. |associat|
|00003320| 65 64 20 77 69 74 68 20 | 7b 5c 74 74 20 66 6f 72 |ed with |{\tt for|
|00003330| 7d 2c 20 7b 5c 74 74 20 | 69 66 7d 2c 20 61 6e 64 |}, {\tt |if}, and|
|00003340| 20 7b 5c 74 74 20 77 68 | 69 6c 65 7d 2c 20 61 6e | {\tt wh|ile}, an|
|00003350| 64 20 74 68 65 20 6c 69 | 73 74 0a 20 20 73 74 72 |d the li|st. str|
|00003360| 75 63 74 75 72 65 73 20 | 75 73 65 64 20 62 79 20 |uctures |used by |
|00003370| 7b 5c 74 74 20 6c 69 6e | 64 65 78 7d 20 61 6e 64 |{\tt lin|dex} and|
|00003380| 20 74 68 65 20 6f 74 68 | 65 72 20 6c 69 73 74 20 | the oth|er list |
|00003390| 63 6f 6d 6d 61 6e 64 73 | 2c 20 61 6e 64 20 73 6f |commands|, and so|
|000033a0| 20 6f 6e 2e 0a 20 20 49 | 6e 20 74 68 65 20 66 6f | on.. I|n the fo|
|000033b0| 6c 6c 6f 77 69 6e 67 20 | 65 78 61 6d 70 6c 65 2c |llowing |example,|
|000033c0| 20 69 66 20 61 72 67 75 | 6d 65 6e 74 73 20 77 65 | if argu|ments we|
|000033d0| 72 65 6e 27 74 20 69 6e | 64 69 76 69 64 75 61 6c |ren't in|dividual|
|000033e0| 6c 79 20 70 61 72 73 65 | 64 2c 20 74 68 65 0a 20 |ly parse|d, the. |
|000033f0| 20 62 6f 64 79 20 6f 66 | 20 74 68 69 73 20 7b 5c | body of| this {\|
|00003400| 74 74 20 66 6f 72 7d 20 | 6c 6f 6f 70 20 77 6f 75 |tt for} |loop wou|
|00003410| 6c 64 20 72 65 6d 61 69 | 6e 20 69 6e 20 73 74 72 |ld remai|n in str|
|00003420| 69 6e 67 20 66 6f 72 6d | 2c 20 61 6e 64 20 77 6f |ing form|, and wo|
|00003430| 75 6c 64 0a 20 20 72 65 | 71 75 69 72 65 20 72 75 |uld. re|quire ru|
|00003440| 6e 74 69 6d 65 20 70 61 | 72 73 69 6e 67 2c 20 61 |ntime pa|rsing, a|
|00003450| 6e 64 20 74 68 75 73 20 | 74 68 65 20 63 6f 6d 70 |nd thus |the comp|
|00003460| 69 6c 65 72 20 77 6f 75 | 6c 64 20 70 72 6f 76 69 |iler wou|ld provi|
|00003470| 64 65 20 6c 69 74 74 6c | 65 0a 20 20 70 65 72 66 |de littl|e. perf|
|00003480| 6f 72 6d 61 6e 63 65 20 | 69 6d 70 72 6f 76 65 6d |ormance |improvem|
|00003490| 65 6e 74 2e 0a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |ent...\b|egin{ver|
|000034a0| 62 61 74 69 6d 7d 0a 20 | 20 66 6f 72 20 7b 73 65 |batim}. | for {se|
|000034b0| 74 20 69 20 30 7d 20 7b | 24 69 3c 31 30 30 30 7d |t i 0} {|$i<1000}|
|000034c0| 20 7b 69 6e 63 72 20 69 | 7d 20 7b 0a 20 20 20 20 | {incr i|} {. |
|000034d0| 20 20 3c 6d 61 6e 79 20 | 6c 69 6e 65 73 20 6f 66 | <many |lines of|
|000034e0| 20 63 6f 64 65 3e 0a 20 | 20 7d 0a 5c 65 6e 64 7b | code>. | }.\end{|
|000034f0| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 6f 20 61 63 |verbatim|}..To ac|
|00003500| 63 6f 6d 70 6c 69 73 68 | 20 74 68 69 73 2c 20 61 |complish| this, a|
|00003510| 20 74 79 70 69 6e 67 20 | 73 79 73 74 65 6d 20 66 | typing |system f|
|00003520| 6f 72 20 54 63 6c 20 69 | 73 20 6e 65 65 64 65 64 |or Tcl i|s needed|
|00003530| 2c 20 77 68 65 72 65 20 | 6f 6e 65 20 64 6f 65 73 |, where |one does|
|00003540| 6e 27 74 0a 20 20 65 78 | 69 73 74 2e 20 20 4e 6f |n't. ex|ist. No|
|00003550| 72 6d 61 6c 6c 79 2c 20 | 74 68 65 20 74 79 70 65 |rmally, |the type|
|00003560| 73 20 61 72 65 20 63 6f | 65 72 63 65 64 20 66 72 |s are co|erced fr|
|00003570| 6f 6d 20 73 74 72 69 6e | 67 20 64 61 74 61 20 61 |om strin|g data a|
|00003580| 74 20 72 75 6e 74 69 6d | 65 2c 20 6f 6e 20 61 0a |t runtim|e, on a.|
|00003590| 20 20 70 65 72 2d 63 6f | 6d 6d 61 6e 64 20 62 61 | per-co|mmand ba|
|000035a0| 73 69 73 2e 20 20 49 74 | 20 69 73 20 68 61 70 70 |sis. It| is happ|
|000035b0| 65 6e 73 74 61 6e 63 65 | 20 74 68 61 74 20 74 68 |enstance| that th|
|000035c0| 65 20 6c 69 73 74 20 66 | 6f 72 6d 61 74 20 69 73 |e list f|ormat is|
|000035d0| 20 75 6e 69 76 65 72 73 | 61 6c 0a 20 20 61 6d 6f | univers|al. amo|
|000035e0| 6e 67 20 6c 69 73 74 20 | 63 6f 6d 6d 61 6e 64 73 |ng list |commands|
|000035f0| 2c 20 66 6f 72 20 65 78 | 61 6d 70 6c 65 2e 20 20 |, for ex|ample. |
|00003600| 54 68 75 73 2c 20 73 6f | 6d 65 20 77 61 79 20 69 |Thus, so|me way i|
|00003610| 73 20 6e 65 65 64 65 64 | 20 74 6f 20 69 6e 66 6f |s needed| to info|
|00003620| 72 6d 20 74 68 65 0a 20 | 20 63 6f 6d 70 69 6c 65 |rm the. | compile|
|00003630| 72 20 61 73 20 74 6f 20 | 74 68 65 20 61 72 67 75 |r as to |the argu|
|00003640| 6d 65 6e 74 20 74 79 70 | 65 73 20 65 61 63 68 20 |ment typ|es each |
|00003650| 63 6f 6d 6d 61 6e 64 20 | 65 78 70 65 63 74 73 2e |command |expects.|
|00003660| 20 20 54 68 65 6e 2c 20 | 69 66 20 61 0a 20 20 73 | Then, |if a. s|
|00003670| 74 61 74 69 63 20 73 74 | 72 69 6e 67 20 69 73 20 |tatic st|ring is |
|00003680| 66 6f 75 6e 64 20 61 74 | 20 63 6f 6d 70 69 6c 65 |found at| compile|
|00003690| 2d 74 69 6d 65 2c 20 77 | 65 20 63 61 6e 20 70 72 |-time, w|e can pr|
|000036a0| 65 70 61 72 73 65 20 74 | 68 69 73 20 74 6f 20 62 |eparse t|his to b|
|000036b0| 65 20 6f 66 0a 20 20 74 | 68 61 74 20 74 79 70 65 |e of. t|hat type|
|000036c0| 2e 20 20 46 6f 72 20 65 | 78 61 6d 70 6c 65 2c 20 |. For e|xample, |
|000036d0| 73 69 6e 63 65 20 61 6c | 6d 6f 73 74 20 61 6c 6c |since al|most all|
|000036e0| 20 63 6d 64 6c 69 73 74 | 73 20 61 72 65 20 73 75 | cmdlist|s are su|
|000036f0| 72 72 6f 75 6e 64 65 64 | 20 62 79 0a 20 20 63 75 |rrounded| by. cu|
|00003700| 72 6c 79 20 62 72 61 63 | 65 73 20 69 6e 20 54 63 |rly brac|es in Tc|
|00003710| 6c 20 73 6f 75 72 63 65 | 20 63 6f 64 65 2c 20 74 |l source| code, t|
|00003720| 68 65 20 63 6f 6e 74 65 | 6e 74 73 20 61 72 65 20 |he conte|nts are |
|00003730| 73 74 61 74 69 63 20 28 | 6e 6f 20 73 75 62 73 74 |static (|no subst|
|00003740| 69 74 75 74 69 6f 6e 0a | 20 20 77 69 6c 6c 20 6f |itution.| will o|
|00003750| 63 63 75 72 20 70 72 69 | 6f 72 20 74 6f 20 74 68 |ccur pri|or to th|
|00003760| 65 20 61 72 67 75 6d 65 | 6e 74 20 62 65 69 6e 67 |e argume|nt being|
|00003770| 20 70 61 73 73 65 64 20 | 74 6f 20 74 68 65 20 63 | passed |to the c|
|00003780| 6f 6d 6d 61 6e 64 29 2e | 20 20 54 68 65 73 65 20 |ommand).| These |
|00003790| 63 61 6e 0a 20 20 74 68 | 65 6e 20 62 65 20 70 61 |can. th|en be pa|
|000037a0| 72 73 65 64 20 61 74 20 | 63 6f 6d 70 69 6c 65 2d |rsed at |compile-|
|000037b0| 74 69 6d 65 2c 20 61 6e | 64 20 74 72 65 61 74 65 |time, an|d treate|
|000037c0| 64 20 61 73 20 61 20 6c | 69 73 74 20 6f 66 20 63 |d as a l|ist of c|
|000037d0| 6f 6d 6d 61 6e 64 73 2e | 20 20 49 6e 0a 20 20 74 |ommands.| In. t|
|000037e0| 68 65 20 63 61 73 65 20 | 77 68 65 72 65 20 76 61 |he case |where va|
|000037f0| 72 69 61 62 6c 65 20 73 | 75 62 73 74 69 74 75 74 |riable s|ubstitut|
|00003800| 69 6f 6e 20 69 73 20 61 | 6c 6c 6f 77 65 64 2c 20 |ion is a|llowed, |
|00003810| 73 75 63 68 20 70 72 65 | 70 61 72 73 69 6e 67 20 |such pre|parsing |
|00003820| 63 61 6e 6e 6f 74 0a 20 | 20 68 61 70 70 65 6e 2c |cannot. | happen,|
|00003830| 20 73 69 6e 63 65 20 74 | 68 65 20 61 72 67 75 6d | since t|he argum|
|00003840| 65 6e 74 20 76 61 6c 75 | 65 20 64 65 70 65 6e 64 |ent valu|e depend|
|00003850| 73 20 6f 6e 20 61 20 76 | 61 72 69 61 62 6c 65 27 |s on a v|ariable'|
|00003860| 73 20 76 61 6c 75 65 2c | 20 77 68 69 63 68 20 69 |s value,| which i|
|00003870| 73 0a 20 20 75 6e 6b 6e | 6f 77 6e 20 61 74 20 63 |s. unkn|own at c|
|00003880| 6f 6d 70 69 6c 65 2d 74 | 69 6d 65 2e 0a 0a 5c 73 |ompile-t|ime...\s|
|00003890| 75 62 73 65 63 74 69 6f | 6e 7b 53 6f 6c 76 69 6e |ubsectio|n{Solvin|
|000038a0| 67 20 74 68 65 20 53 69 | 64 65 20 45 66 66 65 63 |g the Si|de Effec|
|000038b0| 74 73 20 50 72 6f 62 6c | 65 6d 7d 0a 0a 57 68 69 |ts Probl|em}..Whi|
|000038c0| 6c 65 20 69 74 20 73 65 | 65 6d 73 20 74 68 61 74 |le it se|ems that|
|000038d0| 20 75 73 65 72 2d 64 65 | 66 69 6e 65 64 20 43 20 | user-de|fined C |
|000038e0| 63 61 6c 6c 62 61 63 6b | 73 20 70 72 65 73 65 6e |callback|s presen|
|000038f0| 74 20 61 6e 20 69 6e 74 | 72 61 63 74 61 62 6c 65 |t an int|ractable|
|00003900| 0a 20 20 6f 70 74 69 6d | 69 7a 61 74 69 6f 6e 20 |. optim|ization |
|00003910| 70 72 6f 62 6c 65 6d 2c | 20 69 74 20 61 63 74 75 |problem,| it actu|
|00003920| 61 6c 6c 79 20 69 73 20 | 70 6f 73 73 69 62 6c 65 |ally is |possible|
|00003930| 20 74 6f 20 67 75 65 73 | 73 20 74 68 65 20 73 74 | to gues|s the st|
|00003940| 61 74 65 20 6f 66 20 74 | 68 65 0a 20 20 76 69 72 |ate of t|he. vir|
|00003950| 74 75 61 6c 20 6d 61 63 | 68 69 6e 65 20 66 72 6f |tual mac|hine fro|
|00003960| 6d 20 74 68 65 20 54 63 | 6c 20 73 6f 75 72 63 65 |m the Tc|l source|
|00003970| 20 63 6f 64 65 2e 20 20 | 49 6e 20 54 63 6c 2c 20 | code. |In Tcl, |
|00003980| 75 73 65 72 2d 64 65 66 | 69 6e 65 64 20 63 61 6c |user-def|ined cal|
|00003990| 6c 62 61 63 6b 73 0a 20 | 20 61 72 65 20 72 65 71 |lbacks. | are req|
|000039a0| 75 69 72 65 64 20 74 6f | 20 75 73 65 20 61 20 73 |uired to| use a s|
|000039b0| 65 74 20 6f 66 20 43 20 | 6c 69 62 72 61 72 79 20 |et of C |library |
|000039c0| 72 6f 75 74 69 6e 65 73 | 20 74 6f 20 61 63 63 65 |routines| to acce|
|000039d0| 73 73 20 74 68 65 20 54 | 63 6c 0a 20 20 69 6e 74 |ss the T|cl. int|
|000039e0| 65 72 6e 61 6c 73 20 28 | 69 65 2e 20 76 61 72 69 |ernals (|ie. vari|
|000039f0| 61 62 6c 65 20 76 61 6c | 75 65 73 29 2e 20 20 4f |able val|ues). O|
|00003a00| 75 72 20 73 79 73 74 65 | 6d 20 61 64 64 73 20 68 |ur syste|m adds h|
|00003a10| 6f 6f 6b 73 20 74 6f 20 | 74 68 69 73 20 63 6f 72 |ooks to |this cor|
|00003a20| 65 20 54 63 6c 0a 20 20 | 6c 69 62 72 61 72 79 2c |e Tcl. |library,|
|00003a30| 20 77 68 69 63 68 20 77 | 69 6c 6c 20 63 61 6c 6c | which w|ill call|
|00003a40| 20 6f 75 74 20 74 6f 20 | 54 43 20 72 6f 75 74 69 | out to |TC routi|
|00003a50| 6e 65 73 20 77 68 65 6e | 20 74 72 69 67 67 65 72 |nes when| trigger|
|00003a60| 65 64 2e 20 20 54 68 69 | 73 20 61 6c 6c 6f 77 73 |ed. Thi|s allows|
|00003a70| 0a 20 20 74 68 65 20 54 | 43 20 72 75 6e 74 69 6d |. the T|C runtim|
|00003a80| 65 20 74 6f 20 6d 61 69 | 6e 74 61 69 6e 20 6d 6f |e to mai|ntain mo|
|00003a90| 72 65 20 65 66 66 69 63 | 69 65 6e 74 20 73 74 72 |re effic|ient str|
|00003aa0| 75 63 74 75 72 65 73 2c | 20 61 6e 64 20 6b 65 65 |uctures,| and kee|
|00003ab0| 70 20 74 68 65 6d 0a 20 | 20 75 70 64 61 74 65 64 |p them. | updated|
|00003ac0| 20 69 66 20 74 68 65 79 | 20 63 68 61 6e 67 65 20 | if they| change |
|00003ad0| 75 6e 65 78 70 65 63 74 | 65 64 6c 79 2e 20 20 46 |unexpect|edly. F|
|00003ae0| 6f 72 20 65 78 61 6d 70 | 6c 65 2c 20 74 68 65 20 |or examp|le, the |
|00003af0| 54 43 20 72 75 6e 74 69 | 6d 65 0a 20 20 6d 61 69 |TC runti|me. mai|
|00003b00| 6e 74 61 69 6e 73 20 61 | 20 74 61 62 6c 65 20 6f |ntains a| table o|
|00003b10| 66 20 63 6f 6d 6d 61 6e | 64 73 2c 20 77 68 69 63 |f comman|ds, whic|
|00003b20| 68 20 69 73 20 64 69 72 | 65 63 74 6c 79 20 69 6e |h is dir|ectly in|
|00003b30| 64 65 78 65 64 2c 20 69 | 6e 20 6f 72 64 65 72 20 |dexed, i|n order |
|00003b40| 74 6f 0a 20 20 73 61 76 | 65 20 6f 6e 20 74 68 65 |to. sav|e on the|
|00003b50| 20 68 61 73 68 69 6e 67 | 20 63 6f 73 74 73 20 6e | hashing| costs n|
|00003b60| 6f 72 6d 61 6c 6c 79 20 | 61 73 73 6f 63 69 61 74 |ormally |associat|
|00003b70| 65 64 20 77 69 74 68 20 | 54 63 6c 20 76 61 72 69 |ed with |Tcl vari|
|00003b80| 61 62 6c 65 20 61 63 63 | 65 73 73 2e 0a 20 20 57 |able acc|ess.. W|
|00003b90| 68 65 6e 20 61 20 43 20 | 63 61 6c 6c 62 61 63 6b |hen a C |callback|
|00003ba0| 20 66 75 6e 63 74 69 6f | 6e 20 61 74 74 65 6d 70 | functio|n attemp|
|00003bb0| 74 73 20 74 6f 20 72 65 | 6e 61 6d 65 20 61 20 63 |ts to re|name a c|
|00003bc0| 6f 6d 6d 61 6e 64 2c 20 | 74 68 69 73 20 69 73 20 |ommand, |this is |
|00003bd0| 74 72 61 70 70 65 64 0a | 20 20 61 6e 64 20 74 68 |trapped.| and th|
|00003be0| 65 20 74 61 62 6c 65 20 | 65 6e 74 72 79 20 69 73 |e table |entry is|
|00003bf0| 20 75 70 64 61 74 65 64 | 2e 0a 0a 48 6f 77 65 76 | updated|...Howev|
|00003c00| 65 72 2c 20 74 68 69 73 | 20 6d 65 63 68 61 6e 69 |er, this| mechani|
|00003c10| 73 6d 20 69 73 20 73 74 | 69 6c 6c 20 69 6e 73 75 |sm is st|ill insu|
|00003c20| 66 66 69 63 69 65 6e 74 | 20 74 6f 20 61 6c 6c 6f |fficient| to allo|
|00003c30| 77 20 66 6f 72 20 6d 6f | 72 65 20 61 67 67 72 65 |w for mo|re aggre|
|00003c40| 73 73 69 76 65 0a 20 20 | 6f 70 74 69 6d 69 7a 61 |ssive. |optimiza|
|00003c50| 74 69 6f 6e 73 2c 20 73 | 69 6e 63 65 20 79 6f 75 |tions, s|ince you|
|00003c60| 20 63 61 6e 6e 6f 74 20 | 64 65 74 65 72 6d 69 6e | cannot |determin|
|00003c70| 65 20 77 68 61 74 20 74 | 68 65 20 64 65 70 65 6e |e what t|he depen|
|00003c80| 64 65 6e 63 69 65 73 20 | 61 72 65 20 75 6e 74 69 |dencies |are unti|
|00003c90| 6c 0a 20 20 74 68 65 79 | 20 61 72 65 20 74 72 69 |l. they| are tri|
|00003ca0| 67 67 65 72 65 64 2e 20 | 20 54 68 75 73 2c 20 69 |ggered. | Thus, i|
|00003cb0| 74 20 69 73 20 69 6d 70 | 6f 73 73 69 62 6c 65 20 |t is imp|ossible |
|00003cc0| 74 6f 20 69 6d 70 6c 65 | 6d 65 6e 74 20 6f 70 74 |to imple|ment opt|
|00003cd0| 69 6d 69 7a 61 74 69 6f | 6e 73 0a 20 20 74 68 61 |imizatio|ns. tha|
|00003ce0| 74 20 69 6e 76 6f 6c 76 | 65 20 63 6f 64 65 20 6d |t involv|e code m|
|00003cf0| 6f 74 69 6f 6e 2c 20 65 | 6c 69 6d 69 6e 61 74 69 |otion, e|liminati|
|00003d00| 6f 6e 20 6f 66 20 75 6e | 75 73 65 64 20 76 61 72 |on of un|used var|
|00003d10| 69 61 62 6c 65 20 61 73 | 73 69 67 6e 6d 65 6e 74 |iable as|signment|
|00003d20| 73 2c 20 61 6e 64 0a 20 | 20 73 6f 20 6f 6e 2e 0a |s, and. | so on..|
|00003d30| 0a 5c 73 65 63 74 69 6f | 6e 7b 54 68 65 20 54 43 |.\sectio|n{The TC|
|00003d40| 20 49 6d 70 6c 65 6d 65 | 6e 74 61 74 69 6f 6e 7d | Impleme|ntation}|
|00003d50| 0a 0a 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 50 72 |..\subse|ction{Pr|
|00003d60| 65 70 61 72 73 69 6e 67 | 2d 20 45 78 70 72 65 73 |eparsing|- Expres|
|00003d70| 73 69 6f 6e 20 46 6f 72 | 65 73 74 7d 0a 0a 54 68 |sion For|est}..Th|
|00003d80| 65 20 54 63 6c 20 63 6f | 6d 70 69 6c 65 72 20 75 |e Tcl co|mpiler u|
|00003d90| 73 65 73 20 61 20 70 72 | 65 70 61 72 73 69 6e 67 |ses a pr|eparsing|
|00003da0| 20 6d 65 74 68 6f 64 2c | 20 61 73 20 64 65 73 63 | method,| as desc|
|00003db0| 72 69 62 65 64 20 61 62 | 6f 76 65 2c 20 74 6f 20 |ribed ab|ove, to |
|00003dc0| 6f 75 74 70 75 74 20 61 | 0a 20 20 74 72 65 65 2d |output a|. tree-|
|00003dd0| 6c 69 6b 65 20 73 74 72 | 75 63 74 75 72 69 6e 67 |like str|ucturing|
|00003de0| 20 6f 66 20 65 78 70 72 | 65 73 73 69 6f 6e 73 20 | of expr|essions |
|00003df0| 61 6e 64 20 63 6f 6d 6d | 61 6e 64 73 2e 20 20 41 |and comm|ands. A|
|00003e00| 74 20 74 68 65 20 72 6f | 6f 74 73 20 61 72 65 20 |t the ro|ots are |
|00003e10| 74 68 65 0a 20 20 69 6e | 64 69 76 69 64 75 61 6c |the. in|dividual|
|00003e20| 20 74 6f 70 20 6c 65 76 | 65 6c 20 73 63 72 69 70 | top lev|el scrip|
|00003e30| 74 20 73 74 61 74 65 6d | 65 6e 74 73 2c 20 77 68 |t statem|ents, wh|
|00003e40| 69 63 68 20 69 6e 63 6c | 75 64 65 20 6f 6e 6c 79 |ich incl|ude only|
|00003e50| 20 74 68 6f 73 65 20 63 | 6f 6d 6d 61 6e 64 73 0a | those c|ommands.|
|00003e60| 20 20 6e 6f 74 20 6e 65 | 73 74 65 64 20 69 6e 20 | not ne|sted in |
|00003e70| 63 6d 64 6c 69 73 74 73 | 20 77 69 74 68 69 6e 20 |cmdlists| within |
|00003e80| 63 6f 6e 74 72 6f 6c 20 | 73 74 72 75 63 74 75 72 |control |structur|
|00003e90| 65 73 2e 20 20 46 6f 72 | 20 65 78 61 6d 70 6c 65 |es. For| example|
|00003ea0| 2c 20 61 6c 6c 0a 20 20 | 63 6f 6d 6d 61 6e 64 73 |, all. |commands|
|00003eb0| 20 66 6f 75 6e 64 20 77 | 69 74 68 69 6e 20 74 68 | found w|ithin th|
|00003ec0| 65 20 61 72 67 6c 69 73 | 74 73 20 66 6f 72 20 63 |e arglis|ts for c|
|00003ed0| 6f 6d 6d 61 6e 64 73 20 | 6c 69 6b 65 20 7b 5c 74 |ommands |like {\t|
|00003ee0| 74 20 70 72 6f 63 7d 2c | 20 7b 5c 74 74 0a 20 20 |t proc},| {\tt. |
|00003ef0| 69 66 7d 2c 20 65 74 63 | 2e 20 20 63 61 6e 6e 6f |if}, etc|. canno|
|00003f00| 74 20 62 65 20 72 6f 6f | 74 73 20 6f 66 20 74 68 |t be roo|ts of th|
|00003f10| 65 20 74 72 65 65 2c 20 | 61 6c 74 68 6f 75 67 68 |e tree, |although|
|00003f20| 20 74 68 65 20 7b 5c 74 | 74 20 70 72 6f 63 7d 2c | the {\t|t proc},|
|00003f30| 20 65 74 63 2e 0a 20 20 | 63 6f 6d 6d 61 6e 64 73 | etc.. |commands|
|00003f40| 20 63 61 6e 20 62 65 2c | 20 69 66 20 74 68 65 79 | can be,| if they|
|00003f50| 20 74 68 65 6d 73 65 6c | 76 65 73 20 61 72 65 20 | themsel|ves are |
|00003f60| 6e 6f 74 20 6e 65 73 74 | 65 64 2e 0a 0a 54 68 65 |not nest|ed...The|
|00003f70| 20 6e 6f 64 65 20 74 79 | 70 65 73 20 66 6f 72 20 | node ty|pes for |
|00003f80| 74 68 69 73 20 74 72 65 | 65 20 69 6e 63 6c 75 64 |this tre|e includ|
|00003f90| 65 20 6e 6f 74 61 74 69 | 6f 6e 73 20 66 6f 72 20 |e notati|ons for |
|00003fa0| 6e 65 73 74 65 64 20 63 | 6f 6d 6d 61 6e 64 73 20 |nested c|ommands |
|00003fb0| 28 7b 5c 74 74 20 5b 0a | 20 20 2e 2e 2e 20 20 5d |({\tt [.| ... ]|
|00003fc0| 7d 29 2c 20 63 6f 6e 63 | 61 74 65 6e 61 74 65 64 |}), conc|atenated|
|00003fd0| 20 65 78 70 72 65 73 73 | 69 6f 6e 73 20 28 69 65 | express|ions (ie|
|00003fe0| 2e 20 7b 5c 74 74 20 5c | 24 61 5c 24 62 7d 29 2c |. {\tt \|$a\$b}),|
|00003ff0| 20 65 74 63 2e 20 20 41 | 6e 20 65 78 61 6d 70 6c | etc. A|n exampl|
|00004000| 65 0a 20 20 66 6f 6c 6c | 6f 77 73 3a 0a 0a 5c 76 |e. foll|ows:..\v|
|00004010| 73 70 61 63 65 7b 2e 31 | 69 6e 7d 0a 0a 7b 5c 62 |space{.1|in}..{\b|
|00004020| 66 20 53 6f 75 72 63 65 | 20 43 6f 64 65 7d 0a 0a |f Source| Code}..|
|00004030| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00004040| 0a 23 20 74 68 69 73 20 | 69 73 20 61 20 63 6f 6d |.# this |is a com|
|00004050| 6d 65 6e 74 0a 73 65 74 | 20 61 20 35 20 20 20 20 |ment.set| a 5 |
|00004060| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00004070| 0a 0a 23 20 63 6f 6e 63 | 61 74 65 6e 61 74 65 20 |..# conc|atenate |
|00004080| 74 68 65 20 72 65 74 75 | 72 6e 73 20 6f 66 20 74 |the retu|rns of t|
|00004090| 68 65 20 74 77 6f 20 6e | 65 73 74 65 64 0a 23 20 |he two n|ested.# |
|000040a0| 20 20 63 6f 6d 6d 61 6e | 64 73 20 61 6e 64 20 70 | comman|ds and p|
|000040b0| 61 73 73 20 69 74 20 61 | 73 20 61 6e 20 61 72 67 |ass it a|s an arg|
|000040c0| 20 74 6f 20 66 6f 6f 2e | 0a 66 6f 6f 20 5b 62 61 | to foo.|.foo [ba|
|000040d0| 72 20 73 65 74 5d 5b 66 | 6f 6f 20 7b 35 7d 5d 20 |r set][f|oo {5}] |
|000040e0| 20 20 20 20 0a 5c 65 6e | 64 7b 76 65 72 62 61 74 | .\en|d{verbat|
|000040f0| 69 6d 7d 0a 0a 5c 76 73 | 70 61 63 65 7b 2e 31 69 |im}..\vs|pace{.1i|
|00004100| 6e 7d 0a 0a 7b 5c 62 66 | 20 45 78 70 72 65 73 73 |n}..{\bf| Express|
|00004110| 69 6f 6e 20 44 69 63 74 | 69 6f 6e 61 72 79 20 28 |ion Dict|ionary (|
|00004120| 50 61 72 73 65 20 54 72 | 65 65 29 7d 0a 5c 62 65 |Parse Tr|ee)}.\be|
|00004130| 67 69 6e 7b 74 61 62 62 | 69 6e 67 7d 0a 20 20 78 |gin{tabb|ing}. x|
|00004140| 78 78 78 20 5c 3d 20 78 | 78 78 78 20 5c 3d 20 78 |xxx \= x|xxx \= x|
|00004150| 78 78 78 78 78 78 78 78 | 78 78 78 78 78 78 78 20 |xxxxxxxx|xxxxxxx |
|00004160| 5c 3d 20 5c 6b 69 6c 6c | 0a 20 20 5c 3e 20 31 2e |\= \kill|. \> 1.|
|00004170| 20 5c 3e 20 20 63 6d 64 | 20 20 20 09 5c 3e 09 60 | \> cmd| .\>.`|
|00004180| 60 73 65 74 27 27 20 5c | 5c 0a 20 20 5c 3e 20 32 |`set'' \|\. \> 2|
|00004190| 2e 20 5c 3e 20 20 63 6f | 6e 73 74 61 6e 74 20 20 |. \> co|nstant |
|000041a0| 5c 3e 20 20 60 60 61 27 | 27 20 5c 5c 0a 20 20 5c |\> ``a'|' \\. \|
|000041b0| 3e 20 33 2e 20 5c 3e 20 | 20 63 6f 6e 73 74 61 6e |> 3. \> | constan|
|000041c0| 74 20 20 5c 3e 20 20 60 | 60 35 27 27 20 5c 5c 0a |t \> `|`5'' \\.|
|000041d0| 20 20 5c 3e 20 34 2e 20 | 5c 3e 20 20 63 6d 64 20 | \> 4. |\> cmd |
|000041e0| 20 20 09 5c 3e 09 60 60 | 66 6f 6f 27 27 20 5c 5c | .\>.``|foo'' \\|
|000041f0| 0a 20 20 5c 3e 20 35 2e | 20 5c 3e 20 20 63 6d 64 |. \> 5.| \> cmd|
|00004200| 20 20 20 09 5c 3e 09 60 | 60 62 61 72 27 27 20 5c | .\>.`|`bar'' \|
|00004210| 5c 0a 20 20 5c 3e 20 36 | 2e 20 5c 3e 20 20 63 6f |\. \> 6|. \> co|
|00004220| 6e 73 74 61 6e 74 20 20 | 5c 3e 20 20 60 60 73 65 |nstant |\> ``se|
|00004230| 74 27 27 20 5c 5c 0a 20 | 20 5c 3e 20 37 2e 20 5c |t'' \\. | \> 7. \|
|00004240| 3e 20 20 6e 65 73 74 65 | 64 20 73 74 61 74 65 6d |> neste|d statem|
|00004250| 65 6e 74 20 20 5c 3e 20 | 20 20 20 20 20 5b 32 20 |ent \> | [2 |
|00004260| 61 72 67 73 5d 5b 5c 23 | 35 5d 5b 5c 23 36 5d 20 |args][\#|5][\#6] |
|00004270| 5c 5c 0a 20 20 5c 3e 20 | 38 2e 20 5c 3e 20 20 6e |\\. \> |8. \> n|
|00004280| 65 73 74 65 64 20 73 74 | 61 74 65 6d 65 6e 74 20 |ested st|atement |
|00004290| 20 5c 3e 20 20 20 20 20 | 20 5b 32 20 61 72 67 73 | \> | [2 args|
|000042a0| 5d 5b 5c 23 34 5d 5b 5c | 23 33 5d 20 5c 5c 0a 20 |][\#4][\|#3] \\. |
|000042b0| 20 5c 3e 20 39 2e 20 5c | 3e 20 20 63 6f 6e 63 61 | \> 9. \|> conca|
|000042c0| 74 20 20 20 20 20 5c 3e | 20 20 20 5b 32 20 61 72 |t \>| [2 ar|
|000042d0| 67 73 5d 5b 5c 23 37 5d | 5b 5c 23 38 5d 0a 5c 65 |gs][\#7]|[\#8].\e|
|000042e0| 6e 64 7b 74 61 62 62 69 | 6e 67 7d 0a 0a 5c 76 73 |nd{tabbi|ng}..\vs|
|000042f0| 70 61 63 65 7b 2e 31 69 | 6e 7d 0a 0a 7b 5c 62 66 |pace{.1i|n}..{\bf|
|00004300| 20 54 6f 70 20 4c 65 76 | 65 6c 20 43 6f 6d 6d 61 | Top Lev|el Comma|
|00004310| 6e 64 20 4c 69 73 74 20 | 28 54 72 65 65 20 52 6f |nd List |(Tree Ro|
|00004320| 6f 74 73 29 7d 0a 0a 5c | 62 65 67 69 6e 7b 76 65 |ots)}..\|begin{ve|
|00004330| 72 62 61 74 69 6d 7d 0a | 20 20 5b 33 20 61 72 67 |rbatim}.| [3 arg|
|00004340| 73 5d 5b 23 31 5d 5b 23 | 32 5d 5b 23 33 5d 5b 32 |s][#1][#|2][#3][2|
|00004350| 20 61 72 67 73 5d 5b 23 | 34 5d 5b 23 39 5d 0a 5c | args][#|4][#9].\|
|00004360| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0a 0a 4e |end{verb|atim}..N|
|00004370| 6f 74 65 73 3a 20 60 60 | 5c 23 6e 27 27 20 72 65 |otes: ``|\#n'' re|
|00004380| 66 65 72 73 20 74 6f 20 | 61 20 72 65 66 65 72 65 |fers to |a refere|
|00004390| 6e 63 65 20 74 6f 20 69 | 74 65 6d 20 6e 75 6d 62 |nce to i|tem numb|
|000043a0| 65 72 20 6e 2e 20 20 54 | 68 65 20 63 6f 6d 70 69 |er n. T|he compi|
|000043b0| 6c 65 72 0a 20 20 64 65 | 74 65 63 74 73 20 6d 75 |ler. de|tects mu|
|000043c0| 6c 74 69 70 6c 65 20 75 | 73 65 73 20 6f 66 20 74 |ltiple u|ses of t|
|000043d0| 68 65 20 73 61 6d 65 20 | 63 6f 6e 73 74 61 6e 74 |he same |constant|
|000043e0| 73 20 61 6e 64 20 6f 74 | 68 65 72 20 70 72 69 6d |s and ot|her prim|
|000043f0| 69 74 69 76 65 20 6f 62 | 6a 65 63 74 73 2c 0a 20 |itive ob|jects,. |
|00004400| 20 61 6e 64 20 72 65 75 | 73 65 73 20 74 68 65 73 | and reu|ses thes|
|00004410| 65 20 65 6e 74 72 69 65 | 73 2e 20 20 46 6f 72 20 |e entrie|s. For |
|00004420| 65 78 61 6d 70 6c 65 2c | 20 74 68 65 20 65 6e 74 |example,| the ent|
|00004430| 72 79 20 66 6f 72 20 74 | 68 65 20 7b 5c 62 66 20 |ry for t|he {\bf |
|00004440| 66 6f 6f 7d 0a 20 20 63 | 6f 6d 6d 61 6e 64 20 28 |foo}. c|ommand (|
|00004450| 5c 23 34 29 20 69 73 20 | 72 65 75 73 65 64 2e 20 |\#4) is |reused. |
|00004460| 20 54 68 69 73 20 73 79 | 73 74 65 6d 20 69 73 20 | This sy|stem is |
|00004470| 61 6c 73 6f 20 61 62 6c | 65 20 74 6f 20 72 65 63 |also abl|e to rec|
|00004480| 6f 67 6e 69 7a 65 20 74 | 68 65 0a 20 20 64 69 66 |ognize t|he. dif|
|00004490| 66 65 72 65 6e 63 65 20 | 62 65 74 77 65 65 6e 20 |ference |between |
|000044a0| 63 6f 6d 6d 61 6e 64 73 | 20 61 6e 64 20 73 74 61 |commands| and sta|
|000044b0| 74 69 63 20 73 74 72 69 | 6e 67 73 2c 20 77 68 65 |tic stri|ngs, whe|
|000044c0| 72 65 20 74 68 65 20 63 | 6f 6d 6d 61 6e 64 20 6e |re the c|ommand n|
|000044d0| 61 6d 65 20 69 73 0a 20 | 20 74 68 65 20 66 69 72 |ame is. | the fir|
|000044e0| 73 74 20 61 72 67 75 6d | 65 6e 74 2e 20 20 49 74 |st argum|ent. It|
|000044f0| 20 61 6c 73 6f 20 73 74 | 72 69 70 73 20 74 68 65 | also st|rips the|
|00004500| 20 63 75 72 6c 79 20 62 | 72 61 63 65 73 20 66 72 | curly b|races fr|
|00004510| 6f 6d 20 74 68 65 20 73 | 74 61 74 69 63 0a 20 20 |om the s|tatic. |
|00004520| 73 74 72 69 6e 67 20 69 | 6e 20 74 68 65 20 74 68 |string i|n the th|
|00004530| 69 72 64 20 6c 69 6e 65 | 20 6f 66 20 63 6f 64 65 |ird line| of code|
|00004540| 2e 20 20 54 68 65 20 63 | 6f 6e 63 61 74 65 6e 61 |. The c|oncatena|
|00004550| 74 69 6f 6e 20 61 6e 64 | 20 6e 65 73 74 65 64 20 |tion and| nested |
|00004560| 63 6f 6d 6d 61 6e 64 73 | 0a 20 20 77 65 72 65 20 |commands|. were |
|00004570| 64 69 73 63 6f 76 65 72 | 65 64 20 61 74 20 63 6f |discover|ed at co|
|00004580| 6d 70 69 6c 65 20 74 69 | 6d 65 2e 20 20 4c 61 73 |mpile ti|me. Las|
|00004590| 74 6c 79 2c 20 63 6f 6d | 6d 65 6e 74 73 20 68 61 |tly, com|ments ha|
|000045a0| 76 65 20 62 65 65 6e 20 | 73 74 72 69 70 70 65 64 |ve been |stripped|
|000045b0| 2e 0a 0a 5c 73 75 62 73 | 65 63 74 69 6f 6e 7b 41 |...\subs|ection{A|
|000045c0| 72 67 75 6d 65 6e 74 20 | 50 61 72 73 69 6e 67 7d |rgument |Parsing}|
|000045d0| 0a 0a 41 73 20 64 65 73 | 63 72 69 62 65 64 20 70 |..As des|cribed p|
|000045e0| 72 65 76 69 6f 75 73 6c | 79 2c 20 69 74 20 69 73 |reviousl|y, it is|
|000045f0| 20 6e 65 63 65 73 73 61 | 72 79 20 74 6f 20 70 72 | necessa|ry to pr|
|00004600| 65 70 61 72 73 65 20 61 | 72 67 75 6d 65 6e 74 73 |eparse a|rguments|
|00004610| 20 69 6e 20 6f 72 64 65 | 72 20 74 6f 0a 20 20 61 | in orde|r to. a|
|00004620| 63 68 69 65 76 65 20 72 | 65 61 6c 20 70 65 72 66 |chieve r|eal perf|
|00004630| 6f 72 6d 61 6e 63 65 20 | 67 61 69 6e 73 2e 20 20 |ormance |gains. |
|00004640| 54 6f 20 73 75 70 70 6f | 72 74 20 74 68 69 73 2c |To suppo|rt this,|
|00004650| 20 77 65 20 69 6e 74 72 | 6f 64 75 63 65 20 61 20 | we intr|oduce a |
|00004660| 74 79 70 65 0a 20 20 73 | 79 73 74 65 6d 20 69 6e |type. s|ystem in|
|00004670| 74 6f 20 54 63 6c 20 66 | 6f 72 20 70 61 72 73 69 |to Tcl f|or parsi|
|00004680| 6e 67 20 63 6f 6d 70 69 | 6c 65 2d 74 69 6d 65 20 |ng compi|le-time |
|00004690| 63 6f 6e 73 74 61 6e 74 | 73 2c 20 61 6e 64 20 61 |constant|s, and a|
|000046a0| 20 73 79 73 74 65 6d 20 | 66 6f 72 0a 20 20 64 65 | system |for. de|
|000046b0| 74 65 72 6d 69 6e 69 6e | 67 20 77 68 69 63 68 20 |terminin|g which |
|000046c0| 62 75 69 6c 74 69 6e 20 | 63 6f 6d 6d 61 6e 64 73 |builtin |commands|
|000046d0| 20 65 78 70 65 63 74 20 | 77 68 69 63 68 20 74 79 | expect |which ty|
|000046e0| 70 65 73 20 66 6f 72 20 | 65 61 63 68 20 61 72 67 |pes for |each arg|
|000046f0| 75 6d 65 6e 74 2e 0a 20 | 20 0a 43 6f 6e 73 69 64 |ument.. | .Consid|
|00004700| 65 72 20 74 68 65 20 60 | 69 6e 63 72 27 20 63 6f |er the `|incr' co|
|00004710| 6d 6d 61 6e 64 2e 20 20 | 49 6e 20 69 74 73 20 66 |mmand. |In its f|
|00004720| 69 72 73 74 20 61 72 67 | 75 6d 65 6e 74 2c 20 69 |irst arg|ument, i|
|00004730| 74 20 65 78 70 65 63 74 | 73 20 74 6f 20 62 65 0a |t expect|s to be.|
|00004740| 20 20 70 61 73 73 65 64 | 20 74 68 65 20 6e 61 6d | passed| the nam|
|00004750| 65 20 6f 66 20 61 20 76 | 61 72 69 61 62 6c 65 2e |e of a v|ariable.|
|00004760| 20 20 49 6e 20 69 74 73 | 20 73 65 63 6f 6e 64 20 | In its| second |
|00004770| 61 72 67 75 6d 65 6e 74 | 20 69 74 20 28 6f 70 74 |argument| it (opt|
|00004780| 69 6f 6e 61 6c 6c 79 29 | 0a 20 20 65 78 70 65 63 |ionally)|. expec|
|00004790| 74 73 20 61 6e 20 69 6e | 74 65 67 65 72 20 76 61 |ts an in|teger va|
|000047a0| 6c 75 65 20 28 61 20 73 | 74 72 69 6e 67 20 77 68 |lue (a s|tring wh|
|000047b0| 69 63 68 20 63 61 6e 20 | 62 65 20 70 61 72 73 65 |ich can |be parse|
|000047c0| 64 20 61 73 20 61 6e 20 | 69 6e 74 65 67 65 72 29 |d as an |integer)|
|000047d0| 2e 0a 20 20 54 68 75 73 | 2c 20 69 66 20 74 68 65 |.. Thus|, if the|
|000047e0| 20 69 6e 70 75 74 20 63 | 6f 6e 74 61 69 6e 73 20 | input c|ontains |
|000047f0| 74 68 65 20 73 74 61 74 | 65 6d 65 6e 74 0a 0a 5c |the stat|ement..\|
|00004800| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0a |begin{ve|rbatim}.|
|00004810| 20 20 69 6e 63 72 20 61 | 20 35 0a 5c 65 6e 64 7b | incr a| 5.\end{|
|00004820| 76 65 72 62 61 74 69 6d | 7d 0a 0a 20 20 77 65 20 |verbatim|}.. we |
|00004830| 63 61 6e 20 6b 6e 6f 77 | 20 74 6f 20 74 72 65 61 |can know| to trea|
|00004840| 74 20 60 60 61 27 27 20 | 61 73 20 74 68 65 20 76 |t ``a'' |as the v|
|00004850| 61 72 69 61 62 6c 65 20 | 77 68 6f 73 65 20 6e 61 |ariable |whose na|
|00004860| 6d 65 20 69 73 20 60 60 | 61 27 27 2c 20 6e 6f 74 |me is ``|a'', not|
|00004870| 20 74 68 65 0a 20 20 73 | 74 72 69 6e 67 20 60 60 | the. s|tring ``|
|00004880| 61 27 27 2e 20 20 4c 69 | 6b 65 77 69 73 65 2c 20 |a''. Li|kewise, |
|00004890| 60 60 35 27 27 20 68 65 | 72 65 20 69 73 20 74 68 |``5'' he|re is th|
|000048a0| 65 20 69 6e 74 65 67 65 | 72 20 76 61 6c 75 65 20 |e intege|r value |
|000048b0| 35 2e 20 20 4e 6f 74 65 | 20 74 68 61 74 20 69 66 |5. Note| that if|
|000048c0| 0a 20 20 74 68 65 20 60 | 60 35 27 27 20 77 65 72 |. the `|`5'' wer|
|000048d0| 65 20 72 65 70 6c 61 63 | 65 64 20 62 79 20 60 60 |e replac|ed by ``|
|000048e0| 5c 24 62 27 27 20 66 6f | 72 20 65 78 61 6d 70 6c |\$b'' fo|r exampl|
|000048f0| 65 2c 20 74 68 65 6e 20 | 77 65 20 63 6f 75 6c 64 |e, then |we could|
|00004900| 6e 27 74 20 61 73 73 75 | 6d 65 0a 20 20 61 6e 79 |n't assu|me. any|
|00004910| 74 68 69 6e 67 2c 20 65 | 78 63 65 70 74 20 74 68 |thing, e|xcept th|
|00004920| 61 74 20 74 68 65 20 76 | 61 6c 75 65 20 6f 66 20 |at the v|alue of |
|00004930| 62 20 6d 69 67 68 74 20 | 62 65 20 61 20 73 74 72 |b might |be a str|
|00004940| 69 6e 67 20 77 68 69 63 | 68 20 68 61 73 20 61 6e |ing whic|h has an|
|00004950| 0a 20 20 69 6e 74 65 67 | 65 72 20 72 65 70 72 65 |. integ|er repre|
|00004960| 73 65 6e 74 61 74 69 6f | 6e 2e 20 20 45 76 65 6e |sentatio|n. Even|
|00004970| 20 74 68 69 73 20 69 73 | 20 6e 6f 74 20 6e 65 63 | this is| not nec|
|00004980| 65 73 73 61 72 69 6c 79 | 20 74 72 75 65 2c 20 73 |essarily| true, s|
|00004990| 69 6e 63 65 20 54 63 6c | 0a 20 20 73 75 70 70 6f |ince Tcl|. suppo|
|000049a0| 72 74 73 20 65 78 63 65 | 70 74 69 6f 6e 20 68 61 |rts exce|ption ha|
|000049b0| 6e 64 6c 69 6e 67 2c 20 | 73 6f 20 74 68 69 73 20 |ndling, |so this |
|000049c0| 62 6c 75 6e 64 65 72 20 | 6d 61 79 20 62 65 20 69 |blunder |may be i|
|000049d0| 6e 74 65 6e 74 69 6f 6e | 61 6c 21 20 20 54 68 65 |ntention|al! The|
|000049e0| 0a 20 20 68 61 6e 64 6c | 69 6e 67 20 6f 66 20 74 |. handl|ing of t|
|000049f0| 68 65 73 65 20 6d 6f 72 | 65 20 64 69 66 66 69 63 |hese mor|e diffic|
|00004a00| 75 6c 74 20 63 61 73 65 | 73 20 69 73 20 64 69 73 |ult case|s is dis|
|00004a10| 63 75 73 73 65 64 20 62 | 65 6c 6f 77 20 69 6e 20 |cussed b|elow in |
|00004a20| 74 68 65 20 72 75 6e 74 | 69 6d 65 0a 20 20 73 79 |the runt|ime. sy|
|00004a30| 73 74 65 6d 2c 20 73 69 | 6e 63 65 20 74 68 65 73 |stem, si|nce thes|
|00004a40| 65 20 61 72 65 20 64 79 | 6e 61 6d 69 63 20 65 66 |e are dy|namic ef|
|00004a50| 66 65 63 74 73 20 74 68 | 61 74 20 61 72 65 20 6f |fects th|at are o|
|00004a60| 72 74 68 6f 67 6e 61 6c | 20 74 6f 20 74 68 65 0a |rthognal| to the.|
|00004a70| 20 20 70 72 6f 62 6c 65 | 6d 73 20 65 6e 63 6f 75 | proble|ms encou|
|00004a80| 6e 74 65 72 65 64 20 62 | 79 20 74 68 65 20 63 6f |ntered b|y the co|
|00004a90| 6d 70 69 6c 65 72 2e 0a | 0a 49 74 20 77 6f 75 6c |mpiler..|.It woul|
|00004aa0| 64 20 62 65 20 65 6e 74 | 69 72 65 6c 79 20 70 6f |d be ent|irely po|
|00004ab0| 73 73 69 62 6c 65 20 74 | 6f 20 68 61 72 64 63 6f |ssible t|o hardco|
|00004ac0| 64 65 20 74 68 65 20 63 | 6f 6d 70 69 6c 65 72 20 |de the c|ompiler |
|00004ad0| 74 6f 20 72 65 63 6f 67 | 6e 69 7a 65 20 74 68 65 |to recog|nize the|
|00004ae0| 73 65 0a 20 20 74 79 70 | 65 73 20 61 6e 64 20 74 |se. typ|es and t|
|00004af0| 68 65 20 63 6f 6d 6d 61 | 6e 64 73 20 77 68 69 63 |he comma|nds whic|
|00004b00| 68 20 75 73 65 20 74 68 | 65 6d 2e 20 20 48 6f 77 |h use th|em. How|
|00004b10| 65 76 65 72 2c 20 54 63 | 6c 20 69 73 20 65 78 74 |ever, Tc|l is ext|
|00004b20| 65 6e 64 61 62 6c 65 2e | 20 20 54 68 69 73 0a 20 |endable.| This. |
|00004b30| 20 6d 65 61 6e 73 20 74 | 68 61 74 20 61 20 75 73 | means t|hat a us|
|00004b40| 65 72 20 63 6f 75 6c 64 | 20 70 6f 74 65 6e 74 69 |er could| potenti|
|00004b50| 61 6c 6c 79 20 61 75 74 | 68 6f 72 20 68 69 73 20 |ally aut|hor his |
|00004b60| 6f 72 20 68 65 72 20 6f | 77 6e 20 62 75 69 6c 74 |or her o|wn built|
|00004b70| 69 6e 20 77 68 69 63 68 | 0a 20 20 74 61 6b 65 73 |in which|. takes|
|00004b80| 20 61 73 20 61 6e 20 61 | 72 67 75 6d 65 6e 74 20 | as an a|rgument |
|00004b90| 61 20 6c 69 73 74 20 6f | 72 20 73 6f 6d 65 20 6f |a list o|r some o|
|00004ba0| 74 68 65 72 20 6c 61 72 | 67 65 20 73 74 72 75 63 |ther lar|ge struc|
|00004bb0| 74 75 72 65 2c 20 77 68 | 69 63 68 20 77 65 20 77 |ture, wh|ich we w|
|00004bc0| 6f 75 6c 64 0a 20 20 6c | 69 6b 65 20 70 72 65 70 |ould. l|ike prep|
|00004bd0| 61 72 73 65 2e 20 20 54 | 68 75 73 2c 20 69 74 20 |arse. T|hus, it |
|00004be0| 6d 61 6b 65 73 20 6d 6f | 72 65 20 73 65 6e 73 65 |makes mo|re sense|
|00004bf0| 20 74 6f 20 61 6c 6c 6f | 77 20 74 68 65 20 63 6f | to allo|w the co|
|00004c00| 6d 70 69 6c 65 72 20 69 | 74 73 65 6c 66 20 74 6f |mpiler i|tself to|
|00004c10| 0a 20 20 62 65 20 65 78 | 74 65 6e 73 69 62 6c 65 |. be ex|tensible|
|00004c20| 2c 20 73 6f 20 73 75 63 | 68 20 70 6f 77 65 72 20 |, so suc|h power |
|00004c30| 75 73 65 72 73 20 63 61 | 6e 20 63 6f 6d 70 69 6c |users ca|n compil|
|00004c40| 65 20 74 68 65 69 72 20 | 6f 77 6e 20 63 6f 6d 6d |e their |own comm|
|00004c50| 61 6e 64 73 20 61 6e 64 | 0a 20 20 61 72 67 75 6d |ands and|. argum|
|00004c60| 65 6e 74 73 2e 0a 0a 46 | 6f 72 20 74 68 69 73 20 |ents...F|or this |
|00004c70| 6a 6f 62 2c 20 54 63 6c | 20 69 74 73 65 6c 66 20 |job, Tcl| itself |
|00004c80| 69 73 20 69 64 65 61 6c | 2c 20 61 6e 64 20 68 65 |is ideal|, and he|
|00004c90| 6e 63 65 20 77 65 20 65 | 6d 62 65 64 20 61 6e 20 |nce we e|mbed an |
|00004ca0| 69 6e 74 65 72 70 72 65 | 74 65 72 20 69 6e 74 6f |interpre|ter into|
|00004cb0| 0a 20 20 74 68 65 20 63 | 6f 6d 70 69 6c 65 72 2e |. the c|ompiler.|
|00004cc0| 20 20 54 68 69 73 20 69 | 6e 74 65 72 70 72 65 74 | This i|nterpret|
|00004cd0| 65 72 20 72 65 61 64 73 | 20 69 6e 20 61 20 63 6f |er reads| in a co|
|00004ce0| 6e 66 69 67 20 73 63 72 | 69 70 74 20 61 74 20 73 |nfig scr|ipt at s|
|00004cf0| 74 61 72 74 75 70 20 77 | 68 69 63 68 0a 20 20 64 |tartup w|hich. d|
|00004d00| 65 63 6c 61 72 65 73 20 | 64 61 74 61 20 74 79 70 |eclares |data typ|
|00004d10| 65 20 73 75 70 70 6f 72 | 74 20 61 6e 64 20 61 73 |e suppor|t and as|
|00004d20| 73 6f 63 69 61 74 65 73 | 20 74 68 65 6d 20 74 6f |sociates| them to|
|00004d30| 20 62 75 69 6c 74 69 6e | 20 63 6f 6d 6d 61 6e 64 | builtin| command|
|00004d40| 73 2e 20 20 54 68 65 0a | 20 20 54 63 6c 20 73 63 |s. The.| Tcl sc|
|00004d50| 72 69 70 74 20 63 6f 6e | 74 61 69 6e 73 20 74 68 |ript con|tains th|
|00004d60| 65 20 66 6f 6c 6c 6f 77 | 69 6e 67 20 74 77 6f 20 |e follow|ing two |
|00004d70| 63 6f 6d 6d 61 6e 64 73 | 2c 20 69 6e 20 61 64 64 |commands|, in add|
|00004d80| 69 74 69 6f 6e 20 74 6f | 20 74 68 65 20 54 63 6c |ition to| the Tcl|
|00004d90| 0a 20 20 63 6f 72 65 2e | 20 20 54 68 65 20 62 61 |. core.| The ba|
|00004da0| 63 6b 73 6c 61 68 65 73 | 20 69 6e 64 69 63 61 74 |ckslahes| indicat|
|00004db0| 65 20 74 68 61 74 20 74 | 68 65 20 61 72 67 75 6d |e that t|he argum|
|00004dc0| 65 6e 74 73 20 73 68 6f | 75 6c 64 20 62 65 20 70 |ents sho|uld be p|
|00004dd0| 61 72 74 20 6f 66 20 61 | 20 73 69 6e 67 6c 65 0a |art of a| single.|
|00004de0| 20 20 63 6f 6d 6d 61 6e | 64 2e 0a 0a 7b 5c 73 6d | comman|d...{\sm|
|00004df0| 61 6c 6c 0a 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |all.\beg|in{verba|
|00004e00| 74 69 6d 7d 0a 20 20 74 | 79 70 65 20 3c 6e 61 6d |tim}. t|ype <nam|
|00004e10| 65 3e 20 3c 70 61 72 73 | 65 70 72 6f 63 3e 20 3c |e> <pars|eproc> <|
|00004e20| 63 6f 64 65 67 65 6e 70 | 72 6f 63 3e 20 5c 0a 20 |codegenp|roc> \. |
|00004e30| 20 20 20 20 20 20 3c 6c | 6f 61 64 70 72 6f 63 3e | <l|oadproc>|
|00004e40| 20 3c 70 72 69 6e 74 70 | 72 6f 63 3e 0a 5c 65 6e | <printp|roc>.\en|
|00004e50| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0a 7d 0a 0a 54 |d{verbat|im}.}..T|
|00004e60| 68 69 73 20 64 65 63 6c | 61 72 65 73 20 61 20 6e |his decl|ares a n|
|00004e70| 65 77 20 61 72 67 75 6d | 65 6e 74 20 74 79 70 65 |ew argum|ent type|
|00004e80| 2c 20 77 68 69 63 68 20 | 77 69 6c 6c 20 75 73 65 |, which |will use|
|00004e90| 20 7b 5c 74 74 20 70 61 | 72 73 65 70 72 6f 63 7d | {\tt pa|rseproc}|
|00004ea0| 20 74 6f 0a 20 20 63 6f | 6e 76 65 72 74 20 73 74 | to. co|nvert st|
|00004eb0| 72 69 6e 67 20 64 61 74 | 61 20 69 6e 74 6f 20 70 |ring dat|a into p|
|00004ec0| 61 72 73 65 64 20 64 61 | 74 61 20 6f 66 20 74 68 |arsed da|ta of th|
|00004ed0| 69 73 20 74 79 70 65 2c | 20 7b 5c 74 74 20 63 6f |is type,| {\tt co|
|00004ee0| 64 65 67 65 6e 70 72 6f | 63 7d 20 74 6f 0a 20 20 |degenpro|c} to. |
|00004ef0| 6f 75 74 70 75 74 20 69 | 6e 74 6f 20 62 69 6e 61 |output i|nto bina|
|00004f00| 72 79 20 66 6f 72 6d 2c | 20 7b 5c 74 74 20 6c 6f |ry form,| {\tt lo|
|00004f10| 61 64 70 72 6f 63 7d 20 | 74 6f 20 6c 6f 61 64 20 |adproc} |to load |
|00004f20| 61 74 20 72 75 6e 74 69 | 6d 65 2c 20 61 6e 64 20 |at runti|me, and |
|00004f30| 7b 5c 74 74 0a 20 20 70 | 72 69 6e 74 70 72 6f 63 |{\tt. p|rintproc|
|00004f40| 7d 20 74 6f 20 63 6f 6e | 76 65 72 74 65 64 20 62 |} to con|verted b|
|00004f50| 61 63 6b 20 69 6e 74 6f | 20 73 74 72 69 6e 67 20 |ack into| string |
|00004f60| 66 6f 72 6d 20 66 6f 72 | 20 6f 75 74 70 75 74 2e |form for| output.|
|00004f70| 20 20 54 68 65 73 65 20 | 70 72 6f 63 73 0a 20 20 | These |procs. |
|00004f80| 61 72 65 20 6a 75 73 74 | 20 6e 61 6d 65 73 2c 20 |are just| names, |
|00004f90| 77 68 69 63 68 20 61 72 | 65 20 61 73 73 6f 63 69 |which ar|e associ|
|00004fa0| 61 74 65 64 20 73 74 61 | 74 69 63 61 6c 6c 79 20 |ated sta|tically |
|00004fb0| 62 79 20 74 68 65 20 43 | 20 63 61 6c 6c 62 61 63 |by the C| callbac|
|00004fc0| 6b 73 20 74 6f 0a 20 20 | 72 65 61 6c 20 43 20 66 |ks to. |real C f|
|00004fd0| 75 6e 63 74 69 6f 6e 20 | 70 6f 69 6e 74 65 72 73 |unction |pointers|
|00004fe0| 20 74 61 6b 69 6e 67 20 | 73 70 65 63 69 66 69 63 | taking |specific|
|00004ff0| 20 61 72 67 75 6d 65 6e | 74 73 2c 20 75 73 69 6e | argumen|ts, usin|
|00005000| 67 20 74 68 65 20 54 63 | 6c 20 68 61 73 68 69 6e |g the Tc|l hashin|
|00005010| 67 0a 20 20 6d 65 63 68 | 61 6e 69 73 6d 20 70 72 |g. mech|anism pr|
|00005020| 6f 76 69 64 65 64 20 62 | 79 20 74 68 65 20 54 63 |ovided b|y the Tc|
|00005030| 6c 20 63 6f 72 65 20 6c | 69 62 72 61 72 79 20 28 |l core l|ibrary (|
|00005040| 54 63 6c 5c 5f 48 61 73 | 68 58 78 78 78 29 2e 0a |Tcl\_Has|hXxxx)..|
|00005050| 0a 7b 5c 73 6d 61 6c 6c | 0a 5c 62 65 67 69 6e 7b |.{\small|.\begin{|
|00005060| 76 65 72 62 61 74 69 6d | 7d 0a 20 20 62 75 69 6c |verbatim|}. buil|
|00005070| 74 69 6e 20 3c 6e 61 6d | 65 3e 20 3c 70 61 72 73 |tin <nam|e> <pars|
|00005080| 65 70 72 6f 63 3e 20 3c | 63 6f 64 65 67 65 6e 70 |eproc> <|codegenp|
|00005090| 72 6f 63 3e 20 5c 0a 20 | 20 20 20 20 20 20 20 20 |roc> \. | |
|000050a0| 20 3c 6c 6f 61 64 70 72 | 6f 63 3e 20 3c 65 78 65 | <loadpr|oc> <exe|
|000050b0| 63 70 72 6f 63 3e 20 7b | 0a 20 20 20 20 20 20 7b |cproc> {|. {|
|000050c0| 20 3c 74 79 70 65 31 3e | 20 20 20 3c 61 72 67 6e | <type1>| <argn|
|000050d0| 61 6d 65 31 3e 20 7d 0a | 20 20 20 20 20 20 7b 20 |ame1> }.| { |
|000050e0| 3c 74 79 70 65 32 3e 20 | 20 20 3c 61 72 67 6e 61 |<type2> | <argna|
|000050f0| 6d 65 32 3e 20 3c 64 65 | 66 61 75 6c 74 32 3e 20 |me2> <de|fault2> |
|00005100| 7d 0a 20 20 20 20 20 20 | 2e 2e 2e 0a 20 20 7d 20 |}. |.... } |
|00005110| 3c 72 65 74 75 72 6e 5f | 74 79 70 65 3e 0a 5c 65 |<return_|type>.\e|
|00005120| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0a 7d 0a 0a |nd{verba|tim}.}..|
|00005130| 54 68 69 73 20 64 65 63 | 6c 61 72 65 73 20 61 20 |This dec|lares a |
|00005140| 6e 65 77 20 63 6f 6d 6d | 61 6e 64 20 74 6f 20 62 |new comm|and to b|
|00005150| 65 20 63 6f 6d 70 69 6c | 65 64 20 73 70 65 63 69 |e compil|ed speci|
|00005160| 61 6c 6c 79 2c 20 6e 61 | 6d 65 64 20 7b 5c 74 74 |ally, na|med {\tt|
|00005170| 20 3c 6e 61 6d 65 3e 7d | 2c 0a 20 20 77 69 74 68 | <name>}|,. with|
|00005180| 20 70 72 6f 63 73 20 64 | 65 66 69 6e 65 64 20 66 | procs d|efined f|
|00005190| 6f 72 20 69 74 73 20 63 | 6f 6d 70 69 6c 61 74 69 |or its c|ompilati|
|000051a0| 6f 6e 20 61 6e 64 20 65 | 76 61 6c 75 61 74 69 6f |on and e|valuatio|
|000051b0| 6e 2e 20 20 4e 6f 74 65 | 20 74 68 61 74 20 61 6c |n. Note| that al|
|000051c0| 6c 20 62 75 74 0a 20 20 | 74 68 65 20 65 78 65 63 |l but. |the exec|
|000051d0| 70 72 6f 63 20 6d 61 79 | 20 62 65 20 6c 65 66 74 |proc may| be left|
|000051e0| 20 65 6d 70 74 79 20 28 | 70 61 73 73 65 64 20 7b | empty (|passed {|
|000051f0| 5c 74 74 20 5c 7b 5c 7d | 20 7d 2c 20 77 68 69 63 |\tt \{\}| }, whic|
|00005200| 68 20 65 76 61 6c 75 61 | 74 65 73 20 74 6f 0a 20 |h evalua|tes to. |
|00005210| 20 74 68 65 20 6e 75 6c | 6c 20 73 74 72 69 6e 67 | the nul|l string|
|00005220| 29 20 62 65 63 61 75 73 | 65 20 76 69 72 74 75 61 |) becaus|e virtua|
|00005230| 6c 6c 79 20 61 6c 6c 20 | 63 6f 6d 6d 61 6e 64 73 |lly all |commands|
|00005240| 20 66 6f 6c 6c 6f 77 20 | 61 20 73 74 61 6e 64 61 | follow |a standa|
|00005250| 72 64 20 73 74 79 6c 65 | 0a 20 20 65 6d 70 6c 6f |rd style|. emplo|
|00005260| 79 69 6e 67 20 6b 6e 6f | 77 6e 20 74 79 70 65 73 |ying kno|wn types|
|00005270| 20 66 6f 72 20 65 61 63 | 68 20 61 72 67 75 6d 65 | for eac|h argume|
|00005280| 6e 74 2e 20 20 57 68 65 | 6e 20 6c 65 66 74 20 65 |nt. Whe|n left e|
|00005290| 6d 70 74 79 2c 20 54 43 | 20 73 75 62 73 74 69 74 |mpty, TC| substit|
|000052a0| 75 74 65 73 0a 20 20 61 | 20 64 65 66 61 75 6c 74 |utes. a| default|
|000052b0| 20 72 6f 75 74 69 6e 65 | 20 74 6f 20 70 72 6f 63 | routine| to proc|
|000052c0| 65 73 73 20 74 68 65 20 | 62 75 69 6c 74 69 6e 2e |ess the |builtin.|
|000052d0| 0a 0a 46 6f 72 20 65 61 | 63 68 20 6c 69 73 74 20 |..For ea|ch list |
|000052e0| 65 6c 65 6d 65 6e 74 20 | 69 6e 20 74 68 65 20 62 |element |in the b|
|000052f0| 6f 64 79 20 6f 66 20 74 | 68 65 20 62 75 69 6c 74 |ody of t|he built|
|00005300| 69 6e 20 64 65 63 6c 61 | 72 61 74 69 6f 6e 2c 20 |in decla|ration, |
|00005310| 77 65 20 73 70 65 63 69 | 66 79 0a 20 20 77 68 61 |we speci|fy. wha|
|00005320| 74 20 61 72 67 75 6d 65 | 6e 74 20 74 79 70 65 20 |t argume|nt type |
|00005330| 73 68 6f 75 6c 64 20 62 | 65 20 70 61 73 73 65 64 |should b|e passed|
|00005340| 20 74 6f 20 74 68 69 73 | 20 63 6f 6d 6d 61 6e 64 | to this| command|
|00005350| 2e 20 20 41 20 6e 61 6d | 65 20 69 73 20 72 65 71 |. A nam|e is req|
|00005360| 75 69 72 65 64 0a 20 20 | 66 6f 72 20 69 64 65 6e |uired. |for iden|
|00005370| 74 69 66 69 63 61 74 69 | 6f 6e 2c 20 64 65 62 75 |tificati|on, debu|
|00005380| 67 67 69 6e 67 2c 20 61 | 6e 64 20 62 6f 6f 6b 6b |gging, a|nd bookk|
|00005390| 65 65 70 69 6e 67 20 70 | 75 72 70 6f 73 65 73 2e |eeping p|urposes.|
|000053a0| 20 20 54 68 65 20 6f 70 | 74 69 6f 6e 61 6c 0a 20 | The op|tional. |
|000053b0| 20 74 68 69 72 64 20 65 | 6c 65 6d 65 6e 74 20 69 | third e|lement i|
|000053c0| 73 20 61 20 64 65 66 61 | 75 6c 74 20 73 74 72 69 |s a defa|ult stri|
|000053d0| 6e 67 20 66 6f 72 20 74 | 68 61 74 20 61 72 67 75 |ng for t|hat argu|
|000053e0| 6d 65 6e 74 2e 20 20 46 | 6f 72 20 65 78 61 6d 70 |ment. F|or examp|
|000053f0| 6c 65 2c 20 74 68 65 0a | 20 20 60 69 6e 63 72 27 |le, the.| `incr'|
|00005400| 20 63 6f 6d 6d 61 6e 64 | 20 69 73 20 64 65 73 63 | command| is desc|
|00005410| 72 69 62 65 64 20 61 73 | 20 66 6f 6c 6c 6f 77 73 |ribed as| follows|
|00005420| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|00005430| 69 6d 7d 0a 20 20 62 75 | 69 6c 74 69 6e 20 69 6e |im}. bu|iltin in|
|00005440| 63 72 20 7b 7d 20 7b 7d | 20 7b 7d 20 65 78 65 63 |cr {} {}| {} exec|
|00005450| 5f 69 6e 63 72 20 7b 0a | 20 20 20 20 20 20 7b 20 |_incr {.| { |
|00005460| 76 61 72 69 61 62 6c 65 | 09 76 61 72 20 7d 0a 20 |variable|.var }. |
|00005470| 20 20 20 20 20 7b 20 69 | 6e 74 65 67 65 72 09 69 | { i|nteger.i|
|00005480| 09 31 20 7d 0a 20 20 7d | 20 69 6e 74 65 67 65 72 |.1 }. }| integer|
|00005490| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 0a |.\end{ve|rbatim}.|
|000054a0| 0a 54 68 65 20 60 60 31 | 27 27 20 69 73 20 70 72 |.The ``1|'' is pr|
|000054b0| 65 70 61 72 73 65 64 20 | 61 73 20 74 79 70 65 20 |eparsed |as type |
|000054c0| 69 6e 74 65 67 65 72 20 | 61 6e 64 20 65 6e 74 65 |integer |and ente|
|000054d0| 72 65 64 20 69 6e 74 6f | 20 74 68 65 20 64 69 63 |red into| the dic|
|000054e0| 74 69 6f 6e 61 72 79 2e | 20 20 49 66 0a 20 20 7b |tionary.| If. {|
|000054f0| 5c 74 74 20 69 6e 63 72 | 7d 20 69 73 20 63 61 6c |\tt incr|} is cal|
|00005500| 6c 65 64 20 77 69 74 68 | 20 6f 6e 6c 79 20 6f 6e |led with| only on|
|00005510| 65 20 61 72 67 75 6d 65 | 6e 74 2c 20 74 68 65 20 |e argume|nt, the |
|00005520| 72 75 6e 74 69 6d 65 20 | 77 69 6c 6c 20 73 75 62 |runtime |will sub|
|00005530| 73 74 69 74 75 74 65 0a | 20 20 74 68 69 73 20 64 |stitute.| this d|
|00005540| 65 66 61 75 6c 74 20 76 | 61 6c 75 65 20 66 6f 72 |efault v|alue for|
|00005550| 20 74 68 65 20 73 65 63 | 6f 6e 64 20 61 72 67 75 | the sec|ond argu|
|00005560| 6d 65 6e 74 2e 0a 0a 5c | 73 65 63 74 69 6f 6e 7b |ment...\|section{|
|00005570| 52 75 6e 74 69 6d 65 20 | 49 73 73 75 65 73 7d 0a |Runtime |Issues}.|
|00005580| 0a 41 73 20 64 65 73 63 | 72 69 62 65 64 20 70 72 |.As desc|ribed pr|
|00005590| 65 76 69 6f 75 73 6c 79 | 2c 20 74 68 65 20 54 43 |eviously|, the TC|
|000055a0| 20 72 75 6e 74 69 6d 65 | 20 63 6f 6e 73 69 73 74 | runtime| consist|
|000055b0| 73 20 6f 66 20 61 6e 20 | 69 6e 74 65 72 70 72 65 |s of an |interpre|
|000055c0| 74 65 72 20 63 61 70 61 | 62 6c 65 0a 20 20 6f 66 |ter capa|ble. of|
|000055d0| 20 72 65 61 64 69 6e 67 | 20 69 6e 20 62 79 74 65 | reading| in byte|
|000055e0| 20 65 6e 63 6f 64 65 64 | 20 54 63 6c 20 73 63 72 | encoded| Tcl scr|
|000055f0| 69 70 74 73 2c 20 70 72 | 65 70 61 72 73 65 64 20 |ipts, pr|eparsed |
|00005600| 61 73 20 61 62 6f 76 65 | 2e 20 20 49 6e 20 6f 72 |as above|. In or|
|00005610| 64 65 72 20 74 6f 0a 20 | 20 73 75 70 70 6f 72 74 |der to. | support|
|00005620| 20 70 6f 73 73 69 62 6c | 65 20 73 74 61 74 65 20 | possibl|e state |
|00005630| 63 68 61 6e 67 65 73 20 | 73 75 63 68 20 61 73 20 |changes |such as |
|00005640| 63 6f 6d 6d 61 6e 64 20 | 72 65 6e 61 6d 69 6e 67 |command |renaming|
|00005650| 2c 20 74 68 65 0a 20 20 | 54 63 6c 20 63 6f 72 65 |, the. |Tcl core|
|00005660| 20 6c 69 62 72 61 72 79 | 20 69 73 20 6d 6f 64 69 | library| is modi|
|00005670| 66 69 65 64 20 74 6f 20 | 75 70 64 61 74 65 20 74 |fied to |update t|
|00005680| 68 65 20 73 74 61 74 65 | 20 6f 66 20 74 68 65 20 |he state| of the |
|00005690| 62 79 74 65 2d 63 6f 64 | 65 0a 20 20 69 6e 74 65 |byte-cod|e. inte|
|000056a0| 72 70 72 65 74 65 72 20 | 77 68 65 6e 20 74 68 65 |rpreter |when the|
|000056b0| 73 65 20 63 68 61 6e 67 | 65 73 20 6f 63 63 75 72 |se chang|es occur|
|000056c0| 2e 0a 0a 49 74 20 69 73 | 20 6e 6f 77 20 61 70 70 |...It is| now app|
|000056d0| 72 6f 70 72 69 61 74 65 | 20 74 6f 20 64 69 73 63 |ropriate| to disc|
|000056e0| 75 73 73 20 74 68 65 20 | 61 63 74 75 61 6c 20 65 |uss the |actual e|
|000056f0| 78 65 63 75 74 69 6f 6e | 20 6f 66 20 63 6f 6d 6d |xecution| of comm|
|00005700| 61 6e 64 73 20 69 6e 20 | 74 68 69 73 0a 20 20 6e |ands in |this. n|
|00005710| 65 77 20 65 6e 76 69 72 | 6f 6e 6d 65 6e 74 2e 20 |ew envir|onment. |
|00005720| 20 49 6e 20 6f 72 64 65 | 72 20 74 6f 20 74 61 6b | In orde|r to tak|
|00005730| 65 20 61 64 76 61 6e 74 | 61 67 65 20 6f 66 20 74 |e advant|age of t|
|00005740| 68 65 20 70 72 65 70 61 | 72 73 69 6e 67 20 74 68 |he prepa|rsing th|
|00005750| 65 0a 20 20 63 6f 6d 70 | 69 6c 65 72 20 68 61 73 |e. comp|iler has|
|00005760| 20 64 6f 6e 65 2c 20 77 | 65 20 6e 65 65 64 20 61 | done, w|e need a|
|00005770| 20 6e 65 77 20 63 61 6c | 6c 62 61 63 6b 20 69 6e | new cal|lback in|
|00005780| 74 65 72 66 61 63 65 2e | 20 20 54 68 69 73 20 69 |terface.| This i|
|00005790| 73 20 62 65 63 61 75 73 | 65 20 74 68 65 0a 20 20 |s becaus|e the. |
|000057a0| 73 74 61 6e 64 61 72 64 | 20 61 72 67 63 2f 61 72 |standard| argc/ar|
|000057b0| 67 76 20 69 6e 74 65 72 | 66 61 63 65 20 64 65 66 |gv inter|face def|
|000057c0| 65 61 74 73 20 74 68 65 | 20 70 75 72 70 6f 73 65 |eats the| purpose|
|000057d0| 20 6f 66 20 70 72 65 70 | 61 72 73 69 6e 67 20 62 | of prep|arsing b|
|000057e0| 79 20 74 61 6b 69 6e 67 | 0a 20 20 73 74 72 69 6e |y taking|. strin|
|000057f0| 67 20 61 73 20 61 72 67 | 75 6d 65 6e 74 73 2e 0a |g as arg|uments..|
|00005800| 0a 54 68 69 73 20 69 6d | 70 6c 69 65 73 20 74 68 |.This im|plies th|
|00005810| 65 20 6e 65 65 64 20 74 | 6f 20 6d 6f 64 69 66 79 |e need t|o modify|
|00005820| 20 74 68 65 20 43 20 63 | 61 6c 6c 62 61 63 6b 20 | the C c|allback |
|00005830| 72 6f 75 74 69 6e 65 73 | 20 66 6f 72 20 61 6e 79 |routines| for any|
|00005840| 20 63 6f 6d 6d 61 6e 64 | 73 0a 20 20 77 68 69 63 | command|s. whic|
|00005850| 68 20 61 72 65 20 74 6f | 20 62 65 20 63 6f 6d 70 |h are to| be comp|
|00005860| 69 6c 65 64 2e 20 20 54 | 68 69 73 20 72 65 71 75 |iled. T|his requ|
|00005870| 69 72 65 6d 65 6e 74 20 | 69 73 20 65 6e 74 69 72 |irement |is entir|
|00005880| 65 6c 79 20 72 65 61 73 | 6f 6e 61 62 6c 65 2e 0a |ely reas|onable..|
|00005890| 20 20 46 69 72 73 74 2c | 20 74 68 65 20 6e 65 77 | First,| the new|
|000058a0| 20 69 6e 74 65 72 66 61 | 63 65 20 69 73 20 76 65 | interfa|ce is ve|
|000058b0| 72 79 20 65 61 73 79 20 | 74 6f 20 63 6f 6e 73 74 |ry easy |to const|
|000058c0| 72 75 63 74 20 66 72 6f | 6d 20 74 68 65 20 61 72 |ruct fro|m the ar|
|000058d0| 67 63 2f 61 72 67 76 20 | 6f 6e 65 0a 20 20 66 6f |gc/argv |one. fo|
|000058e0| 72 20 61 20 67 69 76 65 | 6e 20 63 6f 6d 6d 61 6e |r a give|n comman|
|000058f0| 64 2e 20 20 53 65 63 6f | 6e 64 2c 20 74 68 65 20 |d. Seco|nd, the |
|00005900| 61 72 67 63 2f 61 72 67 | 76 20 69 6e 74 65 72 66 |argc/arg|v interf|
|00005910| 61 63 65 20 69 73 20 65 | 78 74 72 65 6d 65 6c 79 |ace is e|xtremely|
|00005920| 20 73 6c 6f 77 0a 20 20 | 64 75 65 20 74 6f 20 69 | slow. |due to i|
|00005930| 74 73 20 75 73 65 20 6f | 66 20 72 75 6e 74 69 6d |ts use o|f runtim|
|00005940| 65 20 70 61 72 73 69 6e | 67 2c 20 61 6e 64 20 77 |e parsin|g, and w|
|00005950| 6f 75 6c 64 20 72 65 71 | 75 69 72 65 20 6d 6f 64 |ould req|uire mod|
|00005960| 69 66 69 63 61 74 69 6f | 6e 20 69 6e 20 61 6e 79 |ificatio|n in any|
|00005970| 0a 20 20 68 69 67 68 65 | 72 2d 70 65 72 66 6f 72 |. highe|r-perfor|
|00005980| 6d 61 6e 63 65 20 73 79 | 73 74 65 6d 2e 20 20 4c |mance sy|stem. L|
|00005990| 61 73 74 6c 79 2c 20 6e | 6f 74 20 62 75 69 6c 74 |astly, n|ot built|
|000059a0| 69 6e 73 20 6e 65 65 64 | 20 74 6f 20 62 65 20 63 |ins need| to be c|
|000059b0| 6f 6d 70 69 6c 65 64 2e | 0a 20 20 4f 6e 6c 79 20 |ompiled.|. Only |
|000059c0| 74 68 6f 73 65 20 77 68 | 69 63 68 20 61 72 65 20 |those wh|ich are |
|000059d0| 66 72 65 71 75 65 6e 74 | 6c 79 20 63 61 6c 6c 65 |frequent|ly calle|
|000059e0| 64 20 6f 72 20 77 68 69 | 63 68 20 61 72 65 20 70 |d or whi|ch are p|
|000059f0| 61 73 73 65 73 20 6c 61 | 72 67 65 20 61 6d 6f 75 |asses la|rge amou|
|00005a00| 6e 74 73 0a 20 20 6f 66 | 20 64 61 74 61 20 69 6d |nts. of| data im|
|00005a10| 70 61 63 74 20 74 68 65 | 20 70 65 72 66 6f 72 6d |pact the| perform|
|00005a20| 61 6e 63 65 20 6f 66 20 | 74 68 65 20 66 69 6e 61 |ance of |the fina|
|00005a30| 6c 20 61 70 70 6c 69 63 | 61 74 69 6f 6e 2e 0a 0a |l applic|ation...|
|00005a40| 54 68 69 73 20 6d 6f 64 | 65 6c 20 6e 65 65 64 73 |This mod|el needs|
|00005a50| 20 74 6f 20 62 65 20 65 | 78 74 65 6e 64 65 64 20 | to be e|xtended |
|00005a60| 69 6e 20 6f 72 64 65 72 | 20 74 6f 20 6d 69 6e 69 |in order| to mini|
|00005a70| 6d 69 7a 65 20 74 68 65 | 20 70 61 72 73 69 6e 67 |mize the| parsing|
|00005a80| 20 64 6f 6e 65 20 61 74 | 0a 20 20 72 75 6e 74 69 | done at|. runti|
|00005a90| 6d 65 2c 20 77 68 69 63 | 68 20 73 74 69 6c 6c 20 |me, whic|h still |
|00005aa0| 68 61 70 70 65 6e 73 20 | 66 6f 72 20 6e 6f 6e 2d |happens |for non-|
|00005ab0| 73 74 61 74 69 63 20 73 | 74 72 69 6e 67 73 2e 20 |static s|trings. |
|00005ac0| 20 46 69 72 73 74 2c 20 | 77 65 20 6d 6f 64 69 66 | First, |we modif|
|00005ad0| 79 0a 20 20 74 68 65 20 | 64 61 74 61 20 72 65 74 |y. the |data ret|
|00005ae0| 75 72 6e 20 73 79 73 74 | 65 6d 20 66 72 6f 6d 20 |urn syst|em from |
|00005af0| 75 73 69 6e 67 20 6f 6e | 6c 79 20 73 74 72 69 6e |using on|ly strin|
|00005b00| 67 73 20 28 54 63 6c 5c | 5f 41 70 70 65 6e 64 52 |gs (Tcl\|_AppendR|
|00005b10| 65 73 75 6c 74 28 29 29 | 20 74 6f 0a 20 20 75 73 |esult())| to. us|
|00005b20| 69 6e 67 20 74 68 69 73 | 20 70 61 72 73 65 64 20 |ing this| parsed |
|00005b30| 66 6f 72 6d 20 6f 66 20 | 61 20 74 79 70 65 64 20 |form of |a typed |
|00005b40| 64 61 74 61 20 70 6f 69 | 6e 74 65 72 20 77 68 65 |data poi|nter whe|
|00005b50| 6e 20 74 68 65 20 6e 65 | 77 20 73 74 79 6c 65 20 |n the ne|w style |
|00005b60| 6f 66 0a 20 20 63 6f 6d | 70 69 6c 65 64 20 63 61 |of. com|piled ca|
|00005b70| 6c 6c 62 61 63 6b 73 20 | 61 72 65 20 69 6e 20 75 |llbacks |are in u|
|00005b80| 73 65 2e 20 20 54 68 69 | 73 20 69 73 20 6e 65 65 |se. Thi|s is nee|
|00005b90| 64 65 64 20 73 6f 20 74 | 68 61 74 20 74 68 65 20 |ded so t|hat the |
|00005ba0| 72 65 73 75 6c 74 73 20 | 6f 66 20 6f 6e 65 0a 20 |results |of one. |
|00005bb0| 20 63 6f 6d 6d 61 6e 64 | 20 63 61 6e 20 62 65 20 | command| can be |
|00005bc0| 70 61 73 73 65 64 20 64 | 69 72 65 63 74 6c 79 20 |passed d|irectly |
|00005bd0| 74 6f 20 61 6e 6f 74 68 | 65 72 20 77 69 74 68 6f |to anoth|er witho|
|00005be0| 75 74 20 72 65 70 61 72 | 73 69 6e 67 20 74 68 65 |ut repar|sing the|
|00005bf0| 20 64 61 74 61 0a 20 20 | 72 65 74 75 72 6e 2e 20 | data. |return. |
|00005c00| 20 41 6e 20 65 78 61 6d | 70 6c 65 20 66 6f 6c 6c | An exam|ple foll|
|00005c10| 6f 77 73 3a 0a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |ows:..\b|egin{ver|
|00005c20| 62 61 74 69 6d 7d 0a 20 | 20 69 6e 63 72 20 61 20 |batim}. | incr a |
|00005c30| 5b 65 78 70 72 20 34 2b | 35 5d 0a 5c 65 6e 64 7b |[expr 4+|5].\end{|
|00005c40| 76 65 72 62 61 74 69 6d | 7d 0a 0a 20 20 41 73 73 |verbatim|}.. Ass|
|00005c50| 75 6d 69 6e 67 20 74 68 | 61 74 20 62 6f 74 68 20 |uming th|at both |
|00005c60| 7b 5c 74 74 20 69 6e 63 | 72 7d 20 61 6e 64 20 7b |{\tt inc|r} and {|
|00005c70| 5c 74 74 20 65 78 70 72 | 7d 20 61 72 65 20 62 65 |\tt expr|} are be|
|00005c80| 69 6e 67 20 63 6f 6d 70 | 69 6c 65 64 2c 20 77 65 |ing comp|iled, we|
|00005c90| 20 77 6f 75 6c 64 0a 20 | 20 6c 69 6b 65 20 74 68 | would. | like th|
|00005ca0| 65 20 72 65 74 75 72 6e | 20 66 72 6f 6d 20 7b 5c |e return| from {\|
|00005cb0| 74 74 20 65 78 70 72 7d | 20 74 6f 20 62 65 20 74 |tt expr}| to be t|
|00005cc0| 68 65 20 76 61 6c 75 65 | 20 39 2c 20 6e 6f 74 20 |he value| 9, not |
|00005cd0| 74 68 65 20 73 74 72 69 | 6e 67 20 60 60 39 27 27 |the stri|ng ``9''|
|00005ce0| 2e 0a 20 20 54 68 69 73 | 20 63 6f 75 6c 64 20 74 |.. This| could t|
|00005cf0| 68 65 6e 20 62 65 20 64 | 69 72 65 63 74 6c 79 20 |hen be d|irectly |
|00005d00| 73 65 6e 74 20 69 6e 74 | 6f 20 7b 5c 74 74 20 69 |sent int|o {\tt i|
|00005d10| 6e 63 72 7d 20 77 69 74 | 68 6f 75 74 20 72 65 70 |ncr} wit|hout rep|
|00005d20| 61 72 73 69 6e 67 2e 20 | 20 54 68 65 0a 20 20 6f |arsing. | The. o|
|00005d30| 6e 6c 79 20 77 61 79 20 | 74 6f 20 61 76 6f 69 64 |nly way |to avoid|
|00005d40| 20 73 75 63 68 20 72 65 | 70 61 72 73 69 6e 67 20 | such re|parsing |
|00005d50| 69 73 20 69 66 20 7b 5c | 74 74 20 65 78 70 72 7d |is if {\|tt expr}|
|00005d60| 20 64 6f 65 73 6e 27 74 | 20 63 6f 6e 76 65 72 74 | doesn't| convert|
|00005d70| 20 69 74 73 0a 20 20 72 | 65 73 75 6c 74 20 69 6e | its. r|esult in|
|00005d80| 74 6f 20 73 74 72 69 6e | 67 20 66 6f 72 6d 61 74 |to strin|g format|
|00005d90| 2e 20 20 48 65 6e 63 65 | 20 74 68 65 20 6e 65 65 |. Hence| the nee|
|00005da0| 64 20 66 6f 72 20 74 68 | 69 73 20 6e 65 77 20 73 |d for th|is new s|
|00005db0| 74 79 6c 65 20 6f 66 20 | 72 65 74 75 72 6e 2e 0a |tyle of |return..|
|00005dc0| 0a 57 65 20 61 6c 73 6f | 20 6e 65 65 64 20 74 6f |.We also| need to|
|00005dd0| 20 63 68 61 6e 67 65 20 | 74 68 65 20 77 61 79 20 | change |the way |
|00005de0| 74 68 61 74 20 76 61 72 | 69 61 62 6c 65 73 20 61 |that var|iables a|
|00005df0| 72 65 20 73 74 6f 72 65 | 64 20 69 6e 20 74 68 65 |re store|d in the|
|00005e00| 20 54 63 6c 0a 20 20 69 | 6e 74 65 72 70 72 65 74 | Tcl. i|nterpret|
|00005e10| 65 72 2e 20 20 49 66 20 | 77 65 20 74 61 6b 65 20 |er. If |we take |
|00005e20| 74 68 65 20 61 62 6f 76 | 65 20 65 78 61 6d 70 6c |the abov|e exampl|
|00005e30| 65 20 61 6e 64 20 6d 6f | 64 69 66 79 20 69 74 20 |e and mo|dify it |
|00005e40| 74 6f 20 72 65 61 64 0a | 0a 5c 62 65 67 69 6e 7b |to read.|.\begin{|
|00005e50| 76 65 72 62 61 74 69 6d | 7d 0a 20 20 73 65 74 20 |verbatim|}. set |
|00005e60| 62 20 5b 65 78 70 72 20 | 34 2b 35 5d 0a 20 20 69 |b [expr |4+5]. i|
|00005e70| 6e 63 72 20 61 20 24 62 | 0a 5c 65 6e 64 7b 76 65 |ncr a $b|.\end{ve|
|00005e80| 72 62 61 74 69 6d 7d 0a | 0a 20 20 69 74 20 62 65 |rbatim}.|. it be|
|00005e90| 63 6f 6d 65 73 20 63 6c | 65 61 72 20 74 68 61 74 |comes cl|ear that|
|00005ea0| 20 69 66 20 77 65 20 64 | 69 73 61 6c 6c 6f 77 20 | if we d|isallow |
|00005eb0| 74 68 65 20 76 61 6c 75 | 65 20 6f 66 20 60 60 62 |the valu|e of ``b|
|00005ec0| 27 27 20 74 6f 20 62 65 | 20 73 74 6f 72 65 64 20 |'' to be| stored |
|00005ed0| 69 6e 0a 20 20 70 61 72 | 73 65 64 20 66 6f 72 6d |in. par|sed form|
|00005ee0| 2c 20 77 65 20 63 61 6e | 6e 6f 74 20 61 76 6f 69 |, we can|not avoi|
|00005ef0| 64 20 72 65 70 61 72 73 | 69 6e 67 20 69 74 20 62 |d repars|ing it b|
|00005f00| 65 66 6f 72 65 20 69 74 | 73 20 75 73 61 67 65 20 |efore it|s usage |
|00005f10| 69 6e 20 7b 5c 74 74 20 | 69 6e 63 72 7d 2e 0a 20 |in {\tt |incr}.. |
|00005f20| 20 54 68 75 73 2c 20 54 | 43 20 60 60 64 75 61 6c | Thus, T|C ``dual|
|00005f30| 2d 70 6f 72 74 73 27 27 | 20 69 74 73 20 76 61 72 |-ports''| its var|
|00005f40| 69 61 62 6c 65 73 2c 20 | 73 74 6f 72 69 6e 67 20 |iables, |storing |
|00005f50| 62 6f 74 68 20 61 20 73 | 74 72 69 6e 67 20 70 6f |both a s|tring po|
|00005f60| 69 6e 74 65 72 20 61 73 | 0a 20 20 77 65 6c 6c 20 |inter as|. well |
|00005f70| 61 73 20 61 20 63 6f 6d | 70 69 6c 65 64 20 64 61 |as a com|piled da|
|00005f80| 74 61 20 76 61 6c 75 65 | 20 28 74 68 65 20 60 60 |ta value| (the ``|
|00005f90| 74 79 70 65 64 20 64 61 | 74 61 20 66 69 65 6c 64 |typed da|ta field|
|00005fa0| 27 27 29 2e 20 20 4e 6f | 77 2c 20 69 66 20 7b 5c |''). No|w, if {\|
|00005fb0| 74 74 0a 20 20 65 78 70 | 72 7d 20 72 65 74 75 72 |tt. exp|r} retur|
|00005fc0| 6e 73 20 61 6e 20 69 6e | 74 65 67 65 72 2c 20 74 |ns an in|teger, t|
|00005fd0| 68 65 6e 20 60 60 62 27 | 27 20 77 69 6c 6c 20 73 |hen ``b'|' will s|
|00005fe0| 74 6f 72 65 20 69 74 20 | 69 6e 20 74 68 65 20 74 |tore it |in the t|
|00005ff0| 79 70 65 64 20 64 61 74 | 61 0a 20 20 66 69 65 6c |yped dat|a. fiel|
|00006000| 64 2c 20 61 6e 64 20 69 | 6e 76 61 6c 69 64 61 74 |d, and i|nvalidat|
|00006010| 65 20 74 68 65 20 73 74 | 72 69 6e 67 20 66 69 65 |e the st|ring fie|
|00006020| 6c 64 2e 20 20 7b 5c 74 | 74 20 69 6e 63 72 7d 20 |ld. {\t|t incr} |
|00006030| 63 61 6e 20 74 68 65 6e | 20 62 65 20 63 61 6c 6c |can then| be call|
|00006040| 65 64 0a 20 20 64 69 72 | 65 63 74 6c 79 20 77 69 |ed. dir|ectly wi|
|00006050| 74 68 20 74 68 69 73 20 | 70 61 72 73 65 64 20 76 |th this |parsed v|
|00006060| 61 6c 75 65 2e 20 20 49 | 66 20 60 60 62 27 27 20 |alue. I|f ``b'' |
|00006070| 77 65 72 65 20 6f 66 20 | 73 6f 6d 65 20 6f 74 68 |were of |some oth|
|00006080| 65 72 20 74 79 70 65 2c | 20 69 74 0a 20 20 77 6f |er type,| it. wo|
|00006090| 75 6c 64 20 6e 65 65 64 | 20 74 6f 20 62 65 20 63 |uld need| to be c|
|000060a0| 6f 6e 76 65 72 74 65 64 | 20 74 6f 20 61 20 73 74 |onverted| to a st|
|000060b0| 72 69 6e 67 20 66 69 72 | 73 74 2c 20 74 68 65 6e |ring fir|st, then|
|000060c0| 20 62 61 63 6b 20 74 6f | 20 61 6e 20 69 6e 74 65 | back to| an inte|
|000060d0| 67 65 72 2c 20 61 73 0a | 20 20 54 63 6c 20 63 75 |ger, as.| Tcl cu|
|000060e0| 72 72 65 6e 74 6c 79 20 | 64 6f 65 73 20 69 6d 70 |rrently |does imp|
|000060f0| 6c 69 63 69 74 6c 79 2e | 0a 0a 49 66 20 74 68 69 |licitly.|..If thi|
|00006100| 73 20 73 65 65 6d 73 20 | 6f 76 65 72 6c 79 20 63 |s seems |overly c|
|00006110| 6f 6d 70 6c 65 78 2c 20 | 72 65 63 61 6c 6c 20 74 |omplex, |recall t|
|00006120| 68 61 74 20 54 63 6c 20 | 69 73 20 61 20 74 79 70 |hat Tcl |is a typ|
|00006130| 65 6c 65 73 73 20 6c 61 | 6e 67 75 61 67 65 2e 0a |eless la|nguage..|
|00006140| 20 20 4c 69 73 74 73 2c | 20 62 6f 6f 6c 65 61 6e | Lists,| boolean|
|00006150| 20 65 78 70 72 65 73 73 | 69 6f 6e 73 2c 20 69 6e | express|ions, in|
|00006160| 74 65 67 65 72 73 20 61 | 6e 64 20 73 6f 20 6f 6e |tegers a|nd so on|
|00006170| 20 61 72 65 20 6e 6f 74 | 20 64 69 73 74 69 6e 67 | are not| disting|
|00006180| 75 69 73 68 65 64 20 62 | 79 0a 20 20 54 63 6c 20 |uished b|y. Tcl |
|00006190| 75 6e 74 69 6c 20 69 6e | 64 69 76 69 64 75 61 6c |until in|dividual|
|000061a0| 20 63 6f 6d 6d 61 6e 64 | 73 20 74 68 72 6f 77 20 | command|s throw |
|000061b0| 65 78 63 65 70 74 69 6f | 6e 73 20 62 61 73 65 64 |exceptio|ns based|
|000061c0| 20 6f 6e 20 62 61 64 20 | 64 61 74 61 2e 20 20 54 | on bad |data. T|
|000061d0| 68 65 0a 20 20 66 6f 6c | 6c 6f 77 69 6e 67 20 63 |he. fol|lowing c|
|000061e0| 6f 64 65 20 77 69 74 68 | 20 65 78 65 63 75 74 65 |ode with| execute|
|000061f0| 20 77 69 74 68 6f 75 74 | 20 65 72 72 6f 72 3a 0a | without| error:.|
|00006200| 0a 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00006210| 7d 0a 20 20 70 72 6f 63 | 20 63 64 72 20 7b 6c 69 |}. proc| cdr {li|
|00006220| 73 74 7d 20 7b 20 0a 20 | 20 20 20 20 20 72 65 74 |st} { . | ret|
|00006230| 75 72 6e 20 5b 6c 72 61 | 6e 67 65 20 24 6c 69 73 |urn [lra|nge $lis|
|00006240| 74 20 31 20 65 6e 64 5d | 0a 20 20 7d 0a 20 20 73 |t 1 end]|. }. s|
|00006250| 65 74 20 69 20 32 3b 20 | 73 65 74 20 6a 20 33 3b |et i 2; |set j 3;|
|00006260| 20 73 65 74 20 6b 20 22 | 33 20 34 22 0a 20 20 6c | set k "|3 4". l|
|00006270| 69 6e 73 65 72 74 20 22 | 24 6a 20 24 6b 22 20 5b |insert "|$j $k" [|
|00006280| 63 64 72 20 7b 31 20 32 | 7d 5d 20 24 69 24 6a 0a |cdr {1 2|}] $i$j.|
|00006290| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 0a |\end{ver|batim}..|
|000062a0| 20 20 54 68 65 20 6f 75 | 74 70 75 74 20 6f 66 20 | The ou|tput of |
|000062b0| 74 68 69 73 20 63 6f 6d | 6d 61 6e 64 20 69 73 20 |this com|mand is |
|000062c0| 60 60 33 20 33 20 32 33 | 20 34 27 27 2e 20 20 44 |``3 3 23| 4''. D|
|000062d0| 75 72 69 6e 67 20 74 68 | 65 20 63 6f 75 72 73 65 |uring th|e course|
|000062e0| 20 6f 66 0a 20 20 65 78 | 65 63 75 74 69 6f 6e 20 | of. ex|ecution |
|000062f0| 77 65 20 68 61 76 65 20 | 69 6d 70 6c 69 63 69 74 |we have |implicit|
|00006300| 6c 79 20 63 6f 6e 76 65 | 72 74 65 64 20 66 72 6f |ly conve|rted fro|
|00006310| 6d 20 73 74 72 69 6e 67 | 20 74 6f 20 69 6e 74 65 |m string| to inte|
|00006320| 67 65 72 73 2c 20 73 74 | 72 69 6e 67 73 0a 20 20 |gers, st|rings. |
|00006330| 74 6f 20 6c 69 73 74 73 | 2c 20 6c 69 73 74 73 20 |to lists|, lists |
|00006340| 74 6f 20 69 6e 74 65 67 | 65 72 73 2c 20 61 6e 64 |to integ|ers, and|
|00006350| 20 69 6e 74 65 67 65 72 | 73 20 74 6f 20 73 74 72 | integer|s to str|
|00006360| 69 6e 67 73 2e 20 20 57 | 68 69 6c 65 20 74 68 69 |ings. W|hile thi|
|00006370| 73 20 69 73 0a 20 20 63 | 6c 65 61 72 6c 79 20 6e |s is. c|learly n|
|00006380| 6f 74 20 61 6e 20 65 78 | 61 6d 70 6c 65 20 6f 66 |ot an ex|ample of|
|00006390| 20 67 6f 6f 64 20 63 6f | 64 69 6e 67 20 70 72 61 | good co|ding pra|
|000063a0| 63 74 69 63 65 2c 20 69 | 74 20 69 73 20 6c 65 67 |ctice, i|t is leg|
|000063b0| 61 6c 20 54 63 6c 20 69 | 6e 70 75 74 2c 0a 20 20 |al Tcl i|nput,. |
|000063c0| 61 6e 64 20 69 6e 20 6d | 61 6e 79 20 63 61 73 65 |and in m|any case|
|000063d0| 73 20 73 69 6d 69 6c 61 | 72 20 75 73 61 67 65 73 |s simila|r usages|
|000063e0| 20 6d 61 79 20 61 70 70 | 65 61 72 20 69 6e 20 72 | may app|ear in r|
|000063f0| 65 61 6c 20 73 6f 75 72 | 63 65 20 63 6f 64 65 2e |eal sour|ce code.|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.