Re: Capturing input-output relation of a function
Stavros Macrakis <[email protected]> Tue, 21 Jan 2025 13:45:49 -0500
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <CACLVabXS9Hb=oQARQzh7NVzjFcmGDXVW4z8-3ZsPQdQntCX3_w@mail.gmail.com> |
Thanks for the quick and very helpful replies!
Re-reading the *trace* doc, I now see that I could also do this (but not as
elegantly or robustly) like this:
(defvar *call-rets* nil)
(defvar *calls* nil)
(defun rep (depth func inout frame values)
(cond ((eq inout :enter) (push values *calls*))
((eq inout :exit) (push (list (pop *calls*) values) *call-rets*))
(t (error "rep can't handle non-local exits: ~S" (list depth func
inout frame values)))))
(trace ff :report rep)
(setq *call-rets* nil *calls* nil)
(ff 3) => 6
*call-rets* =>
(((3) (6)) ((2) (2)) ((1) (1)))
-s
On Tue, Jan 21, 2025 at 8:28 AM Douglas Katzman <[email protected]> wrote:
> * (defvar *ff-args/results* nil)
> *FF-ARGS/RESULTS*
> * (sb-int:encapsulate 'ff 'wrap (lambda (realfun arg) (let ((answer
> (funcall realfun arg))) (push (list arg answer) *ff-args/results*) answer)))
> #<FUNCTION SB-IMPL::ENCAPSULATION {1000BD539B}>
> * (ff 3)
> 6
> * (reverse *ff-args/results*)
> ((1 1) (2 2) (3 6))
>
_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help