Reputation: 3
In TCL (running v8.6.6) I want to create an array with a substitution of one or more of the value of the array with the value of another variable.
If we were in C I will write
float a = 10;
float b[4] = {1.0, 2.0, 3.0, 4.0};
b[2]=a;
and if I print on stdout I got 1.0 10.0 3.3 4.0.
In TCL instead I started by a simple exampe. I wrote
set a 10.0
set b $a
puts $b
I got 10.0 as output, but if I want to do the same in a array so I wrote
set a 10.0
set b {1.0 $a 3.0 4.0}
puts $b
and I'm expecting
1.0 10.0 3.0 4.0
but I got
-0.5 $a 0.5 0.79
Any idea?
Thanks a lot
Upvotes: 0
Views: 191
Reputation: 137557
Though you've found that creating a list with substitutions is done via the list
command, here's how to do the assignment to an element that is equivalent to b[2]=a;
from C.
lset b 2 $a
Upvotes: 0
Reputation: 4372
Curly brackets {}
prevent substitution, try:
set b [list 1.0 $a 3.0 4.0]
Upvotes: 2