lseqTcl 9.1 only

Makes a list of numbers in an arithmetic series.

lseq COUNT
lseq START ?to|..? END ??by? STEP?
lseq START count COUNT ??by? STEP?

Description

Gives a list of numbers from START, each one STEP more than the one before. The three forms are:

by before STEP is an optional word. The default STEP is 1, or -1 when END is less than START. A STEP that goes away from END gives an empty list, and a STEP of 0 gives START once.

Each number is an integer when each argument is an integer, in any form of Tcl such as 0x10. With a double, each number is a double rounded to the most decimal places of the arguments, so lseq 0 1 0.25 gives 0.0 0.25 0.5 0.75 1.0. An argument is a number: an expression such as 1+1 is an error.

Arguments

ArgumentTypeDefaultDescription
COUNTintegerrequiredThe count of numbers.
STARTnumberrequiredThe first number.
ENDnumberrequiredThe bound of the series: the last number when the series meets it.
STEPnumber1, or -1 when END is less than STARTThe difference between two numbers in a row.

Returns

The list of numbers.

Examples

% lseq 5
0 1 2 3 4

% lseq 1 5
1 2 3 4 5

% lseq 5 1
5 4 3 2 1

% lseq 1 to 9 by 3
1 4 7

% lseq 1 .. 4
1 2 3 4

% lseq 10 count 3
10 11 12

% lseq 10 count 3 by 2
10 12 14

% lseq 0 1 0.25
0.0 0.25 0.5 0.75 1.0

% lseq 0 1 by 0.3
0.0 0.3 0.6 0.9

% lseq 1 10 -1

% lseq 0x10 0x12
16 17 18

Errors

% lseq x
expected number but got "x"
-errorcode TCL VALUE NUMBER

% lseq 1+1
expected number but got "1+1"
-errorcode TCL VALUE NUMBER

% lseq 1 to
missing "to" value.
-errorcode NONE

% lseq 1 2 3 4 5
wrong # args: should be "lseq n ??op? n ??by? n??"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

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

See also