Sujet : Re: The best way to copy a list?
De : apnmbx-public (at) *nospam* yahoo.com (Ashok)
Groupes : comp.lang.tclDate : 18. Jun 2025, 12:33:36
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102u86g$33dlm$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
Not sure I understand the question. Why not just
set b $a
?
Also, your code will not always give identical results using
expr ([expr {$x}] is not always $x). For example,
% set a {a 0x10 b}
a 0x10 b
% set b [lmap x $a {expr {$x}}]
a 16 b
You could use one of the following forms instead
% set b [lmap x $a {lindex $x}]
a 0x10 b
% set b [lmap x $a {string cat $x}]
a 0x10 b
% set b [lmap x $a {return -level 0 $x}]
a 0x10 b
but as I said, why not just set a $b ?
/Ashok
set a {a 0x10 b}
On 6/18/2025 12:49 PM, Mark Summerfield wrote:
Is using `lmap` the best way to copy a list? For example:
package require struct::list 1
set a {a bc def ghij klmno}
# is the following the best way to copy a list?
set b [lmap x $a {expr {$x}}]
puts "a={$a} b={$b} a==b=[struct::list equal $a $b]"
Output:
a={a bc def ghij klmno} b={a bc def ghij klmno} a==b=1