Ale*_*kov 7 wolfram-mathematica dump binaryfiles binary-data
正如文档所说," DumpSave以二进制格式写出定义,这些格式针对Mathematica的输入进行了优化." 有没有办法将Mathematica二进制转储文件转换回定义列表而不评估它们?Import["file.mx","HeldExpression"]不起作用......
DumpSave存储与符号,即相关联的值OwnValues,DownValues,UpValues,SubValues,DefaultValues,NValues,FormatValues.
所有的评估都是在Mathematica的会话中完成的,然后DumpSave保存了它的结果.
这些值存储在内部正式中.读取MX文件只会创建符号,并通过读取此内部格式来绕过评估程序,使用这些值填充它们.
也许你可以分享促使你提出这个问题的问题.
f[x_Real] := x^2 + 1
DumpSave[FileNameJoin[{$HomeDirectory, "Desktop", "set_delayed.mx"}],
f];
Remove[f]
f[x_Real] = x^2 + 1;
DumpSave[FileNameJoin[{$HomeDirectory, "Desktop", "set.mx"}], f];
setBytes =
Import[FileNameJoin[{$HomeDirectory, "Desktop", "set.mx"}], "Byte"];
setDelayedBytes =
Import[FileNameJoin[{$HomeDirectory, "Desktop", "set_delayed.mx"}],
"Byte"];
Run Code Online (Sandbox Code Playgroud)
然后,人们可以用SequenceAlignment[setBytes, setDelayedBytes]它来看出差异.我不知道为什么这样做,但我的观点是立场.所有使用值构建的评估Set都已在Mathematica会话中完成,然后才能保存DumpSave.当读取MX文件时,内部表示将被读回到Mathematica会话中,并且实际上不会对加载的定义进行评估.