| 1 |
'\" |
| 2 |
'\" Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans |
| 3 |
'\" Copyright (c) 2004 Donal K. Fellows |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH lassign n 8.5 Tcl "Tcl Built-In Commands" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
'\" Note: do not modify the .SH NAME line immediately below! |
| 12 |
.SH NAME |
| 13 |
lassign \- Assign list elements to variables |
| 14 |
.SH SYNOPSIS |
| 15 |
\fBlassign \fIlist \fR?\fIvarName ...\fR? |
| 16 |
.BE |
| 17 |
.SH DESCRIPTION |
| 18 |
.PP |
| 19 |
This command treats the value \fIlist\fR as a list and assigns |
| 20 |
successive elements from that list to the variables given by the |
| 21 |
\fIvarName\fR arguments in order. If there are more variable names |
| 22 |
than list elements, the remaining variables are set to the empty |
| 23 |
string. If there are more list elements than variables, a list of |
| 24 |
unassigned elements is returned. |
| 25 |
.SH EXAMPLES |
| 26 |
.PP |
| 27 |
An illustration of how multiple assignment works, and what happens |
| 28 |
when there are either too few or too many elements. |
| 29 |
.PP |
| 30 |
.CS |
| 31 |
\fBlassign\fR {a b c} x y z ;# Empty return |
| 32 |
puts $x ;# Prints "a" |
| 33 |
puts $y ;# Prints "b" |
| 34 |
puts $z ;# Prints "c" |
| 35 |
|
| 36 |
\fBlassign\fR {d e} x y z ;# Empty return |
| 37 |
puts $x ;# Prints "d" |
| 38 |
puts $y ;# Prints "e" |
| 39 |
puts $z ;# Prints "" |
| 40 |
|
| 41 |
\fBlassign\fR {f g h i} x y ;# Returns "h i" |
| 42 |
puts $x ;# Prints "f" |
| 43 |
puts $y ;# Prints "g" |
| 44 |
.CE |
| 45 |
.PP |
| 46 |
The \fBlassign\fR command has other uses. It can be used to create |
| 47 |
the analogue of the |
| 48 |
.QW shift |
| 49 |
command in many shell languages like this: |
| 50 |
.PP |
| 51 |
.CS |
| 52 |
set ::argv [\fBlassign\fR $::argv argumentToReadOff] |
| 53 |
.CE |
| 54 |
.SH "SEE ALSO" |
| 55 |
lindex(n), list(n), lrange(n), lset(n), set(n) |
| 56 |
.SH KEYWORDS |
| 57 |
assign, element, list, multiple, set, variable |
| 58 |
'\"Local Variables: |
| 59 |
'\"mode: nroff |
| 60 |
'\"End: |