I want to save some definitions to an .mx file in order to be able to load them quickly. However, I run into a strange problem.

If I do,

Export["file1.txt", Definition[test1]]

I get a file containing the definitions I want (this is human readable, so I can check the file contains what I want) and I can then load it with Get["file1"] after which the definitions have been loaded.

However, when I do the same with the MX format:

Export["file2.mx", Definition[test1], "MX"]

and then Get["file2.mx"] it returns Null and does not load the definitions (of course here I cannot check whether the mx file really contains the correct definitions so I don't know whether the issue is in saving or loading the file).

What am I doing wrong?

  • $\begingroup$ In your first example I get "Export::infer: Cannot infer format of file file1." are you sure you are not giving a file extension? $\endgroup$
    – rhermans
    Commented May 24, 2018 at 16:30
  • $\begingroup$ @rhermans, sorry I am. $\endgroup$
    – Kvothe
    Commented May 24, 2018 at 16:32

1 Answer 1


The issue

From the documentation of Definition:

Definition[symbol] prints as all values and attributes defined for symbol.

(emphasis mine)

The key here is the word "prints": Definition[symbol] only looks like the definitions of symbol, it's not actually replaced by them:

(* f[x_]:=x^2 *)
(* Definition[f] *)

Exporting in a human readable format causes the StandardForm of the expression to be exported (please correct me if it's another form), which is why it works. Exporting to "MX" exports the FullForm, which does not do what you want:

(* Definition[f] *)

How to do what you want

Basically, see DumpSave.

  • $\begingroup$ Thanks. I should have known. I have been burned by this before, but I forgot. $\endgroup$
    – Kvothe
    Commented May 24, 2018 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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