For certain persistence locations, such as "Notebook" or "FrontEndSession", Once adds $CellContext` to all Global` symbols, e.g.
Once[x, "Notebook"]
after the second evaluation (when the persistent object has been created) will only give
$CellContext`x
and not just x.
I'm sure there's a good reason for this (avoiding collisions), but I see two problems at the moment:
- The obvious problem that all names of symbols are now changed.
- In my case, in place of
xI have an expression that returns a fairly long result, and the addition of$CellContext`to each symbol name blows up the stored result unnecessarily.
How can I get Once not to add $CellContext` to every symbol name?
I have already tried some tricks such as Block[{$Context = "System`"}, …] (as in Exporting notebooks inserts unwanted $CellContext. Workaround?), but Once appears to be treatment-resistant.
(I'm aware that one can access and change the content of the corresponding PersistentObject and in this way manually remove the added context, but this seems like a risky brute force solution to me.)
Once[...]should produce the same output on each subsequent evaluation as it did for its first evaluation—that's its whole deal! In the meantime...hmmm. Maybe you could remove the$CellContexts forcibly after evaluation as a workaround? Might defeat the point ofOncethough... – thorimur May 16 '22 at 05:53PersistentObjectafter creation (although I'm not sure how the hashes are created) and then change the value insidePersistentObject[…]["Value"]. Seems risky to me. I think the main problem is thatOnceis hard to control — compare how in the answer I referenced there was indeed a solution withBlockthat doesn't work here. – Deniz May 16 '22 at 06:00Log[64, (16*16)^8]is 10 and 2/3. – thorimur May 16 '22 at 08:26