Group Abstract Group Abstract

Message Boards Message Boards

Saving data directly in notebooks

Posted 8 years ago
POSTED BY: Szabolcs Horvát
8 Replies
Posted 8 years ago

Very cool Szabolcs, much better than pasting large matrices in an input cell and walling it off within a Section.

POSTED BY: Updating Name

About CellLabel... the same thing happens with CellTags. I don't know of other options like this that behave differently (i.e. last option takes precedence). I have already reported this issue to Wolfram Technical Support. If you know of more, then please let me know and I'll update the report.

POSTED BY: Kevin Daily
Posted 8 years ago
POSTED BY: Data Computist
POSTED BY: Szabolcs Horvát

I forgot to say that when you create summary boxes, you must be extremely careful not to introduce evaluation leaks. Here's a naive way to do it, which will then cause problems:

ClearAll[date]
date /: MakeBoxes[expr : date[{y_, m_, d_}], form : StandardForm | TraditionalForm] :=
 With[{boxes = 
    ToBoxes[Panel@Grid[{{"year:", y}, {"month:", m}, {"day:", d}}], form]},
  InterpretationBox[boxes, expr]
  ]

enter image description here

All good so far.

Now let's make a function that creates a date:

make2017Date[{m_, d_}] := date[{2017, m, d}]

And see its definition:

enter image description here

Still looking good. But now define:

m = 12;

enter image description here

Oops! Evaluation leak!

Something much worse could happen too. What if m contains code, like m := Print["Boo!"]?

The simple way to fix it is to put checks on your values:

date /: MakeBoxes[expr : date[{y_Integer, m_Integer, d_Integer}], ...] := ...
POSTED BY: Szabolcs Horvát

I think that this functionality should be built into Wolfram Language. It is similar to static variables or #defines in c and other languages.

POSTED BY: EDITORIAL BOARD

Very neat! Thanks for sharing!

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard