lseq(n)
๐ lseq(n) โ bestie, let's build a whole numeric sequence ๐
ok so this is the manual page for lseq, a Tcl Built-In Command, and honestly? it's giving "make me a list of numbers real quick" and I am obsessed. no cap, it does exactly what it says on the tin and the tin is cute.
โจ NAME โจ
lseq โ Build a numeric sequence returned as a list ๐ฆ
๐ธ SYNOPSIS ๐ธ
lseq start ?(..|to)? end ??by? step?
lseq start count count ??by? step?
lseq count ?by step?
likeโฆ look at those forms. three whole moods. pick ur fighter ๐
๐ DESCRIPTION ๐
The lseq command creates a sequence of numeric values โ and those values can be either wide integers or doubles โ using the parameters you hand it: start, end, and step. The operation argument .. or to is what defines the range. The count option is used to define a count of the number of elements in the list. And there's a short form too: if you just give it a single count value, it'll create a range from 0 to count-1. iconic behavior honestly โจ
lseq can produce both increasing and decreasing sequences, bestie. When both start and end are provided without a step value, then if start <= end, the sequence will be increasing, and if start > end it will be decreasing. But if a step value is included, its sign should agree with the direction of the sequence (descending โ negative, ascending โ positive), otherwise an empty list is returned. like, nothing. ghosted. ๐ for example:
% lseq 1 to 5 ;# increasing
โ 1 2 3 4 5
% lseq 5 to 1 ;# decreasing
โ 5 4 3 2 1
% lseq 0 0.5 by 0.1 ;# doubles
โ 0.0 0.1 0.2 0.3 0.4 0.5
% lseq 6 to 1 by 2 ;# decreasing, step wrong sign, empty list
% lseq 1 to 5 by 0 ;# all step sizes of 0 produce an empty list
The numeric arguments โ start, end, step, and count โ may also be a valid expression. The expression will be evaluated and the numeric result will be used. But heads up: an expression that does not evaluate to a number will produce an invalid argument error. so keep it numeric, babe ๐
Start defines the initial value, and end defines the limit โ not necessarily the last value, ok? important distinction, don't come for me. lseq produces a list with count elements, and if count is not supplied, it is computed as:
count = int( (end - start + step) / step )
math girlies rise ๐งฎ๐
๐ EXAMPLES ๐
ok this is the fun part. watch:
lseq 3
โ 0 1 2
lseq 3 0
โ 3 2 1 0
lseq 10 .. 1 by -2
โ 10 8 6 4 2
set l [lseq 0 -5]
โ 0 -1 -2 -3 -4 -5
foreach i [lseq [llength $l]] {
puts l($i)=[lindex $l $i]
}
โ l(0)=0
โ l(1)=-1
โ l(2)=-2
โ l(3)=-3
โ l(4)=-4
โ l(5)=-5
foreach i [lseq {[llength $l]-1} 0] {
puts l($i)=[lindex $l $i]
}
โ l(5)=-5
โ l(4)=-4
โ l(3)=-3
โ l(2)=-2
โ l(1)=-1
โ l(0)=0
set i 17
โ 17
if {$i in [lseq 0 50]} { # equivalent to: (0 <= $i && $i <= 50)
puts "Ok"
} else {
puts "outside :("
}
โ Ok
set sqrs [lmap i [lseq 1 10] { expr {$i*$i} }]
โ 1 4 9 16 25 36 49 64 81 100
the range check one? main character energy. and that last one literally squares everything, ate and left no crumbs ๐ฅ
๐ SEE ALSO ๐
run don't walk to these besties:
foreach(n)list(n)lappend(n)lassign(n)lindex(n)linsert(n)llength(n)lmap(n)lpop(n)lrange(n)lremove(n)lreplace(n)lreverse(n)lsearch(n)lset(n)lsort(n)
๐ KEYWORDS ๐
element, index, list โ the holy trinity fr fr ๐ธ
ok that's the whole page, no skips, no cap. go make some sequences, bestie ๐
and that's a wrap!! this was the lseq(n) page from Tcl 9.0 ๐ซถ mwah, tysm for reading, go forth and sequence responsibly โจ๐
๐ฆ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 ยท TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 ยท TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 ยท TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 ยท TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 2022 Eric Taylor. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms