# How can I get TracePrint to treat certain functions as atomic?

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
Globalf



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?

-

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

They should really mention that option on the TracePrint help page! –  celtschk Apr 17 '12 at 9:52
@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
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