You at least have to provide k0
with a delayed definition, otherwise you've fallen at the first hurdle, since the original input will already have been lost. This will give you a fighting chance:
k0 := 0.4 π;
Now, we need to work with the (unevaluated) ownvalues of this symbol, rather than allowing its definition ever to evaluate. Since we don't know what might be contained within the list (symbols or otherwise), we need rules to deal with all possibilities rather than just passing them indiscriminately to OwnValues
:
ClearAll[myOwnValues];
SetAttributes[myOwnValues, HoldAll];
myOwnValues[lst_List] := myOwnValues /@ Unevaluated[lst];
myOwnValues[sym_Symbol] := OwnValues[sym];
myOwnValues[_] := {};
Now,
Flatten@myOwnValues[{1, k0}]
(* -> {HoldPattern[k0] :> 0.4 π} *)
which is a reasonable start.
Modifying your fhold
to use this is straightforward:
ClearAll[fhold];
SetAttributes[fhold, HoldAll];
fhold[para_List] := ToString[HoldForm[para] /. Flatten@myOwnValues[para]];
And,
fhold[{1, k0}]
(* -> "{1, 0.4 Pi}" *)
as desired.
If you insist on π
instead of Pi
, you will need to specify ToString[..., StandardForm]
rather than the default second argument of OutputForm
. Or, remove ToString
entirely and just leave HoldForm
as the wrapper for this output.
fhold
seesk0
,k0
has already evaluated to1.25664
. You can't work back from this; the solution is to have e.g.k0 = HoldForm[0.4 \[Pi]]
. Then,fhold
works as it is. $\endgroup$DumpSave
the result into a file, and I use "{1,0.4π}" in the file name $\endgroup$k0
is a key variable, and its value is used in many other place, so I assign the value specifically $\endgroup$