3

As discussed here and here, the state of a notebook can be backed up by saving all variables using:

DumpSave["backup.mx", "Global`"];  

These variables can be restored using

<< "backup.mx"

Is there a way to do the same processes using the shorthand notation of the Put function, that is, by using >>.

Something like:

Names["Globa`*"]>>"backup.mx"`

(which doesn't work because Names returns a list of strings).

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Miladiouss
  • 1,883
  • 11
  • 26
  • If you are looking to write to a human-readable text file, like Put does, then use Save instead of DumpSave. Minor correction: What you show saves the state of the kernel. This state is not local to the notebook, so it doesn't really make sense to talk about the "state of the notebook". If you choose to use a default context local to the notebook (in the Evaluation menu), then symbols won't live in Global` anymore, so this command won't save them. – Szabolcs Aug 24 '17 at 09:00

1 Answers1

4

You could introduce a wrapper:

Dump /: Put[Dump[objects_], file_] := DumpSave[file, objects]

Then:

Dump["Global`"]>>"foo.mx"

will do a DumpSave and not a Put.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355