I was digging inside the Iconize
implementation a little bit and saw that there's a function BoxForm`BoxFormAutoLoad
which loads the FormatValues
for objects.
For the most part it's boring, but one interesting function that I saw in it was Internal`WithTimeStamps
. A sample usage of BoxForm`BoxFormAutoLoad
is:
BoxForm`BoxFormAutoLoad[MakeBoxes,
IconizedObject["asd"],
StandardForm,
"NotebookTools`Iconize`",
{{IconizedObject, _}},
Hold[IconizedObject]
]
And tracking the WithTimeStamps
call inside we see it's running:
Internal`WithTimestampsPreserved[
{IconizedObject},
Apply[
(BoxForm`wasProtected = Unprotect[#1];
(* Uninteresting Which block removed *);
Protect[Evaluate[BoxForm`wasProtected]]) &,
{{IconizedObject, _}},
{1}
];
DumpGet[System`Private`$SystemFileDir <>
System`Dump`fixfile["NotebookTools`Iconize`"] <> "x"];
]
Running this seems to do nothing interesting so I'm wondering why it exists and in what way there are "Timestamps" in the call.
Answer
It is an internal and undocumented function that can be used to prevent reevaluation of expressions whenever particular symbols contained in them change. This is a simple example:
Clear[a, b];
b = 1 + a
(* 1 + a *)
Internal`WithTimestampsPreserved[{a}, a = 1];
{a, b}
(* {1, 1 + a} *)
Although the value of a
changed, the evaluator did not think that b
might need reevaluation.
That is because we preserved the timestamp of a
, i.e. forced it to remain the same.
Contrast with the normal behavior where updating a
also changed its timestamp, so now b
is out of date and must be reevaluated.
a = 1; {a, b}
(* {1, 2} *)
In some sense, it accomplishes the opposite of Update
, which can be used to force reevaluation in certain situations.
Comments
Post a Comment