Re: Capturing input-output relation of a function
Marco Antoniotti <[email protected]> Tue, 21 Jan 2025 14:19:50 +0100
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <CAG0Nw2=uQdYPDp9Mo_J4OtJCezhQCTkATx538BMevG3TE9D4Lg@mail.gmail.com> |
What's wrong with
(defun memoize-calls (fun &rest args-tuples)
(mapcar #'(lambda (args-tuple)
(list fun args-tuple (apply fun args-tuple)))
args-tuples))
?
Or something like that, only more correct?
MA
On Tue, Jan 21, 2025 at 1:35 PM Andreas Franke via Sbcl-help <
[email protected]> wrote:
>
> (defun capture-args/values ()
> (destructuring-bind (breakpoint-fun-frame . more-frames)
> (list-backtrace :start 3 :count 3)
> (destructuring-bind (_lambda _lambda-list _in _trace-breakpoint-fun)
> (first breakpoint-fun-frame)
> (assert (eql 'lambda _lambda))
> (assert (listp _lambda-list))
> (assert (eql :in _in))
> (ecase _trace-breakpoint-fun
> ((sb-debug::trace-start-breakpoint-fun)
> (let ((args (cdddr breakpoint-fun-frame)))
> (destructuring-bind (_trace-call _trace-info _f . _args)
> (first more-frames)
> (declare (ignorable _trace-info))
> (assert (eql 'sb-debug::trace-call _trace-call))
> (assert (equal args _args))
> (list (sb-kernel:%fun-name _f)
> :args _args))))
> ((sb-debug::trace-end-breakpoint-fun)
> (let ((values (cadddr breakpoint-fun-frame)))
> (destructuring-bind (_trace-call _trace-info _f . _args)
> (second more-frames)
> (declare (ignorable _trace-info))
> (assert (eql 'sb-debug::trace-call _trace-call))
> (list (sb-kernel:%fun-name _f)
> :args _args
> :values values))))))))
>
> (trace ff :condition-all (progn (push (capture-args/values) mystack) nil))
>
> (ff 3)
>
> (progn (mapc #'print (reverse mystack)) (values))
> ==>
> (FF :ARGS (3))
> (FF :ARGS (2))
> (FF :ARGS (1))
> (FF :ARGS (1) :VALUES (1))
> (FF :ARGS (2) :VALUES (2))
> (FF :ARGS (3) :VALUES (6))
>
> Using :condition-after should give you what you need.
>
> HTH,
> Andreas
>
>
> Given
>
>
> (defun ff (n) (if (< n 2) 1 (* n (ff (1- n)))))
>
> (ff 3)
>
>
> I want to capture the input-output pairs:
>
> (ff 1 1)
> (ff 2 2)
> (ff 3 6)
>
>
> (defvar mystack nil)
>
> _______________________________________________
> Sbcl-help mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sbcl-help
>
--
Marco Antoniotti, Professor, Director tel. +39 - 02 64 48 79 01
DISCo, University of Milan-Bicocca U14 2043 http://dcb.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY
_______________________________________________
Sbcl-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sbcl-help