Sujet : Re: The "leading zero means octal" thing...
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tclDate : 06. Jan 2025, 04:12:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vlfhng$1ande$2@dont-email.me>
References : 1 2 3 4
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Luc <
luc@sep.invalid> wrote:
So thanks to you, I have updated the code once again.
You do know about the "foreach" loop, that specifically iterates across
each element of a list, right?
Even if you don't want to use lmap (which does require 8.6 IIRC) you
don't need a C style "for" loop to iterate a list. Your "for {set x 0}
loop could be something like:
set cleanargs {}
foreach arg $args {
if {[string length $arg] > 1} {
lappend cleanargs [string trimleft $arg 0]
} else {
lappend cleanargs $arg
}
}
Alternately, since you are recreating seq, which only expects numbers
as args, you could do:
set cleanargs {}
foreach arg $args {
lappend cleanargs [scan $arg %d]
}
Which will handle any number of leading zeros (while producing decimal
output) and will error out on non-numeric inputs.
And, if you are willing to use lmap, the above four lines can become
this single line:
set args [lmap arg $args {scan $arg %d}]