MathGroup Archive 2007

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

Search the Archive

Re: Symbol name extraction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73777] Re: Symbol name extraction
  • From: "zac" <replicatorzed at gmail.com>
  • Date: Wed, 28 Feb 2007 04:32:21 -0500 (EST)
  • References: <errlbu$83p$1@smc.vnet.net><es135k$o03$1@smc.vnet.net>

That's crystal clear, using this information
I've created the function that satisfies my taste:

Attributes[PrintSymbolValue] = {HoldAll, Listable};
PrintSymbolValue[sym_Symbol] := SymbolName[Unevaluated[sym]] <>
    " = " <> ToString[FullForm[sym]] <> ";\n";

applied to a list of variables. A final StringJoin concatenates the
output list of strings.
Thank you Daniel.

Istvan


On Feb 27, 12:03 pm, dh <d... at metrohm.ch> wrote:
> Hi,
>
> The easy way to get your definitions into a file is "Save". If you still
>
> want to go the hard way, here it is:
>
> First, the argument of an ordinary function will be evaluated.
>
> Therefore, your function does not see the symbol at all. Therefore, we
>
> need the attribute "HoldFirst" or "HoldAll".
>
> Second, the same problem appears with the function Map inside
>
> printSymbol. You could define a new function myMap that has the
>
> necessary attribute, but I think an easier approach is to declare your
>
> function for a single argument and to give it the additional attribute
>
> "Listable".
>
> Third, the argument from SymbolName has to be protected against
>
> evaluation by "Unevaluated".
>
> Fourth, FullForm does not return a string, you have to convert.
>
> Here we go:
>
> zac wrote:
> > Dear Group,
>
> > I have to write a list of parameters to a file, in string format.
> > In the first shot, I've tried something like this:
>
> > a = "x";
> > b = 0;
> > c = {1, 2, 3};
>
> > printSymbol[vars__] :=StringJoin[Map[(SymbolName[#] <> " = " <>
> > FullForm[#] <>";\n") &, {vars}]];
>
> > printSymbol[a, b, c]
>
> > but it fails to recognize symbol names. Any suggestion?
> > thanks in advance
>
> > Istvan Zachar




  • Prev by Date: Re: disable SyntaxQ beep
  • Next by Date: Re: Why is 1 smaller than 0?
  • Previous by thread: Re: Symbol name extraction
  • Next by thread: Re: reliability function drawing