MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

removing those annoying $$$$'s from local variables names?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79676] removing those annoying $$$$'s from local variables names?
  • From: Nasser Abbasi <nma at 12000.org>
  • Date: Wed, 1 Aug 2007 05:12:54 -0400 (EDT)

Hello;

This is a problem I am sure many have seen. May be there is a simple
solution for it, but I can't find it.

This problem is when a function returns back a symbol which is local
to the function, then these synbols will have $nnnn tacked to them,
and so when the caller say prints the symbol, it will have those $'s
numbers, which make it annoying to look it and print, say as a table
or such.

This is an example:

------------- example 1 -------------

foo[] := Module[{c, k},
              c = Array[k, 3]
          ];

c = foo[];
Print[c];

{k$76[1], k$76[2], k$76[3]}
--------------------------------------------------

You see, since k is local to foo[], then when I print it, I see those $
$$ signs.

Only way to remove this $$$'s is to make k global as follows

------------------------ example 2 -------------------
Remove[k];
foo[] := Module[{c},
              c = Array[k, 3]
          ];

c = foo[];
Print[c];

{k[1], k[2], k[3]}
----------------------------------------

But making 'k' global is something I do NOT want to do, since now I
have to worry about 'k' having a value somewhere else in the code, and
it goes against the whole idea of encapsulation. If I start making all
my symbols global, then the code becomes hard to manage.

So, what should one do in this case?  How can make all the symbols
local to a function, but at the same time not see these $$$'s when the
symbols are used when they are returned from the function back to the
caller?

thanks,
Nasser



  • Prev by Date: RE: How do you set up third party (or your own) packages?
  • Next by Date: Re: Setting and Unsetting values, memory usage problems.
  • Previous by thread: Re: How do you set up third party (or your own) packages?
  • Next by thread: Re: removing those annoying $$$$'s from local variables names?