Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg79710] Re: removing those annoying $$$$'s from local variables names?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 2 Aug 2007 03:53:56 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <f8pk78$2i1$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

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

will do that ...
but you have to keep care for the result
because
k=4;
foo[]

will produce
{4[1],4[2],4[3]}

if you don't care, that this is what you see, is not
that what you have than

myfoo[] :=
  Module[{c, k}, MakeBoxes[k, fmt_: StandardForm] := RowBox[{"k"}];
   c = Array[k, 3]]

will work.

Regards
   Jens

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
> 
> 


  • Prev by Date: Re: Differentiation w.r.t. elements of lists
  • Next by Date: Re: Unbearably slow plotting (v6)David Bailey,http://www.dbaileyconsultancy.co.uk
  • Previous by thread: Re: removing those annoying $$$$'s from local variables names?
  • Next by thread: Re: removing those annoying $$$$'s from local variables names?