Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why join result of lreplace when it will be interpreted as a list anyway?

36 views
Skip to first unread message

clt.to...@dfgh.net

unread,
Jul 25, 2022, 3:12:03 PM7/25/22
to
tkcon appears to create

proc lremove {args} {
array set opts {-all 0 pattern -exact}
while {[string match -* [lindex $args 0]]} {
switch -glob -- [lindex $args 0] {
-a* { set opts(-all) 1 }
-g* { set opts(pattern) -glob }
-r* { set opts(pattern) -regexp }
-- { set args [lreplace $args 0 0]; break }
default {return -code error "unknown option \"[lindex $args 0]\""}
}
set args [lreplace $args 0 0]
}
set l [lindex $args 0]
foreach i [join [lreplace $args 0 0]] {
if {[set ix [lsearch $opts(pattern) $l $i]] == -1} continue
set l [lreplace $l $ix $ix]
if {$opts(-all)} {
while {[set ix [lsearch $opts(pattern) $l $i]] != -1} {
set l [lreplace $l $ix $ix]
}
}
}
return $l
}

which is useful. However I do not see why "join" is used in the foreach line:

foreach i [join [lreplace $args 0 0]] {

It appears to convert the list from lreplace to a string, which is then converted back to a list by foreach

What am I missing?

Dave B

0 new messages