Re: macro that renames a function and records in a global list each non-local exit
Stavros Macrakis <[email protected]> Wed, 3 Jun 2026 14:49:14 -0400
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Message-ID | <CACLVabXeN3LRY_mzvEN3eiae_XahFR_=mw+EyysF8SE28Y70ew@mail.gmail.com> |
You might want to look into the *cl-advice* library, or maybe making functions into CLOS generic functions and then using the *:before, :after, *and *:around* methods. On Wed, Jun 3, 2026 at 8:19 AM Barton Willis via Maxima-discuss < [email protected]> wrote: > > > > Here is an AI‑assisted macro (with some push‑back from me along the way) > that renames a Common Lisp function and records information about each > non‑local exit in a global list: > > ;; AI written > (defmacro define-renamed-with-nlexit (old-name new-name log-var) > "Rename OLD-NAME to NEW-NAME and wrap OLD-NAME so that any non-local > exit is recorded in LOG-VAR, which must be a place suitable for PUSH." > (let ((args (gensym "ARGS"))) > `(progn > ;; Save the old definition under NEW-NAME > (setf (symbol-function ',new-name) > (symbol-function ',old-name)) > > ;; Define the wrapper under OLD-NAME > (setf (symbol-function ',old-name) > (lambda (&rest ,args) > (handler-case > (apply #',new-name ,args) > > (condition (c) > (push (ftake 'mlist :function ',old-name > :renamed ',new-name > ;; Maxima list of args: (mlist arg1 arg2 > ...) > :args (cons (list 'mlist) ,args) > :condition c > :timestamp (get-universal-time)) > ,log-var) > (signal c))))) > > ',old-name))) > > Running the testsuite with > > (defvar *nonlocal-exit-limit* nil) > (define-renamed-with-nlexit $limit old-limit *nonlocal-exit-limit*) > > Results in > > (%i5) :lisp(msetq $xxx (fapply 'mlist *nonlocal-exit-limit*)) > > < stuff deleted> > > (%i5) map(sixth,xxx); > > (%o5) [[inf/ind],[1/(zerob+zeroa)],[x,x,box(inf)]] > > Maybe somebody could refine this macro further. > > --Barton > > _______________________________________________ > Maxima-discuss mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > _______________________________________________ Maxima-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/maxima-discuss