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 ?varName ...?
12_________________________________________________________________
13
14
16 This command treats the value list as a list and assigns successive
17 elements from that list to the variables given by the varName arguments
18 in order. If there are more variable names than list elements, the
19 remaining variables are set to the empty string. If there are more
20 list elements than variables, a list of unassigned elements is
21 returned.
22
24 An illustration of how multiple assignment works, and what happens when
25 there are either too few or too many elements.
26 lassign {a b c} x y z ;# Empty return
27 puts $x ;# Prints "a"
28 puts $y ;# Prints "b"
29 puts $z ;# Prints "c"
30
31 lassign {d e} x y z ;# Empty return
32 puts $x ;# Prints "d"
33 puts $y ;# Prints "e"
34 puts $z ;# Prints ""
35
36 lassign {f g h i} x y ;# Returns "h i"
37 puts $x ;# Prints "f"
38 puts $y ;# Prints "g"
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 set ::argv [lassign $::argv argumentToReadOff]
42
44 lindex(n), list(n), lset(n), set(n)
45
46
48 assign, element, list, multiple, set, variable
49
50
51
52Tcl 8.5 lassign(n)