Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Consider the following example:

In[1]:= f[x_]:=x+1;g[x_]:=f[2x]

In[2]:= TracePrint[g[1]]
 g[1]
  g
  1
 f[2 1]
  f
  2 1
   Times
   2
   1
  2
 f[2]
 2 + 1
  Plus
  2
  1
 3

Out[2]= 3

So far, so good. However I'd now like to instruct TracePrint to treat evaluation of f as atomic, that is not to print the intermediate steps of evaluating f[2], so that the next line after f[2] would be 3 (but without excluding any other lines). My first idea was to just make f read protected:

In[3]:= SetAttributes[f,ReadProtected]

In[4]:= TracePrint[g[1]]
 g[1]
  g
  1
 f[2 1]
  f
  2 1
   Times
   2
   1
  2
 f[2]
 2 + 1
  Plus
  2
  1
 3

Out[4]= 3

As you can see, the inner working of f is still traced. However the attribute is otherwise honoured:

In[5]:= ?f
Global`f

Attributes[f] = {ReadProtected}

Another thing which does not work is

TracePrint[g[1],Except[_f]]

which again gives the complete trace.

So how do I instruct TracePrint to treat the function f as atomic?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Maybe

  TracePrint[g[1], TraceOff -> f]

?

share|improve this answer
5  
They should really mention that option on the TracePrint help page! –  celtschk Apr 17 '12 at 9:52
    
@celtschk, couldn't agree more. –  kguler Apr 17 '12 at 9:53
1  
@celtschk The documentation of Trace has a whole list of options. The documentation of TracePrint says (among other things): "TracePrint does not support the TraceBackward option of Trace." which (rather vaguely, I agree) implies other options of Trace should work. See also this tracing overview –  Sjoerd C. de Vries Apr 17 '12 at 10:51
1  
Don't forget TraceInternal a boolean flag (previously documented, but not anymore) which will allow tracing into the internal functions not normally traceable. –  rcollyer Apr 24 '12 at 2:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.