Group Abstract Group Abstract

Message Boards Message Boards

Saving data directly in notebooks

Posted 9 years ago
POSTED BY: Szabolcs Horvát
8 Replies
Posted 9 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 9 years ago

I wonder if a user can make his own iconography thingy like the one in Out[3] in https://reference.wolfram.com/language/ref/TimeSeries.html? It has more features like myFunctionHead[ ] around the icon and the + button, etc.

POSTED BY: Data Computist

Yes. They are called “summary boxes”. See here:

See István's answer on how to create summary boxes that are just like the builtin ones. This requires using some undocumented things (but I don't expect that to be problematic in this case). See my answer on how to imitate them by using only documented constructs.

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.

enter image description here - Congratulations! This post is now a Staff Pick! Thank you for your wonderful contributions. Please, keep them coming!

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