Re: macro that renames a function and records in a global list each non-local exit
Barton Willis via Maxima-discuss <[email protected]> Thu, 4 Jun 2026 15:47:12 +0000
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Message-ID | <SN6PR07MB7952A3AB583E0BFC20A47773B6102@SN6PR07MB7952.namprd07.prod.outlook.com> |
Thanks, I didn't know about 'cl-advice'. My understanding is that `cl-advice` is not included in any ANSI CL implementation. Maybe I'll stick to pedestrian ways. --Barton ________________________________ From: Stavros Macrakis <[email protected]> Sent: Wednesday, June 3, 2026 1:49 PM To: Barton Willis <[email protected]> Cc: <[email protected]> <[email protected]> Subject: Re: [Maxima-discuss] macro that renames a function and records in a global list each non-local exit Caution: Non-NU Email 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]<mailto:[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]<mailto:[email protected]> https://lists.sourceforge.net/lists/listinfo/maxima-discuss<https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!BvFvSokXqsMJ6zEYclOHwkLI0GEF4Cu6Yh0hnI_j4OaK-ISaItMDz64sFFHHZzxwtxSuxHPa2KUsP08$> _______________________________________________ Maxima-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/maxima-discuss