1lassign(n) Tcl Built-In Commands lassign(n)
2
3
4
5______________________________________________________________________________
6
8 lassign - Assign list elements to variables
9
11 lassign list ?varName ...?
12______________________________________________________________________________
13
15 This command treats the value list as a list and assigns successive el‐
16 ements from that list to the variables given by the varName arguments
17 in order. If there are more variable names than list elements, the re‐
18 maining variables are set to the empty string. If there are more list
19 elements than variables, a list of unassigned elements is returned.
20
22 An illustration of how multiple assignment works, and what happens when
23 there are either too few or too many elements.
24
25 lassign {a b c} x y z ;# Empty return
26 puts $x ;# Prints "a"
27 puts $y ;# Prints "b"
28 puts $z ;# Prints "c"
29
30 lassign {d e} x y z ;# Empty return
31 puts $x ;# Prints "d"
32 puts $y ;# Prints "e"
33 puts $z ;# Prints ""
34
35 lassign {f g h i} x y ;# Returns "h i"
36 puts $x ;# Prints "f"
37 puts $y ;# Prints "g"
38
39 The lassign command has other uses. It can be used to create the ana‐
40 logue of the “shift” command in many shell languages like this:
41
42 set ::argv [lassign $::argv argumentToReadOff]
43
45 lindex(n), list(n), lrange(n), lset(n), set(n)
46
48 assign, element, list, multiple, set, variable
49
50
51
52Tcl 8.5 lassign(n)