lrepeat

Makes a list with the same elements repeated a number of times.

lrepeat COUNT ?ELEMENT ...?

Description

Gives a list of the ELEMENT arguments, in order, COUNT times. Each ELEMENT stays one element. A COUNT of 0 gives an empty list, and so does no ELEMENT. A negative COUNT is an error. The result counts toward the memory limit of the interpreter.

Arguments

ArgumentTypeDefaultDescription
COUNTinteger, 0 or morerequiredThe count of copies.
ELEMENTany valuenoneAn element of each copy.

Returns

The new list.

Examples

% lrepeat 3 a b
a b a b a b

% lrepeat 2 {a b}
{a b} {a b}

% lrepeat 0 a

Errors

% lrepeat -1 a
bad count "-1": must be integer >= 0
-errorcode NONE

% lrepeat x a
expected integer but got "x"
-errorcode NONE

Differences from Tcl

Facts

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

See also