Hex Artifact Content

Login

Artifact 74af8aa08f3296a523b0d2e073304338fd06e286ab823983ce620c3ee0dc364e:


0000: 54 49 50 3a 20 20 20 20 20 20 20 20 20 20 20 20  TIP:            
0010: 31 37 30 0a 54 69 74 6c 65 3a 20 20 20 20 20 20  170.Title:      
0020: 20 20 20 20 42 65 74 74 65 72 20 53 75 70 70 6f      Better Suppo
0030: 72 74 20 66 6f 72 20 4e 65 73 74 65 64 20 4c 69  rt for Nested Li
0040: 73 74 73 0a 56 65 72 73 69 6f 6e 3a 20 20 20 20  sts.Version:    
0050: 20 20 20 20 24 52 65 76 69 73 69 6f 6e 3a 20 31      $Revision: 1
0060: 2e 33 20 24 0a 41 75 74 68 6f 72 3a 20 20 20 20  .3 $.Author:    
0070: 20 20 20 20 20 53 65 72 67 65 79 20 42 61 62 6b       Sergey Babk
0080: 69 6e 20 3c 62 61 62 6b 69 6e 40 66 72 65 65 62  in <babkin@freeb
0090: 73 64 2e 6f 72 67 3e 0a 41 75 74 68 6f 72 3a 20  sd.org>.Author: 
00a0: 20 20 20 20 20 20 20 20 44 6f 6e 20 50 6f 72 74          Don Port
00b0: 65 72 20 3c 64 67 70 40 75 73 65 72 73 2e 73 66  er <[email protected]
00c0: 2e 6e 65 74 3e 0a 53 74 61 74 65 3a 20 20 20 20  .net>.State:    
00d0: 20 20 20 20 20 20 44 72 61 66 74 0a 54 79 70 65        Draft.Type
00e0: 3a 20 20 20 20 20 20 20 20 20 20 20 50 72 6f 6a  :           Proj
00f0: 65 63 74 0a 56 6f 74 65 3a 20 20 20 20 20 20 20  ect.Vote:       
0100: 20 20 20 20 50 65 6e 64 69 6e 67 0a 43 72 65 61      Pending.Crea
0110: 74 65 64 3a 20 20 20 20 20 20 20 20 33 30 2d 4a  ted:        30-J
0120: 61 6e 2d 32 30 30 34 0a 50 6f 73 74 2d 48 69 73  an-2004.Post-His
0130: 74 6f 72 79 3a 20 20 20 0a 54 63 6c 2d 56 65 72  tory:   .Tcl-Ver
0140: 73 69 6f 6e 3a 20 20 20 20 38 2e 35 0a 0a 7e 20  sion:    8.5..~ 
0150: 41 62 73 74 72 61 63 74 0a 0a 4e 65 73 74 65 64  Abstract..Nested
0160: 20 6c 69 73 74 73 20 61 72 65 20 65 61 73 79 20   lists are easy 
0170: 74 6f 20 63 72 65 61 74 65 20 77 69 74 68 20 54  to create with T
0180: 63 6c 20 62 75 74 20 74 68 65 6e 20 6d 61 6e 69  cl but then mani
0190: 70 75 6c 61 74 69 6e 67 20 74 68 65 6d 20 69 73  pulating them is
01a0: 0a 6e 6f 74 20 65 61 73 79 2e 20 46 6f 72 20 65  .not easy. For e
01b0: 78 61 6d 70 6c 65 2c 20 74 68 69 6e 6b 20 61 62  xample, think ab
01c0: 6f 75 74 20 68 6f 77 20 74 6f 20 63 68 61 6e 67  out how to chang
01d0: 65 20 61 20 76 61 6c 75 65 20 6e 65 73 74 65 64  e a value nested
01e0: 20 69 6e 20 61 0a 6c 69 73 74 20 32 20 6c 65 76   in a.list 2 lev
01f0: 65 6c 73 20 64 65 65 70 3f 20 20 48 6f 77 20 61  els deep?  How a
0200: 62 6f 75 74 20 34 20 6c 65 76 65 6c 73 20 64 65  bout 4 levels de
0210: 65 70 3f 20 20 54 68 65 20 70 72 6f 70 6f 73 65  ep?  The propose
0220: 64 20 6e 65 77 0a 63 6f 6d 6d 61 6e 64 73 20 6d  d new.commands m
0230: 61 6b 65 20 73 75 63 68 20 6d 61 6e 69 70 75 6c  ake such manipul
0240: 61 74 69 6f 6e 20 65 61 73 79 2c 20 61 6e 64 20  ation easy, and 
0250: 6d 61 6b 65 20 74 68 65 20 6e 65 73 74 65 64 20  make the nested 
0260: 6c 69 73 74 73 20 61 0a 67 72 65 61 74 20 72 65  lists a.great re
0270: 70 6c 61 63 65 6d 65 6e 74 20 66 6f 72 20 61 72  placement for ar
0280: 72 61 79 73 20 61 6e 64 20 73 74 72 75 63 74 75  rays and structu
0290: 72 65 73 20 69 6e 20 43 2d 6c 69 6b 65 20 6c 61  res in C-like la
02a0: 6e 67 75 61 67 65 73 2e 0a 0a 7e 52 61 74 69 6f  nguages...~Ratio
02b0: 6e 61 6c 65 20 61 6e 64 20 53 70 65 63 69 66 69  nale and Specifi
02c0: 63 61 74 69 6f 6e 0a 0a 54 68 65 20 6e 65 77 20  cation..The new 
02d0: 70 72 6f 70 6f 73 65 64 20 63 6f 6d 6d 61 6e 64  proposed command
02e0: 73 20 73 74 61 72 74 20 77 69 74 68 20 74 68 65  s start with the
02f0: 20 70 72 65 66 69 78 20 22 6c 64 65 65 70 22 2e   prefix "ldeep".
0300: 20 54 68 65 79 20 61 72 65 0a 64 65 73 67 69 6e   They are.desgin
0310: 65 64 20 74 6f 20 72 65 73 65 6d 62 6c 65 20 74  ed to resemble t
0320: 68 65 20 63 6c 61 73 73 69 63 20 6c 69 73 74 20  he classic list 
0330: 63 6f 6d 6d 61 6e 64 73 20 77 69 74 68 20 22 6c  commands with "l
0340: 22 20 6e 61 6d 65 73 2e 20 49 6e 20 74 68 65 0a  " names. In the.
0350: 63 61 73 65 73 20 77 68 65 6e 20 74 68 65 20 6d  cases when the m
0360: 65 61 6e 69 6e 67 20 6f 66 20 22 6c 64 65 65 70  eaning of "ldeep
0370: 22 20 63 6f 6d 6d 61 6e 64 20 64 69 66 66 65 72  " command differ
0380: 73 20 73 75 62 73 74 61 6e 74 69 61 6c 6c 79 20  s substantially 
0390: 66 72 6f 6d 0a 74 68 65 20 22 6c 22 20 63 6f 6d  from.the "l" com
03a0: 6d 61 6e 64 2c 20 74 68 65 20 6e 61 6d 65 20 68  mand, the name h
03b0: 61 73 20 62 65 65 6e 20 73 65 6c 65 63 74 65 64  as been selected
03c0: 20 74 6f 20 62 65 20 64 69 66 66 65 72 65 6e 74   to be different
03d0: 20 28 73 75 63 68 20 61 73 0a 22 6c 64 65 65 70   (such as."ldeep
03e0: 72 65 70 22 2c 20 6e 6f 74 20 22 6c 64 65 65 70  rep", not "ldeep
03f0: 72 65 70 6c 61 63 65 22 29 2e 0a 0a 54 68 65 20  replace")...The 
0400: 63 6f 6d 6d 61 6e 64 73 20 68 61 76 65 20 62 65  commands have be
0410: 65 6e 20 65 78 74 65 6e 73 69 76 65 6c 79 20 75  en extensively u
0420: 73 65 64 20 69 6e 20 74 68 65 20 4e 6f 74 20 41  sed in the Not A
0430: 20 43 6f 6d 6d 61 6e 64 65 72 20 70 72 6f 6a 65   Commander proje
0440: 63 74 0a 5b 68 74 74 70 3a 2f 2f 6e 61 63 2e 73  ct.[http://nac.s
0450: 66 2e 6e 65 74 2f 5d 20 61 6e 64 20 68 61 76 65  f.net/] and have
0460: 20 62 65 65 6e 20 61 64 6a 75 73 74 65 64 20 74   been adjusted t
0470: 6f 20 74 68 65 20 6f 62 73 65 72 76 65 64 20 6e  o the observed n
0480: 65 65 64 73 20 6f 66 0a 70 72 61 63 74 69 63 61  eeds of.practica
0490: 6c 20 75 73 65 2e 0a 0a 41 6c 6c 20 74 68 65 73  l use...All thes
04a0: 65 20 63 6f 6d 6d 61 6e 64 20 75 73 65 20 74 68  e command use th
04b0: 65 20 63 6f 6e 63 65 70 74 20 6f 66 20 22 70 61  e concept of "pa
04c0: 74 68 22 2e 20 54 68 65 20 69 64 65 61 20 69 73  th". The idea is
04d0: 20 74 68 61 74 20 79 6f 75 20 63 61 6e 0a 69 64   that you can.id
04e0: 65 6e 74 69 66 79 20 61 20 6c 6f 63 61 74 69 6f  entify a locatio
04f0: 6e 20 69 6e 20 61 20 6e 65 73 74 65 64 20 6c 69  n in a nested li
0500: 73 74 20 62 79 20 61 20 73 65 71 75 65 6e 63 65  st by a sequence
0510: 20 6f 66 20 69 6e 64 65 78 65 73 2e 20 46 6f 72   of indexes. For
0520: 0a 65 78 61 6d 70 6c 65 2c 20 74 68 65 20 70 61  .example, the pa
0530: 74 68 20 22 31 20 32 20 33 22 20 69 64 65 6e 74  th "1 2 3" ident
0540: 69 66 69 65 73 20 74 68 65 20 65 6c 65 6d 65 6e  ifies the elemen
0550: 74 20 74 68 61 74 20 63 61 6e 20 62 65 20 61 63  t that can be ac
0560: 63 65 73 73 65 64 0a 61 73 0a 0a 7c 20 20 5b 6c  cessed.as..|  [l
0570: 69 6e 64 65 78 20 5b 6c 69 6e 64 65 78 20 20 5b  index [lindex  [
0580: 6c 69 6e 64 65 78 20 24 6c 69 73 74 20 31 5d 20  lindex $list 1] 
0590: 32 5d 20 33 5d 0a 0a 41 20 70 61 74 68 20 63 61  2] 3]..A path ca
05a0: 6e 20 62 65 20 6e 61 74 75 72 61 6c 6c 79 20 72  n be naturally r
05b0: 65 70 72 65 73 65 6e 74 65 64 20 61 73 20 61 20  epresented as a 
05c0: 6c 69 73 74 20 69 74 73 65 6c 66 2e 20 49 6e 20  list itself. In 
05d0: 70 72 61 63 74 69 63 65 20 69 74 0a 69 73 20 61  practice it.is a
05e0: 6c 73 6f 20 63 6f 6e 76 65 6e 69 65 6e 74 20 74  lso convenient t
05f0: 6f 20 73 70 65 63 69 66 79 20 70 61 74 68 73 20  o specify paths 
0600: 61 73 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 6c  as two or more l
0610: 69 73 74 73 20 74 68 61 74 20 67 65 74 0a 6c 6f  ists that get.lo
0620: 67 69 63 61 6c 6c 79 20 63 6f 6e 63 61 74 65 6e  gically concaten
0630: 61 74 65 64 20 77 69 74 68 69 6e 20 61 20 63 6f  ated within a co
0640: 6d 6d 61 6e 64 2c 20 74 6f 20 72 65 70 72 65 73  mmand, to repres
0650: 65 6e 74 20 61 20 22 62 61 73 65 0a 6c 6f 63 61  ent a "base.loca
0660: 74 69 6f 6e 22 20 28 74 68 65 20 66 69 72 73 74  tion" (the first
0670: 20 6c 69 73 74 29 20 61 6e 64 20 22 6c 6f 63 61   list) and "loca
0680: 74 69 6f 6e 20 72 65 6c 61 74 69 76 65 20 74 6f  tion relative to
0690: 20 74 68 65 20 62 61 73 65 22 20 28 74 68 65 0a   the base" (the.
06a0: 73 65 63 6f 6e 64 20 6c 69 73 74 29 2e 20 41 6e  second list). An
06b0: 20 65 6d 70 74 79 20 70 61 74 68 20 6c 69 73 74   empty path list
06c0: 20 69 73 20 61 6c 73 6f 20 76 61 6c 69 64 2c 20   is also valid, 
06d0: 69 74 20 6d 65 61 6e 73 20 22 74 68 65 20 77 68  it means "the wh
06e0: 6f 6c 65 0a 6f 72 69 67 69 6e 61 6c 20 6c 69 73  ole.original lis
06f0: 74 22 2e 20 54 68 65 20 63 75 72 72 65 6e 74 20  t". The current 
0700: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 64  implementation d
0710: 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f 72 74 20  oes not support 
0720: 22 65 6e 64 22 20 61 73 20 61 0a 76 61 6c 69 64  "end" as a.valid
0730: 20 65 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 20   element of the 
0740: 70 61 74 68 20 73 69 6e 63 65 20 69 74 20 64 6f  path since it do
0750: 65 73 20 6e 6f 74 20 73 65 65 6d 20 74 6f 20 6d  es not seem to m
0760: 61 6b 65 20 6d 75 63 68 20 73 65 6e 73 65 3a 0a  ake much sense:.
0770: 74 68 65 20 6c 6f 63 61 74 69 6f 6e 20 69 64 65  the location ide
0780: 6e 74 69 66 69 65 64 20 62 79 20 73 75 63 68 20  ntified by such 
0790: 61 20 70 61 74 68 20 77 6f 75 6c 64 20 66 6c 6f  a path would flo
07a0: 61 74 20 61 73 20 74 68 65 20 6c 65 6e 67 74 68  at as the length
07b0: 20 6f 66 0a 74 68 65 20 69 6e 74 65 72 6d 65 64   of.the intermed
07c0: 69 61 74 65 20 6c 69 73 74 73 20 63 68 61 6e 67  iate lists chang
07d0: 65 73 2e 20 42 75 74 20 69 74 20 63 61 6e 20 62  es. But it can b
07e0: 65 20 61 64 64 65 64 20 69 66 20 64 65 73 69 72  e added if desir
07f0: 65 64 2e 0a 0a 54 68 65 20 6e 65 77 20 70 72 6f  ed...The new pro
0800: 70 6f 73 65 64 20 63 6f 6d 6d 61 6e 64 73 20 61  posed commands a
0810: 72 65 3a 0a 0a 7c 6c 64 65 65 70 69 6e 64 65 78  re:..|ldeepindex
0820: 20 6c 69 73 74 20 70 61 74 68 20 3f 70 61 74 68   list path ?path
0830: 3f 2e 2e 2e 0a 0a 20 3e 20 45 78 74 72 61 63 74  ?..... > Extract
0840: 20 61 6e 20 65 6c 65 6d 65 6e 74 20 66 72 6f 6d   an element from
0850: 20 61 20 6e 65 73 74 65 64 20 6c 69 73 74 2e 20   a nested list. 
0860: 54 68 65 20 65 6c 65 6d 65 6e 74 20 69 73 20 69  The element is i
0870: 64 65 6e 74 69 66 69 65 64 20 62 79 0a 20 20 20  dentified by.   
0880: 74 68 65 20 6c 6f 67 69 63 61 6c 20 63 6f 6e 63  the logical conc
0890: 61 74 65 6e 61 74 69 6f 6e 20 6f 66 20 74 68 65  atenation of the
08a0: 20 70 61 74 68 73 2e 20 49 74 20 72 65 74 75 72   paths. It retur
08b0: 6e 73 20 74 68 65 20 65 78 74 72 61 63 74 65 64  ns the extracted
08c0: 0a 20 20 20 65 6c 65 6d 65 6e 74 2e 0a 0a 7c 6c  .   element...|l
08d0: 64 65 65 70 6c 65 6e 20 6c 69 73 74 20 70 61 74  deeplen list pat
08e0: 68 20 3f 70 61 74 68 3f 2e 2e 2e 0a 0a 20 3e 20  h ?path?..... > 
08f0: 46 69 6e 64 20 74 68 65 20 6c 65 6e 67 74 68 20  Find the length 
0900: 6f 66 20 61 20 6e 65 73 74 65 64 20 73 75 62 6c  of a nested subl
0910: 69 73 74 2e 20 54 68 65 20 73 75 62 6c 69 73 74  ist. The sublist
0920: 20 69 73 20 69 64 65 6e 74 69 66 69 65 64 20 62   is identified b
0930: 79 0a 20 20 20 74 68 65 20 6c 6f 67 69 63 61 6c  y.   the logical
0940: 20 63 6f 6e 63 61 74 65 6e 61 74 69 6f 6e 20 6f   concatenation o
0950: 66 20 74 68 65 20 70 61 74 68 73 2e 20 20 49 74  f the paths.  It
0960: 20 72 65 74 75 72 6e 73 20 74 68 65 20 66 6f 75   returns the fou
0970: 6e 64 0a 20 20 20 6c 65 6e 67 74 68 2e 20 20 41  nd.   length.  A
0980: 20 6e 6f 6e 2d 65 78 69 73 74 69 6e 67 20 73 75   non-existing su
0990: 62 6c 69 73 74 20 69 73 20 61 73 73 75 6d 65 64  blist is assumed
09a0: 20 74 6f 20 68 61 76 65 20 74 68 65 20 6c 65 6e   to have the len
09b0: 67 74 68 20 6f 66 20 30 2e 0a 0a 7c 6c 64 65 65  gth of 0...|ldee
09c0: 70 72 61 6e 67 65 20 6c 69 73 74 20 70 61 74 68  prange list path
09d0: 20 3f 70 61 74 68 3f 2e 2e 2e 20 66 69 72 73 74   ?path?... first
09e0: 20 6c 61 73 74 0a 0a 20 3e 20 45 78 74 72 61 63   last.. > Extrac
09f0: 74 20 61 20 73 75 62 6c 69 73 74 20 66 72 6f 6d  t a sublist from
0a00: 20 61 20 6e 65 73 74 65 64 20 6c 69 73 74 2e 20   a nested list. 
0a10: 54 68 69 73 20 63 6f 6d 6d 61 6e 64 20 69 73 20  This command is 
0a20: 61 20 63 6f 6e 76 65 6e 69 65 6e 74 0a 20 20 20  a convenient.   
0a30: 65 71 75 69 76 61 6c 65 6e 74 20 6f 66 0a 0a 7c  equivalent of..|
0a40: 20 20 20 6c 72 61 6e 67 65 20 5b 6c 64 65 65 70     lrange [ldeep
0a50: 69 6e 64 65 78 20 6c 69 73 74 20 70 61 74 68 20  index list path 
0a60: 3f 70 61 74 68 3f 5d 20 66 69 72 73 74 20 6c 61  ?path?] first la
0a70: 73 74 5d 0a 0a 20 3e 20 22 65 6e 64 22 20 69 73  st].. > "end" is
0a80: 20 73 75 70 70 6f 72 74 65 64 20 61 73 20 74 68   supported as th
0a90: 65 20 66 69 72 73 74 20 6f 72 20 6c 61 73 74 20  e first or last 
0aa0: 69 6e 64 65 78 2e 20 20 49 74 20 72 65 74 75 72  index.  It retur
0ab0: 6e 73 20 74 68 65 0a 20 20 20 65 78 74 72 61 63  ns the.   extrac
0ac0: 74 65 64 20 73 75 62 6c 69 73 74 2e 0a 0a 7c 6c  ted sublist...|l
0ad0: 64 65 65 70 73 65 74 20 6c 69 73 74 76 61 72 20  deepset listvar 
0ae0: 70 61 74 68 20 3f 70 61 74 68 3f 2e 2e 2e 20 76  path ?path?... v
0af0: 61 6c 75 65 0a 0a 20 3e 20 53 65 74 20 61 20 76  alue.. > Set a v
0b00: 61 6c 75 65 20 69 6e 20 61 20 6e 65 73 74 65 64  alue in a nested
0b10: 20 6c 69 73 74 20 76 61 72 69 61 62 6c 65 2e 20   list variable. 
0b20: 49 66 20 74 68 65 20 76 61 72 69 61 62 6c 65 20  If the variable 
0b30: 64 69 64 20 6e 6f 74 0a 20 20 20 65 78 69 73 74  did not.   exist
0b40: 20 70 72 65 76 69 6f 75 73 6c 79 2c 20 69 74 20   previously, it 
0b50: 69 73 20 63 72 65 61 74 65 64 2e 20 49 66 20 74  is created. If t
0b60: 68 65 20 69 6e 74 65 72 6d 65 64 69 61 74 65 20  he intermediate 
0b70: 6c 69 73 74 73 0a 20 20 20 73 70 65 63 69 66 69  lists.   specifi
0b80: 65 64 20 69 6e 20 74 68 65 20 70 61 74 68 20 64  ed in the path d
0b90: 69 64 20 6e 6f 74 20 65 78 69 73 74 2c 20 74 68  id not exist, th
0ba0: 65 79 20 61 72 65 20 63 72 65 61 74 65 64 20 61  ey are created a
0bb0: 73 20 65 6d 70 74 79 0a 20 20 20 6c 69 73 74 73  s empty.   lists
0bc0: 2e 20 54 68 69 73 20 69 6e 63 6c 75 64 65 73 20  . This includes 
0bd0: 74 68 65 20 22 66 69 6c 6c 65 72 22 20 65 6c 65  the "filler" ele
0be0: 6d 65 6e 74 73 3a 20 66 6f 72 20 65 78 61 6d 70  ments: for examp
0bf0: 6c 65 2c 20 69 66 20 6c 69 73 74 76 61 72 0a 20  le, if listvar. 
0c00: 20 20 63 6f 6e 74 61 69 6e 65 64 20 61 20 6c 69    contained a li
0c10: 73 74 20 6f 66 20 6f 6e 65 20 65 6c 65 6d 65 6e  st of one elemen
0c20: 74 20 61 6e 64 20 74 68 65 20 70 61 74 68 20 73  t and the path s
0c30: 74 61 72 74 73 20 77 69 74 68 20 22 35 20 2e 2e  tarts with "5 ..
0c40: 2e 22 2c 0a 20 20 20 74 68 65 20 65 6c 65 6d 65  .",.   the eleme
0c50: 6e 74 73 20 77 69 74 68 20 69 6e 64 65 78 65 73  nts with indexes
0c60: 20 31 2c 20 32 2c 20 33 2c 20 34 20 61 6e 64 20   1, 2, 3, 4 and 
0c70: 35 20 77 69 6c 6c 20 61 6c 6c 20 62 65 20 63 72  5 will all be cr
0c80: 65 61 74 65 64 20 61 6e 64 0a 20 20 20 74 68 65  eated and.   the
0c90: 20 74 68 65 20 66 75 72 74 68 65 72 20 63 72 65   the further cre
0ca0: 61 74 69 6f 6e 20 77 69 74 68 69 6e 20 74 68 65  ation within the
0cb0: 20 65 6c 65 6d 65 6e 74 20 61 74 20 69 6e 64 65   element at inde
0cc0: 78 20 35 20 77 69 6c 6c 0a 20 20 20 70 72 6f 63  x 5 will.   proc
0cd0: 65 65 64 2e 0a 0a 20 3e 20 41 20 73 70 65 63 69  eed... > A speci
0ce0: 61 6c 20 6d 65 61 6e 69 6e 67 20 69 73 20 61 73  al meaning is as
0cf0: 73 69 67 6e 65 64 20 62 79 20 74 68 69 73 20 63  signed by this c
0d00: 6f 6d 6d 61 6e 64 20 74 6f 20 74 68 65 20 6e 65  ommand to the ne
0d10: 67 61 74 69 76 65 0a 20 20 20 69 6e 64 65 78 65  gative.   indexe
0d20: 73 20 69 6e 20 74 68 65 20 70 61 74 68 3a 20 74  s in the path: t
0d30: 68 65 79 20 6d 65 61 6e 20 22 61 64 64 20 61 20  hey mean "add a 
0d40: 6e 65 77 20 65 6c 65 6d 65 6e 74 20 61 74 20 74  new element at t
0d50: 68 65 20 65 6e 64 20 6f 66 20 74 68 65 0a 20 20  he end of the.  
0d60: 20 6c 69 73 74 22 2e 20 53 6f 20 74 68 69 73 20   list". So this 
0d70: 63 6f 6d 6d 61 6e 64 20 61 6c 73 6f 20 64 6f 75  command also dou
0d80: 62 6c 65 73 20 61 73 20 61 20 6e 65 73 74 65 64  bles as a nested
0d90: 20 76 65 72 73 69 6f 6e 20 6f 66 0a 20 20 20 6c   version of.   l
0da0: 61 70 70 65 6e 64 2e 20 46 6f 72 20 65 78 61 6d  append. For exam
0db0: 70 6c 65 2c 0a 0a 7c 20 20 20 6c 64 65 65 70 73  ple,..|   ldeeps
0dc0: 65 74 20 6c 69 73 74 76 61 72 20 2d 31 20 76 61  et listvar -1 va
0dd0: 6c 75 65 0a 0a 20 3e 20 6d 65 61 6e 73 20 74 68  lue.. > means th
0de0: 65 20 73 61 6d 65 20 74 68 69 6e 67 20 61 73 0a  e same thing as.
0df0: 0a 7c 20 20 20 6c 61 70 70 65 6e 64 20 6c 69 73  .|   lappend lis
0e00: 74 76 61 72 20 76 61 6c 75 65 0a 0a 20 3e 20 54  tvar value.. > T
0e10: 68 69 73 20 6d 65 72 67 69 6e 67 20 68 61 73 20  his merging has 
0e20: 68 61 70 70 65 6e 65 64 20 62 65 63 61 75 73 65  happened because
0e30: 20 69 74 27 73 20 6f 66 74 65 6e 20 6e 65 63 63   it's often necc
0e40: 65 73 73 61 72 79 20 74 6f 20 61 64 64 0a 20 20  essary to add.  
0e50: 20 65 6c 65 6d 65 6e 74 73 20 74 6f 20 74 68 65   elements to the
0e60: 20 6c 69 73 74 73 20 69 6e 20 74 68 65 20 6d 69   lists in the mi
0e70: 64 64 6c 65 20 6f 66 20 74 68 65 20 70 61 74 68  ddle of the path
0e80: 2e 20 54 68 65 20 70 61 72 74 69 63 75 6c 61 72  . The particular
0e90: 0a 20 20 20 76 61 6c 75 65 20 75 73 65 64 20 74  .   value used t
0ea0: 6f 20 69 6e 64 69 63 61 74 65 20 74 68 65 20 61  o indicate the a
0eb0: 64 64 69 74 69 6f 6e 20 6f 66 20 61 6e 20 65 6c  ddition of an el
0ec0: 65 6d 65 6e 74 20 63 61 6e 20 62 65 20 63 68 61  ement can be cha
0ed0: 6e 67 65 64 20 74 6f 0a 20 20 20 73 6f 6d 65 74  nged to.   somet
0ee0: 68 69 6e 67 20 6d 6f 72 65 20 73 79 6d 62 6f 6c  hing more symbol
0ef0: 69 63 2c 20 66 6f 72 20 65 78 61 6d 70 6c 65 20  ic, for example 
0f00: 74 6f 20 22 61 70 70 65 6e 64 22 20 69 6e 73 74  to "append" inst
0f10: 65 61 64 20 6f 66 20 61 0a 20 20 20 6e 65 67 61  ead of a.   nega
0f20: 74 69 76 65 20 76 61 6c 75 65 2e 0a 0a 20 3e 20  tive value... > 
0f30: 54 68 65 20 27 27 6c 64 65 65 70 73 65 74 27 27  The ''ldeepset''
0f40: 20 63 6f 6d 6d 61 6e 64 20 72 65 74 75 72 6e 73   command returns
0f50: 20 6e 6f 74 68 69 6e 67 2e 20 53 69 6e 63 65 20   nothing. Since 
0f60: 74 68 65 20 76 65 72 73 69 6f 6e 20 77 69 74 68  the version with
0f70: 6f 75 74 0a 20 20 20 76 61 6c 75 65 20 61 73 20  out.   value as 
0f80: 69 6e 20 74 68 65 20 63 6f 6d 6d 6f 6e 20 73 65  in the common se
0f90: 74 20 63 61 6e 20 6e 6f 74 20 62 65 20 75 73 65  t can not be use
0fa0: 64 2c 20 72 65 74 75 72 6e 69 6e 67 20 74 68 65  d, returning the
0fb0: 20 76 61 6c 75 65 20 64 69 64 0a 20 20 20 6e 6f   value did.   no
0fc0: 74 20 73 65 65 6d 20 74 6f 20 6d 61 6b 65 20 73  t seem to make s
0fd0: 65 6e 73 65 2e 20 20 41 6c 73 6f 20 77 68 65 6e  ense.  Also when
0fe0: 20 65 78 70 65 72 69 6d 65 6e 74 69 6e 67 20 77   experimenting w
0ff0: 69 74 68 20 6c 61 72 67 65 20 6c 69 73 74 73 0a  ith large lists.
1000: 20 20 20 66 72 6f 6d 20 74 68 65 20 63 6f 6d 6d     from the comm
1010: 61 6e 64 20 6c 69 6e 65 2c 20 72 65 74 75 72 6e  and line, return
1020: 69 6e 67 20 74 68 65 20 76 61 6c 75 65 20 74 68  ing the value th
1030: 61 74 20 69 73 20 61 20 6c 61 72 67 65 20 6c 69  at is a large li
1040: 73 74 0a 20 20 20 69 74 73 65 6c 66 20 77 6f 75  st.   itself wou
1050: 6c 64 20 63 61 75 73 65 20 61 20 6c 6f 6e 67 20  ld cause a long 
1060: 61 6e 64 20 75 6e 70 6c 65 61 73 61 6e 74 20 70  and unpleasant p
1070: 72 69 6e 74 6f 75 74 20 6f 66 20 69 74 2e 0a 0a  rintout of it...
1080: 7c 6c 64 65 65 70 69 6e 63 72 20 6c 73 74 76 61  |ldeepincr lstva
1090: 72 20 70 61 74 68 20 3f 70 61 74 68 3f 2e 2e 2e  r path ?path?...
10a0: 20 69 6e 74 2d 76 61 6c 75 65 0a 0a 20 3e 20 49   int-value.. > I
10b0: 6e 63 72 65 61 73 65 20 61 20 76 61 6c 75 65 20  ncrease a value 
10c0: 77 69 74 68 69 6e 20 61 20 6e 65 73 74 65 64 20  within a nested 
10d0: 6c 69 73 74 20 62 79 20 69 6e 74 2d 76 61 6c 75  list by int-valu
10e0: 65 2e 20 4e 6f 74 65 20 74 68 61 74 20 73 69 6e  e. Note that sin
10f0: 63 65 0a 20 20 20 74 68 65 20 61 6d 6f 75 6e 74  ce.   the amount
1100: 20 6f 66 20 69 6e 63 72 65 61 73 65 20 68 61 73   of increase has
1110: 20 74 6f 20 62 65 20 64 69 66 66 65 72 65 6e 74   to be different
1120: 69 61 74 65 64 20 66 72 6f 6d 20 74 68 65 20 70  iated from the p
1130: 61 74 68 2c 20 69 74 27 73 0a 20 20 20 6d 61 6e  ath, it's.   man
1140: 64 61 74 6f 72 79 20 65 76 65 6e 20 66 6f 72 20  datory even for 
1150: 74 68 65 20 76 61 6c 75 65 20 6f 66 20 31 2e 20  the value of 1. 
1160: 54 68 69 73 20 69 73 20 61 20 63 6f 6e 76 65 6e  This is a conven
1170: 69 65 6e 74 20 61 6e 64 20 6f 66 74 65 6e 0a 20  ient and often. 
1180: 20 20 75 73 65 64 20 73 68 6f 72 74 63 75 74 20    used shortcut 
1190: 66 6f 72 20 74 68 65 20 6c 64 65 65 70 69 6e 64  for the ldeepind
11a0: 65 78 2d 65 78 70 72 2d 6c 64 65 65 70 73 65 74  ex-expr-ldeepset
11b0: 20 73 65 71 75 65 6e 63 65 2e 20 20 49 74 0a 20   sequence.  It. 
11c0: 20 20 72 65 74 75 72 6e 73 20 74 68 65 20 76 61    returns the va
11d0: 6c 75 65 20 6f 66 20 74 68 65 20 65 6c 65 6d 65  lue of the eleme
11e0: 6e 74 20 61 66 74 65 72 20 69 6e 63 72 65 61 73  nt after increas
11f0: 65 2e 0a 0a 7c 6c 64 65 65 70 72 65 70 20 6c 73  e...|ldeeprep ls
1200: 74 76 61 72 20 70 61 74 68 20 3f 70 61 74 68 3f  tvar path ?path?
1210: 2e 2e 2e 20 66 69 72 73 74 20 6c 61 73 74 20 65  ... first last e
1220: 6c 65 6d 65 6e 74 2d 6c 69 73 74 0a 0a 20 3e 20  lement-list.. > 
1230: 52 65 70 6c 61 63 65 20 61 20 72 61 6e 67 65 20  Replace a range 
1240: 6f 66 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61  of elements in a
1250: 20 73 75 62 6c 69 73 74 20 69 64 65 6e 74 69 66   sublist identif
1260: 69 65 64 20 62 79 20 74 68 65 20 70 61 74 68 0a  ied by the path.
1270: 20 20 20 77 69 74 68 20 74 68 65 20 65 6c 65 6d     with the elem
1280: 65 6e 74 73 20 66 72 6f 6d 20 74 68 65 20 65 6c  ents from the el
1290: 65 6d 65 6e 74 2d 6c 69 73 74 2e 20 20 49 74 20  ement-list.  It 
12a0: 72 65 74 75 72 6e 73 20 6e 6f 74 68 69 6e 67 2e  returns nothing.
12b0: 0a 0a 20 3e 20 54 68 69 73 20 63 6f 6d 6d 61 6e  .. > This comman
12c0: 64 20 69 73 20 64 69 66 66 65 72 65 6e 74 20 66  d is different f
12d0: 72 6f 6d 20 6c 72 65 70 6c 61 63 65 20 69 6e 20  rom lreplace in 
12e0: 74 77 6f 20 77 61 79 73 2c 20 68 65 6e 63 65 20  two ways, hence 
12f0: 74 68 65 20 6e 61 6d 65 0a 20 20 20 63 68 61 6e  the name.   chan
1300: 67 65 2e 20 20 46 69 72 73 74 2c 20 69 74 20 61  ge.  First, it a
1310: 63 74 73 20 6f 6e 20 64 61 74 61 20 69 6e 20 61  cts on data in a
1320: 20 76 61 72 69 61 62 6c 65 2c 20 6e 6f 74 20 6f   variable, not o
1330: 6e 20 61 20 6c 69 73 74 20 61 73 20 61 6e 0a 20  n a list as an. 
1340: 20 20 61 72 67 75 6d 65 6e 74 2e 20 53 65 63 6f    argument. Seco
1350: 6e 64 2c 20 74 68 65 20 65 6c 65 6d 65 6e 74 73  nd, the elements
1360: 20 66 6f 72 20 72 65 70 6c 61 63 65 6d 65 6e 74   for replacement
1370: 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 69   are contained i
1380: 6e 20 61 0a 20 20 20 6c 69 73 74 2c 20 6e 6f 74  n a.   list, not
1390: 20 61 73 20 73 65 70 61 72 61 74 65 20 65 6c 65   as separate ele
13a0: 6d 65 6e 74 73 20 6f 6e 20 63 6f 6d 6d 61 6e 64  ments on command
13b0: 20 6c 69 6e 65 2e 20 42 6f 74 68 20 64 69 66 66   line. Both diff
13c0: 65 72 65 6e 63 65 73 0a 20 20 20 77 65 72 65 20  erences.   were 
13d0: 63 72 65 61 74 65 64 20 66 6f 72 20 63 6f 6e 76  created for conv
13e0: 65 6e 69 65 6e 63 65 20 6f 66 20 70 72 61 63 74  enience of pract
13f0: 69 63 61 6c 20 75 73 65 2c 20 70 6c 75 73 20 74  ical use, plus t
1400: 6f 20 61 6c 6c 6f 77 20 74 68 65 0a 20 20 20 70  o allow the.   p
1410: 61 74 68 20 74 6f 20 70 69 63 6b 20 75 70 20 74  ath to pick up t
1420: 68 65 20 76 61 72 69 61 62 6c 65 20 6e 75 6d 62  he variable numb
1430: 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 2e  er of arguments.
1440: 20 49 20 68 61 76 65 20 66 6f 75 6e 64 20 74 68   I have found th
1450: 61 74 0a 20 20 20 49 20 61 6c 77 61 79 73 20 6e  at.   I always n
1460: 65 65 64 20 74 6f 20 72 65 70 6c 61 63 65 20 65  eed to replace e
1470: 6c 65 6d 65 6e 74 73 20 69 6e 20 61 20 76 61 72  lements in a var
1480: 69 61 62 6c 65 2c 20 6e 6f 74 20 61 73 20 61 0a  iable, not as a.
1490: 20 20 20 70 61 73 73 2d 74 68 72 6f 75 67 68 20     pass-through 
14a0: 6f 70 65 72 61 74 6f 72 2c 20 61 6e 64 20 74 68  operator, and th
14b0: 61 74 20 49 20 61 6c 6d 6f 73 74 20 61 6c 77 61  at I almost alwa
14c0: 79 73 20 6e 65 65 64 20 74 6f 20 69 6e 73 65 72  ys need to inser
14d0: 74 0a 20 20 20 65 6c 65 6d 65 6e 74 73 20 66 72  t.   elements fr
14e0: 6f 6d 20 61 6e 6f 74 68 65 72 20 6c 69 73 74 2c  om another list,
14f0: 20 6e 6f 74 20 6a 75 73 74 20 73 6f 6d 65 20 66   not just some f
1500: 69 78 65 64 20 73 65 74 20 6f 66 20 65 6c 65 6d  ixed set of elem
1510: 65 6e 74 73 2e 0a 0a 7c 6c 64 65 65 70 70 6f 70  ents...|ldeeppop
1520: 20 6c 73 74 76 61 72 20 70 61 74 68 20 3f 70 61   lstvar path ?pa
1530: 74 68 3f 2e 2e 2e 20 63 6f 75 6e 74 0a 0a 20 3e  th?... count.. >
1540: 20 52 65 6d 6f 76 65 20 63 6f 75 6e 74 20 65 6c   Remove count el
1550: 65 6d 65 6e 74 73 20 66 72 6f 6d 20 74 68 65 20  ements from the 
1560: 65 6e 64 20 6f 66 20 74 68 65 20 73 75 62 6c 69  end of the subli
1570: 73 74 20 69 64 65 6e 74 69 66 69 65 64 20 62 79  st identified by
1580: 0a 20 20 20 70 61 74 68 20 69 6e 20 74 68 65 20  .   path in the 
1590: 76 61 72 69 61 62 6c 65 20 61 6e 64 20 72 65 74  variable and ret
15a0: 75 72 6e 20 74 68 65 6d 20 69 6e 20 61 20 6c 69  urn them in a li
15b0: 73 74 2e 0a 0a 20 3e 20 54 68 69 73 20 63 6f 6d  st... > This com
15c0: 6d 61 6e 64 20 77 61 73 20 69 6e 73 70 69 72 65  mand was inspire
15d0: 64 20 62 79 20 74 68 65 20 70 6f 70 20 6f 70 65  d by the pop ope
15e0: 72 61 74 6f 72 20 69 6e 20 50 65 72 6c 2e 20 53  rator in Perl. S
15f0: 6f 6d 65 68 6f 77 20 49 27 76 65 0a 20 20 20 6e  omehow I've.   n
1600: 65 76 65 72 20 68 61 73 20 61 20 76 65 72 79 20  ever has a very 
1610: 73 74 72 69 6e 67 20 6e 65 65 64 20 66 6f 72 20  string need for 
1620: 74 68 65 20 6f 74 68 65 72 20 73 69 6d 69 6c 61  the other simila
1630: 72 20 63 6f 6d 6d 61 6e 64 73 20 28 77 68 69 63  r commands (whic
1640: 68 0a 20 20 20 77 6f 75 6c 64 20 62 65 20 27 27  h.   would be ''
1650: 6c 64 65 65 70 70 75 73 68 27 27 20 74 6f 20 61  ldeeppush'' to a
1660: 64 64 20 65 6c 65 6d 65 6e 74 73 2c 20 61 6e 64  dd elements, and
1670: 20 27 27 6c 64 65 65 70 73 68 69 66 74 27 27 20   ''ldeepshift'' 
1680: 61 6e 64 0a 20 20 20 27 27 6c 64 65 65 70 75 6e  and.   ''ldeepun
1690: 73 68 69 66 74 27 27 20 66 6f 72 20 6f 70 65 72  shift'' for oper
16a0: 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 20 73 74  ations on the st
16b0: 61 72 74 20 6f 66 20 74 68 65 20 6c 69 73 74 29  art of the list)
16c0: 20 62 75 74 20 74 68 65 79 0a 20 20 20 63 61 6e   but they.   can
16d0: 20 62 65 20 65 61 73 69 6c 79 20 61 64 64 65 64   be easily added
16e0: 20 61 73 20 77 65 6c 6c 20 66 6f 72 20 63 6f 6d   as well for com
16f0: 70 6c 65 74 65 6e 65 73 73 2e 0a 0a 20 3e 20 54  pleteness... > T
1700: 68 65 20 63 6f 6d 6d 61 6e 64 20 72 65 74 75 72  he command retur
1710: 6e 73 20 74 68 65 20 6c 69 73 74 20 6f 66 20 74  ns the list of t
1720: 68 65 20 70 6f 70 70 65 64 20 65 6c 65 6d 65 6e  he popped elemen
1730: 74 73 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e  ts in the origin
1740: 61 6c 0a 20 20 20 6f 72 64 65 72 2e 20 46 6f 72  al.   order. For
1750: 20 65 78 61 6d 70 6c 65 2c 20 69 66 20 6c 73 74   example, if lst
1760: 76 61 72 20 63 6f 6e 74 61 69 6e 65 64 20 7b 30  var contained {0
1770: 20 31 20 32 20 33 20 34 20 35 7d 2c 20 22 6c 64   1 2 3 4 5}, "ld
1780: 65 65 70 70 6f 70 0a 20 20 20 6c 73 74 76 61 72  eeppop.   lstvar
1790: 20 7b 7d 20 32 22 20 77 6f 75 6c 64 20 72 65 74   {} 2" would ret
17a0: 75 72 6e 20 7b 34 20 35 7d 2c 20 4e 4f 54 20 7b  urn {4 5}, NOT {
17b0: 35 20 34 7d 2e 0a 0a 7e 4f 74 68 65 72 20 45 78  5 4}...~Other Ex
17c0: 74 65 6e 73 69 6f 6e 73 20 66 6f 72 20 4c 69 73  tensions for Lis
17d0: 74 20 53 75 70 70 6f 72 74 0a 0a 49 6e 20 6d 79  t Support..In my
17e0: 20 70 72 61 63 74 69 63 65 20 49 20 68 61 76 65   practice I have
17f0: 20 66 6f 75 6e 64 20 74 68 61 74 20 61 20 66 65   found that a fe
1800: 77 20 6f 74 68 65 72 20 63 6f 6d 6d 61 6e 64 73  w other commands
1810: 20 6d 61 6b 65 20 77 6f 72 6b 69 6e 67 0a 77 69   make working.wi
1820: 74 68 20 6c 69 73 74 73 20 6d 75 63 68 20 6d 6f  th lists much mo
1830: 72 65 20 63 6f 6e 76 65 6e 69 65 6e 74 2e 20 54  re convenient. T
1840: 68 65 79 20 61 72 65 20 6e 6f 74 20 64 69 72 65  hey are not dire
1850: 63 74 6c 79 20 72 65 6c 61 74 65 64 20 74 6f 20  ctly related to 
1860: 74 68 65 0a 6e 65 73 74 65 64 20 6c 69 73 74 73  the.nested lists
1870: 20 62 75 74 20 74 6f 20 74 68 65 20 6c 69 73 74   but to the list
1880: 73 20 69 6e 20 67 65 6e 65 72 61 6c 2e 0a 0a 7c  s in general...|
1890: 6c 63 6f 6e 63 61 74 20 73 75 62 6c 69 73 74 20  lconcat sublist 
18a0: 3f 73 75 62 6c 69 73 74 3f 2e 2e 2e 0a 0a 20 3e  ?sublist?..... >
18b0: 20 43 6f 6e 63 61 74 65 6e 61 74 65 20 74 68 65   Concatenate the
18c0: 20 61 72 67 75 6d 65 6e 74 20 6c 69 73 74 73 20   argument lists 
18d0: 61 6e 64 20 72 65 74 75 72 6e 20 74 68 65 20 72  and return the r
18e0: 65 73 75 6c 74 69 6e 67 20 6c 69 73 74 2e 20 20  esulting list.  
18f0: 54 68 69 73 0a 20 20 20 63 6f 6d 6d 61 6e 64 20  This.   command 
1900: 69 73 20 73 69 6d 69 6c 61 72 20 74 6f 20 63 6f  is similar to co
1910: 6e 63 61 74 20 62 75 74 20 61 76 6f 69 64 73 20  ncat but avoids 
1920: 63 6f 6e 76 65 72 74 69 6e 67 20 74 68 65 20 76  converting the v
1930: 61 6c 75 65 73 20 74 6f 0a 20 20 20 73 74 72 69  alues to.   stri
1940: 6e 67 73 2c 20 63 6f 6e 63 61 74 65 6e 61 74 69  ngs, concatenati
1950: 6e 67 20 74 68 65 20 73 74 72 69 6e 67 73 20 61  ng the strings a
1960: 6e 64 20 74 68 65 6e 20 72 65 2d 70 61 72 73 69  nd then re-parsi
1970: 6e 67 20 74 68 65 0a 20 20 20 73 74 72 69 6e 67  ng the.   string
1980: 73 2e 20 57 68 65 6e 20 74 68 65 20 6c 69 73 74  s. When the list
1990: 73 20 69 6e 76 6f 6c 76 65 64 20 67 72 6f 77 20  s involved grow 
19a0: 74 6f 20 61 20 66 65 77 20 6d 65 67 61 62 79 74  to a few megabyt
19b0: 65 73 2c 20 63 6f 6e 63 61 74 0a 20 20 20 62 65  es, concat.   be
19c0: 63 6f 6d 65 73 20 76 65 72 79 20 69 6e 65 66 66  comes very ineff
19d0: 69 63 69 65 6e 74 20 62 6f 74 68 20 69 6e 20 74  icient both in t
19e0: 68 65 20 73 65 6e 73 65 20 6f 66 20 74 69 6d 65  he sense of time
19f0: 20 61 6e 64 20 6d 65 6d 6f 72 79 0a 20 20 20 75   and memory.   u
1a00: 73 61 67 65 2e 20 27 27 6c 63 6f 6e 63 61 74 27  sage. ''lconcat'
1a10: 27 20 72 65 73 6f 6c 76 65 64 20 74 68 69 73 20  ' resolved this 
1a20: 69 6e 65 66 66 69 63 69 65 6e 63 79 2e 20 4e 6f  inefficiency. No
1a30: 74 65 20 74 68 61 74 20 69 74 20 64 6f 65 73 0a  te that it does.
1a40: 20 20 20 27 27 6e 6f 74 27 27 20 72 65 70 6c 61     ''not'' repla
1a50: 63 65 20 27 27 63 6f 6e 63 61 74 27 27 2c 20 77  ce ''concat'', w
1a60: 68 69 63 68 20 63 61 6e 20 62 65 20 75 73 65 64  hich can be used
1a70: 20 74 6f 20 61 73 73 65 6d 62 6c 65 20 6c 69 73   to assemble lis
1a80: 74 73 0a 20 20 20 66 72 6f 6d 20 70 69 65 63 65  ts.   from piece
1a90: 73 20 69 6e 20 64 69 66 66 65 72 65 6e 74 20 61  s in different a
1aa0: 72 67 75 6d 65 6e 74 20 73 74 72 69 6e 67 73 2e  rgument strings.
1ab0: 20 20 54 68 65 20 63 6f 6d 6d 61 6e 64 20 72 65    The command re
1ac0: 74 75 72 6e 73 20 74 68 65 0a 20 20 20 63 6f 6e  turns the.   con
1ad0: 63 61 74 65 6e 61 74 65 64 20 6c 69 73 74 2e 0a  catenated list..
1ae0: 0a 7c 6d 73 65 74 20 6c 69 73 74 2d 6f 66 2d 76  .|mset list-of-v
1af0: 61 72 69 61 62 6c 65 2d 6e 61 6d 65 73 20 6c 69  ariable-names li
1b00: 73 74 2d 6f 66 2d 76 61 6c 75 65 73 0a 0a 20 3e  st-of-values.. >
1b10: 20 53 65 74 20 74 68 65 20 76 61 6c 75 65 73 20   Set the values 
1b20: 66 72 6f 6d 20 74 68 65 20 76 61 6c 75 65 20 6c  from the value l
1b30: 69 73 74 20 74 6f 20 74 68 65 20 76 61 72 69 61  ist to the varia
1b40: 62 6c 65 20 69 6e 20 74 68 65 20 76 61 72 69 61  ble in the varia
1b50: 62 6c 65 0a 20 20 20 6c 69 73 74 20 61 74 20 74  ble.   list at t
1b60: 68 65 20 73 61 6d 65 20 69 6e 64 65 78 2e 20 54  he same index. T
1b70: 68 65 20 63 6f 6d 6d 61 6e 64 20 6e 61 6d 65 20  he command name 
1b80: 73 74 61 6e 64 73 20 66 6f 72 20 22 6d 75 6c 74  stands for "mult
1b90: 69 70 6c 65 0a 20 20 20 73 65 74 22 2e 20 54 68  iple.   set". Th
1ba0: 69 73 20 63 6f 6d 6d 61 6e 64 20 69 73 20 69 6e  is command is in
1bb0: 73 70 69 72 65 64 20 62 79 20 61 73 73 69 67 6e  spired by assign
1bc0: 6d 65 6e 74 73 20 69 6e 20 50 65 72 6c 2e 0a 0a  ments in Perl...
1bd0: 20 3e 20 49 66 20 74 68 65 72 65 20 77 65 72 65   > If there were
1be0: 20 6d 6f 72 65 20 76 61 72 69 61 62 6c 65 73 20   more variables 
1bf0: 74 68 61 6e 20 74 68 65 20 76 61 6c 75 65 73 2c  than the values,
1c00: 20 74 68 65 20 72 65 73 74 20 6f 66 20 76 61 72   the rest of var
1c10: 69 61 62 6c 65 73 0a 20 20 20 61 72 65 20 73 65  iables.   are se
1c20: 74 20 74 6f 20 61 6e 20 65 6d 70 74 79 20 76 61  t to an empty va
1c30: 6c 75 65 2e 20 49 66 20 74 68 65 72 65 20 77 65  lue. If there we
1c40: 72 65 20 6d 6f 72 65 20 76 61 6c 75 65 73 20 74  re more values t
1c50: 68 61 6e 0a 20 20 20 76 61 72 69 61 62 6c 65 73  han.   variables
1c60: 2c 20 74 68 65 6e 20 74 68 65 20 6c 61 73 74 20  , then the last 
1c70: 76 61 72 69 61 62 6c 65 20 69 73 20 61 73 73 69  variable is assi
1c80: 67 6e 65 64 20 74 68 65 20 77 68 6f 6c 65 20 65  gned the whole e
1c90: 6e 64 20 6f 66 20 61 0a 20 20 20 6c 69 73 74 20  nd of a.   list 
1ca0: 28 61 73 20 61 20 6c 69 73 74 29 2e 0a 0a 20 3e  (as a list)... >
1cb0: 20 41 20 73 70 65 63 69 61 6c 20 76 61 72 69 61   A special varia
1cc0: 62 6c 65 20 6e 61 6d 65 20 22 2d 22 20 63 61 6e  ble name "-" can
1cd0: 20 62 65 20 75 73 65 64 20 74 6f 20 74 68 72 6f   be used to thro
1ce0: 77 20 61 77 61 79 20 61 20 76 61 6c 75 65 2c 20  w away a value, 
1cf0: 6f 72 0a 20 20 20 74 68 65 20 77 68 6f 6c 65 20  or.   the whole 
1d00: 65 6e 64 20 6f 66 20 74 68 65 20 76 61 6c 75 65  end of the value
1d10: 20 6c 69 73 74 20 69 66 20 69 74 27 73 20 73 70   list if it's sp
1d20: 65 63 69 66 69 65 64 20 61 73 20 74 68 65 20 6c  ecified as the l
1d30: 61 73 74 20 6f 6e 65 0a 20 20 20 69 6e 20 74 68  ast one.   in th
1d40: 65 20 76 61 72 69 61 62 6c 65 20 6c 69 73 74 2e  e variable list.
1d50: 0a 0a 20 3e 20 54 68 65 20 63 6f 6d 6d 61 6e 64  .. > The command
1d60: 20 72 65 74 75 72 6e 73 20 6e 6f 74 68 69 6e 67   returns nothing
1d70: 2e 20 49 74 20 63 61 6e 20 62 65 20 61 72 67 75  . It can be argu
1d80: 65 64 20 74 68 61 74 20 69 74 20 77 6f 75 6c 64  ed that it would
1d90: 20 6d 61 6b 65 0a 20 20 20 73 65 6e 73 65 20 74   make.   sense t
1da0: 6f 20 72 65 74 75 72 6e 20 74 68 65 20 6c 65 6e  o return the len
1db0: 67 74 68 20 6f 66 20 74 68 65 20 6f 72 69 67 69  gth of the origi
1dc0: 6e 61 6c 20 6c 69 73 74 2c 20 6f 72 20 74 68 65  nal list, or the
1dd0: 20 64 69 66 66 65 72 65 6e 63 65 0a 20 20 20 62   difference.   b
1de0: 65 74 77 65 65 6e 20 74 68 65 20 6c 65 6e 67 74  etween the lengt
1df0: 68 20 6f 66 20 74 68 65 20 76 61 6c 75 65 73 20  h of the values 
1e00: 6c 69 73 74 20 61 6e 64 20 74 68 65 20 6c 65 6e  list and the len
1e10: 67 74 68 20 6f 66 20 74 68 65 0a 20 20 20 76 61  gth of the.   va
1e20: 72 69 61 62 6c 65 73 20 6c 69 73 74 2e 20 49 20  riables list. I 
1e30: 64 6f 6e 27 74 20 6b 6e 6f 77 20 77 68 69 63 68  don't know which
1e40: 20 6f 6e 65 20 69 73 20 62 65 74 74 65 72 2e 0a   one is better..
1e50: 0a 20 3e 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64  . > This command
1e60: 20 69 73 20 70 61 72 74 69 63 75 6c 61 72 6c 79   is particularly
1e70: 20 63 6f 6e 76 65 6e 69 65 6e 74 20 66 6f 72 20   convenient for 
1e80: 72 65 74 75 72 6e 69 6e 67 20 6d 75 6c 74 69 70  returning multip
1e90: 6c 65 0a 20 20 20 76 61 6c 75 65 73 20 66 72 6f  le.   values fro
1ea0: 6d 20 61 20 70 72 6f 63 65 64 75 72 65 2e 20 20  m a procedure.  
1eb0: 46 6f 72 20 65 78 61 6d 70 6c 65 3a 0a 0a 7c 20  For example:..| 
1ec0: 20 20 70 72 6f 63 20 78 78 78 20 7b 61 20 62 7d    proc xxx {a b}
1ed0: 20 7b 0a 7c 20 20 20 20 20 20 72 65 74 75 72 6e   {.|      return
1ee0: 20 5b 6c 69 73 74 20 5b 65 78 70 72 20 24 62 2b   [list [expr $b+
1ef0: 24 61 5d 20 5b 65 78 70 72 20 24 62 2a 24 61 5d  $a] [expr $b*$a]
1f00: 5d 0a 7c 20 20 20 7d 0a 7c 20 20 20 6d 73 65 74  ].|   }.|   mset
1f10: 20 7b 73 75 6d 20 70 72 6f 64 75 63 74 7d 20 5b   {sum product} [
1f20: 78 78 78 20 31 20 32 5d 0a 0a 7c 6c 64 75 70 20  xxx 1 2]..|ldup 
1f30: 63 6f 75 6e 74 20 65 6c 65 6d 65 6e 74 20 3f 65  count element ?e
1f40: 6c 65 6d 65 6e 74 3f 2e 2e 2e 0a 0a 20 3e 20 54  lement?..... > T
1f50: 68 69 73 20 72 65 74 75 72 6e 73 20 61 20 6c 69  his returns a li
1f60: 73 74 20 70 72 6f 64 75 63 65 64 20 62 79 20 64  st produced by d
1f70: 75 70 6c 69 63 61 74 69 6e 67 20 74 68 65 20 73  uplicating the s
1f80: 65 71 75 65 6e 63 65 20 6f 66 0a 20 20 20 65 6c  equence of.   el
1f90: 65 6d 65 6e 74 73 20 27 27 63 6f 75 6e 74 27 27  ements ''count''
1fa0: 20 74 69 6d 65 73 2e 20 20 54 68 69 73 20 63 6f   times.  This co
1fb0: 6d 6d 61 6e 64 20 69 73 20 69 6e 73 70 69 72 65  mmand is inspire
1fc0: 64 20 62 79 20 74 68 65 20 6f 70 65 72 61 74 6f  d by the operato
1fd0: 72 0a 20 20 20 22 78 22 20 69 6e 20 50 65 72 6c  r.   "x" in Perl
1fe0: 2c 20 61 6e 64 20 69 74 20 69 73 20 61 20 6c 6f  , and it is a lo
1ff0: 67 69 63 61 6c 20 65 71 75 69 76 61 6c 65 6e 74  gical equivalent
2000: 20 6f 66 3a 0a 0a 7c 20 20 20 70 72 6f 63 20 6c   of:..|   proc l
2010: 64 75 70 20 7b 63 6f 75 6e 74 20 61 72 67 73 7d  dup {count args}
2020: 20 7b 0a 7c 20 20 20 20 20 20 73 65 74 20 72 65   {.|      set re
2030: 73 20 7b 7d 0a 7c 20 20 20 20 20 20 66 6f 72 20  s {}.|      for 
2040: 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20 3c 20  {set i 0} {$i < 
2050: 24 63 6f 75 6e 74 7d 20 7b 69 6e 63 72 20 69 7d  $count} {incr i}
2060: 20 7b 0a 7c 20 20 20 20 20 20 20 20 20 73 65 74   {.|         set
2070: 20 72 65 73 20 5b 6c 63 6f 6e 63 61 74 20 24 72   res [lconcat $r
2080: 65 73 20 24 61 72 67 73 5d 0a 7c 20 20 20 20 20  es $args].|     
2090: 20 7d 0a 7c 20 20 20 20 20 20 72 65 74 75 72 6e   }.|      return
20a0: 20 24 72 65 73 0a 7c 20 20 20 7d 0a 0a 7c 6c 76   $res.|   }..|lv
20b0: 64 75 70 20 63 6f 75 6e 74 20 65 6c 65 6d 65 6e  dup count elemen
20c0: 74 2d 6c 69 73 74 0a 0a 20 3e 20 54 68 69 73 20  t-list.. > This 
20d0: 72 65 74 75 72 6e 73 20 61 20 6c 69 73 74 20 70  returns a list p
20e0: 72 6f 64 75 63 65 64 20 62 79 20 64 75 70 6c 69  roduced by dupli
20f0: 63 61 74 69 6e 67 20 74 68 65 20 65 6c 65 6d 65  cating the eleme
2100: 6e 74 2d 6c 69 73 74 20 63 6f 75 6e 74 0a 20 20  nt-list count.  
2110: 20 74 69 6d 65 73 2e 20 20 54 68 69 73 20 63 6f   times.  This co
2120: 6d 6d 61 6e 64 20 69 73 20 69 6e 73 70 69 72 65  mmand is inspire
2130: 64 20 62 79 20 74 68 65 20 6f 70 65 72 61 74 6f  d by the operato
2140: 72 20 22 78 22 20 69 6e 20 50 65 72 6c 2c 20 61  r "x" in Perl, a
2150: 6e 64 0a 20 20 20 69 74 20 69 73 20 61 20 6c 6f  nd.   it is a lo
2160: 67 69 63 61 6c 20 65 71 75 69 76 61 6c 65 6e 74  gical equivalent
2170: 20 6f 66 0a 0a 7c 20 20 20 70 72 6f 63 20 6c 76   of..|   proc lv
2180: 64 75 70 20 7b 63 6f 75 6e 74 20 6c 69 73 74 7d  dup {count list}
2190: 20 7b 0a 7c 20 20 20 20 20 20 73 65 74 20 72 65   {.|      set re
21a0: 73 20 7b 7d 0a 7c 20 20 20 20 20 20 66 6f 72 20  s {}.|      for 
21b0: 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20 3c 20  {set i 0} {$i < 
21c0: 24 63 6f 75 6e 74 7d 20 7b 69 6e 63 72 20 69 7d  $count} {incr i}
21d0: 20 7b 0a 7c 20 20 20 20 20 20 20 20 20 73 65 74   {.|         set
21e0: 20 72 65 73 20 5b 6c 63 6f 6e 63 61 74 20 24 72   res [lconcat $r
21f0: 65 73 20 24 6c 69 73 74 5d 0a 7c 20 20 20 20 20  es $list].|     
2200: 20 7d 0a 7c 20 20 20 20 20 20 72 65 74 75 72 6e   }.|      return
2210: 20 24 72 65 73 0a 7c 20 20 20 7d 0a 0a 7e 52 65   $res.|   }..~Re
2220: 66 65 72 65 6e 63 65 20 49 6d 70 6c 65 6d 65 6e  ference Implemen
2230: 74 61 74 69 6f 6e 0a 0a 54 68 65 20 72 65 66 65  tation..The refe
2240: 72 65 6e 63 65 20 69 6d 70 6c 65 6d 65 6e 74 61  rence implementa
2250: 74 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c  tion is availabl
2260: 65 20 61 73 20 70 61 72 74 20 6f 66 20 74 68 65  e as part of the
2270: 20 4e 6f 74 20 41 0a 43 6f 6d 6d 61 6e 64 65 72   Not A.Commander
2280: 20 70 72 6f 6a 65 63 74 20 5b 68 74 74 70 3a 2f   project [http:/
2290: 2f 6e 61 63 2e 73 66 2e 6e 65 74 2f 5d 2c 20 74  /nac.sf.net/], t
22a0: 68 65 20 73 6f 75 72 63 65 20 66 69 6c 65 20 27  he source file '
22b0: 27 63 75 74 69 6c 2e 63 27 27 2e 0a 54 6f 20 69  'cutil.c''..To i
22c0: 6e 63 6c 75 64 65 20 74 68 65 20 6e 65 77 20 63  nclude the new c
22d0: 6f 6d 6d 61 6e 64 73 20 69 6e 74 6f 20 54 63 6c  ommands into Tcl
22e0: 2c 20 74 68 65 20 65 72 72 6f 72 20 6d 65 73 73  , the error mess
22f0: 61 67 65 73 20 77 69 6c 6c 20 68 61 76 65 20 74  ages will have t
2300: 6f 0a 62 65 20 61 64 6a 75 73 74 65 64 20 74 6f  o.be adjusted to
2310: 20 6d 61 74 63 68 20 74 68 65 20 73 74 79 6c 65   match the style
2320: 20 75 73 65 64 20 69 6e 20 54 63 6c 2c 20 61 6e   used in Tcl, an
2330: 64 20 74 68 65 20 6d 61 6e 20 70 61 67 65 73 20  d the man pages 
2340: 77 69 6c 6c 0a 68 61 76 65 20 74 6f 20 62 65 20  will.have to be 
2350: 77 72 69 74 74 65 6e 2e 20 20 54 68 65 20 63 75  written.  The cu
2360: 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61  rrent implementa
2370: 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 20 74 65  tion has been te
2380: 73 74 65 64 20 69 6e 0a 66 61 69 72 20 61 6d 6f  sted in.fair amo
2390: 75 6e 74 73 20 66 6f 72 20 62 6f 74 68 20 63 6f  unts for both co
23a0: 72 72 65 63 74 6e 65 73 73 20 61 6e 64 20 65 66  rrectness and ef
23b0: 66 69 63 69 65 6e 63 79 20 62 79 20 75 73 61 67  ficiency by usag
23c0: 65 20 69 6e 20 74 68 65 20 4e 6f 74 20 41 0a 43  e in the Not A.C
23d0: 6f 6d 6d 61 6e 64 65 72 20 70 72 6f 6a 65 63 74  ommander project
23e0: 2c 20 74 68 65 20 66 6f 72 6d 61 6c 20 74 65 73  , the formal tes
23f0: 74 20 73 75 69 74 65 20 77 6f 75 6c 64 20 68 61  t suite would ha
2400: 76 65 20 74 6f 20 62 65 20 77 72 69 74 74 65 6e  ve to be written
2410: 2e 0a 46 75 72 74 68 65 72 20 70 72 6f 67 72 65  ..Further progre
2420: 73 73 20 69 6e 20 74 68 69 73 20 64 69 72 65 63  ss in this direc
2430: 74 69 6f 6e 20 64 65 70 65 6e 64 73 20 6f 6e 20  tion depends on 
2440: 61 63 63 65 70 74 61 6e 63 65 20 6f 66 20 74 68  acceptance of th
2450: 69 73 0a 70 72 6f 70 6f 73 61 6c 2e 0a 0a 7e 43  is.proposal...~C
2460: 6f 6d 6d 65 6e 74 73 0a 0a 4d 65 73 73 61 67 65  omments..Message
2470: 73 20 6f 6e 20 74 68 65 20 54 43 4c 43 4f 52 45  s on the TCLCORE
2480: 20 6d 61 69 6c 69 6e 67 20 6c 69 73 74 20 68 61   mailing list ha
2490: 76 65 20 70 6f 69 6e 74 65 64 20 6f 75 74 0a 74  ve pointed out.t
24a0: 68 61 74 20 6e 65 61 72 6c 79 20 65 76 65 72 79  hat nearly every
24b0: 74 68 69 6e 67 20 70 72 6f 70 6f 73 65 64 20 68  thing proposed h
24c0: 65 72 65 20 69 73 20 65 69 74 68 65 72 20 65 71  ere is either eq
24d0: 75 69 76 61 6c 65 6e 74 0a 74 6f 2c 20 6f 72 20  uivalent.to, or 
24e0: 74 72 69 76 69 61 6c 6c 79 20 63 72 65 61 74 65  trivially create
24f0: 64 20 62 79 20 63 6f 6d 70 6f 73 69 74 69 6f 6e  d by composition
2500: 20 6f 66 20 74 68 65 20 65 78 69 73 74 69 6e 67   of the existing
2510: 0a 63 6f 6d 6d 61 6e 64 73 20 27 27 27 6c 69 6e  .commands '''lin
2520: 64 65 78 27 27 27 2c 20 27 27 27 6c 72 61 6e 67  dex''', '''lrang
2530: 65 27 27 27 2c 20 27 27 27 6c 73 65 74 27 27 27  e''', '''lset'''
2540: 2c 0a 27 27 27 6c 61 73 73 69 67 6e 27 27 27 2c  ,.'''lassign''',
2550: 20 61 6e 64 20 27 27 27 6c 72 65 70 65 61 74 27   and '''lrepeat'
2560: 27 27 2e 20 20 54 68 65 20 6f 6e 6c 79 20 6e 6f  ''.  The only no
2570: 76 65 6c 0a 74 68 69 6e 67 20 70 72 6f 70 6f 73  vel.thing propos
2580: 65 64 20 69 73 20 74 68 65 20 61 62 69 6c 69 74  ed is the abilit
2590: 79 20 6f 66 20 27 27 27 6c 73 65 74 27 27 27 20  y of '''lset''' 
25a0: 74 6f 0a 63 72 65 61 74 65 20 6e 65 77 20 6c 69  to.create new li
25b0: 73 74 20 65 6c 65 6d 65 6e 74 73 2e 20 20 49 66  st elements.  If
25c0: 20 74 68 61 74 27 73 20 73 74 69 6c 6c 20 64 65   that's still de
25d0: 73 69 72 65 64 2c 0a 61 20 73 65 70 61 72 61 74  sired,.a separat
25e0: 65 20 6e 65 77 20 54 49 50 20 70 72 6f 70 6f 73  e new TIP propos
25f0: 69 6e 67 20 74 68 61 74 20 61 6c 6f 6e 65 20 77  ing that alone w
2600: 6f 75 6c 64 20 62 65 20 0a 74 68 65 20 62 65 73  ould be .the bes
2610: 74 20 77 61 79 20 74 6f 20 64 65 61 6c 20 77 69  t way to deal wi
2620: 74 68 20 74 68 61 74 2e 0a 0a 49 20 63 61 6c 6c  th that...I call
2630: 20 6f 6e 20 74 68 65 20 61 75 74 68 6f 72 20 74   on the author t
2640: 6f 20 77 69 74 68 64 72 61 77 20 74 68 69 73 20  o withdraw this 
2650: 54 49 50 2e 0a 0a 7e 43 6f 70 79 72 69 67 68 74  TIP...~Copyright
2660: 0a 0a 54 68 69 73 20 64 6f 63 75 6d 65 6e 74 20  ..This document 
2670: 68 61 73 20 62 65 65 6e 20 70 6c 61 63 65 64 20  has been placed 
2680: 69 6e 20 74 68 65 20 70 75 62 6c 69 63 20 64 6f  in the public do
2690: 6d 61 69 6e 2e 0a                                main..