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

what does this piece of code mean?

49 views
Skip to first unread message

chenyo...@gmail.com

unread,
May 17, 2013, 4:02:21 AM5/17/13
to
Hi,

I found a piece of code like this:

puts "chk point1.2: pArr(value) is $pArr(value)";
eval "set pArr(value) \[$pArr(value)\]";
puts "chk point1.3: pArr(value) is $pArr(value)";

what does this eval "set pArr(value) \[$pArr(value)\]" mean? I have tried this code and got output as

chk point1.2: pArr(value) is PHY_DLL_SLAVE_CTRL_REG_rank0 data_slice 0
chk point1.3: pArr(value) is 16448

It seems $pArr(value) is a string, but how can "\[$pArr(value)\]" make this string to be a number? I was confused. Could you please give me some help? thanks.

Georgios Petasis

unread,
May 17, 2013, 5:30:49 AM5/17/13
to
Its easy, "eval" in the begining "executes" the string. Its like you
have written:

set pArr(value) [PHY_DLL_SLAVE_CTRL_REG_rank0 data_slice 0]

George

Don Porter

unread,
May 17, 2013, 10:07:36 AM5/17/13
to
On 05/17/2013 04:02 AM, chenyo...@gmail.com wrote:
> puts "chk point1.2: pArr(value) is $pArr(value)";
> eval "set pArr(value) \[$pArr(value)\]";
> puts "chk point1.3: pArr(value) is $pArr(value)";
>
> what does this eval "set pArr(value) \[$pArr(value)\]" mean? I have tried this code and got output as

That should be more clearly written as the equivalent:

set pArr(value) [eval $pArr(value)]

For the particular example, this would do as well, though it's not
precisely the same:

set pArr(value) [{*}$pArr(value)]

Just as a general observation, if you see example Tcl code with both a
semicolon and a newline terminating each command, don't expect it to be
the most idiomatic of examples. Get your role models somewhere else.

--
| Don Porter Applied and Computational Mathematics Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|
0 new messages