lrange

Gives the elements of a list from one index to another, as a list.

lrange LIST FIRST LAST

Description

Gives the elements of LIST from FIRST to LAST, both included, as a new list. A FIRST below 0 counts as 0, and a LAST past the end counts as the last element. When FIRST is after LAST, after that clamp, the result is an empty list.

The elements keep their form: an element in braces stays in braces.

Arguments

ArgumentTypeDefaultDescription
LISTlistrequiredThe list.
FIRSTindexrequiredThe index of the first element of the result.
LASTindexrequiredThe index of the last element of the result.

Returns

A list, empty when the range has no element.

Examples

% lrange {a b c d} 1 end-1
b c

% lrange {a b c d} -3 1
a b

% lrange {a b c d} 2 99
c d

% lrange {a b c d} 2 1

% lrange {a {b c} d} 1 1
{b c}

Errors

% lrange {a b} x 1
bad index "x": must be integer?[+-]integer? or end?[+-]integer?
-errorcode NONE

% lrange {a b} 0
wrong # args: should be "lrange list first last"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

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

See also