lrepeat(n) Tcl Built-In Commands lrepeat(n)


lrepeat - Build a list by repeating elements

lrepeat number element1 ?element2 element3 ...?


The lrepeat command creates a list of size number * number of elements by repeating number times the sequence of elements element1 element2 .... number must be a positive integer, elementn can be any Tcl value. Note that lrepeat 1 arg ... is identical to list arg ..., though the arg is required with lrepeat.

lrepeat 3 a

→ a a a lrepeat 3 [lrepeat 3 0]
→ {0 0 0} {0 0 0} {0 0 0} lrepeat 3 a b c
→ a b c a b c a b c lrepeat 3 [lrepeat 2 a] b c
→ {a a} b c {a a} b c {a a} b c

list(n), lappend(n), linsert(n), llength(n), lset(n)

element, index, list

8.5 Tcl