Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.3K Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

Evaluate code at the startup of a notebook

Posted 2 years ago

Hey guys,

Is there any way to put expressions to be executed automatically when the notebook starts? For example, among others, I would like the following code to run when a notebook is opened:

ClearAttributes[If, HoldRest]

Regards,

Sinval

POSTED BY: Sinval Santos
5 Replies

On a side note, if you want a version of If[] without the HoldRest attribute to use only in your notebook's code, just define one. For example:

IfUnheld = If[##] &;
POSTED BY: Michael Rogers
Posted 2 years ago

Thanks Michael for the tip. I will try this procedure as well.

POSTED BY: Sinval Santos
Posted 2 years ago

Thanks to Eric and David for the alert and information. I will review this procedure.

POSTED BY: Sinval Santos

You can look at NotebookDynamicExpression. But I echo the comment by Eric, it would be an exceedingly, and perhaps, fatal mistake to make those changes to the If statement. To misquote, Shakespeare: there are more things in heaven and If than are dreamt of in your philosophy…

There are huge amounts of Mathematica code behind the scenes, running things. And if you change that attribute, it’s likely that your entire universe will collapse around you. Be careful out there it’s wild.

POSTED BY: David Reiss
Posted 2 years ago

You can make cells into Initialization Cells via Cell->Cell Properties.

Having said that, it strikes me as a very bad idea to clear the HoldRest property of If.

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