Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $printCache = {};
- cachedPrint[code_] :=
- Internal`InheritedBlock[{Print},
- Unprotect@Print;
- Print[stuff__] /; (! TrueQ@$printCachingOverload) :=
- Block[{$printCachingOverload = True},
- AppendTo[$printCache, {stuff}];
- Print[stuff]
- ];
- Protect@Print;
- code
- ];
- cachedPrint~SetAttributes~HoldFirst;
- cachedPrint[Do[someSuperCoolFunction[x]; Print[x, " etc."], {x, 10}]]
- In[33]:= $printCache
- Out[33]= {{1, " etc."}, {2, " etc."}, {3, " etc."}, {4, " etc."}, {5,
- " etc."}, {6, " etc."}, {7, " etc."}, {8, " etc."}, {9,
- " etc."}, {10, " etc."}}
- In[34]:= DownValues@Print
- Out[34]= {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement