func[i_] := i
Do[
"func["<>ToString@i<>"] = "<>ToString@func@i >>> "out.m"
, {i,1,3}
]
Edit 1: It's not clear to me what's your scope but, this does what you asked
"func["<>ToString@#<>"] = "<>ToString@func@# & /@ Range@3 //
Export["out.m", #~StringRiffle~"\n"<>"\n","Text"]&
Edit 2: Given that your scope is to create a file that contains only the DownValues
of a symbol f
, you do not need to define a substitution rule (:=
) for f
. So, let's just define the DownValues
of f and export them in a text file
Remove@f
f@#~Set~# &/@ Range@3
ToString@Information[f]@"DownValues" //
Export["out.m",#,"Text"]&
DumpSave
? $\endgroup$ – CA Trevillian Oct 13 '19 at 21:51out.m
being overwritten each time. I think you’re looking for something likeOpenWrite
see here for some other examples. $\endgroup$ – CA Trevillian Oct 14 '19 at 9:31DumpSave
you should be able to use the third option down in the templated examples, for this question. $\endgroup$ – CA Trevillian Oct 14 '19 at 9:34Save
would have worked if I just define just sayfun1=func[1]
, then it would have written inside out.m asfun1=1
. But I wantfunc[1]=1
in the output. And in a generic case thisfunc
definition may not be this simple. $\endgroup$ – Boogeyman Oct 14 '19 at 9:37