the lset command cannot change the size of a list
Closed / Out of Dateb55589c55b36c9908294e1f9631ea98ca98d6ae9Created 4 years agoUpdated 4 years ago
Descriptionmarkdown2023-02-17 14:41:26
The doc says...
The integer appearing in each index argument must be greater than or equal to zero. The integer appearing in each index argument must be strictly less than the length of the corresponding list. In other words, the lset command cannot change the size of a list. If an index is outside the permitted range, an error is reported.
my test case:
set abc [list a b c];
puts "${abc}";
puts "[lset abc 2 x]";
# error cases
puts "[catch {lset abc -2 x} res] res:$res";
puts "[llength ${abc}]";
puts "[catch {lset abc 14 x} res] res:$res";
puts "[catch {lset abc 13 x} res] res:$res";
puts "[catch {lset abc 12 x} res] res:$res";
puts "[catch {lset abc 3 x} res] res:$res";
puts "[llength ${abc}]";
puts "[catch {lset abc 4 x} res] res:$res";
puts "[llength ${abc}]";
returns
a b c
a b x
1 res:list index out of range
3
1 res:list index out of range
1 res:list index out of range
1 res:list index out of range
0 res:a b x x
4
0 res:a b x x x
5
Notice that when the index is exactly the length of the list that the newvalue is appended to the list, however, the doc says "STRICTLY" cannot change the size of the list.
jan.nijtmanswiki2023-02-17 16:14:21
Current documentation says something different:
https://core.tcl-lang.org/tcl/file?udc=1&ln=82-88&ci=04cf08d26a77fbc3&name=doc%2Flset.n
So, please report this to the place where you got your documentation from.
Log in (anonymous is fine) to add a comment.