| Deutsch English Français Italiano |
|
<vlfhng$1ande$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Rich <rich@example.invalid>
Newsgroups: comp.lang.tcl
Subject: Re: The "leading zero means octal" thing...
Date: Mon, 6 Jan 2025 03:12:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <vlfhng$1ande$2@dont-email.me>
References: <vlcbrr$2ito3$1@news.xmission.com> <20250105164657.7eeaf441@lud1.home> <vles5e$16v92$1@dont-email.me> <20250105201301.1fe87ba4@lud1.home>
Injection-Date: Mon, 06 Jan 2025 04:12:49 +0100 (CET)
Injection-Info: dont-email.me; posting-host="aacc148df4532970fbc7162b818dee32";
logging-data="1400238"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sMLy1/BaTbNvW9NeZICRO"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:r4USznsKp7x8f8W7iWGxSNYtlBM=
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}]