4
$\begingroup$

I tried to follow the answer in How to save/load (export/import) symbolized variables?. In my case, I would add the code:

 DumpSave[ "~/file.mx",{"`*", NotationMakeBoxes, NotationMakeExpression} ]

where it was recommended to not use Block for a DumpSave. This does not work as I get the following error message:

enter image description here

If I try instead:

DumpSave["~/file.mx",{Evaluate[Context[]], NotationMakeBoxes, NotationMakeExpression} ]

then I get:

enter image description here

although this IS a context and in fact works, if it is the only argument as in:

 DumpSave["~/file.mx",Evaluate[Context[]]]
$\endgroup$
4
$\begingroup$

Notice that DumpSave has attribute HoldRest which prevents evaluation of all but its first argument.

The documentation of Evaluate states:

  • You can use Evaluate to override HoldFirst etc. attributes of built-in functions.

  • Evaluate only overrides HoldFirst etc. attributes when it appears directly as the head of the function argument that would otherwise be held.

But in

DumpSave["~/file.mx",{Evaluate[Context[]], NotationMakeBoxes, NotationMakeExpression} ]

Evaluate does not wrap the second argument so it is held unevaluated. Yes, Evaluated does appear in the second argument, but not at its top level (level 0, a.k.a. head of the expression).

Try to use

DumpSave["~/file.mx", Evaluate@{Context[], NotationMakeBoxes, NotationMakeExpression}]

or

With[{context = Context[]},
 DumpSave["~/file.mx", {context, NotationMakeBoxes, NotationMakeExpression}]
 ]
$\endgroup$
  • $\begingroup$ Thank you very much! Both methods work. Just for clarity, I can understand why the second proposition works, but why does the first work, compared to trying to use Evaluate only on Context? $\endgroup$ – Patrick.B Feb 3 at 18:05
  • $\begingroup$ Your Evaluate was on the second level of the second argument and the HoldRest attribute of DumpSave prevented scanning of the second level. Try also SetAttributes[f, HoldRest];f[1, {Evaluate@Context[]}] vs.SetAttributes[f, HoldRest];f[1, Evaluate@{Context[]}]. $\endgroup$ – Henrik Schumacher Feb 3 at 18:07
  • 2
    $\begingroup$ You have assumed @Patrick.B knows how Evaluate works. And without reading its documentation your explanation may be vague. (sorry for being picky but another question was posted that assured me that it is the case) $\endgroup$ – Kuba Feb 3 at 19:04
  • 1
    $\begingroup$ @Kuba Yes, I've seen that other question. I added some more (pun allert!) context. $\endgroup$ – Henrik Schumacher Feb 3 at 19:11
  • $\begingroup$ Thanks for the patience you are showing to me. I indeed am not aware on the internal mechanism of Evaluate (or just about any built-in functions to be frank). The explanation and examples ended being clear to me in the end though. Thanks again for putting up with me. $\endgroup$ – Patrick.B Feb 3 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.