lassign

Puts the elements of a list in variables, and gives the elements that are left.

lassign LIST ?VAR ...?

Description

Sets each VAR to the element of LIST at its place: the first VAR to the first element, and so on. A VAR with no element left gets an empty string. The elements after the last VAR are the result, as a list.

With no VAR the result is LIST, as a list.

Arguments

ArgumentTypeDefaultDescription
LISTlistrequiredThe list.
VARvariable namenoneA variable for one element.

Returns

The elements of LIST that no variable got, as a list.

Examples

% lassign {1 2 3} a b
3

% lassign {1} a b
> list $a $b
1 {}

% lassign {1 2}
1 2

Errors

% lassign "a {b" x
unmatched open brace in list
-errorcode TCL VALUE LIST BRACE

% lassign
wrong # args: should be "lassign list ?varName ...?"
-errorcode TCL WRONGARGS

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also