summaryrefslogtreecommitdiffstats
path: root/doc/lassign.n
blob: 4d1c3c89a66d101b06061239469f4b56caad8619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'\"
'\" Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans
'\" Copyright (c) 2004 Donal K. Fellows
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\" 
'\" RCS: @(#) $Id: lassign.n,v 1.2 2007/10/25 09:31:52 dkf Exp $
'\" 
.so man.macros
.TH lassign n 8.5 Tcl "Tcl Built-In Commands"
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
lassign \- Assign list elements to variables
.SH SYNOPSIS
\fBlassign \fIlist varName \fR?\fIvarName ...\fR?
.BE
.SH DESCRIPTION
.PP
This command treats the value \fIlist\fR as a list and assigns
successive elements from that list to the variables given by the
\fIvarName\fR arguments in order.  If there are more variable names
than list elements, the remaining variables are set to the empty
string.  If there are more list elements than variables, a list of
unassigned elements is returned.
.SH EXAMPLES
An illustration of how multiple assignment works, and what happens
when there are either too few or too many elements.
.CS
.ta 2.5i
lassign {a b c} x y z	\fB\(->\fI Empty return\fR
puts $x	\fB\(->\fI Prints "a"\fR
puts $y	\fB\(->\fI Prints "b"\fR
puts $z	\fB\(->\fI Prints "c"\fR

lassign {d e} x y z	\fB\(->\fI Empty return\fR
puts $x	\fB\(->\fI Prints "d"\fR
puts $y	\fB\(->\fI Prints "e"\fR
puts $z	\fB\(->\fI Prints ""\fR

lassign {f g h i} x y	\fB\(->\fI Returns "h i"\fR
puts $x	\fB\(->\fI Prints "f"\fR
puts $y	\fB\(->\fI Prints "g"\fR
.CE
.PP
The \fBlassign\fR command has other uses.  It can be used to create
the analogue of the
.QW shift
command in many shell languages like this:
.CS
set ::argv [lassign $::argv argumentToReadOff]
.CE
.SH "SEE ALSO"
lindex(n), list(n), lset(n), set(n)
.SH KEYWORDS
assign, element, list, multiple, set, variable