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

How to implement pointer operation

9 views
Skip to first unread message

prabu

unread,
Jun 28, 2007, 8:53:04 AM6/28/07
to
Hi,

This may be a simple one. Consider the following.

set a 10
set b $a

Now I want to print the value of "a" using the variable "b". How can I
do this?

Thanks in Advance,
Prabu.

Ron Fox

unread,
Jun 28, 2007, 9:17:27 AM6/28/07
to


You want something like this:

set a 10
set b a; # B 'points' to a

puts [set $b]

In the puts command, first $b is substituted leaving [set a]
Then the []'s are done and the result of [set a] is the contents
of the variable a.. or 10.

Ron.

Donal K. Fellows

unread,
Jun 28, 2007, 11:26:44 AM6/28/07
to
Ron Fox wrote:
> You want something like this:
>
> set a 10
> set b a; # B 'points' to a
> puts [set $b]

The other thing is that almost all code that does this a lot is better
written using arrays.

set ary(a) 10
set b a
puts $ary($b)

Donal.

prabu

unread,
Jun 29, 2007, 12:28:27 AM6/29/07
to
On Jun 28, 8:26 pm, "Donal K. Fellows"

Thanks guys

Tobias Hippler

unread,
Jun 29, 2007, 4:10:00 AM6/29/07
to

Hi,

in addition to the already proposed solutions, you can always use
"upvar" to create sort of references to variables:

set a 10
upvar 0 a b

set b 17
puts $a; # output: 17

Tobi.

0 new messages