Re: "Skip this Input cell" module?

*To*: mathgroup at smc.vnet.net*Subject*: [mg68868] Re: "Skip this Input cell" module?*From*: albert <awnl at arcor.de>*Date*: Mon, 21 Aug 2006 06:33:25 -0400 (EDT)*References*: <ecbp11$rd4$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

> Suppose at the start of a notebook one defines two functions > > doCell[expr_] = expr ; skipCell[expr_] = Null ; > > (or maybe skipCell[expr_] = Print["Input skipped"] ) > that are intended to be wrapped around the full contents of certain > Input cells in order to temporarily allow or suppress execution of those > particular Input cells. > > Assuming the Input cells always contain a proper sequence of executable > expressions, will these definitions have any hidden "gotchas"? the gotcha is that expr will be evaluated in both cases, the second only suppresses the output. To make sure expr is not evaluated, you will need to: SetAttributes[skippCell[HoldFirst]] > Would they be better defined with = or := ? (or as Modules?) I think it does not make a difference in this case. > Should the argument be [expr_] or [expr_Expression]? use the first variant, the second would match almost never, I presume. > (Is Expression a > Head? The Mathematica Book doesn't seem to be totally clear about this.) It's not for just 'an expression', but why not just try that out? In[11]:= Head[a+b/2] Out[11]= Plus Of course, you can make it the head of an expression by defining the Expression explicitly: In[12]:= expr = Expression[a]; In[13]:= Head[expr] Out[13]= Expression but this has no meaning to mathematica. Anyway, Expression is a symbol in the system context, but only used as a tag for formatting information: In[14]:= ??Expression Expression is a symbol that represents an ordinary Mathematica expression in Read and related functions. Attributes[Expression] = {Protected} > Any other hidden gotchas if one defines instead > > doCell[test_, expr_] = If[test, expr, Print["input skipped"]]; again, to really prevent expr from being evaluated if test fails, you must now give doCell the Attribute HoldAll or HoldRest. hth, albert