|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file:
;; https://anggtwu.net/LISP/2026-save-orig.lisp.html
;; https://anggtwu.net/LISP/2026-save-orig.lisp
;; (find-angg "LISP/2026-save-orig.lisp")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;; See: (find-es "lisp" "save-orig")
;;
;; (defun e () (interactive) (find-angg "LISP/2026-save-orig.lisp"))
;; (find-clhsdoci "intern")
(defun mydbg-add-orig (f) (intern (format nil "~s-ORIG" f)))
(defun mydbg-save-orig (f)
(let ((f-orig (mydbg-add-orig f)))
(cond ((fboundp f-orig)
(format nil "~s already defined, not redefining" f-orig))
(t (setf (fdefinition f-orig)
(fdefinition f))
(format nil "~s -> ~s" f f-orig)))))
#|
* (eepitch-sbcl)
* (eepitch-kill)
* (eepitch-sbcl)
(load "2026-save-orig.lisp")
(mydbg-add-orig 'foo) ;;-> FOO-ORIG
(defun foo (a b) (+ a b))
(mydbg-save-orig 'foo) ;;-> "FOO -> FOO-ORIG"
(defun foo (a b) (+ (* 10 a) b))
(mydbg-save-orig 'foo) ;;-> "FOO-ORIG already defined, not redefining"
(foo-orig 2 3) ;;-> 5
(foo 2 3) ;;-> 23
|#
(defvar mydbg-stack)
(defvar mydbg-ind)
(setq mydbg-stack nil)
(setq mydbg-ind 0)
(defun mydbg-ind (delta) (setq mydbg-ind (+ mydbg-ind delta)))
(defun mydbg-spaces () (make-string mydbg-ind :initial-element #\Space))
(defun mydbg-push (list) (push `(,(mydbg-spaces) ,@list) mydbg-stack))
(defun mydbg-push-c (list) (mydbg-push `(c ,@list)) (mydbg-ind +1))
(defun mydbg-push-r (list) (mydbg-ind -1) (mydbg-push `(r ,@list)))
(defun mydbg-run-orig (f args)
(mydbg-push-c `(,f ,@(copy-tree args)))
(let ((retval (apply (mydbg-add-orig f) args)))
(mydbg-push-r `(,f ,@(copy-tree retval)))
retval))
(defun mydbg-trace (f)
(mydbg-save-orig f)
(eval `(defun ,f (&rest args) (mydbg-run-orig ',f args))))
(defun mydbg-stack-print ()
(loop for o in (reverse mydbg-stack)
do (format t "~S~%" o)))
(mydbg-trace 'meval)
(mydbg-trace 'simplifya)
#|
* (eepitch-maxima)
* (eepitch-kill)
* (eepitch-maxima)
f(x) := (1+2)*x;
to_lisp();
(load "2026-save-orig.lisp")
#$f(4)$
(mydbg-stack-print)
(macroexpand '(
(defun simplifya-dbg (&rest args)
(mydbg-push-c `(simplifya ,@(copy-tree args)))
(let ((retval (apply #'simplifya-orig args)))
(mydbg-push-r `(simplifya ,(copy-tree retval)))
retval))
)
)
(to-maxima)
|#
;; Local Variables:
;; coding: utf-8-unix
;; End: