MathGroup Archive 2007

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79701] Re: [mg79676] removing those annoying $$$$'s from local variables names?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 2 Aug 2007 03:49:15 -0400 (EDT)
  • Organization: Deep Space Corps of Engineers
  • References: <28372402.1185986494635.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Perhaps this will satisfy:

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

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

At a later time you can still replace "k" with k:

Clear[k]
d = c /. "k" -> k

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

That looks the same, but it isn't:

FullForm[c]
List["k"[1],"k"[2],"k"[3]]

FullForm[d]
List[k[1],k[2],k[3]]

Bobby

On Wed, 01 Aug 2007 04:12:54 -0500, Nasser Abbasi <nma at 12000.org> 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
>
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Serious Problem with GridLines
  • Next by Date: Re: removing those annoying $$$$'s from local variables names?
  • Previous by thread: Re: removing those annoying $$$$'s from local variables names?
  • Next by thread: Re: removing those annoying $$$$'s from local variables names?