llength

Gives the count of elements of a list.

llength LIST

Description

Gives the count of elements of LIST. White space around and between the elements does not count, and an empty string is an empty list with 0 elements. An element in braces counts as one element, whatever it has inside.

LIST must be a valid list: an unbalanced brace or quote is an error.

Arguments

ArgumentTypeDefaultDescription
LISTlistrequiredThe list to count.

Returns

A non-negative integer.

Examples

% llength {a {b c} d}
3

% llength {}
0

% llength "  a   b  "
2

Errors

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

% llength a b
wrong # args: should be "llength list"
-errorcode TCL WRONGARGS

Facts

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

See also