Re: removing those annoying $$$$'s from local variables names?
- To: mathgroup at smc.vnet.net
- Subject: [mg79716] Re: removing those annoying $$$$'s from local variables names?
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Thu, 2 Aug 2007 03:57:03 -0400 (EDT)
- References: <f8pk78$2i1$1@smc.vnet.net>
Nasser Abbasi wrote:
> 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
>
>
The point is that symbols local to a Module should not ideally be
returned - most people consider this to be a mistake. Every symbol must
have a name, and to a first approximation the only difference between a
local name and a global one is the $... appended to the name.
Why not tell us a bit more about what you are trying to do.
David Bailey
http://www.dbaileyconsultancy.co.uk