0000: 27 5c 22 0a 27 5c 22 20 43 6f 70 79 72 69 67 68 '\".'\" Copyrigh
0010: 74 20 28 63 29 20 32 30 30 33 20 44 6f 6e 61 6c t (c) 2003 Donal
0020: 20 4b 2e 20 46 65 6c 6c 6f 77 73 0a 27 5c 22 0a K. Fellows.'\".
0030: 27 5c 22 20 53 65 65 20 74 68 65 20 66 69 6c 65 '\" See the file
0040: 20 22 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73 22 "license.terms"
0050: 20 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e for information
0060: 20 6f 6e 20 75 73 61 67 65 20 61 6e 64 20 72 65 on usage and re
0070: 64 69 73 74 72 69 62 75 74 69 6f 6e 0a 27 5c 22 distribution.'\"
0080: 20 6f 66 20 74 68 69 73 20 66 69 6c 65 2c 20 61 of this file, a
0090: 6e 64 20 66 6f 72 20 61 20 44 49 53 43 4c 41 49 nd for a DISCLAI
00a0: 4d 45 52 20 4f 46 20 41 4c 4c 20 57 41 52 52 41 MER OF ALL WARRA
00b0: 4e 54 49 45 53 2e 0a 27 5c 22 0a 2e 54 48 20 64 NTIES..'\"..TH d
00c0: 69 63 74 20 6e 20 38 2e 35 20 54 63 6c 20 22 54 ict n 8.5 Tcl "T
00d0: 63 6c 20 42 75 69 6c 74 2d 49 6e 20 43 6f 6d 6d cl Built-In Comm
00e0: 61 6e 64 73 22 0a 2e 73 6f 20 6d 61 6e 2e 6d 61 ands"..so man.ma
00f0: 63 72 6f 73 0a 2e 42 53 0a 27 5c 22 20 4e 6f 74 cros..BS.'\" Not
0100: 65 3a 20 20 64 6f 20 6e 6f 74 20 6d 6f 64 69 66 e: do not modif
0110: 79 20 74 68 65 20 2e 53 48 20 4e 41 4d 45 20 6c y the .SH NAME l
0120: 69 6e 65 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 ine immediately
0130: 62 65 6c 6f 77 21 0a 2e 53 48 20 4e 41 4d 45 0a below!..SH NAME.
0140: 64 69 63 74 20 5c 2d 20 4d 61 6e 69 70 75 6c 61 dict \- Manipula
0150: 74 65 20 64 69 63 74 69 6f 6e 61 72 69 65 73 0a te dictionaries.
0160: 2e 53 48 20 53 59 4e 4f 50 53 49 53 0a 5c 66 42 .SH SYNOPSIS.\fB
0170: 64 69 63 74 20 5c 66 49 6f 70 74 69 6f 6e 20 61 dict \fIoption a
0180: 72 67 20 5c 66 52 3f 5c 66 49 61 72 67 20 2e 2e rg \fR?\fIarg ..
0190: 2e 5c 66 52 3f 0a 2e 42 45 0a 2e 53 48 20 44 45 .\fR?..BE..SH DE
01a0: 53 43 52 49 50 54 49 4f 4e 0a 2e 50 50 0a 50 65 SCRIPTION..PP.Pe
01b0: 72 66 6f 72 6d 73 20 6f 6e 65 20 6f 66 20 73 65 rforms one of se
01c0: 76 65 72 61 6c 20 6f 70 65 72 61 74 69 6f 6e 73 veral operations
01d0: 20 6f 6e 20 64 69 63 74 69 6f 6e 61 72 79 20 76 on dictionary v
01e0: 61 6c 75 65 73 20 6f 72 20 76 61 72 69 61 62 6c alues or variabl
01f0: 65 73 0a 63 6f 6e 74 61 69 6e 69 6e 67 20 64 69 es.containing di
0200: 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 73 20 ctionary values
0210: 28 73 65 65 20 74 68 65 20 5c 66 42 44 49 43 54 (see the \fBDICT
0220: 49 4f 4e 41 52 59 20 56 41 4c 55 45 53 5c 66 52 IONARY VALUES\fR
0230: 20 73 65 63 74 69 6f 6e 0a 62 65 6c 6f 77 20 66 section.below f
0240: 6f 72 20 61 20 64 65 73 63 72 69 70 74 69 6f 6e or a description
0250: 29 2c 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 ), depending on
0260: 5c 66 49 6f 70 74 69 6f 6e 5c 66 52 2e 20 20 54 \fIoption\fR. T
0270: 68 65 20 6c 65 67 61 6c 0a 5c 66 49 6f 70 74 69 he legal.\fIopti
0280: 6f 6e 5c 66 52 73 20 28 77 68 69 63 68 20 6d 61 on\fRs (which ma
0290: 79 20 62 65 20 61 62 62 72 65 76 69 61 74 65 64 y be abbreviated
02a0: 29 20 61 72 65 3a 0a 2e 54 50 0a 5c 66 42 64 69 ) are:..TP.\fBdi
02b0: 63 74 20 61 70 70 65 6e 64 20 5c 66 49 64 69 63 ct append \fIdic
02c0: 74 69 6f 6e 61 72 79 56 61 72 69 61 62 6c 65 20 tionaryVariable
02d0: 6b 65 79 20 5c 66 52 3f 5c 66 49 73 74 72 69 6e key \fR?\fIstrin
02e0: 67 20 2e 2e 2e 5c 66 52 3f 0a 2e 0a 54 68 69 73 g ...\fR?...This
02f0: 20 61 70 70 65 6e 64 73 20 74 68 65 20 67 69 76 appends the giv
0300: 65 6e 20 73 74 72 69 6e 67 20 28 6f 72 20 73 74 en string (or st
0310: 72 69 6e 67 73 29 20 74 6f 20 74 68 65 20 76 61 rings) to the va
0320: 6c 75 65 20 74 68 61 74 20 74 68 65 20 67 69 76 lue that the giv
0330: 65 6e 0a 6b 65 79 20 6d 61 70 73 20 74 6f 20 69 en.key maps to i
0340: 6e 20 74 68 65 20 64 69 63 74 69 6f 6e 61 72 79 n the dictionary
0350: 20 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 value contained
0360: 20 69 6e 20 74 68 65 20 67 69 76 65 6e 20 76 61 in the given va
0370: 72 69 61 62 6c 65 2c 0a 77 72 69 74 69 6e 67 20 riable,.writing
0380: 74 68 65 20 72 65 73 75 6c 74 69 6e 67 20 64 69 the resulting di
0390: 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 20 62 ctionary value b
03a0: 61 63 6b 20 74 6f 20 74 68 61 74 20 76 61 72 69 ack to that vari
03b0: 61 62 6c 65 2e 0a 4e 6f 6e 2d 65 78 69 73 74 65 able..Non-existe
03c0: 6e 74 20 6b 65 79 73 20 61 72 65 20 74 72 65 61 nt keys are trea
03d0: 74 65 64 20 61 73 20 69 66 20 74 68 65 79 20 6d ted as if they m
03e0: 61 70 20 74 6f 20 61 6e 20 65 6d 70 74 79 20 73 ap to an empty s
03f0: 74 72 69 6e 67 2e 20 54 68 65 0a 75 70 64 61 74 tring. The.updat
0400: 65 64 20 64 69 63 74 69 6f 6e 61 72 79 20 76 61 ed dictionary va
0410: 6c 75 65 20 69 73 20 72 65 74 75 72 6e 65 64 2e lue is returned.
0420: 0a 2e 54 50 0a 5c 66 42 64 69 63 74 20 63 72 65 ..TP.\fBdict cre
0430: 61 74 65 20 5c 66 52 3f 5c 66 49 6b 65 79 20 76 ate \fR?\fIkey v
0440: 61 6c 75 65 20 2e 2e 2e 5c 66 52 3f 0a 2e 0a 52 alue ...\fR?...R
0450: 65 74 75 72 6e 20 61 20 6e 65 77 20 64 69 63 74 eturn a new dict
0460: 69 6f 6e 61 72 79 20 74 68 61 74 20 63 6f 6e 74 ionary that cont
0470: 61 69 6e 73 20 65 61 63 68 20 6f 66 20 74 68 65 ains each of the
0480: 20 6b 65 79 2f 76 61 6c 75 65 20 6d 61 70 70 69 key/value mappi
0490: 6e 67 73 0a 6c 69 73 74 65 64 20 61 73 20 61 72 ngs.listed as ar
04a0: 67 75 6d 65 6e 74 73 20 28 6b 65 79 73 20 61 6e guments (keys an
04b0: 64 20 76 61 6c 75 65 73 20 61 6c 74 65 72 6e 61 d values alterna
04c0: 74 69 6e 67 2c 20 77 69 74 68 20 65 61 63 68 20 ting, with each
04d0: 6b 65 79 20 62 65 69 6e 67 0a 66 6f 6c 6c 6f 77 key being.follow
04e0: 65 64 20 62 79 20 69 74 73 20 61 73 73 6f 63 69 ed by its associ
04f0: 61 74 65 64 20 76 61 6c 75 65 2e 29 0a 2e 54 50 ated value.)..TP
0500: 0a 5c 66 42 64 69 63 74 20 65 78 69 73 74 73 20 .\fBdict exists
0510: 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 6c \fIdictionaryVal
0520: 75 65 20 6b 65 79 20 5c 66 52 3f 5c 66 49 6b 65 ue key \fR?\fIke
0530: 79 20 2e 2e 2e 5c 66 52 3f 0a 2e 0a 54 68 69 73 y ...\fR?...This
0540: 20 72 65 74 75 72 6e 73 20 61 20 62 6f 6f 6c 65 returns a boole
0550: 61 6e 20 76 61 6c 75 65 20 69 6e 64 69 63 61 74 an value indicat
0560: 69 6e 67 20 77 68 65 74 68 65 72 20 74 68 65 20 ing whether the
0570: 67 69 76 65 6e 20 6b 65 79 20 28 6f 72 20 70 61 given key (or pa
0580: 74 68 0a 6f 66 20 6b 65 79 73 20 74 68 72 6f 75 th.of keys throu
0590: 67 68 20 61 20 73 65 74 20 6f 66 20 6e 65 73 74 gh a set of nest
05a0: 65 64 20 64 69 63 74 69 6f 6e 61 72 69 65 73 29 ed dictionaries)
05b0: 20 65 78 69 73 74 73 20 69 6e 20 74 68 65 20 67 exists in the g
05c0: 69 76 65 6e 0a 64 69 63 74 69 6f 6e 61 72 79 20 iven.dictionary
05d0: 76 61 6c 75 65 2e 20 54 68 69 73 20 72 65 74 75 value. This retu
05e0: 72 6e 73 20 61 20 74 72 75 65 20 76 61 6c 75 65 rns a true value
05f0: 20 65 78 61 63 74 6c 79 20 77 68 65 6e 20 5c 66 exactly when \f
0600: 42 64 69 63 74 0a 67 65 74 5c 66 52 20 6f 6e 20 Bdict.get\fR on
0610: 74 68 61 74 20 70 61 74 68 20 77 69 6c 6c 20 73 that path will s
0620: 75 63 63 65 65 64 2e 0a 2e 54 50 0a 5c 66 42 64 ucceed...TP.\fBd
0630: 69 63 74 20 66 69 6c 74 65 72 20 5c 66 49 64 69 ict filter \fIdi
0640: 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 66 69 ctionaryValue fi
0650: 6c 74 65 72 54 79 70 65 20 61 72 67 20 5c 66 52 lterType arg \fR
0660: 3f 5c 66 49 61 72 67 20 2e 2e 2e 5c 66 52 3f 0a ?\fIarg ...\fR?.
0670: 2e 0a 54 68 69 73 20 74 61 6b 65 73 20 61 20 64 ..This takes a d
0680: 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 20 ictionary value
0690: 61 6e 64 20 72 65 74 75 72 6e 73 20 61 20 6e 65 and returns a ne
06a0: 77 20 64 69 63 74 69 6f 6e 61 72 79 20 74 68 61 w dictionary tha
06b0: 74 0a 63 6f 6e 74 61 69 6e 73 20 6a 75 73 74 20 t.contains just
06c0: 74 68 6f 73 65 20 6b 65 79 2f 76 61 6c 75 65 20 those key/value
06d0: 70 61 69 72 73 20 74 68 61 74 20 6d 61 74 63 68 pairs that match
06e0: 20 74 68 65 20 73 70 65 63 69 66 69 65 64 20 66 the specified f
06f0: 69 6c 74 65 72 0a 74 79 70 65 20 28 77 68 69 63 ilter.type (whic
0700: 68 20 6d 61 79 20 62 65 20 61 62 62 72 65 76 69 h may be abbrevi
0710: 61 74 65 64 2e 29 20 20 53 75 70 70 6f 72 74 65 ated.) Supporte
0720: 64 20 66 69 6c 74 65 72 20 74 79 70 65 73 20 61 d filter types a
0730: 72 65 3a 0a 2e 52 53 0a 2e 54 50 0a 5c 66 42 64 re:..RS..TP.\fBd
0740: 69 63 74 20 66 69 6c 74 65 72 20 5c 66 49 64 69 ict filter \fIdi
0750: 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c 66 ctionaryValue \f
0760: 42 6b 65 79 5c 66 52 20 3f 5c 66 49 67 6c 6f 62 Bkey\fR ?\fIglob
0770: 50 61 74 74 65 72 6e 20 2e 2e 2e 5c 66 52 3f 0a Pattern ...\fR?.
0780: 2e 56 53 20 38 2e 36 0a 54 68 65 20 6b 65 79 20 .VS 8.6.The key
0790: 72 75 6c 65 20 6f 6e 6c 79 20 6d 61 74 63 68 65 rule only matche
07a0: 73 20 74 68 6f 73 65 20 6b 65 79 2f 76 61 6c 75 s those key/valu
07b0: 65 20 70 61 69 72 73 20 77 68 6f 73 65 20 6b 65 e pairs whose ke
07c0: 79 73 20 6d 61 74 63 68 20 61 6e 79 0a 6f 66 20 ys match any.of
07d0: 74 68 65 20 67 69 76 65 6e 20 70 61 74 74 65 72 the given patter
07e0: 6e 73 20 28 69 6e 20 74 68 65 20 73 74 79 6c 65 ns (in the style
07f0: 20 6f 66 20 5c 66 42 73 74 72 69 6e 67 20 6d 61 of \fBstring ma
0800: 74 63 68 5c 66 52 2e 29 0a 2e 56 45 20 38 2e 36 tch\fR.)..VE 8.6
0810: 0a 2e 54 50 0a 5c 66 42 64 69 63 74 20 66 69 6c ..TP.\fBdict fil
0820: 74 65 72 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 ter \fIdictionar
0830: 79 56 61 6c 75 65 20 5c 66 42 73 63 72 69 70 74 yValue \fBscript
0840: 20 7b 5c 66 49 6b 65 79 56 61 72 69 61 62 6c 65 {\fIkeyVariable
0850: 20 76 61 6c 75 65 56 61 72 69 61 62 6c 65 5c 66 valueVariable\f
0860: 42 7d 20 5c 66 49 73 63 72 69 70 74 5c 66 52 0a B} \fIscript\fR.
0870: 2e 0a 54 68 65 20 73 63 72 69 70 74 20 72 75 6c ..The script rul
0880: 65 20 74 65 73 74 73 20 66 6f 72 20 6d 61 74 63 e tests for matc
0890: 68 69 6e 67 20 62 79 20 61 73 73 69 67 6e 69 6e hing by assignin
08a0: 67 20 74 68 65 20 6b 65 79 20 74 6f 20 74 68 65 g the key to the
08b0: 0a 5c 66 49 6b 65 79 56 61 72 69 61 62 6c 65 5c .\fIkeyVariable\
08c0: 66 52 20 61 6e 64 20 74 68 65 20 76 61 6c 75 65 fR and the value
08d0: 20 74 6f 20 74 68 65 20 5c 66 49 76 61 6c 75 65 to the \fIvalue
08e0: 56 61 72 69 61 62 6c 65 5c 66 52 2c 20 61 6e 64 Variable\fR, and
08f0: 20 74 68 65 6e 20 65 76 61 6c 75 61 74 69 6e 67 then evaluating
0900: 0a 74 68 65 20 67 69 76 65 6e 20 73 63 72 69 70 .the given scrip
0910: 74 20 77 68 69 63 68 20 73 68 6f 75 6c 64 20 72 t which should r
0920: 65 74 75 72 6e 20 61 20 62 6f 6f 6c 65 61 6e 20 eturn a boolean
0930: 76 61 6c 75 65 20 28 77 69 74 68 20 74 68 65 0a value (with the.
0940: 6b 65 79 2f 76 61 6c 75 65 20 70 61 69 72 20 6f key/value pair o
0950: 6e 6c 79 20 62 65 69 6e 67 20 69 6e 63 6c 75 64 nly being includ
0960: 65 64 20 69 6e 20 74 68 65 20 72 65 73 75 6c 74 ed in the result
0970: 20 6f 66 20 74 68 65 20 5c 66 42 64 69 63 74 0a of the \fBdict.
0980: 66 69 6c 74 65 72 5c 66 52 20 77 68 65 6e 20 61 filter\fR when a
0990: 20 74 72 75 65 20 76 61 6c 75 65 20 69 73 20 72 true value is r
09a0: 65 74 75 72 6e 65 64 2e 29 20 20 4e 6f 74 65 20 eturned.) Note
09b0: 74 68 61 74 20 74 68 65 20 66 69 72 73 74 0a 61 that the first.a
09c0: 72 67 75 6d 65 6e 74 20 61 66 74 65 72 20 74 68 rgument after th
09d0: 65 20 72 75 6c 65 20 73 65 6c 65 63 74 69 6f 6e e rule selection
09e0: 20 77 6f 72 64 20 69 73 20 61 20 74 77 6f 2d 65 word is a two-e
09f0: 6c 65 6d 65 6e 74 20 6c 69 73 74 2e 20 20 49 66 lement list. If
0a00: 20 74 68 65 0a 5c 66 49 73 63 72 69 70 74 5c 66 the.\fIscript\f
0a10: 52 20 72 65 74 75 72 6e 73 20 77 69 74 68 20 61 R returns with a
0a20: 20 63 6f 6e 64 69 74 69 6f 6e 20 6f 66 20 5c 66 condition of \f
0a30: 42 54 43 4c 5f 42 52 45 41 4b 5c 66 52 2c 20 6e BTCL_BREAK\fR, n
0a40: 6f 20 66 75 72 74 68 65 72 0a 6b 65 79 2f 76 61 o further.key/va
0a50: 6c 75 65 20 70 61 69 72 73 20 61 72 65 20 63 6f lue pairs are co
0a60: 6e 73 69 64 65 72 65 64 20 66 6f 72 20 69 6e 63 nsidered for inc
0a70: 6c 75 73 69 6f 6e 20 69 6e 20 74 68 65 20 72 65 lusion in the re
0a80: 73 75 6c 74 69 6e 67 0a 64 69 63 74 69 6f 6e 61 sulting.dictiona
0a90: 72 79 2c 20 61 6e 64 20 61 20 63 6f 6e 64 69 74 ry, and a condit
0aa0: 69 6f 6e 20 6f 66 20 5c 66 42 54 43 4c 5f 43 4f ion of \fBTCL_CO
0ab0: 4e 54 49 4e 55 45 5c 66 52 20 69 73 20 65 71 75 NTINUE\fR is equ
0ac0: 69 76 61 6c 65 6e 74 20 74 6f 20 61 20 66 61 6c ivalent to a fal
0ad0: 73 65 0a 72 65 73 75 6c 74 2e 20 54 68 65 20 6b se.result. The k
0ae0: 65 79 2f 76 61 6c 75 65 20 70 61 69 72 73 20 61 ey/value pairs a
0af0: 72 65 20 74 65 73 74 65 64 20 69 6e 20 74 68 65 re tested in the
0b00: 20 6f 72 64 65 72 20 69 6e 20 77 68 69 63 68 20 order in which
0b10: 74 68 65 20 6b 65 79 73 0a 77 65 72 65 20 69 6e the keys.were in
0b20: 73 65 72 74 65 64 20 69 6e 74 6f 20 74 68 65 20 serted into the
0b30: 64 69 63 74 69 6f 6e 61 72 79 2e 0a 2e 54 50 0a dictionary...TP.
0b40: 5c 66 42 64 69 63 74 20 66 69 6c 74 65 72 20 5c \fBdict filter \
0b50: 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 6c 75 fIdictionaryValu
0b60: 65 20 5c 66 42 76 61 6c 75 65 20 5c 66 52 3f 5c e \fBvalue \fR?\
0b70: 66 49 67 6c 6f 62 50 61 74 74 65 72 6e 20 2e 2e fIglobPattern ..
0b80: 2e 5c 66 52 3f 0a 2e 56 53 20 38 2e 36 0a 54 68 .\fR?..VS 8.6.Th
0b90: 65 20 76 61 6c 75 65 20 72 75 6c 65 20 6f 6e 6c e value rule onl
0ba0: 79 20 6d 61 74 63 68 65 73 20 74 68 6f 73 65 20 y matches those
0bb0: 6b 65 79 2f 76 61 6c 75 65 20 70 61 69 72 73 20 key/value pairs
0bc0: 77 68 6f 73 65 20 76 61 6c 75 65 73 20 6d 61 74 whose values mat
0bd0: 63 68 20 61 6e 79 0a 6f 66 20 74 68 65 20 67 69 ch any.of the gi
0be0: 76 65 6e 20 70 61 74 74 65 72 6e 73 20 28 69 6e ven patterns (in
0bf0: 20 74 68 65 20 73 74 79 6c 65 20 6f 66 20 5c 66 the style of \f
0c00: 42 73 74 72 69 6e 67 20 6d 61 74 63 68 5c 66 52 Bstring match\fR
0c10: 2e 29 0a 2e 56 45 20 38 2e 36 0a 2e 52 45 0a 2e .)..VE 8.6..RE..
0c20: 54 50 0a 5c 66 42 64 69 63 74 20 66 6f 72 20 7b TP.\fBdict for {
0c30: 5c 66 49 6b 65 79 56 61 72 69 61 62 6c 65 20 76 \fIkeyVariable v
0c40: 61 6c 75 65 56 61 72 69 61 62 6c 65 5c 66 42 7d alueVariable\fB}
0c50: 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 \fIdictionaryVa
0c60: 6c 75 65 20 62 6f 64 79 5c 66 52 0a 2e 0a 54 68 lue body\fR...Th
0c70: 69 73 20 63 6f 6d 6d 61 6e 64 20 74 61 6b 65 73 is command takes
0c80: 20 74 68 72 65 65 20 61 72 67 75 6d 65 6e 74 73 three arguments
0c90: 2c 20 74 68 65 20 66 69 72 73 74 20 61 20 74 77 , the first a tw
0ca0: 6f 2d 65 6c 65 6d 65 6e 74 20 6c 69 73 74 20 6f o-element list o
0cb0: 66 0a 76 61 72 69 61 62 6c 65 20 6e 61 6d 65 73 f.variable names
0cc0: 20 28 66 6f 72 20 74 68 65 20 6b 65 79 20 61 6e (for the key an
0cd0: 64 20 76 61 6c 75 65 20 72 65 73 70 65 63 74 69 d value respecti
0ce0: 76 65 6c 79 20 6f 66 20 65 61 63 68 20 6d 61 70 vely of each map
0cf0: 70 69 6e 67 20 69 6e 0a 74 68 65 20 64 69 63 74 ping in.the dict
0d00: 69 6f 6e 61 72 79 29 2c 20 74 68 65 20 73 65 63 ionary), the sec
0d10: 6f 6e 64 20 74 68 65 20 64 69 63 74 69 6f 6e 61 ond the dictiona
0d20: 72 79 20 76 61 6c 75 65 20 74 6f 20 69 74 65 72 ry value to iter
0d30: 61 74 65 20 61 63 72 6f 73 73 2c 0a 61 6e 64 20 ate across,.and
0d40: 74 68 65 20 74 68 69 72 64 20 61 20 73 63 72 69 the third a scri
0d50: 70 74 20 74 6f 20 62 65 20 65 76 61 6c 75 61 74 pt to be evaluat
0d60: 65 64 20 66 6f 72 20 65 61 63 68 20 6d 61 70 70 ed for each mapp
0d70: 69 6e 67 20 77 69 74 68 20 74 68 65 20 6b 65 79 ing with the key
0d80: 0a 61 6e 64 20 76 61 6c 75 65 20 76 61 72 69 61 .and value varia
0d90: 62 6c 65 73 20 73 65 74 20 61 70 70 72 6f 70 72 bles set appropr
0da0: 69 61 74 65 6c 79 20 28 69 6e 20 74 68 65 20 6d iately (in the m
0db0: 61 6e 6e 65 72 20 6f 66 20 5c 66 42 66 6f 72 65 anner of \fBfore
0dc0: 61 63 68 5c 66 52 2e 29 0a 54 68 65 20 72 65 73 ach\fR.).The res
0dd0: 75 6c 74 20 6f 66 20 74 68 65 20 63 6f 6d 6d 61 ult of the comma
0de0: 6e 64 20 69 73 20 61 6e 20 65 6d 70 74 79 20 73 nd is an empty s
0df0: 74 72 69 6e 67 2e 20 49 66 20 61 6e 79 20 65 76 tring. If any ev
0e00: 61 6c 75 61 74 69 6f 6e 20 6f 66 20 74 68 65 0a aluation of the.
0e10: 62 6f 64 79 20 67 65 6e 65 72 61 74 65 73 20 61 body generates a
0e20: 20 5c 66 42 54 43 4c 5f 42 52 45 41 4b 5c 66 52 \fBTCL_BREAK\fR
0e30: 20 72 65 73 75 6c 74 2c 20 6e 6f 20 66 75 72 74 result, no furt
0e40: 68 65 72 20 70 61 69 72 73 20 66 72 6f 6d 20 74 her pairs from t
0e50: 68 65 0a 64 69 63 74 69 6f 6e 61 72 79 20 77 69 he.dictionary wi
0e60: 6c 6c 20 62 65 20 69 74 65 72 61 74 65 64 20 6f ll be iterated o
0e70: 76 65 72 20 61 6e 64 20 74 68 65 20 5c 66 42 64 ver and the \fBd
0e80: 69 63 74 20 66 6f 72 5c 66 52 20 63 6f 6d 6d 61 ict for\fR comma
0e90: 6e 64 20 77 69 6c 6c 0a 74 65 72 6d 69 6e 61 74 nd will.terminat
0ea0: 65 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 69 e successfully i
0eb0: 6d 6d 65 64 69 61 74 65 6c 79 2e 20 49 66 20 61 mmediately. If a
0ec0: 6e 79 20 65 76 61 6c 75 61 74 69 6f 6e 20 6f 66 ny evaluation of
0ed0: 20 74 68 65 20 62 6f 64 79 0a 67 65 6e 65 72 61 the body.genera
0ee0: 74 65 73 20 61 20 5c 66 42 54 43 4c 5f 43 4f 4e tes a \fBTCL_CON
0ef0: 54 49 4e 55 45 5c 66 52 20 72 65 73 75 6c 74 2c TINUE\fR result,
0f00: 20 74 68 69 73 20 73 68 61 6c 6c 20 62 65 20 74 this shall be t
0f10: 72 65 61 74 65 64 20 65 78 61 63 74 6c 79 20 6c reated exactly l
0f20: 69 6b 65 20 61 0a 6e 6f 72 6d 61 6c 20 5c 66 42 ike a.normal \fB
0f30: 54 43 4c 5f 4f 4b 5c 66 52 20 72 65 73 75 6c 74 TCL_OK\fR result
0f40: 2e 20 54 68 65 20 6f 72 64 65 72 20 6f 66 20 69 . The order of i
0f50: 74 65 72 61 74 69 6f 6e 20 69 73 20 74 68 65 20 teration is the
0f60: 6f 72 64 65 72 20 69 6e 0a 77 68 69 63 68 20 74 order in.which t
0f70: 68 65 20 6b 65 79 73 20 77 65 72 65 20 69 6e 73 he keys were ins
0f80: 65 72 74 65 64 20 69 6e 74 6f 20 74 68 65 20 64 erted into the d
0f90: 69 63 74 69 6f 6e 61 72 79 2e 0a 2e 54 50 0a 5c ictionary...TP.\
0fa0: 66 42 64 69 63 74 20 67 65 74 20 5c 66 49 64 69 fBdict get \fIdi
0fb0: 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c 66 ctionaryValue \f
0fc0: 52 3f 5c 66 49 6b 65 79 20 2e 2e 2e 5c 66 52 3f R?\fIkey ...\fR?
0fd0: 0a 2e 0a 47 69 76 65 6e 20 61 20 64 69 63 74 69 ...Given a dicti
0fe0: 6f 6e 61 72 79 20 76 61 6c 75 65 20 28 66 69 72 onary value (fir
0ff0: 73 74 20 61 72 67 75 6d 65 6e 74 29 20 61 6e 64 st argument) and
1000: 20 61 20 6b 65 79 20 28 73 65 63 6f 6e 64 20 61 a key (second a
1010: 72 67 75 6d 65 6e 74 29 2c 0a 74 68 69 73 20 77 rgument),.this w
1020: 69 6c 6c 20 72 65 74 72 69 65 76 65 20 74 68 65 ill retrieve the
1030: 20 76 61 6c 75 65 20 66 6f 72 20 74 68 61 74 20 value for that
1040: 6b 65 79 2e 20 57 68 65 72 65 20 73 65 76 65 72 key. Where sever
1050: 61 6c 20 6b 65 79 73 20 61 72 65 0a 73 75 70 70 al keys are.supp
1060: 6c 69 65 64 2c 20 74 68 65 20 62 65 68 61 76 69 lied, the behavi
1070: 6f 75 72 20 6f 66 20 74 68 65 20 63 6f 6d 6d 61 our of the comma
1080: 6e 64 20 73 68 61 6c 6c 20 62 65 20 61 73 20 69 nd shall be as i
1090: 66 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 0a f the result of.
10a0: 5c 66 42 64 69 63 74 20 67 65 74 20 24 64 69 63 \fBdict get $dic
10b0: 74 56 61 6c 20 24 6b 65 79 5c 66 52 20 77 61 73 tVal $key\fR was
10c0: 20 70 61 73 73 65 64 20 61 73 20 74 68 65 20 66 passed as the f
10d0: 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f irst argument to
10e0: 0a 5c 66 42 64 69 63 74 20 67 65 74 5c 66 52 20 .\fBdict get\fR
10f0: 77 69 74 68 20 74 68 65 20 72 65 6d 61 69 6e 69 with the remaini
1100: 6e 67 20 61 72 67 75 6d 65 6e 74 73 20 61 73 20 ng arguments as
1110: 73 65 63 6f 6e 64 20 28 61 6e 64 20 70 6f 73 73 second (and poss
1120: 69 62 6c 79 0a 73 75 62 73 65 71 75 65 6e 74 29 ibly.subsequent)
1130: 20 61 72 67 75 6d 65 6e 74 73 2e 20 54 68 69 73 arguments. This
1140: 20 66 61 63 69 6c 69 74 61 74 65 73 20 6c 6f 6f facilitates loo
1150: 6b 75 70 73 20 69 6e 20 6e 65 73 74 65 64 0a 64 kups in nested.d
1160: 69 63 74 69 6f 6e 61 72 69 65 73 2e 20 46 6f 72 ictionaries. For
1170: 20 65 78 61 6d 70 6c 65 2c 20 74 68 65 20 66 6f example, the fo
1180: 6c 6c 6f 77 69 6e 67 20 74 77 6f 20 63 6f 6d 6d llowing two comm
1190: 61 6e 64 73 20 61 72 65 20 65 71 75 69 76 61 6c ands are equival
11a0: 65 6e 74 3a 0a 2e 52 53 0a 2e 50 50 0a 2e 43 53 ent:..RS..PP..CS
11b0: 0a 64 69 63 74 20 67 65 74 20 24 64 69 63 74 20 .dict get $dict
11c0: 66 6f 6f 20 62 61 72 20 73 70 6f 6e 67 0a 64 69 foo bar spong.di
11d0: 63 74 20 67 65 74 20 5b 64 69 63 74 20 67 65 74 ct get [dict get
11e0: 20 5b 64 69 63 74 20 67 65 74 20 24 64 69 63 74 [dict get $dict
11f0: 20 66 6f 6f 5d 20 62 61 72 5d 20 73 70 6f 6e 67 foo] bar] spong
1200: 0a 2e 43 45 0a 2e 50 50 0a 49 66 20 6e 6f 20 6b ..CE..PP.If no k
1210: 65 79 73 20 61 72 65 20 70 72 6f 76 69 64 65 64 eys are provided
1220: 2c 20 5c 66 42 64 69 63 74 20 67 65 74 5c 66 52 , \fBdict get\fR
1230: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 61 20 6c will return a l
1240: 69 73 74 20 63 6f 6e 74 61 69 6e 69 6e 67 20 70 ist containing p
1250: 61 69 72 73 20 6f 66 0a 65 6c 65 6d 65 6e 74 73 airs of.elements
1260: 20 69 6e 20 61 20 6d 61 6e 6e 65 72 20 73 69 6d in a manner sim
1270: 69 6c 61 72 20 74 6f 20 5c 66 42 61 72 72 61 79 ilar to \fBarray
1280: 20 67 65 74 5c 66 52 2e 20 54 68 61 74 20 69 73 get\fR. That is
1290: 2c 20 74 68 65 20 66 69 72 73 74 0a 65 6c 65 6d , the first.elem
12a0: 65 6e 74 20 6f 66 20 65 61 63 68 20 70 61 69 72 ent of each pair
12b0: 20 77 6f 75 6c 64 20 62 65 20 74 68 65 20 6b 65 would be the ke
12c0: 79 20 61 6e 64 20 74 68 65 20 73 65 63 6f 6e 64 y and the second
12d0: 20 65 6c 65 6d 65 6e 74 20 77 6f 75 6c 64 20 62 element would b
12e0: 65 0a 74 68 65 20 76 61 6c 75 65 20 66 6f 72 20 e.the value for
12f0: 74 68 61 74 20 6b 65 79 2e 0a 2e 50 50 0a 49 74 that key...PP.It
1300: 20 69 73 20 61 6e 20 65 72 72 6f 72 20 74 6f 20 is an error to
1310: 61 74 74 65 6d 70 74 20 74 6f 20 72 65 74 72 69 attempt to retri
1320: 65 76 65 20 61 20 76 61 6c 75 65 20 66 6f 72 20 eve a value for
1330: 61 20 6b 65 79 20 74 68 61 74 20 69 73 20 6e 6f a key that is no
1340: 74 0a 70 72 65 73 65 6e 74 20 69 6e 20 74 68 65 t.present in the
1350: 20 64 69 63 74 69 6f 6e 61 72 79 2e 0a 2e 52 45 dictionary...RE
1360: 0a 2e 54 50 0a 5c 66 42 64 69 63 74 20 69 6e 63 ..TP.\fBdict inc
1370: 72 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 r \fIdictionaryV
1380: 61 72 69 61 62 6c 65 20 6b 65 79 20 5c 66 52 3f ariable key \fR?
1390: 5c 66 49 69 6e 63 72 65 6d 65 6e 74 5c 66 52 3f \fIincrement\fR?
13a0: 0a 2e 0a 54 68 69 73 20 61 64 64 73 20 74 68 65 ...This adds the
13b0: 20 67 69 76 65 6e 20 69 6e 63 72 65 6d 65 6e 74 given increment
13c0: 20 76 61 6c 75 65 20 28 61 6e 20 69 6e 74 65 67 value (an integ
13d0: 65 72 20 74 68 61 74 20 64 65 66 61 75 6c 74 73 er that defaults
13e0: 20 74 6f 20 31 20 69 66 0a 6e 6f 74 20 73 70 65 to 1 if.not spe
13f0: 63 69 66 69 65 64 29 20 74 6f 20 74 68 65 20 76 cified) to the v
1400: 61 6c 75 65 20 74 68 61 74 20 74 68 65 20 67 69 alue that the gi
1410: 76 65 6e 20 6b 65 79 20 6d 61 70 73 20 74 6f 20 ven key maps to
1420: 69 6e 20 74 68 65 0a 64 69 63 74 69 6f 6e 61 72 in the.dictionar
1430: 79 20 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 65 y value containe
1440: 64 20 69 6e 20 74 68 65 20 67 69 76 65 6e 20 76 d in the given v
1450: 61 72 69 61 62 6c 65 2c 20 77 72 69 74 69 6e 67 ariable, writing
1460: 20 74 68 65 0a 72 65 73 75 6c 74 69 6e 67 20 64 the.resulting d
1470: 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 20 ictionary value
1480: 62 61 63 6b 20 74 6f 20 74 68 61 74 20 76 61 72 back to that var
1490: 69 61 62 6c 65 2e 20 4e 6f 6e 2d 65 78 69 73 74 iable. Non-exist
14a0: 65 6e 74 20 6b 65 79 73 0a 61 72 65 20 74 72 65 ent keys.are tre
14b0: 61 74 65 64 20 61 73 20 69 66 20 74 68 65 79 20 ated as if they
14c0: 6d 61 70 20 74 6f 20 30 2e 20 49 74 20 69 73 20 map to 0. It is
14d0: 61 6e 20 65 72 72 6f 72 20 74 6f 20 69 6e 63 72 an error to incr
14e0: 65 6d 65 6e 74 20 61 20 76 61 6c 75 65 0a 66 6f ement a value.fo
14f0: 72 20 61 6e 20 65 78 69 73 74 69 6e 67 20 6b 65 r an existing ke
1500: 79 20 69 66 20 74 68 61 74 20 76 61 6c 75 65 20 y if that value
1510: 69 73 20 6e 6f 74 20 61 6e 20 69 6e 74 65 67 65 is not an intege
1520: 72 2e 20 54 68 65 20 75 70 64 61 74 65 64 0a 64 r. The updated.d
1530: 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 20 ictionary value
1540: 69 73 20 72 65 74 75 72 6e 65 64 2e 0a 2e 54 50 is returned...TP
1550: 0a 5c 66 42 64 69 63 74 20 69 6e 66 6f 20 5c 66 .\fBdict info \f
1560: 49 64 69 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 IdictionaryValue
1570: 5c 66 52 0a 2e 0a 54 68 69 73 20 72 65 74 75 72 \fR...This retur
1580: 6e 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 28 ns information (
1590: 69 6e 74 65 6e 64 65 64 20 66 6f 72 20 64 69 73 intended for dis
15a0: 70 6c 61 79 20 74 6f 20 70 65 6f 70 6c 65 29 20 play to people)
15b0: 61 62 6f 75 74 20 74 68 65 0a 67 69 76 65 6e 20 about the.given
15c0: 64 69 63 74 69 6f 6e 61 72 79 20 74 68 6f 75 67 dictionary thoug
15d0: 68 20 74 68 65 20 66 6f 72 6d 61 74 20 6f 66 20 h the format of
15e0: 74 68 69 73 20 64 61 74 61 20 69 73 20 64 65 70 this data is dep
15f0: 65 6e 64 65 6e 74 20 6f 6e 20 74 68 65 0a 69 6d endent on the.im
1600: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 plementation of
1610: 74 68 65 20 64 69 63 74 69 6f 6e 61 72 79 2e 20 the dictionary.
1620: 46 6f 72 20 64 69 63 74 69 6f 6e 61 72 69 65 73 For dictionaries
1630: 20 74 68 61 74 20 61 72 65 0a 69 6d 70 6c 65 6d that are.implem
1640: 65 6e 74 65 64 20 62 79 20 68 61 73 68 20 74 61 ented by hash ta
1650: 62 6c 65 73 2c 20 69 74 20 69 73 20 65 78 70 65 bles, it is expe
1660: 63 74 65 64 20 74 68 61 74 20 74 68 69 73 20 77 cted that this w
1670: 69 6c 6c 20 72 65 74 75 72 6e 20 74 68 65 0a 73 ill return the.s
1680: 74 72 69 6e 67 20 70 72 6f 64 75 63 65 64 20 62 tring produced b
1690: 79 20 5c 66 42 54 63 6c 5f 48 61 73 68 53 74 61 y \fBTcl_HashSta
16a0: 74 73 5c 66 52 2c 20 73 69 6d 69 6c 61 72 20 74 ts\fR, similar t
16b0: 6f 20 5c 66 42 61 72 72 61 79 20 73 74 61 74 69 o \fBarray stati
16c0: 73 74 69 63 73 5c 66 52 2e 0a 2e 54 50 0a 5c 66 stics\fR...TP.\f
16d0: 42 64 69 63 74 20 6b 65 79 73 20 5c 66 49 64 69 Bdict keys \fIdi
16e0: 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c 66 ctionaryValue \f
16f0: 52 3f 5c 66 49 67 6c 6f 62 50 61 74 74 65 72 6e R?\fIglobPattern
1700: 5c 66 52 3f 0a 2e 0a 52 65 74 75 72 6e 20 61 20 \fR?...Return a
1710: 6c 69 73 74 20 6f 66 20 61 6c 6c 20 6b 65 79 73 list of all keys
1720: 20 69 6e 20 74 68 65 20 67 69 76 65 6e 20 64 69 in the given di
1730: 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 2e 20 ctionary value.
1740: 49 66 20 61 20 70 61 74 74 65 72 6e 0a 69 73 20 If a pattern.is
1750: 73 75 70 70 6c 69 65 64 2c 20 6f 6e 6c 79 20 74 supplied, only t
1760: 68 6f 73 65 20 6b 65 79 73 20 74 68 61 74 20 6d hose keys that m
1770: 61 74 63 68 20 69 74 20 28 61 63 63 6f 72 64 69 atch it (accordi
1780: 6e 67 20 74 6f 20 74 68 65 20 72 75 6c 65 73 20 ng to the rules
1790: 6f 66 0a 5c 66 42 73 74 72 69 6e 67 20 6d 61 74 of.\fBstring mat
17a0: 63 68 5c 66 52 29 20 77 69 6c 6c 20 62 65 20 72 ch\fR) will be r
17b0: 65 74 75 72 6e 65 64 2e 20 54 68 65 20 72 65 74 eturned. The ret
17c0: 75 72 6e 65 64 20 6b 65 79 73 20 77 69 6c 6c 20 urned keys will
17d0: 62 65 20 69 6e 20 74 68 65 0a 6f 72 64 65 72 20 be in the.order
17e0: 74 68 61 74 20 74 68 65 79 20 77 65 72 65 20 69 that they were i
17f0: 6e 73 65 72 74 65 64 20 69 6e 74 6f 20 74 68 65 nserted into the
1800: 20 64 69 63 74 69 6f 6e 61 72 79 2e 0a 2e 54 50 dictionary...TP
1810: 0a 5c 66 42 64 69 63 74 20 6c 61 70 70 65 6e 64 .\fBdict lappend
1820: 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 \fIdictionaryVa
1830: 72 69 61 62 6c 65 20 6b 65 79 20 5c 66 52 3f 5c riable key \fR?\
1840: 66 49 76 61 6c 75 65 20 2e 2e 2e 5c 66 52 3f 0a fIvalue ...\fR?.
1850: 2e 0a 54 68 69 73 20 61 70 70 65 6e 64 73 20 74 ..This appends t
1860: 68 65 20 67 69 76 65 6e 20 69 74 65 6d 73 20 74 he given items t
1870: 6f 20 74 68 65 20 6c 69 73 74 20 76 61 6c 75 65 o the list value
1880: 20 74 68 61 74 20 74 68 65 20 67 69 76 65 6e 20 that the given
1890: 6b 65 79 20 6d 61 70 73 0a 74 6f 20 69 6e 20 74 key maps.to in t
18a0: 68 65 20 64 69 63 74 69 6f 6e 61 72 79 20 76 61 he dictionary va
18b0: 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e lue contained in
18c0: 20 74 68 65 20 67 69 76 65 6e 20 76 61 72 69 61 the given varia
18d0: 62 6c 65 2c 20 77 72 69 74 69 6e 67 0a 74 68 65 ble, writing.the
18e0: 20 72 65 73 75 6c 74 69 6e 67 20 64 69 63 74 69 resulting dicti
18f0: 6f 6e 61 72 79 20 76 61 6c 75 65 20 62 61 63 6b onary value back
1900: 20 74 6f 20 74 68 61 74 20 76 61 72 69 61 62 6c to that variabl
1910: 65 2e 20 4e 6f 6e 2d 65 78 69 73 74 65 6e 74 0a e. Non-existent.
1920: 6b 65 79 73 20 61 72 65 20 74 72 65 61 74 65 64 keys are treated
1930: 20 61 73 20 69 66 20 74 68 65 79 20 6d 61 70 20 as if they map
1940: 74 6f 20 61 6e 20 65 6d 70 74 79 20 6c 69 73 74 to an empty list
1950: 2c 20 61 6e 64 20 69 74 20 69 73 20 6c 65 67 61 , and it is lega
1960: 6c 20 66 6f 72 0a 74 68 65 72 65 20 74 6f 20 62 l for.there to b
1970: 65 20 6e 6f 20 69 74 65 6d 73 20 74 6f 20 61 70 e no items to ap
1980: 70 65 6e 64 20 74 6f 20 74 68 65 20 6c 69 73 74 pend to the list
1990: 2e 20 49 74 20 69 73 20 61 6e 20 65 72 72 6f 72 . It is an error
19a0: 20 66 6f 72 20 74 68 65 0a 76 61 6c 75 65 20 74 for the.value t
19b0: 68 61 74 20 74 68 65 20 6b 65 79 20 6d 61 70 73 hat the key maps
19c0: 20 74 6f 20 74 6f 20 6e 6f 74 20 62 65 20 72 65 to to not be re
19d0: 70 72 65 73 65 6e 74 61 62 6c 65 20 61 73 20 61 presentable as a
19e0: 20 6c 69 73 74 2e 20 54 68 65 0a 75 70 64 61 74 list. The.updat
19f0: 65 64 20 64 69 63 74 69 6f 6e 61 72 79 20 76 61 ed dictionary va
1a00: 6c 75 65 20 69 73 20 72 65 74 75 72 6e 65 64 2e lue is returned.
1a10: 0a 2e 54 50 0a 5c 66 42 64 69 63 74 20 6d 61 70 ..TP.\fBdict map
1a20: 20 5c 66 52 7b 5c 66 49 6b 65 79 56 61 72 69 61 \fR{\fIkeyVaria
1a30: 62 6c 65 20 76 61 6c 75 65 56 61 72 69 61 62 6c ble valueVariabl
1a40: 65 5c 66 52 7d 20 5c 66 49 64 69 63 74 69 6f 6e e\fR} \fIdiction
1a50: 61 72 79 56 61 6c 75 65 20 62 6f 64 79 5c 66 52 aryValue body\fR
1a60: 0a 2e 0a 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 ...This command
1a70: 61 70 70 6c 69 65 73 20 61 20 74 72 61 6e 73 66 applies a transf
1a80: 6f 72 6d 61 74 69 6f 6e 20 74 6f 20 65 61 63 68 ormation to each
1a90: 20 65 6c 65 6d 65 6e 74 20 6f 66 20 61 20 64 69 element of a di
1aa0: 63 74 69 6f 6e 61 72 79 2c 0a 72 65 74 75 72 6e ctionary,.return
1ab0: 69 6e 67 20 61 20 6e 65 77 20 64 69 63 74 69 6f ing a new dictio
1ac0: 6e 61 72 79 2e 20 49 74 20 74 61 6b 65 73 20 74 nary. It takes t
1ad0: 68 72 65 65 20 61 72 67 75 6d 65 6e 74 73 3a 20 hree arguments:
1ae0: 74 68 65 20 66 69 72 73 74 20 69 73 20 61 0a 74 the first is a.t
1af0: 77 6f 2d 65 6c 65 6d 65 6e 74 20 6c 69 73 74 20 wo-element list
1b00: 6f 66 20 76 61 72 69 61 62 6c 65 20 6e 61 6d 65 of variable name
1b10: 73 20 28 66 6f 72 20 74 68 65 20 6b 65 79 20 61 s (for the key a
1b20: 6e 64 20 76 61 6c 75 65 20 72 65 73 70 65 63 74 nd value respect
1b30: 69 76 65 6c 79 20 6f 66 20 65 61 63 68 0a 6d 61 ively of each.ma
1b40: 70 70 69 6e 67 20 69 6e 20 74 68 65 20 64 69 63 pping in the dic
1b50: 74 69 6f 6e 61 72 79 29 2c 20 74 68 65 20 73 65 tionary), the se
1b60: 63 6f 6e 64 20 74 68 65 20 64 69 63 74 69 6f 6e cond the diction
1b70: 61 72 79 20 76 61 6c 75 65 20 74 6f 20 69 74 65 ary value to ite
1b80: 72 61 74 65 20 61 63 72 6f 73 73 2c 0a 61 6e 64 rate across,.and
1b90: 20 74 68 65 20 74 68 69 72 64 20 61 20 73 63 72 the third a scr
1ba0: 69 70 74 20 74 6f 20 62 65 20 65 76 61 6c 75 61 ipt to be evalua
1bb0: 74 65 64 20 66 6f 72 20 65 61 63 68 20 6d 61 70 ted for each map
1bc0: 70 69 6e 67 20 77 69 74 68 20 74 68 65 20 6b 65 ping with the ke
1bd0: 79 20 61 6e 64 20 76 61 6c 75 65 0a 76 61 72 69 y and value.vari
1be0: 61 62 6c 65 73 20 73 65 74 20 61 70 70 72 6f 70 ables set approp
1bf0: 72 69 61 74 65 6c 79 20 28 69 6e 20 74 68 65 20 riately (in the
1c00: 6d 61 6e 6e 65 72 20 6f 66 20 5c 66 42 6c 6d 61 manner of \fBlma
1c10: 70 5c 66 52 29 2e 20 49 6e 20 61 6e 20 69 74 65 p\fR). In an ite
1c20: 72 61 74 69 6f 6e 0a 77 68 65 72 65 20 74 68 65 ration.where the
1c30: 20 65 76 61 6c 75 61 74 65 64 20 73 63 72 69 70 evaluated scrip
1c40: 74 20 63 6f 6d 70 6c 65 74 65 73 20 6e 6f 72 6d t completes norm
1c50: 61 6c 6c 79 20 28 5c 66 42 54 43 4c 5f 4f 4b 5c ally (\fBTCL_OK\
1c60: 66 52 2c 20 61 73 20 6f 70 70 6f 73 65 64 20 74 fR, as opposed t
1c70: 6f 20 61 6e 0a 5c 66 42 65 72 72 6f 72 5c 66 52 o an.\fBerror\fR
1c80: 2c 20 65 74 63 2e 29 20 74 68 65 20 72 65 73 75 , etc.) the resu
1c90: 6c 74 20 6f 66 20 74 68 65 20 73 63 72 69 70 74 lt of the script
1ca0: 20 69 73 20 70 75 74 20 69 6e 74 6f 20 61 6e 20 is put into an
1cb0: 61 63 63 75 6d 75 6c 61 74 6f 72 0a 64 69 63 74 accumulator.dict
1cc0: 69 6f 6e 61 72 79 20 75 73 69 6e 67 20 74 68 65 ionary using the
1cd0: 20 6b 65 79 20 74 68 61 74 20 69 73 20 74 68 65 key that is the
1ce0: 20 63 75 72 72 65 6e 74 20 63 6f 6e 74 65 6e 74 current content
1cf0: 73 20 6f 66 20 74 68 65 20 5c 66 49 6b 65 79 56 s of the \fIkeyV
1d00: 61 72 69 61 62 6c 65 5c 66 52 0a 76 61 72 69 61 ariable\fR.varia
1d10: 62 6c 65 20 61 74 20 74 68 61 74 20 70 6f 69 6e ble at that poin
1d20: 74 2e 20 54 68 65 20 72 65 73 75 6c 74 20 6f 66 t. The result of
1d30: 20 74 68 65 20 5c 66 42 64 69 63 74 20 6d 61 70 the \fBdict map
1d40: 5c 66 52 20 63 6f 6d 6d 61 6e 64 20 69 73 20 74 \fR command is t
1d50: 68 65 0a 61 63 63 75 6d 75 6c 61 74 6f 72 20 64 he.accumulator d
1d60: 69 63 74 69 6f 6e 61 72 79 20 61 66 74 65 72 20 ictionary after
1d70: 61 6c 6c 20 6b 65 79 73 20 68 61 76 65 20 62 65 all keys have be
1d80: 65 6e 20 69 74 65 72 61 74 65 64 20 6f 76 65 72 en iterated over
1d90: 2e 0a 2e 52 53 0a 2e 50 50 0a 49 66 20 74 68 65 ...RS..PP.If the
1da0: 20 65 76 61 6c 75 61 74 69 6f 6e 20 6f 66 20 74 evaluation of t
1db0: 68 65 20 62 6f 64 79 20 66 6f 72 20 61 6e 79 20 he body for any
1dc0: 70 61 72 74 69 63 75 6c 61 72 20 73 74 65 70 20 particular step
1dd0: 67 65 6e 65 72 61 74 65 73 20 61 20 5c 66 42 62 generates a \fBb
1de0: 72 65 61 6b 5c 66 52 2c 0a 6e 6f 20 66 75 72 74 reak\fR,.no furt
1df0: 68 65 72 20 70 61 69 72 73 20 66 72 6f 6d 20 74 her pairs from t
1e00: 68 65 20 64 69 63 74 69 6f 6e 61 72 79 20 77 69 he dictionary wi
1e10: 6c 6c 20 62 65 20 69 74 65 72 61 74 65 64 20 6f ll be iterated o
1e20: 76 65 72 20 61 6e 64 20 74 68 65 20 5c 66 42 64 ver and the \fBd
1e30: 69 63 74 0a 6d 61 70 5c 66 52 20 63 6f 6d 6d 61 ict.map\fR comma
1e40: 6e 64 20 77 69 6c 6c 20 74 65 72 6d 69 6e 61 74 nd will terminat
1e50: 65 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 69 e successfully i
1e60: 6d 6d 65 64 69 61 74 65 6c 79 2e 20 49 66 20 74 mmediately. If t
1e70: 68 65 20 65 76 61 6c 75 61 74 69 6f 6e 20 6f 66 he evaluation of
1e80: 0a 74 68 65 20 62 6f 64 79 20 66 6f 72 20 61 20 .the body for a
1e90: 70 61 72 74 69 63 75 6c 61 72 20 73 74 65 70 20 particular step
1ea0: 67 65 6e 65 72 61 74 65 73 20 61 20 5c 66 42 63 generates a \fBc
1eb0: 6f 6e 74 69 6e 75 65 5c 66 52 20 72 65 73 75 6c ontinue\fR resul
1ec0: 74 2c 20 74 68 65 20 63 75 72 72 65 6e 74 0a 69 t, the current.i
1ed0: 74 65 72 61 74 69 6f 6e 20 69 73 20 61 62 6f 72 teration is abor
1ee0: 74 65 64 20 61 6e 64 20 74 68 65 20 61 63 63 75 ted and the accu
1ef0: 6d 75 6c 61 74 6f 72 20 64 69 63 74 69 6f 6e 61 mulator dictiona
1f00: 72 79 20 69 73 20 6e 6f 74 20 6d 6f 64 69 66 69 ry is not modifi
1f10: 65 64 2e 20 54 68 65 20 6f 72 64 65 72 0a 6f 66 ed. The order.of
1f20: 20 69 74 65 72 61 74 69 6f 6e 20 69 73 20 74 68 iteration is th
1f30: 65 20 6e 61 74 75 72 61 6c 20 6f 72 64 65 72 20 e natural order
1f40: 6f 66 20 74 68 65 20 64 69 63 74 69 6f 6e 61 72 of the dictionar
1f50: 79 20 28 74 79 70 69 63 61 6c 6c 79 20 74 68 65 y (typically the
1f60: 20 6f 72 64 65 72 20 69 6e 0a 77 68 69 63 68 20 order in.which
1f70: 74 68 65 20 6b 65 79 73 20 77 65 72 65 20 61 64 the keys were ad
1f80: 64 65 64 20 74 6f 20 74 68 65 20 64 69 63 74 69 ded to the dicti
1f90: 6f 6e 61 72 79 3b 20 74 68 65 20 6f 72 64 65 72 onary; the order
1fa0: 20 69 73 20 74 68 65 20 73 61 6d 65 20 61 73 20 is the same as
1fb0: 74 68 61 74 0a 75 73 65 64 20 69 6e 20 5c 66 42 that.used in \fB
1fc0: 64 69 63 74 20 66 6f 72 5c 66 52 29 2e 0a 2e 52 dict for\fR)...R
1fd0: 45 0a 2e 54 50 0a 5c 66 42 64 69 63 74 20 6d 65 E..TP.\fBdict me
1fe0: 72 67 65 20 5c 66 52 3f 5c 66 49 64 69 63 74 69 rge \fR?\fIdicti
1ff0: 6f 6e 61 72 79 56 61 6c 75 65 20 2e 2e 2e 5c 66 onaryValue ...\f
2000: 52 3f 0a 2e 0a 52 65 74 75 72 6e 20 61 20 64 69 R?...Return a di
2010: 63 74 69 6f 6e 61 72 79 20 74 68 61 74 20 63 6f ctionary that co
2020: 6e 74 61 69 6e 73 20 74 68 65 20 63 6f 6e 74 65 ntains the conte
2030: 6e 74 73 20 6f 66 20 65 61 63 68 20 6f 66 20 74 nts of each of t
2040: 68 65 0a 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 he.\fIdictionary
2050: 56 61 6c 75 65 5c 66 52 20 61 72 67 75 6d 65 6e Value\fR argumen
2060: 74 73 2e 20 20 57 68 65 72 65 20 74 77 6f 20 28 ts. Where two (
2070: 6f 72 20 6d 6f 72 65 29 20 64 69 63 74 69 6f 6e or more) diction
2080: 61 72 69 65 73 0a 63 6f 6e 74 61 69 6e 20 61 20 aries.contain a
2090: 6d 61 70 70 69 6e 67 20 66 6f 72 20 74 68 65 20 mapping for the
20a0: 73 61 6d 65 20 6b 65 79 2c 20 74 68 65 20 72 65 same key, the re
20b0: 73 75 6c 74 69 6e 67 20 64 69 63 74 69 6f 6e 61 sulting dictiona
20c0: 72 79 20 6d 61 70 73 20 74 68 61 74 0a 6b 65 79 ry maps that.key
20d0: 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 61 63 to the value ac
20e0: 63 6f 72 64 69 6e 67 20 74 6f 20 74 68 65 20 6c cording to the l
20f0: 61 73 74 20 64 69 63 74 69 6f 6e 61 72 79 20 6f ast dictionary o
2100: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 n the command li
2110: 6e 65 0a 63 6f 6e 74 61 69 6e 69 6e 67 20 61 20 ne.containing a
2120: 6d 61 70 70 69 6e 67 20 66 6f 72 20 74 68 61 74 mapping for that
2130: 20 6b 65 79 2e 0a 2e 54 50 0a 5c 66 42 64 69 63 key...TP.\fBdic
2140: 74 20 72 65 6d 6f 76 65 20 5c 66 49 64 69 63 74 t remove \fIdict
2150: 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c 66 52 3f ionaryValue \fR?
2160: 5c 66 49 6b 65 79 20 2e 2e 2e 5c 66 52 3f 0a 2e \fIkey ...\fR?..
2170: 0a 52 65 74 75 72 6e 20 61 20 6e 65 77 20 64 69 .Return a new di
2180: 63 74 69 6f 6e 61 72 79 20 74 68 61 74 20 69 73 ctionary that is
2190: 20 61 20 63 6f 70 79 20 6f 66 20 61 6e 20 6f 6c a copy of an ol
21a0: 64 20 6f 6e 65 20 70 61 73 73 65 64 20 69 6e 20 d one passed in
21b0: 61 73 0a 66 69 72 73 74 20 61 72 67 75 6d 65 6e as.first argumen
21c0: 74 20 65 78 63 65 70 74 20 77 69 74 68 6f 75 74 t except without
21d0: 20 6d 61 70 70 69 6e 67 73 20 66 6f 72 20 65 61 mappings for ea
21e0: 63 68 20 6f 66 20 74 68 65 20 6b 65 79 73 20 6c ch of the keys l
21f0: 69 73 74 65 64 2e 0a 49 74 20 69 73 20 6c 65 67 isted..It is leg
2200: 61 6c 20 66 6f 72 20 74 68 65 72 65 20 74 6f 20 al for there to
2210: 62 65 20 6e 6f 20 6b 65 79 73 20 74 6f 20 72 65 be no keys to re
2220: 6d 6f 76 65 2c 20 61 6e 64 20 69 74 20 61 6c 73 move, and it als
2230: 6f 20 6c 65 67 61 6c 20 66 6f 72 0a 61 6e 79 20 o legal for.any
2240: 6f 66 20 74 68 65 20 6b 65 79 73 20 74 6f 20 62 of the keys to b
2250: 65 20 72 65 6d 6f 76 65 64 20 74 6f 20 6e 6f 74 e removed to not
2260: 20 62 65 20 70 72 65 73 65 6e 74 20 69 6e 20 74 be present in t
2270: 68 65 20 69 6e 70 75 74 0a 64 69 63 74 69 6f 6e he input.diction
2280: 61 72 79 20 69 6e 20 74 68 65 20 66 69 72 73 74 ary in the first
2290: 20 70 6c 61 63 65 2e 0a 2e 54 50 0a 5c 66 42 64 place...TP.\fBd
22a0: 69 63 74 20 72 65 70 6c 61 63 65 20 5c 66 49 64 ict replace \fId
22b0: 69 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c ictionaryValue \
22c0: 66 52 3f 5c 66 49 6b 65 79 20 76 61 6c 75 65 20 fR?\fIkey value
22d0: 2e 2e 2e 5c 66 52 3f 0a 2e 0a 52 65 74 75 72 6e ...\fR?...Return
22e0: 20 61 20 6e 65 77 20 64 69 63 74 69 6f 6e 61 72 a new dictionar
22f0: 79 20 74 68 61 74 20 69 73 20 61 20 63 6f 70 79 y that is a copy
2300: 20 6f 66 20 61 6e 20 6f 6c 64 20 6f 6e 65 20 70 of an old one p
2310: 61 73 73 65 64 20 69 6e 20 61 73 0a 66 69 72 73 assed in as.firs
2320: 74 20 61 72 67 75 6d 65 6e 74 20 65 78 63 65 70 t argument excep
2330: 74 20 77 69 74 68 20 73 6f 6d 65 20 76 61 6c 75 t with some valu
2340: 65 73 20 64 69 66 66 65 72 65 6e 74 20 6f 72 20 es different or
2350: 73 6f 6d 65 20 65 78 74 72 61 0a 6b 65 79 2f 76 some extra.key/v
2360: 61 6c 75 65 20 70 61 69 72 73 20 61 64 64 65 64 alue pairs added
2370: 2e 20 49 74 20 69 73 20 6c 65 67 61 6c 20 66 6f . It is legal fo
2380: 72 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 20 74 r this command t
2390: 6f 20 62 65 20 63 61 6c 6c 65 64 20 77 69 74 68 o be called with
23a0: 0a 6e 6f 20 6b 65 79 2f 76 61 6c 75 65 20 70 61 .no key/value pa
23b0: 69 72 73 2c 20 62 75 74 20 69 6c 6c 65 67 61 6c irs, but illegal
23c0: 20 66 6f 72 20 74 68 69 73 20 63 6f 6d 6d 61 6e for this comman
23d0: 64 20 74 6f 20 62 65 20 63 61 6c 6c 65 64 20 77 d to be called w
23e0: 69 74 68 20 61 0a 6b 65 79 20 62 75 74 20 6e 6f ith a.key but no
23f0: 20 76 61 6c 75 65 2e 0a 2e 54 50 0a 5c 66 42 64 value...TP.\fBd
2400: 69 63 74 20 73 65 74 20 5c 66 49 64 69 63 74 69 ict set \fIdicti
2410: 6f 6e 61 72 79 56 61 72 69 61 62 6c 65 20 6b 65 onaryVariable ke
2420: 79 20 5c 66 52 3f 5c 66 49 6b 65 79 20 2e 2e 2e y \fR?\fIkey ...
2430: 5c 66 52 3f 20 5c 66 49 76 61 6c 75 65 5c 66 52 \fR? \fIvalue\fR
2440: 0a 2e 0a 54 68 69 73 20 6f 70 65 72 61 74 69 6f ...This operatio
2450: 6e 20 74 61 6b 65 73 20 74 68 65 20 6e 61 6d 65 n takes the name
2460: 20 6f 66 20 61 20 76 61 72 69 61 62 6c 65 20 63 of a variable c
2470: 6f 6e 74 61 69 6e 69 6e 67 20 61 20 64 69 63 74 ontaining a dict
2480: 69 6f 6e 61 72 79 0a 76 61 6c 75 65 20 61 6e 64 ionary.value and
2490: 20 70 6c 61 63 65 73 20 61 6e 20 75 70 64 61 74 places an updat
24a0: 65 64 20 64 69 63 74 69 6f 6e 61 72 79 20 76 61 ed dictionary va
24b0: 6c 75 65 20 69 6e 20 74 68 61 74 20 76 61 72 69 lue in that vari
24c0: 61 62 6c 65 0a 63 6f 6e 74 61 69 6e 69 6e 67 20 able.containing
24d0: 61 20 6d 61 70 70 69 6e 67 20 66 72 6f 6d 20 74 a mapping from t
24e0: 68 65 20 67 69 76 65 6e 20 6b 65 79 20 74 6f 20 he given key to
24f0: 74 68 65 20 67 69 76 65 6e 20 76 61 6c 75 65 2e the given value.
2500: 20 57 68 65 6e 0a 6d 75 6c 74 69 70 6c 65 20 6b When.multiple k
2510: 65 79 73 20 61 72 65 20 70 72 65 73 65 6e 74 2c eys are present,
2520: 20 74 68 69 73 20 6f 70 65 72 61 74 69 6f 6e 20 this operation
2530: 63 72 65 61 74 65 73 20 6f 72 20 75 70 64 61 74 creates or updat
2540: 65 73 20 61 20 63 68 61 69 6e 0a 6f 66 20 6e 65 es a chain.of ne
2550: 73 74 65 64 20 64 69 63 74 69 6f 6e 61 72 69 65 sted dictionarie
2560: 73 2e 20 54 68 65 20 75 70 64 61 74 65 64 20 64 s. The updated d
2570: 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 20 ictionary value
2580: 69 73 20 72 65 74 75 72 6e 65 64 2e 0a 2e 54 50 is returned...TP
2590: 0a 5c 66 42 64 69 63 74 20 73 69 7a 65 20 5c 66 .\fBdict size \f
25a0: 49 64 69 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 IdictionaryValue
25b0: 5c 66 52 0a 2e 0a 52 65 74 75 72 6e 20 74 68 65 \fR...Return the
25c0: 20 6e 75 6d 62 65 72 20 6f 66 20 6b 65 79 2f 76 number of key/v
25d0: 61 6c 75 65 20 6d 61 70 70 69 6e 67 73 20 69 6e alue mappings in
25e0: 20 74 68 65 20 67 69 76 65 6e 20 64 69 63 74 69 the given dicti
25f0: 6f 6e 61 72 79 20 76 61 6c 75 65 2e 0a 2e 54 50 onary value...TP
2600: 0a 5c 66 42 64 69 63 74 20 75 6e 73 65 74 20 5c .\fBdict unset \
2610: 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 72 69 fIdictionaryVari
2620: 61 62 6c 65 20 6b 65 79 20 5c 66 52 3f 5c 66 49 able key \fR?\fI
2630: 6b 65 79 20 2e 2e 2e 5c 66 52 3f 0a 2e 0a 54 68 key ...\fR?...Th
2640: 69 73 20 6f 70 65 72 61 74 69 6f 6e 20 28 74 68 is operation (th
2650: 65 20 63 6f 6d 70 61 6e 69 6f 6e 20 74 6f 20 5c e companion to \
2660: 66 42 64 69 63 74 20 73 65 74 5c 66 52 29 20 74 fBdict set\fR) t
2670: 61 6b 65 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 akes the name of
2680: 20 61 0a 76 61 72 69 61 62 6c 65 20 63 6f 6e 74 a.variable cont
2690: 61 69 6e 69 6e 67 20 61 20 64 69 63 74 69 6f 6e aining a diction
26a0: 61 72 79 20 76 61 6c 75 65 20 61 6e 64 20 70 6c ary value and pl
26b0: 61 63 65 73 20 61 6e 20 75 70 64 61 74 65 64 0a aces an updated.
26c0: 64 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 dictionary value
26d0: 20 69 6e 20 74 68 61 74 20 76 61 72 69 61 62 6c in that variabl
26e0: 65 20 74 68 61 74 20 64 6f 65 73 20 6e 6f 74 20 e that does not
26f0: 63 6f 6e 74 61 69 6e 20 61 20 6d 61 70 70 69 6e contain a mappin
2700: 67 20 66 6f 72 0a 74 68 65 20 67 69 76 65 6e 20 g for.the given
2710: 6b 65 79 2e 20 57 68 65 72 65 20 6d 75 6c 74 69 key. Where multi
2720: 70 6c 65 20 6b 65 79 73 20 61 72 65 20 70 72 65 ple keys are pre
2730: 73 65 6e 74 2c 20 74 68 69 73 20 64 65 73 63 72 sent, this descr
2740: 69 62 65 73 20 61 20 70 61 74 68 0a 74 68 72 6f ibes a path.thro
2750: 75 67 68 20 6e 65 73 74 65 64 20 64 69 63 74 69 ugh nested dicti
2760: 6f 6e 61 72 69 65 73 20 74 6f 20 74 68 65 20 6d onaries to the m
2770: 61 70 70 69 6e 67 20 74 6f 20 72 65 6d 6f 76 65 apping to remove
2780: 2e 20 41 74 20 6c 65 61 73 74 20 6f 6e 65 20 6b . At least one k
2790: 65 79 0a 6d 75 73 74 20 62 65 20 73 70 65 63 69 ey.must be speci
27a0: 66 69 65 64 2c 20 62 75 74 20 74 68 65 20 6c 61 fied, but the la
27b0: 73 74 20 6b 65 79 20 6f 6e 20 74 68 65 20 6b 65 st key on the ke
27c0: 79 2d 70 61 74 68 20 6e 65 65 64 20 6e 6f 74 20 y-path need not
27d0: 65 78 69 73 74 2e 0a 41 6c 6c 20 6f 74 68 65 72 exist..All other
27e0: 20 63 6f 6d 70 6f 6e 65 6e 74 73 20 6f 6e 20 74 components on t
27f0: 68 65 20 70 61 74 68 20 6d 75 73 74 20 65 78 69 he path must exi
2800: 73 74 2e 20 54 68 65 20 75 70 64 61 74 65 64 20 st. The updated
2810: 64 69 63 74 69 6f 6e 61 72 79 0a 76 61 6c 75 65 dictionary.value
2820: 20 69 73 20 72 65 74 75 72 6e 65 64 2e 0a 2e 54 is returned...T
2830: 50 0a 5c 66 42 64 69 63 74 20 75 70 64 61 74 65 P.\fBdict update
2840: 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 \fIdictionaryVa
2850: 72 69 61 62 6c 65 20 6b 65 79 20 76 61 72 4e 61 riable key varNa
2860: 6d 65 20 5c 66 52 3f 5c 66 49 6b 65 79 20 76 61 me \fR?\fIkey va
2870: 72 4e 61 6d 65 20 2e 2e 2e 5c 66 52 3f 20 5c 66 rName ...\fR? \f
2880: 49 62 6f 64 79 5c 66 52 0a 2e 0a 45 78 65 63 75 Ibody\fR...Execu
2890: 74 65 20 74 68 65 20 54 63 6c 20 73 63 72 69 70 te the Tcl scrip
28a0: 74 20 69 6e 20 5c 66 49 62 6f 64 79 5c 66 52 20 t in \fIbody\fR
28b0: 77 69 74 68 20 74 68 65 20 76 61 6c 75 65 20 66 with the value f
28c0: 6f 72 20 65 61 63 68 20 5c 66 49 6b 65 79 5c 66 or each \fIkey\f
28d0: 52 0a 28 61 73 20 66 6f 75 6e 64 20 62 79 20 72 R.(as found by r
28e0: 65 61 64 69 6e 67 20 74 68 65 20 64 69 63 74 69 eading the dicti
28f0: 6f 6e 61 72 79 20 76 61 6c 75 65 20 69 6e 20 5c onary value in \
2900: 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 72 69 fIdictionaryVari
2910: 61 62 6c 65 5c 66 52 29 0a 6d 61 70 70 65 64 20 able\fR).mapped
2920: 74 6f 20 74 68 65 20 76 61 72 69 61 62 6c 65 20 to the variable
2930: 5c 66 49 76 61 72 4e 61 6d 65 5c 66 52 2e 20 54 \fIvarName\fR. T
2940: 68 65 72 65 20 6d 61 79 20 62 65 20 6d 75 6c 74 here may be mult
2950: 69 70 6c 65 0a 5c 66 49 6b 65 79 5c 66 52 2f 5c iple.\fIkey\fR/\
2960: 66 49 76 61 72 4e 61 6d 65 5c 66 52 20 70 61 69 fIvarName\fR pai
2970: 72 73 2e 20 49 66 20 61 20 5c 66 49 6b 65 79 5c rs. If a \fIkey\
2980: 66 52 20 64 6f 65 73 20 6e 6f 74 20 68 61 76 65 fR does not have
2990: 20 61 20 6d 61 70 70 69 6e 67 2c 0a 74 68 61 74 a mapping,.that
29a0: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 corresponds to
29b0: 61 6e 20 75 6e 73 65 74 20 5c 66 49 76 61 72 4e an unset \fIvarN
29c0: 61 6d 65 5c 66 52 2e 20 57 68 65 6e 20 5c 66 49 ame\fR. When \fI
29d0: 62 6f 64 79 5c 66 52 0a 74 65 72 6d 69 6e 61 74 body\fR.terminat
29e0: 65 73 2c 20 61 6e 79 20 63 68 61 6e 67 65 73 20 es, any changes
29f0: 6d 61 64 65 20 74 6f 20 74 68 65 20 5c 66 49 76 made to the \fIv
2a00: 61 72 4e 61 6d 65 5c 66 52 73 20 69 73 20 72 65 arName\fRs is re
2a10: 66 6c 65 63 74 65 64 20 62 61 63 6b 0a 74 6f 20 flected back.to
2a20: 74 68 65 20 64 69 63 74 69 6f 6e 61 72 79 20 77 the dictionary w
2a30: 69 74 68 69 6e 20 5c 66 49 64 69 63 74 69 6f 6e ithin \fIdiction
2a40: 61 72 79 56 61 72 69 61 62 6c 65 5c 66 52 20 28 aryVariable\fR (
2a50: 75 6e 6c 65 73 73 0a 5c 66 49 64 69 63 74 69 6f unless.\fIdictio
2a60: 6e 61 72 79 56 61 72 69 61 62 6c 65 5c 66 52 20 naryVariable\fR
2a70: 69 74 73 65 6c 66 20 62 65 63 6f 6d 65 73 20 75 itself becomes u
2a80: 6e 72 65 61 64 61 62 6c 65 2c 20 77 68 65 6e 20 nreadable, when
2a90: 61 6c 6c 20 75 70 64 61 74 65 73 0a 61 72 65 20 all updates.are
2aa0: 73 69 6c 65 6e 74 6c 79 20 64 69 73 63 61 72 64 silently discard
2ab0: 65 64 29 2c 20 65 76 65 6e 20 69 66 20 74 68 65 ed), even if the
2ac0: 20 72 65 73 75 6c 74 20 6f 66 20 5c 66 49 62 6f result of \fIbo
2ad0: 64 79 5c 66 52 20 69 73 20 61 6e 20 65 72 72 6f dy\fR is an erro
2ae0: 72 0a 6f 72 20 73 6f 6d 65 20 6f 74 68 65 72 20 r.or some other
2af0: 6b 69 6e 64 20 6f 66 20 65 78 63 65 70 74 69 6f kind of exceptio
2b00: 6e 61 6c 20 65 78 69 74 2e 20 54 68 65 20 72 65 nal exit. The re
2b10: 73 75 6c 74 20 6f 66 20 5c 66 42 64 69 63 74 0a sult of \fBdict.
2b20: 75 70 64 61 74 65 5c 66 52 20 69 73 20 28 75 6e update\fR is (un
2b30: 6c 65 73 73 20 73 6f 6d 65 20 6b 69 6e 64 20 6f less some kind o
2b40: 66 20 65 72 72 6f 72 20 6f 63 63 75 72 73 29 20 f error occurs)
2b50: 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 74 68 the result of th
2b60: 65 0a 65 76 61 6c 75 61 74 69 6f 6e 20 6f 66 20 e.evaluation of
2b70: 5c 66 49 62 6f 64 79 5c 66 52 2e 0a 2e 52 53 0a \fIbody\fR...RS.
2b80: 2e 50 50 0a 45 61 63 68 20 5c 66 49 76 61 72 4e .PP.Each \fIvarN
2b90: 61 6d 65 5c 66 52 20 69 73 20 6d 61 70 70 65 64 ame\fR is mapped
2ba0: 20 69 6e 20 74 68 65 20 73 63 6f 70 65 20 65 6e in the scope en
2bb0: 63 6c 6f 73 69 6e 67 20 74 68 65 20 5c 66 42 64 closing the \fBd
2bc0: 69 63 74 20 75 70 64 61 74 65 5c 66 52 3b 0a 69 ict update\fR;.i
2bd0: 74 20 69 73 20 72 65 63 6f 6d 6d 65 6e 64 65 64 t is recommended
2be0: 20 74 68 61 74 20 74 68 69 73 20 63 6f 6d 6d 61 that this comma
2bf0: 6e 64 20 6f 6e 6c 79 20 62 65 20 75 73 65 64 20 nd only be used
2c00: 69 6e 20 61 20 6c 6f 63 61 6c 20 73 63 6f 70 65 in a local scope
2c10: 0a 28 5c 66 42 70 72 6f 63 5c 66 52 65 64 75 72 .(\fBproc\fRedur
2c20: 65 2c 20 6c 61 6d 62 64 61 20 74 65 72 6d 20 66 e, lambda term f
2c30: 6f 72 20 5c 66 42 61 70 70 6c 79 5c 66 52 2c 20 or \fBapply\fR,
2c40: 6f 72 20 6d 65 74 68 6f 64 29 2e 20 42 65 63 61 or method). Beca
2c50: 75 73 65 20 6f 66 0a 74 68 69 73 2c 20 74 68 65 use of.this, the
2c60: 20 76 61 72 69 61 62 6c 65 73 20 73 65 74 20 62 variables set b
2c70: 79 20 5c 66 42 64 69 63 74 20 75 70 64 61 74 65 y \fBdict update
2c80: 5c 66 52 20 77 69 6c 6c 20 63 6f 6e 74 69 6e 75 \fR will continu
2c90: 65 20 74 6f 0a 65 78 69 73 74 20 61 66 74 65 72 e to.exist after
2ca0: 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 66 69 6e the command fin
2cb0: 69 73 68 65 73 20 28 75 6e 6c 65 73 73 20 65 78 ishes (unless ex
2cc0: 70 6c 69 63 69 74 6c 79 20 5c 66 42 75 6e 73 65 plicitly \fBunse
2cd0: 74 5c 66 52 29 2e 0a 4e 6f 74 65 20 74 68 61 74 t\fR)..Note that
2ce0: 20 74 68 65 20 6d 61 70 70 69 6e 67 20 6f 66 20 the mapping of
2cf0: 76 61 6c 75 65 73 20 74 6f 20 76 61 72 69 61 62 values to variab
2d00: 6c 65 73 0a 64 6f 65 73 20 6e 6f 74 20 75 73 65 les.does not use
2d10: 20 74 72 61 63 65 73 3b 20 63 68 61 6e 67 65 73 traces; changes
2d20: 20 74 6f 20 74 68 65 20 5c 66 49 64 69 63 74 69 to the \fIdicti
2d30: 6f 6e 61 72 79 56 61 72 69 61 62 6c 65 5c 66 52 onaryVariable\fR
2d40: 27 73 0a 63 6f 6e 74 65 6e 74 73 20 6f 6e 6c 79 's.contents only
2d50: 20 68 61 70 70 65 6e 20 77 68 65 6e 20 5c 66 49 happen when \fI
2d60: 62 6f 64 79 5c 66 52 20 74 65 72 6d 69 6e 61 74 body\fR terminat
2d70: 65 73 2e 0a 2e 52 45 0a 2e 54 50 0a 5c 66 42 64 es...RE..TP.\fBd
2d80: 69 63 74 20 76 61 6c 75 65 73 20 5c 66 49 64 69 ict values \fIdi
2d90: 63 74 69 6f 6e 61 72 79 56 61 6c 75 65 20 5c 66 ctionaryValue \f
2da0: 52 3f 5c 66 49 67 6c 6f 62 50 61 74 74 65 72 6e R?\fIglobPattern
2db0: 5c 66 52 3f 0a 2e 0a 52 65 74 75 72 6e 20 61 20 \fR?...Return a
2dc0: 6c 69 73 74 20 6f 66 20 61 6c 6c 20 76 61 6c 75 list of all valu
2dd0: 65 73 20 69 6e 20 74 68 65 20 67 69 76 65 6e 20 es in the given
2de0: 64 69 63 74 69 6f 6e 61 72 79 20 76 61 6c 75 65 dictionary value
2df0: 2e 20 49 66 20 61 0a 70 61 74 74 65 72 6e 20 69 . If a.pattern i
2e00: 73 20 73 75 70 70 6c 69 65 64 2c 20 6f 6e 6c 79 s supplied, only
2e10: 20 74 68 6f 73 65 20 76 61 6c 75 65 73 20 74 68 those values th
2e20: 61 74 20 6d 61 74 63 68 20 69 74 20 28 61 63 63 at match it (acc
2e30: 6f 72 64 69 6e 67 20 74 6f 20 74 68 65 0a 72 75 ording to the.ru
2e40: 6c 65 73 20 6f 66 20 5c 66 42 73 74 72 69 6e 67 les of \fBstring
2e50: 20 6d 61 74 63 68 5c 66 52 29 20 77 69 6c 6c 20 match\fR) will
2e60: 62 65 20 72 65 74 75 72 6e 65 64 2e 20 54 68 65 be returned. The
2e70: 20 72 65 74 75 72 6e 65 64 20 76 61 6c 75 65 73 returned values
2e80: 0a 77 69 6c 6c 20 62 65 20 69 6e 20 74 68 65 20 .will be in the
2e90: 6f 72 64 65 72 20 6f 66 20 74 68 61 74 20 74 68 order of that th
2ea0: 65 20 6b 65 79 73 20 61 73 73 6f 63 69 61 74 65 e keys associate
2eb0: 64 20 77 69 74 68 20 74 68 6f 73 65 20 76 61 6c d with those val
2ec0: 75 65 73 0a 77 65 72 65 20 69 6e 73 65 72 74 65 ues.were inserte
2ed0: 64 20 69 6e 74 6f 20 74 68 65 20 64 69 63 74 69 d into the dicti
2ee0: 6f 6e 61 72 79 2e 0a 2e 54 50 0a 5c 66 42 64 69 onary...TP.\fBdi
2ef0: 63 74 20 77 69 74 68 20 5c 66 49 64 69 63 74 69 ct with \fIdicti
2f00: 6f 6e 61 72 79 56 61 72 69 61 62 6c 65 20 5c 66 onaryVariable \f
2f10: 52 3f 5c 66 49 6b 65 79 20 2e 2e 2e 5c 66 52 3f R?\fIkey ...\fR?
2f20: 20 5c 66 49 62 6f 64 79 5c 66 52 0a 2e 0a 45 78 \fIbody\fR...Ex
2f30: 65 63 75 74 65 20 74 68 65 20 54 63 6c 20 73 63 ecute the Tcl sc
2f40: 72 69 70 74 20 69 6e 20 5c 66 49 62 6f 64 79 5c ript in \fIbody\
2f50: 66 52 20 77 69 74 68 20 74 68 65 20 76 61 6c 75 fR with the valu
2f60: 65 20 66 6f 72 20 65 61 63 68 20 6b 65 79 20 69 e for each key i
2f70: 6e 0a 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 n.\fIdictionaryV
2f80: 61 72 69 61 62 6c 65 5c 66 52 20 6d 61 70 70 65 ariable\fR mappe
2f90: 64 20 28 69 6e 20 61 20 6d 61 6e 6e 65 72 20 73 d (in a manner s
2fa0: 69 6d 69 6c 61 72 6c 79 20 74 6f 20 5c 66 42 64 imilarly to \fBd
2fb0: 69 63 74 0a 75 70 64 61 74 65 5c 66 52 29 20 74 ict.update\fR) t
2fc0: 6f 20 61 20 76 61 72 69 61 62 6c 65 20 77 69 74 o a variable wit
2fd0: 68 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 2e h the same name.
2fe0: 20 57 68 65 72 65 20 6f 6e 65 20 6f 72 20 6d 6f Where one or mo
2ff0: 72 65 0a 5c 66 49 6b 65 79 5c 66 52 73 20 61 72 re.\fIkey\fRs ar
3000: 65 20 61 76 61 69 6c 61 62 6c 65 2c 20 74 68 65 e available, the
3010: 73 65 20 69 6e 64 69 63 61 74 65 20 61 20 63 68 se indicate a ch
3020: 61 69 6e 20 6f 66 20 6e 65 73 74 65 64 0a 64 69 ain of nested.di
3030: 63 74 69 6f 6e 61 72 69 65 73 2c 20 77 69 74 68 ctionaries, with
3040: 20 74 68 65 20 69 6e 6e 65 72 6d 6f 73 74 20 64 the innermost d
3050: 69 63 74 69 6f 6e 61 72 79 20 62 65 69 6e 67 20 ictionary being
3060: 74 68 65 20 6f 6e 65 20 6f 70 65 6e 65 64 20 6f the one opened o
3070: 75 74 0a 66 6f 72 20 74 68 65 20 65 78 65 63 75 ut.for the execu
3080: 74 69 6f 6e 20 6f 66 20 5c 66 49 62 6f 64 79 5c tion of \fIbody\
3090: 66 52 2e 20 41 73 20 77 69 74 68 20 5c 66 42 64 fR. As with \fBd
30a0: 69 63 74 20 75 70 64 61 74 65 5c 66 52 2c 20 6d ict update\fR, m
30b0: 61 6b 69 6e 67 0a 5c 66 49 64 69 63 74 69 6f 6e aking.\fIdiction
30c0: 61 72 79 56 61 72 69 61 62 6c 65 5c 66 52 20 75 aryVariable\fR u
30d0: 6e 72 65 61 64 61 62 6c 65 20 77 69 6c 6c 20 6d nreadable will m
30e0: 61 6b 65 20 74 68 65 20 75 70 64 61 74 65 73 20 ake the updates
30f0: 74 6f 20 74 68 65 0a 64 69 63 74 69 6f 6e 61 72 to the.dictionar
3100: 79 20 62 65 20 64 69 73 63 61 72 64 65 64 2c 20 y be discarded,
3110: 61 6e 64 20 74 68 69 73 20 61 6c 73 6f 20 68 61 and this also ha
3120: 70 70 65 6e 73 20 69 66 20 74 68 65 20 63 6f 6e ppens if the con
3130: 74 65 6e 74 73 20 6f 66 0a 5c 66 49 64 69 63 74 tents of.\fIdict
3140: 69 6f 6e 61 72 79 56 61 72 69 61 62 6c 65 5c 66 ionaryVariable\f
3150: 52 20 61 72 65 20 61 64 6a 75 73 74 65 64 20 73 R are adjusted s
3160: 6f 20 74 68 61 74 20 74 68 65 20 63 68 61 69 6e o that the chain
3170: 20 6f 66 0a 64 69 63 74 69 6f 6e 61 72 69 65 73 of.dictionaries
3180: 20 6e 6f 20 6c 6f 6e 67 65 72 20 65 78 69 73 74 no longer exist
3190: 73 2e 20 54 68 65 20 72 65 73 75 6c 74 20 6f 66 s. The result of
31a0: 20 5c 66 42 64 69 63 74 20 77 69 74 68 5c 66 52 \fBdict with\fR
31b0: 20 69 73 0a 28 75 6e 6c 65 73 73 20 73 6f 6d 65 is.(unless some
31c0: 20 6b 69 6e 64 20 6f 66 20 65 72 72 6f 72 20 6f kind of error o
31d0: 63 63 75 72 73 29 20 74 68 65 20 72 65 73 75 6c ccurs) the resul
31e0: 74 20 6f 66 20 74 68 65 20 65 76 61 6c 75 61 74 t of the evaluat
31f0: 69 6f 6e 20 6f 66 0a 5c 66 49 62 6f 64 79 5c 66 ion of.\fIbody\f
3200: 52 2e 0a 2e 52 53 0a 2e 50 50 0a 54 68 65 20 76 R...RS..PP.The v
3210: 61 72 69 61 62 6c 65 73 20 61 72 65 20 6d 61 70 ariables are map
3220: 70 65 64 20 69 6e 20 74 68 65 20 73 63 6f 70 65 ped in the scope
3230: 20 65 6e 63 6c 6f 73 69 6e 67 20 74 68 65 20 5c enclosing the \
3240: 66 42 64 69 63 74 20 77 69 74 68 5c 66 52 3b 0a fBdict with\fR;.
3250: 69 74 20 69 73 20 72 65 63 6f 6d 6d 65 6e 64 65 it is recommende
3260: 64 20 74 68 61 74 20 74 68 69 73 20 63 6f 6d 6d d that this comm
3270: 61 6e 64 20 6f 6e 6c 79 20 62 65 20 75 73 65 64 and only be used
3280: 20 69 6e 20 61 20 6c 6f 63 61 6c 20 73 63 6f 70 in a local scop
3290: 65 0a 28 5c 66 42 70 72 6f 63 5c 66 52 65 64 75 e.(\fBproc\fRedu
32a0: 72 65 2c 20 6c 61 6d 62 64 61 20 74 65 72 6d 20 re, lambda term
32b0: 66 6f 72 20 5c 66 42 61 70 70 6c 79 5c 66 52 2c for \fBapply\fR,
32c0: 20 6f 72 20 6d 65 74 68 6f 64 29 2e 20 42 65 63 or method). Bec
32d0: 61 75 73 65 20 6f 66 0a 74 68 69 73 2c 20 74 68 ause of.this, th
32e0: 65 20 76 61 72 69 61 62 6c 65 73 20 73 65 74 20 e variables set
32f0: 62 79 20 5c 66 42 64 69 63 74 20 77 69 74 68 5c by \fBdict with\
3300: 66 52 20 77 69 6c 6c 20 63 6f 6e 74 69 6e 75 65 fR will continue
3310: 20 74 6f 0a 65 78 69 73 74 20 61 66 74 65 72 20 to.exist after
3320: 74 68 65 20 63 6f 6d 6d 61 6e 64 20 66 69 6e 69 the command fini
3330: 73 68 65 73 20 28 75 6e 6c 65 73 73 20 65 78 70 shes (unless exp
3340: 6c 69 63 69 74 6c 79 20 5c 66 42 75 6e 73 65 74 licitly \fBunset
3350: 5c 66 52 29 2e 0a 4e 6f 74 65 20 74 68 61 74 20 \fR)..Note that
3360: 74 68 65 20 6d 61 70 70 69 6e 67 20 6f 66 20 76 the mapping of v
3370: 61 6c 75 65 73 20 74 6f 20 76 61 72 69 61 62 6c alues to variabl
3380: 65 73 20 64 6f 65 73 20 6e 6f 74 20 75 73 65 0a es does not use.
3390: 74 72 61 63 65 73 3b 20 63 68 61 6e 67 65 73 20 traces; changes
33a0: 74 6f 20 74 68 65 20 5c 66 49 64 69 63 74 69 6f to the \fIdictio
33b0: 6e 61 72 79 56 61 72 69 61 62 6c 65 5c 66 52 27 naryVariable\fR'
33c0: 73 20 63 6f 6e 74 65 6e 74 73 20 6f 6e 6c 79 20 s contents only
33d0: 68 61 70 70 65 6e 0a 77 68 65 6e 20 5c 66 49 62 happen.when \fIb
33e0: 6f 64 79 5c 66 52 20 74 65 72 6d 69 6e 61 74 65 ody\fR terminate
33f0: 73 2e 0a 2e 50 50 0a 49 66 20 74 68 65 20 5c 66 s...PP.If the \f
3400: 49 64 69 63 74 69 6f 6e 61 72 79 56 61 72 69 61 IdictionaryVaria
3410: 62 6c 65 5c 66 52 20 63 6f 6e 74 61 69 6e 73 20 ble\fR contains
3420: 61 20 76 61 6c 75 65 20 74 68 61 74 20 69 73 20 a value that is
3430: 6e 6f 74 20 61 20 64 69 63 74 69 6f 6e 61 72 79 not a dictionary
3440: 20 61 74 0a 74 68 65 20 70 6f 69 6e 74 20 77 68 at.the point wh
3450: 65 6e 20 74 68 65 20 5c 66 49 62 6f 64 79 5c 66 en the \fIbody\f
3460: 52 20 74 65 72 6d 69 6e 61 74 65 73 20 28 77 68 R terminates (wh
3470: 69 63 68 20 63 61 6e 20 65 61 73 69 6c 79 20 68 ich can easily h
3480: 61 70 70 65 6e 20 69 66 20 74 68 65 20 6e 61 6d appen if the nam
3490: 65 0a 69 73 20 74 68 65 20 73 61 6d 65 20 61 73 e.is the same as
34a0: 20 61 6e 79 20 6f 66 20 74 68 65 20 6b 65 79 73 any of the keys
34b0: 20 69 6e 20 64 69 63 74 69 6f 6e 61 72 79 29 20 in dictionary)
34c0: 74 68 65 6e 20 61 6e 20 65 72 72 6f 72 20 6f 63 then an error oc
34d0: 63 75 72 73 20 61 74 20 74 68 61 74 0a 70 6f 69 curs at that.poi
34e0: 6e 74 2e 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 nt. This command
34f0: 20 69 73 20 74 68 75 73 20 6e 6f 74 20 72 65 63 is thus not rec
3500: 6f 6d 6d 65 6e 64 65 64 20 66 6f 72 20 75 73 65 ommended for use
3510: 20 77 68 65 6e 20 74 68 65 20 6b 65 79 73 20 69 when the keys i
3520: 6e 20 74 68 65 0a 64 69 63 74 69 6f 6e 61 72 79 n the.dictionary
3530: 20 61 72 65 20 65 78 70 65 63 74 65 64 20 74 6f are expected to
3540: 20 63 6c 61 73 68 20 77 69 74 68 20 74 68 65 20 clash with the
3550: 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 56 61 72 \fIdictionaryVar
3560: 69 61 62 6c 65 5c 66 52 20 6e 61 6d 65 0a 69 74 iable\fR name.it
3570: 73 65 6c 66 2e 20 57 68 65 72 65 20 74 68 65 20 self. Where the
3580: 63 6f 6e 74 61 69 6e 65 64 20 6b 65 79 20 64 6f contained key do
3590: 65 73 20 6d 61 70 20 74 6f 20 61 20 64 69 63 74 es map to a dict
35a0: 69 6f 6e 61 72 79 2c 20 74 68 65 20 6e 65 74 20 ionary, the net
35b0: 65 66 66 65 63 74 20 69 73 20 74 6f 0a 63 6f 6d effect is to.com
35c0: 62 69 6e 65 20 74 68 61 74 20 69 6e 6e 65 72 20 bine that inner
35d0: 64 69 63 74 69 6f 6e 61 72 79 20 69 6e 74 6f 20 dictionary into
35e0: 74 68 65 20 6f 75 74 65 72 20 64 69 63 74 69 6f the outer dictio
35f0: 6e 61 72 79 3b 20 73 65 65 20 74 68 65 0a 5c 66 nary; see the.\f
3600: 42 45 58 41 4d 50 4c 45 53 5c 66 52 20 62 65 6c BEXAMPLES\fR bel
3610: 6f 77 20 66 6f 72 20 61 6e 20 69 6c 6c 75 73 74 ow for an illust
3620: 72 61 74 69 6f 6e 20 6f 66 20 74 68 69 73 2e 0a ration of this..
3630: 2e 52 45 0a 2e 53 48 20 22 44 49 43 54 49 4f 4e .RE..SH "DICTION
3640: 41 52 59 20 56 41 4c 55 45 53 22 0a 2e 50 50 0a ARY VALUES"..PP.
3650: 44 69 63 74 69 6f 6e 61 72 69 65 73 20 61 72 65 Dictionaries are
3660: 20 76 61 6c 75 65 73 20 74 68 61 74 20 63 6f 6e values that con
3670: 74 61 69 6e 20 61 6e 20 65 66 66 69 63 69 65 6e tain an efficien
3680: 74 2c 20 6f 72 64 65 72 2d 70 72 65 73 65 72 76 t, order-preserv
3690: 69 6e 67 0a 6d 61 70 70 69 6e 67 20 66 72 6f 6d ing.mapping from
36a0: 20 61 72 62 69 74 72 61 72 79 20 6b 65 79 73 20 arbitrary keys
36b0: 74 6f 20 61 72 62 69 74 72 61 72 79 20 76 61 6c to arbitrary val
36c0: 75 65 73 2e 0a 45 61 63 68 20 6b 65 79 20 69 6e ues..Each key in
36d0: 20 74 68 65 20 64 69 63 74 69 6f 6e 61 72 79 20 the dictionary
36e0: 6d 61 70 73 20 74 6f 20 61 20 73 69 6e 67 6c 65 maps to a single
36f0: 20 76 61 6c 75 65 2e 0a 54 68 65 79 20 68 61 76 value..They hav
3700: 65 20 61 20 74 65 78 74 75 61 6c 20 66 6f 72 6d e a textual form
3710: 61 74 20 74 68 61 74 20 69 73 20 65 78 61 63 74 at that is exact
3720: 6c 79 20 74 68 61 74 20 6f 66 20 61 6e 79 20 6c ly that of any l
3730: 69 73 74 20 77 69 74 68 20 61 6e 0a 65 76 65 6e ist with an.even
3740: 20 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 number of eleme
3750: 6e 74 73 2c 20 77 69 74 68 20 65 61 63 68 20 6d nts, with each m
3760: 61 70 70 69 6e 67 20 69 6e 20 74 68 65 20 64 69 apping in the di
3770: 63 74 69 6f 6e 61 72 79 20 62 65 69 6e 67 0a 72 ctionary being.r
3780: 65 70 72 65 73 65 6e 74 65 64 20 61 73 20 74 77 epresented as tw
3790: 6f 20 69 74 65 6d 73 20 69 6e 20 74 68 65 20 6c o items in the l
37a0: 69 73 74 2e 20 57 68 65 6e 20 61 20 63 6f 6d 6d ist. When a comm
37b0: 61 6e 64 20 74 61 6b 65 73 20 61 0a 64 69 63 74 and takes a.dict
37c0: 69 6f 6e 61 72 79 20 61 6e 64 20 70 72 6f 64 75 ionary and produ
37d0: 63 65 73 20 61 20 6e 65 77 20 64 69 63 74 69 6f ces a new dictio
37e0: 6e 61 72 79 20 62 61 73 65 64 20 6f 6e 20 69 74 nary based on it
37f0: 20 28 65 69 74 68 65 72 20 72 65 74 75 72 6e 69 (either returni
3800: 6e 67 0a 69 74 20 6f 72 20 77 72 69 74 69 6e 67 ng.it or writing
3810: 20 69 74 20 62 61 63 6b 20 69 6e 74 6f 20 74 68 it back into th
3820: 65 20 76 61 72 69 61 62 6c 65 20 74 68 61 74 20 e variable that
3830: 74 68 65 20 73 74 61 72 74 69 6e 67 20 64 69 63 the starting dic
3840: 74 69 6f 6e 61 72 79 0a 77 61 73 20 72 65 61 64 tionary.was read
3850: 20 66 72 6f 6d 29 20 74 68 65 20 6e 65 77 20 64 from) the new d
3860: 69 63 74 69 6f 6e 61 72 79 20 77 69 6c 6c 20 68 ictionary will h
3870: 61 76 65 20 74 68 65 20 73 61 6d 65 20 6f 72 64 ave the same ord
3880: 65 72 20 6f 66 20 6b 65 79 73 2c 0a 6d 6f 64 75 er of keys,.modu
3890: 6c 6f 20 61 6e 79 20 64 65 6c 65 74 65 64 20 6b lo any deleted k
38a0: 65 79 73 20 61 6e 64 20 77 69 74 68 20 6e 65 77 eys and with new
38b0: 20 6b 65 79 73 20 61 64 64 65 64 20 6f 6e 20 74 keys added on t
38c0: 6f 20 74 68 65 20 65 6e 64 2e 0a 57 68 65 6e 20 o the end..When
38d0: 61 20 73 74 72 69 6e 67 20 69 73 20 69 6e 74 65 a string is inte
38e0: 72 70 72 65 74 65 64 20 61 73 20 61 20 64 69 63 rpreted as a dic
38f0: 74 69 6f 6e 61 72 79 20 61 6e 64 20 69 74 20 77 tionary and it w
3900: 6f 75 6c 64 20 6f 74 68 65 72 77 69 73 65 0a 68 ould otherwise.h
3910: 61 76 65 20 64 75 70 6c 69 63 61 74 65 20 6b 65 ave duplicate ke
3920: 79 73 2c 20 6f 6e 6c 79 20 74 68 65 20 6c 61 73 ys, only the las
3930: 74 20 76 61 6c 75 65 20 66 6f 72 20 61 20 70 61 t value for a pa
3940: 72 74 69 63 75 6c 61 72 20 6b 65 79 20 69 73 20 rticular key is
3950: 75 73 65 64 3b 0a 74 68 65 20 6f 74 68 65 72 73 used;.the others
3960: 20 61 72 65 20 69 67 6e 6f 72 65 64 2c 20 6d 65 are ignored, me
3970: 61 6e 69 6e 67 20 74 68 61 74 2c 0a 2e 51 57 20 aning that,..QW
3980: 22 61 70 70 6c 65 20 62 61 6e 61 6e 61 22 0a 61 "apple banana".a
3990: 6e 64 0a 2e 51 57 20 22 61 70 70 6c 65 20 63 61 nd..QW "apple ca
39a0: 72 72 6f 74 20 61 70 70 6c 65 20 62 61 6e 61 6e rrot apple banan
39b0: 61 22 0a 61 72 65 20 65 71 75 69 76 61 6c 65 6e a".are equivalen
39c0: 74 20 64 69 63 74 69 6f 6e 61 72 69 65 73 20 28 t dictionaries (
39d0: 77 69 74 68 20 64 69 66 66 65 72 65 6e 74 20 73 with different s
39e0: 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74 61 tring representa
39f0: 74 69 6f 6e 73 29 2e 0a 2e 50 50 0a 4f 70 65 72 tions)...PP.Oper
3a00: 61 74 69 6f 6e 73 20 74 68 61 74 20 64 65 72 69 ations that deri
3a10: 76 65 20 61 20 6e 65 77 20 64 69 63 74 69 6f 6e ve a new diction
3a20: 61 72 79 20 66 72 6f 6d 20 61 6e 20 6f 6c 64 20 ary from an old
3a30: 6f 6e 65 20 28 65 2e 67 2e 2c 20 75 70 64 61 74 one (e.g., updat
3a40: 65 73 0a 6c 69 6b 65 20 5c 66 42 64 69 63 74 20 es.like \fBdict
3a50: 73 65 74 5c 66 52 20 61 6e 64 20 5c 66 42 64 69 set\fR and \fBdi
3a60: 63 74 20 75 6e 73 65 74 5c 66 52 29 20 70 72 65 ct unset\fR) pre
3a70: 73 65 72 76 65 20 74 68 65 20 6f 72 64 65 72 20 serve the order
3a80: 6f 66 20 6b 65 79 73 0a 69 6e 20 74 68 65 20 64 of keys.in the d
3a90: 69 63 74 69 6f 6e 61 72 79 2e 20 54 68 65 20 65 ictionary. The e
3aa0: 78 63 65 70 74 69 6f 6e 73 20 74 6f 20 74 68 69 xceptions to thi
3ab0: 73 20 61 72 65 20 66 6f 72 20 61 6e 79 20 6e 65 s are for any ne
3ac0: 77 20 6b 65 79 73 20 74 68 65 79 0a 61 64 64 2c w keys they.add,
3ad0: 20 77 68 69 63 68 20 61 72 65 20 61 70 70 65 6e which are appen
3ae0: 64 65 64 20 74 6f 20 74 68 65 20 73 65 71 75 65 ded to the seque
3af0: 6e 63 65 2c 20 61 6e 64 20 61 6e 79 20 6b 65 79 nce, and any key
3b00: 73 20 74 68 61 74 20 61 72 65 0a 72 65 6d 6f 76 s that are.remov
3b10: 65 64 2c 20 77 68 69 63 68 20 61 72 65 20 65 78 ed, which are ex
3b20: 63 69 73 65 64 20 66 72 6f 6d 20 74 68 65 20 6f cised from the o
3b30: 72 64 65 72 2e 0a 2e 53 48 20 45 58 41 4d 50 4c rder...SH EXAMPL
3b40: 45 53 0a 2e 50 50 0a 42 61 73 69 63 20 64 69 63 ES..PP.Basic dic
3b50: 74 69 6f 6e 61 72 79 20 75 73 61 67 65 3a 0a 2e tionary usage:..
3b60: 50 50 0a 2e 43 53 0a 23 20 4d 61 6b 65 20 61 20 PP..CS.# Make a
3b70: 64 69 63 74 69 6f 6e 61 72 79 20 74 6f 20 6d 61 dictionary to ma
3b80: 70 20 65 78 74 65 6e 73 69 6f 6e 73 20 74 6f 20 p extensions to
3b90: 64 65 73 63 72 69 70 74 69 6f 6e 73 0a 73 65 74 descriptions.set
3ba0: 20 66 69 6c 65 74 79 70 65 73 20 5b 5c 66 42 64 filetypes [\fBd
3bb0: 69 63 74 20 63 72 65 61 74 65 5c 66 52 20 2e 74 ict create\fR .t
3bc0: 78 74 20 22 54 65 78 74 20 46 69 6c 65 22 20 2e xt "Text File" .
3bd0: 74 63 6c 20 22 54 63 6c 20 46 69 6c 65 22 5d 0a tcl "Tcl File"].
3be0: 0a 23 20 41 64 64 2f 75 70 64 61 74 65 20 74 68 .# Add/update th
3bf0: 65 20 64 69 63 74 69 6f 6e 61 72 79 0a 5c 66 42 e dictionary.\fB
3c00: 64 69 63 74 20 73 65 74 5c 66 52 20 66 69 6c 65 dict set\fR file
3c10: 74 79 70 65 73 20 2e 74 63 6c 20 22 54 63 6c 20 types .tcl "Tcl
3c20: 53 63 72 69 70 74 22 0a 5c 66 42 64 69 63 74 20 Script".\fBdict
3c30: 73 65 74 5c 66 52 20 66 69 6c 65 74 79 70 65 73 set\fR filetypes
3c40: 20 2e 74 6d 20 20 22 54 63 6c 20 4d 6f 64 75 6c .tm "Tcl Modul
3c50: 65 22 0a 5c 66 42 64 69 63 74 20 73 65 74 5c 66 e".\fBdict set\f
3c60: 52 20 66 69 6c 65 74 79 70 65 73 20 2e 67 69 66 R filetypes .gif
3c70: 20 22 47 49 46 20 49 6d 61 67 65 22 0a 5c 66 42 "GIF Image".\fB
3c80: 64 69 63 74 20 73 65 74 5c 66 52 20 66 69 6c 65 dict set\fR file
3c90: 74 79 70 65 73 20 2e 70 6e 67 20 22 50 4e 47 20 types .png "PNG
3ca0: 49 6d 61 67 65 22 0a 0a 23 20 53 69 6d 70 6c 65 Image"..# Simple
3cb0: 20 72 65 61 64 20 66 72 6f 6d 20 74 68 65 20 64 read from the d
3cc0: 69 63 74 69 6f 6e 61 72 79 0a 73 65 74 20 65 78 ictionary.set ex
3cd0: 74 20 22 2e 74 63 6c 22 0a 73 65 74 20 64 65 73 t ".tcl".set des
3ce0: 63 20 5b 5c 66 42 64 69 63 74 20 67 65 74 5c 66 c [\fBdict get\f
3cf0: 52 20 24 66 69 6c 65 74 79 70 65 73 20 24 65 78 R $filetypes $ex
3d00: 74 5d 0a 70 75 74 73 20 22 24 65 78 74 20 69 73 t].puts "$ext is
3d10: 20 66 6f 72 20 61 20 24 64 65 73 63 22 0a 0a 23 for a $desc"..#
3d20: 20 53 6f 6d 65 77 68 61 74 20 6d 6f 72 65 20 63 Somewhat more c
3d30: 6f 6d 70 6c 65 78 2c 20 77 69 74 68 20 65 78 69 omplex, with exi
3d40: 73 74 65 6e 63 65 20 74 65 73 74 0a 66 6f 72 65 stence test.fore
3d50: 61 63 68 20 66 69 6c 65 6e 61 6d 65 20 5b 67 6c ach filename [gl
3d60: 6f 62 20 2a 5d 20 7b 0a 20 20 20 20 73 65 74 20 ob *] {. set
3d70: 65 78 74 20 5b 66 69 6c 65 20 65 78 74 65 6e 73 ext [file extens
3d80: 69 6f 6e 20 24 66 69 6c 65 6e 61 6d 65 5d 0a 20 ion $filename].
3d90: 20 20 20 69 66 20 7b 5b 5c 66 42 64 69 63 74 20 if {[\fBdict
3da0: 65 78 69 73 74 73 5c 66 52 20 24 66 69 6c 65 74 exists\fR $filet
3db0: 79 70 65 73 20 24 65 78 74 5d 7d 20 7b 0a 20 20 ypes $ext]} {.
3dc0: 20 20 20 20 20 20 70 75 74 73 20 22 24 66 69 6c puts "$fil
3dd0: 65 6e 61 6d 65 20 69 73 20 61 20 5b 5c 66 42 64 ename is a [\fBd
3de0: 69 63 74 20 67 65 74 5c 66 52 20 24 66 69 6c 65 ict get\fR $file
3df0: 74 79 70 65 73 20 24 65 78 74 5d 22 0a 20 20 20 types $ext]".
3e00: 20 7d 0a 7d 0a 2e 43 45 0a 2e 50 50 0a 43 6f 6e }.}..CE..PP.Con
3e10: 73 74 72 75 63 74 69 6e 67 20 61 6e 64 20 75 73 structing and us
3e20: 69 6e 67 20 6e 65 73 74 65 64 20 64 69 63 74 69 ing nested dicti
3e30: 6f 6e 61 72 69 65 73 3a 0a 2e 50 50 0a 2e 43 53 onaries:..PP..CS
3e40: 0a 23 20 44 61 74 61 20 66 6f 72 20 6f 6e 65 20 .# Data for one
3e50: 65 6d 70 6c 6f 79 65 65 0a 5c 66 42 64 69 63 74 employee.\fBdict
3e60: 20 73 65 74 5c 66 52 20 65 6d 70 6c 6f 79 65 65 set\fR employee
3e70: 49 6e 66 6f 20 31 32 33 34 35 2d 41 20 66 6f 72 Info 12345-A for
3e80: 65 6e 61 6d 65 73 20 22 4a 6f 65 22 0a 5c 66 42 enames "Joe".\fB
3e90: 64 69 63 74 20 73 65 74 5c 66 52 20 65 6d 70 6c dict set\fR empl
3ea0: 6f 79 65 65 49 6e 66 6f 20 31 32 33 34 35 2d 41 oyeeInfo 12345-A
3eb0: 20 73 75 72 6e 61 6d 65 20 20 20 22 53 63 68 6d surname "Schm
3ec0: 6f 65 22 0a 5c 66 42 64 69 63 74 20 73 65 74 5c oe".\fBdict set\
3ed0: 66 52 20 65 6d 70 6c 6f 79 65 65 49 6e 66 6f 20 fR employeeInfo
3ee0: 31 32 33 34 35 2d 41 20 73 74 72 65 65 74 20 22 12345-A street "
3ef0: 31 34 37 20 53 68 6f 72 74 20 53 74 72 65 65 74 147 Short Street
3f00: 22 0a 5c 66 42 64 69 63 74 20 73 65 74 5c 66 52 ".\fBdict set\fR
3f10: 20 65 6d 70 6c 6f 79 65 65 49 6e 66 6f 20 31 32 employeeInfo 12
3f20: 33 34 35 2d 41 20 63 69 74 79 20 20 20 22 53 70 345-A city "Sp
3f30: 72 69 6e 67 66 69 65 6c 64 22 0a 5c 66 42 64 69 ringfield".\fBdi
3f40: 63 74 20 73 65 74 5c 66 52 20 65 6d 70 6c 6f 79 ct set\fR employ
3f50: 65 65 49 6e 66 6f 20 31 32 33 34 35 2d 41 20 70 eeInfo 12345-A p
3f60: 68 6f 6e 65 20 20 22 35 35 35 2d 31 32 33 34 22 hone "555-1234"
3f70: 0a 23 20 44 61 74 61 20 66 6f 72 20 61 6e 6f 74 .# Data for anot
3f80: 68 65 72 20 65 6d 70 6c 6f 79 65 65 0a 5c 66 42 her employee.\fB
3f90: 64 69 63 74 20 73 65 74 5c 66 52 20 65 6d 70 6c dict set\fR empl
3fa0: 6f 79 65 65 49 6e 66 6f 20 39 38 33 37 32 2d 4a oyeeInfo 98372-J
3fb0: 20 66 6f 72 65 6e 61 6d 65 73 20 22 41 6e 6e 65 forenames "Anne
3fc0: 22 0a 5c 66 42 64 69 63 74 20 73 65 74 5c 66 52 ".\fBdict set\fR
3fd0: 20 65 6d 70 6c 6f 79 65 65 49 6e 66 6f 20 39 38 employeeInfo 98
3fe0: 33 37 32 2d 4a 20 73 75 72 6e 61 6d 65 20 20 20 372-J surname
3ff0: 22 4f 74 68 65 72 22 0a 5c 66 42 64 69 63 74 20 "Other".\fBdict
4000: 73 65 74 5c 66 52 20 65 6d 70 6c 6f 79 65 65 49 set\fR employeeI
4010: 6e 66 6f 20 39 38 33 37 32 2d 4a 20 73 74 72 65 nfo 98372-J stre
4020: 65 74 20 22 33 32 39 39 35 20 4f 61 6b 64 61 6c et "32995 Oakdal
4030: 65 20 57 61 79 22 0a 5c 66 42 64 69 63 74 20 73 e Way".\fBdict s
4040: 65 74 5c 66 52 20 65 6d 70 6c 6f 79 65 65 49 6e et\fR employeeIn
4050: 66 6f 20 39 38 33 37 32 2d 4a 20 63 69 74 79 20 fo 98372-J city
4060: 20 20 22 53 70 72 69 6e 67 66 69 65 6c 64 22 0a "Springfield".
4070: 5c 66 42 64 69 63 74 20 73 65 74 5c 66 52 20 65 \fBdict set\fR e
4080: 6d 70 6c 6f 79 65 65 49 6e 66 6f 20 39 38 33 37 mployeeInfo 9837
4090: 32 2d 4a 20 70 68 6f 6e 65 20 20 22 35 35 35 2d 2-J phone "555-
40a0: 38 37 36 35 22 0a 23 20 54 68 65 20 61 62 6f 76 8765".# The abov
40b0: 65 20 64 61 74 61 20 70 72 6f 62 61 62 6c 79 20 e data probably
40c0: 6f 75 67 68 74 20 74 6f 20 63 6f 6d 65 20 66 72 ought to come fr
40d0: 6f 6d 20 61 20 64 61 74 61 62 61 73 65 2e 2e 2e om a database...
40e0: 0a 0a 23 20 50 72 69 6e 74 20 6f 75 74 20 73 6f ..# Print out so
40f0: 6d 65 20 65 6d 70 6c 6f 79 65 65 20 69 6e 66 6f me employee info
4100: 0a 73 65 74 20 69 20 30 0a 70 75 74 73 20 22 54 .set i 0.puts "T
4110: 68 65 72 65 20 61 72 65 20 5b 5c 66 42 64 69 63 here are [\fBdic
4120: 74 20 73 69 7a 65 5c 66 52 20 24 65 6d 70 6c 6f t size\fR $emplo
4130: 79 65 65 49 6e 66 6f 5d 20 65 6d 70 6c 6f 79 65 yeeInfo] employe
4140: 65 73 22 0a 5c 66 42 64 69 63 74 20 66 6f 72 5c es".\fBdict for\
4150: 66 52 20 7b 69 64 20 69 6e 66 6f 7d 20 24 65 6d fR {id info} $em
4160: 70 6c 6f 79 65 65 49 6e 66 6f 20 7b 0a 20 20 20 ployeeInfo {.
4170: 20 70 75 74 73 20 22 45 6d 70 6c 6f 79 65 65 20 puts "Employee
4180: 23 5b 69 6e 63 72 20 69 5d 3a 20 24 69 64 22 0a #[incr i]: $id".
4190: 20 20 20 20 5c 66 42 64 69 63 74 20 77 69 74 68 \fBdict with
41a0: 5c 66 52 20 69 6e 66 6f 20 7b 0a 20 20 20 20 20 \fR info {.
41b0: 20 20 20 70 75 74 73 20 22 20 20 20 4e 61 6d 65 puts " Name
41c0: 3a 20 24 66 6f 72 65 6e 61 6d 65 73 20 24 73 75 : $forenames $su
41d0: 72 6e 61 6d 65 22 0a 20 20 20 20 20 20 20 20 70 rname". p
41e0: 75 74 73 20 22 20 20 20 41 64 64 72 65 73 73 3a uts " Address:
41f0: 20 24 73 74 72 65 65 74 2c 20 24 63 69 74 79 22 $street, $city"
4200: 0a 20 20 20 20 20 20 20 20 70 75 74 73 20 22 20 . puts "
4210: 20 20 54 65 6c 65 70 68 6f 6e 65 3a 20 24 70 68 Telephone: $ph
4220: 6f 6e 65 22 0a 20 20 20 20 7d 0a 7d 0a 23 20 41 one". }.}.# A
4230: 6e 6f 74 68 65 72 20 77 61 79 20 74 6f 20 69 74 nother way to it
4240: 65 72 61 74 65 20 61 6e 64 20 70 69 63 6b 20 6f erate and pick o
4250: 75 74 20 6e 61 6d 65 73 2e 2e 2e 0a 66 6f 72 65 ut names....fore
4260: 61 63 68 20 69 64 20 5b 5c 66 42 64 69 63 74 20 ach id [\fBdict
4270: 6b 65 79 73 5c 66 52 20 24 65 6d 70 6c 6f 79 65 keys\fR $employe
4280: 65 49 6e 66 6f 5d 20 7b 0a 20 20 20 20 70 75 74 eInfo] {. put
4290: 73 20 22 48 65 6c 6c 6f 2c 20 5b 5c 66 42 64 69 s "Hello, [\fBdi
42a0: 63 74 20 67 65 74 5c 66 52 20 24 65 6d 70 6c 6f ct get\fR $emplo
42b0: 79 65 65 49 6e 66 6f 20 24 69 64 20 66 6f 72 65 yeeInfo $id fore
42c0: 6e 61 6d 65 73 5d 21 22 0a 7d 0a 2e 43 45 0a 2e names]!".}..CE..
42d0: 50 50 0a 41 20 6c 6f 63 61 6c 69 7a 61 62 6c 65 PP.A localizable
42e0: 20 76 65 72 73 69 6f 6e 20 6f 66 20 5c 66 42 73 version of \fBs
42f0: 74 72 69 6e 67 20 74 6f 75 70 70 65 72 5c 66 52 tring toupper\fR
4300: 3a 0a 2e 50 50 0a 2e 43 53 0a 23 20 53 65 74 20 :..PP..CS.# Set
4310: 75 70 20 74 68 65 20 62 61 73 69 63 20 43 20 6c up the basic C l
4320: 6f 63 61 6c 65 0a 73 65 74 20 63 61 70 69 74 61 ocale.set capita
4330: 6c 20 5b 5c 66 42 64 69 63 74 20 63 72 65 61 74 l [\fBdict creat
4340: 65 5c 66 52 20 43 20 5b 5c 66 42 64 69 63 74 20 e\fR C [\fBdict
4350: 63 72 65 61 74 65 5c 66 52 5d 5d 0a 66 6f 72 65 create\fR]].fore
4360: 61 63 68 20 63 20 5b 73 70 6c 69 74 20 7b 61 62 ach c [split {ab
4370: 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 cdefghijklmnopqr
4380: 73 74 75 76 77 78 79 7a 7d 20 22 22 5d 20 7b 0a stuvwxyz} ""] {.
4390: 20 20 20 20 5c 66 42 64 69 63 74 20 73 65 74 5c \fBdict set\
43a0: 66 52 20 63 61 70 69 74 61 6c 20 43 20 24 63 20 fR capital C $c
43b0: 5b 73 74 72 69 6e 67 20 74 6f 75 70 70 65 72 20 [string toupper
43c0: 24 63 5d 0a 7d 0a 0a 23 20 45 6e 67 6c 69 73 68 $c].}..# English
43d0: 20 6c 6f 63 61 6c 65 73 20 63 61 6e 20 6c 75 63 locales can luc
43e0: 6b 69 6c 79 20 73 68 61 72 65 20 74 68 65 20 22 kily share the "
43f0: 43 22 20 6c 6f 63 61 6c 65 0a 5c 66 42 64 69 63 C" locale.\fBdic
4400: 74 20 73 65 74 5c 66 52 20 63 61 70 69 74 61 6c t set\fR capital
4410: 20 65 6e 20 5b 5c 66 42 64 69 63 74 20 67 65 74 en [\fBdict get
4420: 5c 66 52 20 24 63 61 70 69 74 61 6c 20 43 5d 0a \fR $capital C].
4430: 5c 66 42 64 69 63 74 20 73 65 74 5c 66 52 20 63 \fBdict set\fR c
4440: 61 70 69 74 61 6c 20 65 6e 5f 55 53 20 5b 5c 66 apital en_US [\f
4450: 42 64 69 63 74 20 67 65 74 5c 66 52 20 24 63 61 Bdict get\fR $ca
4460: 70 69 74 61 6c 20 43 5d 0a 5c 66 42 64 69 63 74 pital C].\fBdict
4470: 20 73 65 74 5c 66 52 20 63 61 70 69 74 61 6c 20 set\fR capital
4480: 65 6e 5f 47 42 20 5b 5c 66 42 64 69 63 74 20 67 en_GB [\fBdict g
4490: 65 74 5c 66 52 20 24 63 61 70 69 74 61 6c 20 43 et\fR $capital C
44a0: 5d 0a 0a 23 20 2e 2e 2e 20 61 6e 64 20 73 6f 20 ]..# ... and so
44b0: 6f 6e 20 66 6f 72 20 6f 74 68 65 72 20 73 75 70 on for other sup
44c0: 70 6f 72 74 65 64 20 6c 61 6e 67 75 61 67 65 73 ported languages
44d0: 20 2e 2e 2e 0a 0a 23 20 4e 6f 77 20 67 65 74 20 .....# Now get
44e0: 74 68 65 20 6d 61 70 70 69 6e 67 20 66 6f 72 20 the mapping for
44f0: 74 68 65 20 63 75 72 72 65 6e 74 20 6c 6f 63 61 the current loca
4500: 6c 65 20 61 6e 64 20 75 73 65 20 69 74 2e 0a 73 le and use it..s
4510: 65 74 20 75 70 70 65 72 43 61 73 65 4d 61 70 20 et upperCaseMap
4520: 5b 5c 66 42 64 69 63 74 20 67 65 74 5c 66 52 20 [\fBdict get\fR
4530: 24 63 61 70 69 74 61 6c 20 24 65 6e 76 28 4c 41 $capital $env(LA
4540: 4e 47 29 5d 0a 73 65 74 20 75 70 70 65 72 43 61 NG)].set upperCa
4550: 73 65 20 5b 73 74 72 69 6e 67 20 6d 61 70 20 24 se [string map $
4560: 75 70 70 65 72 43 61 73 65 4d 61 70 20 24 73 74 upperCaseMap $st
4570: 72 69 6e 67 5d 0a 2e 43 45 0a 2e 50 50 0a 53 68 ring]..CE..PP.Sh
4580: 6f 77 69 6e 67 20 74 68 65 20 64 65 74 61 69 6c owing the detail
4590: 20 6f 66 20 5c 66 42 64 69 63 74 20 77 69 74 68 of \fBdict with
45a0: 5c 66 52 3a 0a 2e 50 50 0a 2e 43 53 0a 70 72 6f \fR:..PP..CS.pro
45b0: 63 20 73 75 6d 44 69 63 74 69 6f 6e 61 72 79 20 c sumDictionary
45c0: 7b 76 61 72 4e 61 6d 65 7d 20 7b 0a 20 20 20 20 {varName} {.
45d0: 75 70 76 61 72 20 31 20 24 76 61 72 4e 61 6d 65 upvar 1 $varName
45e0: 20 76 62 6c 0a 20 20 20 20 66 6f 72 65 61 63 68 vbl. foreach
45f0: 20 6b 65 79 20 5b 5c 66 42 64 69 63 74 20 6b 65 key [\fBdict ke
4600: 79 73 5c 66 52 20 24 76 62 6c 5d 20 7b 0a 20 20 ys\fR $vbl] {.
4610: 20 20 20 20 20 20 23 20 4d 61 6e 75 66 61 63 74 # Manufact
4620: 75 72 65 20 61 6e 20 65 6e 74 72 79 20 69 6e 20 ure an entry in
4630: 74 68 65 20 73 75 62 64 69 63 74 69 6f 6e 61 72 the subdictionar
4640: 79 0a 20 20 20 20 20 20 20 20 5c 66 42 64 69 63 y. \fBdic
4650: 74 20 73 65 74 5c 66 52 20 76 62 6c 20 24 6b 65 t set\fR vbl $ke
4660: 79 20 74 6f 74 61 6c 20 30 0a 20 20 20 20 20 20 y total 0.
4670: 20 20 23 20 41 64 64 20 74 68 65 20 76 61 6c 75 # Add the valu
4680: 65 73 20 61 6e 64 20 72 65 6d 6f 76 65 20 74 68 es and remove th
4690: 65 20 6f 6c 64 0a 20 20 20 20 20 20 20 20 5c 66 e old. \f
46a0: 42 64 69 63 74 20 77 69 74 68 5c 66 52 20 76 62 Bdict with\fR vb
46b0: 6c 20 24 6b 65 79 20 7b 0a 20 20 20 20 20 20 20 l $key {.
46c0: 20 20 20 20 20 73 65 74 20 74 6f 74 61 6c 20 5b set total [
46d0: 65 78 70 72 20 7b 24 78 20 2b 20 24 79 20 2b 20 expr {$x + $y +
46e0: 24 7a 7d 5d 0a 20 20 20 20 20 20 20 20 20 20 20 $z}].
46f0: 20 75 6e 73 65 74 20 78 20 79 20 7a 0a 20 20 20 unset x y z.
4700: 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 }. }.
4710: 20 70 75 74 73 20 22 6c 61 73 74 20 74 6f 74 61 puts "last tota
4720: 6c 20 77 61 73 20 24 74 6f 74 61 6c 2c 20 66 6f l was $total, fo
4730: 72 20 6b 65 79 20 24 6b 65 79 22 0a 7d 0a 0a 73 r key $key".}..s
4740: 65 74 20 6d 79 44 69 63 74 20 7b 0a 20 20 20 20 et myDict {.
4750: 61 20 7b 78 20 31 20 79 20 32 20 7a 20 33 7d 0a a {x 1 y 2 z 3}.
4760: 20 20 20 20 62 20 7b 78 20 36 20 79 20 35 20 7a b {x 6 y 5 z
4770: 20 34 7d 0a 7d 0a 0a 73 75 6d 44 69 63 74 69 6f 4}.}..sumDictio
4780: 6e 61 72 79 20 6d 79 44 69 63 74 0a 23 20 20 20 nary myDict.#
4790: 20 70 72 69 6e 74 73 3a 20 5c 66 49 6c 61 73 74 prints: \fIlast
47a0: 20 74 6f 74 61 6c 20 77 61 73 20 31 35 2c 20 66 total was 15, f
47b0: 6f 72 20 6b 65 79 20 62 5c 66 52 0a 0a 70 75 74 or key b\fR..put
47c0: 73 20 22 64 69 63 74 69 6f 6e 61 72 79 20 69 73 s "dictionary is
47d0: 20 6e 6f 77 20 5c 5c 22 24 6d 79 44 69 63 74 5c now \\"$myDict\
47e0: 5c 22 22 0a 23 20 20 20 20 70 72 69 6e 74 73 3a \"".# prints:
47f0: 20 5c 66 49 64 69 63 74 69 6f 6e 61 72 79 20 69 \fIdictionary i
4800: 73 20 6e 6f 77 20 22 61 20 7b 74 6f 74 61 6c 20 s now "a {total
4810: 36 7d 20 62 20 7b 74 6f 74 61 6c 20 31 35 7d 22 6} b {total 15}"
4820: 5c 66 52 0a 2e 43 45 0a 2e 50 50 0a 57 68 65 6e \fR..CE..PP.When
4830: 20 5c 66 42 64 69 63 74 20 77 69 74 68 5c 66 52 \fBdict with\fR
4840: 20 69 73 20 75 73 65 64 20 77 69 74 68 20 61 20 is used with a
4850: 6b 65 79 20 74 68 61 74 20 63 6c 61 73 68 65 73 key that clashes
4860: 20 77 69 74 68 20 74 68 65 20 6e 61 6d 65 20 6f with the name o
4870: 66 20 74 68 65 0a 64 69 63 74 69 6f 6e 61 72 79 f the.dictionary
4880: 20 76 61 72 69 61 62 6c 65 3a 0a 2e 50 50 0a 2e variable:..PP..
4890: 43 53 0a 73 65 74 20 66 6f 6f 20 7b 66 6f 6f 20 CS.set foo {foo
48a0: 7b 61 20 62 7d 20 62 61 72 20 32 20 62 61 7a 20 {a b} bar 2 baz
48b0: 33 7d 0a 5c 66 42 64 69 63 74 20 77 69 74 68 5c 3}.\fBdict with\
48c0: 66 52 20 66 6f 6f 20 7b 7d 0a 70 75 74 73 20 24 fR foo {}.puts $
48d0: 66 6f 6f 0a 23 20 20 20 20 70 72 69 6e 74 73 3a foo.# prints:
48e0: 20 5c 66 49 61 20 62 20 66 6f 6f 20 7b 61 20 62 \fIa b foo {a b
48f0: 7d 20 62 61 72 20 32 20 62 61 7a 20 33 5c 66 52 } bar 2 baz 3\fR
4900: 0a 2e 43 45 0a 2e 53 48 20 22 53 45 45 20 41 4c ..CE..SH "SEE AL
4910: 53 4f 22 0a 61 70 70 65 6e 64 28 6e 29 2c 20 61 SO".append(n), a
4920: 72 72 61 79 28 6e 29 2c 20 66 6f 72 65 61 63 68 rray(n), foreach
4930: 28 6e 29 2c 20 69 6e 63 72 28 6e 29 2c 20 6c 69 (n), incr(n), li
4940: 73 74 28 6e 29 2c 20 6c 61 70 70 65 6e 64 28 6e st(n), lappend(n
4950: 29 2c 20 6c 6d 61 70 28 6e 29 2c 20 73 65 74 28 ), lmap(n), set(
4960: 6e 29 0a 2e 53 48 20 4b 45 59 57 4f 52 44 53 0a n)..SH KEYWORDS.
4970: 64 69 63 74 69 6f 6e 61 72 79 2c 20 63 72 65 61 dictionary, crea
4980: 74 65 2c 20 75 70 64 61 74 65 2c 20 6c 6f 6f 6b te, update, look
4990: 75 70 2c 20 69 74 65 72 61 74 65 2c 20 66 69 6c up, iterate, fil
49a0: 74 65 72 2c 20 6d 61 70 0a 27 5c 22 20 4c 6f 63 ter, map.'\" Loc
49b0: 61 6c 20 56 61 72 69 61 62 6c 65 73 3a 0a 27 5c al Variables:.'\
49c0: 22 20 6d 6f 64 65 3a 20 6e 72 6f 66 66 0a 27 5c " mode: nroff.'\
49d0: 22 20 45 6e 64 3a 0a " End:.