Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > globalizing an array
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 26th February 00:49
arenatr
External User
 
Posts: 1
Default globalizing an array



Can it be done?

If I create an array locally, is it possible to globalize it for use by
other procs. I'm assuming it's just an "upvar", right? I tried it and I'm
getting an error that my array isn't a variable. Is there an "uparray?"
Can it be done?

Thanks again!

P.S. with all of my newbie questions, maybe we need a "comp.lang.tcl.newbie"
group where experts can provide us newbies with all of the answers. Might
be a great way for the intermediates to get up to the expert level by
answering newbie questions?
  Reply With Quote


  sponsored links


2 26th February 00:49
don porter
External User
 
Posts: 1
Default globalizing an array



[upvar #0] is sooooo Tcl 7.

You want to learn the [variable] command.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|_________________________________________________ _____________________|
  Reply With Quote
3 28th February 07:47
don porter
External User
 
Posts: 1
Default globalizing an array


Everywhere there is a "global" in Cameron's example, replace it with
"variable".

The resulting script will work exactly the same.

It will also have the advantage that when you later need to encapsulate
your work in a namespace, you will just place the whole thing inside
a [namespace eval] and be done.

IMHO, [global] should be considered a compatibility interface kept
around only to deal with code written for Tcl 7. New programmers
should learn the modern commands.

--
| Don Porter Mathematical and Computational Sciences Division |
| donald.porter@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|_________________________________________________ _____________________|
  Reply With Quote
4 28th February 07:47
donald arseneau
External User
 
Posts: 1
Default globalizing an array


claird@lairds.com (Cameron Laird) writes:

OK, would someone enlighten me? I still use [global], and maybe
my reason is bad too (I am sooo stuck in Tcl 7...)

My main use is for the -textvariable etc of Tk widgets, and I
usually group the variables for a page (toplevel) into a single
array.

Donald Arseneau asnd@triumf.ca
  Reply With Quote
5 28th February 07:47
les cargill
External User
 
Posts: 1
Default globalizing an array


Me too!

I understand that the reason is that it is more consonant with using
namespaces. If "variable foo" is attached to a namespace,
the entire .tcl file can be embedded in an
"eval namespace" without modification.

--
Les Cargill
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666