Re: Symbol name extraction
- To: mathgroup at smc.vnet.net
- Subject: [mg73752] Re: Symbol name extraction
- From: dh <dh at metrohm.ch>
- Date: Tue, 27 Feb 2007 05:51:34 -0500 (EST)
- References: <errlbu$83p$1@smc.vnet.net>
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
>
>