lappend
Adds values as elements to the end of the list in a variable.
lappend VAR ?VALUE ...?
Description
Adds each VALUE as one element to the end of the list in the variable VAR, and gives the new list. A value with spaces stays one element. A VAR with no value starts as an empty list, so lappend also makes a variable. With no VALUE the list stays as it is, and a missing VAR becomes an empty list.
The value of VAR must be a valid list.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable with the list. |
| VALUE | any value | none | An element to add. |
Returns
The new value of VAR.
Examples
% set l {a}
> lappend l "b c"
a {b c}
% unset -nocomplain nl
> lappend nl x y
x y
% set l {a}
> lappend l
a
Errors
% set bad "a \{b"
> lappend bad c
unmatched open brace in list
-errorcode TCL VALUE LIST BRACE
% lappend
wrong # args: should be "lappend varName ?value ...?"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1