Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • $\begingroup$ That answer never gave me the impression that it was saving the data within the notebook itself. Could you expand upon that? $\endgroup$ Commented May 23, 2012 at 15:37
  • $\begingroup$ @rcollyer In that answer, it was not,indeed. To make self-uncompressing within a notebook to work, one would have to write a function which would create a cell with the relevant code, and place it into a proper place (e.g. make it initialization cell), and hook that function to the computations being performed. I did not myself use this scheme, but it should be doable. $\endgroup$ Commented May 23, 2012 at 16:31
  • $\begingroup$ Well, after reading this, I've now written a function to do exactly that: SetAttributes[PermanentSet,HoldAll];PermanentSet[var_,value_]:=(If[a===Unevaluated[a],Module[{nb=EvaluationNotebook[]},SelectionMove[nb,Before,EvaluationCell];NotebookWrite[nb,Cell[ToString[Unevaluated[var]]<>" = Uncompress[\""<>With[{v=var},Compress[var=value]]<>"\"]","Input",Editable->False]]]];var). It assumes that the variable was previously undefined (if not, use =. on that variable in a previous cell). Also, the calculation should better not have any side effect. $\endgroup$ Commented May 23, 2012 at 17:51
  • $\begingroup$ @celtschk Yes, something along these lines. I wanted to write some more general functionality to do this sort of things, add some syntactic sugar etc, but don't have time for that right now. Your function may actually be sufficient for most situations. If you tested it and feel like including it into my answer, please do so. You probably meant var in place of a in your code, and a somewhat better test for whether or not a variable has a value can be found here $\endgroup$ Commented May 23, 2012 at 18:12
  • $\begingroup$ @LeonidShifrin: I've now already added it to my answer. Thanks for catching the bug, I indeed meant var (I always used a as variable in my tests, so I didn't notice). I'll also look into the test you lined. $\endgroup$ Commented May 23, 2012 at 18:22