I am trying to create a function that saves a set of symbols into "test.mx" and is easy to use.
list = {a,b,c}; f[x_] := x^2; z = 12.45; save["test"][list,f,z] In my attempt, something is saved, because the resulting file is not empty, but I cannot retrieve it. I suspect that the original symbols (list,f,z) are evaluated in the moment of passing the arguments to the function, and the symbols are lost.
Following other related posts, I tried a few things with Hold, Evaluate, Unevaluated, ToString, without success. Any comment would be much appreciated.
My attempt:
Clear[save] save[where_][what__]:=Module[{directory,symbols}, directory=NotebookDirectory[]<>"/save/"<>where<>".mx"; If[! DirectoryQ[DirectoryName[directory]], CreateDirectory[DirectoryName[directory]]]; symbols={what}; DumpSave[directory,symbols];]
Module:directory = NotebookDirectory[] <> "/save/"; DumpSave[directory <> "test.mx", {z, f, list}]; SetDirectory[directory]; << test.mx$\endgroup$