Re: tracing all functions in a package



På Fri, 29 Aug 2008 22:35:48 +0200, skrev John Thingstad <jpthing@xxxxxxxxx>:

I wanted to trace all functions in a package and ended up with the unusually thorny code..

(loop for sym being each present-symbol in :pat-match if (fboundp sym) do (eval `(trace ,sym)))

Is there a better way to do this?

Thanks to all that replied. I eventually ended up with the following code.
(Just another utillity in my /Lisp Programs/misc directory.)
Note that 'package can be a a package structure, a package symbol or nick and defaults to current *package*.

use:
(load "../misc/traceall")
(tu:trace-all)
....
(tu:untrace-all)

code:

(defpackage :trace-utilleties
(:nicknames :tu)
(:use :cl)
(:export package-function-symbols trace-all untrace-all))

(in-package :trace-utilleties)

(defun package-function-symbols (&optional (package *package*))
"Return a list of all functions is a package.
A symbol is a function symbol if it is fboundp and not a macro or spesial operator."
(let (result
(current-package (if (packagep package) package (find-package package))))
(assert (not (eq current-package nil)) (package) "package ~S not found." package)
(do-symbols (symbol current-package result)
(when (and (eq (symbol-package symbol) current-package)
(fboundp symbol)
(not (macro-function symbol))
(not (special-operator-p symbol)))
(push symbol result)))
(nreverse result)))

(defmacro trace-all (&optional (package *package*))
"Trace all functions in package. Defaults to the current package."
`(trace ,@(package-function-symbols package)))

(defmacro untrace-all (&optional (package *package*))
"Untrace all the functins in the current package. Defaults to the current package."
`(untrace ,@(package-function-symbols package)))


--------------
John Thingstad
.



Relevant Pages

  • Re: macro problem
    ... little bit I whipped up the following macro. ... "Cause trace to be called on all functions in current package." ... doesn't cause any errors for me in CLISP. ...
    (comp.lang.lisp)
  • Re: Post Office Woes (mostly OT)
    ... I once filled in these humongous forms for lost mail, to help USPS try to trace it. ... One week later, one packet arrived in DK, then a month later I got mail from USPS saying that they had traced it all the way to the receipient (I know they had not been in touch with the recepient, not had the Danish mail). ... Maybe you could ask the GF to put a trace on the package? ...
    (rec.crafts.textiles.quilting)
  • Re: macro problem
    ... "Cause trace to be called on all functions in current package." ... ,@(loop for symbol being each present-symbol in package ... doesn't cause any errors for me in CLISP. ...
    (comp.lang.lisp)
  • Re: I am l so much wiser...
    ... And UPS is on my list right now -- grrrrrr. ... and the package is nowhere to be found. ... UPS won't even try to find it until a trace is initiated from the ... holidays, as I can't imagine a trace is quick, and the holidays will ...
    (rec.crafts.textiles.quilting)
  • Re: I am l so much wiser...
    ... And UPS is on my list right now -- grrrrrr. ... and the package is nowhere to be found. ... UPS won't even try to find it until a trace is initiated from the ... holidays, as I can't imagine a trace is quick, and the holidays will ...
    (rec.crafts.textiles.quilting)