Skip to content

length

Syntax

length(list-expression)

Parameters

list-expression
an expression that evaluates to a list

Returns

The length of the list expression.

Description

The length() action is used to find the number of elements in a list. Since lists are 0-indexed, the index of the last item in a list of length \(n\) is \(n-1\).

It is an error if the argument to length() is not a list-expression.

Examples

Find the length of a list. This returns 3.

length(list(1,1,1))

Find the value of the last element in a list X. This sets last_item to 5.

X = list(1,2,3,4,5)
last_item = select(X, length(X) - 1)

See Also