Your recent patch for mtrace.lisp leaves open the case of functions of
type MFEXPR*, i.e. maxima functions (we are not concerned here with
maxima macros) whose arguments are not automatically evaluated by
MEVAL.
The patch below relies on the following considerations:
1) The variety of maxima functions is much more restricted than what
the table at the beginning of mtrace.lisp shows. I think the
following table gives the correct picture (like its counterpart in
mtrace.lisp, it ignores maxima macros or functional arrays).
;; Maxima function shadow type hook type mget
;; ____________________________________________________________
;; expr expr expr
;; mexpr expr expr t
;; mfexpr* mfexpr* expr
These types have the following meaning: Suppose MFUN evaluates to some
symbol in the MAXIMA package. That this symbol is of type
- EXPR (or SUBR) implies that it has a lisp function definition ==
(SYMBOL-FUNCTION MFUN)
- MEXPR implies that it has a (parsed) maxima language definition ==
(MGET MFUN 'MEXPR) and all arguments are evaluated by MEVAL.
- MFEXPR* implies that it has a lisp function definition == (GET MFUN
'MFEXPR*) and its arguments are not automatically evaluated by
MEVAL.
Note that the shadow type has to agree with the original function's
type in the way arguments are evaluated. On the other hand, I think
we are left with EXPR as the only hook type; as a matter of fact, this
is equivalent to the next point:
2) There is no need for MAKE-TRACE-HOOK to dispatch with respect to
HOOK-TYPE since, roughly speaking, proper handling of the traced
function's arguments is done by the trace handler in concert with
MEVAL*.
Note that I also removed the COPY-LIST used to pass the traced
function's argument list to the trace handler.
There remains an annoying problem with translated functions: tracing
some function of type MEXPR and then loading its translated version
(which is of type EXPR) will not cleanly untrace it (i.e., it is
effectively no longer traced but it remains on the list of traced
functions). I think that this has to be fixed somewhere in the
translation package.
More amusing than annoying is the following feature (the
interpretation of which is left to the reader).
(C1) foo(x):=x;
(D1) foo(x) := x
(C2) trace(foo);
(D2) [foo]
(C3) foo((untrace(foo),0));
*** - APPLY: the function |$foo| is undefined
1. Break MAXIMA[9]>
Fixing this (in case somebody regards this as a bug) would involve
some hacking of MEVAL*, I think.
Anyway, here is my patch.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: mtrace.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/mtrace.lisp,v
retrieving revision 1.1.1.1
diff -C2 -r1.1.1.1 mtrace.lisp
*** mtrace.lisp 8 May 2000 06:09:41 -0000 1.1.1.1
--- mtrace.lisp 30 Jun 2002 11:16:18 -0000
***************
*** 332,340 ****
#+cl
! (defun trace-unfshadow (fun type &aux new-fun)
! (cond ((and (fboundp fun)
! (consp (setq new-fun (symbol-function fun)))
! (consp (second new-fun))
! (among 'trace-args (second new-fun)))
(cond ((memq type '(expr subr fexpr fsubr))
(let ((oldf (trace-oldfun fun)))
--- 332,337 ----
#+cl
! (defun trace-unfshadow (fun type)
! ;; At this point, we know that FUN is traced.
(cond ((memq type '(expr subr fexpr fsubr))
(let ((oldf (trace-oldfun fun)))
***************
*** 344,348 ****
(t (remprop fun (get! type 'shadow))
(fmakunbound fun))))
- (t (format t "~%This function was no longer defined as an interpreted-trace"))))
;--- trace-fsymeval :: find original function
--- 341,344 ----
***************
*** 361,365 ****
(trace-oldfun fun))
(t (if (eq (get! type-of 'shadow) type-of)
! (get (cdr (getl fun (list type-of))) type-of)
(get fun type-of)))))
(trace-fsymeval
--- 357,361 ----
(trace-oldfun fun))
(t (if (eq (get! type-of 'shadow) type-of)
! (cadr (getl (cdr (getl fun `(,type-of))) `(,type-of)))
(get fun type-of)))))
(trace-fsymeval
***************
*** 645,659 ****
#+cl
(defun make-trace-hook (fun type handler)
! (CASE (GET! TYPE 'HOOK-TYPE)
! ((EXPR)
! `(lambda (&rest trace-args)
! (,handler ',fun (copy-list trace-args))))
! ((FEXPR)
! `(LAMBDA ("e &rest TRACE-ARGL)
! (,HANDLER ',FUN (copy-list TRACE-ARGL))))
! ;;;???
! ((MACRO)
! `(lambda ("e &rest TRACE-FORM)
! (,HANDLER (CAAR TRACE-FORM) (copy-list TRACE-FORM))))))
#+Maclisp
--- 641,649 ----
#+cl
(defun make-trace-hook (fun type handler)
! ;; Argument handling according to FUN's TYPE is already done
! ;; elsewhere: HANDLER, meval...
! (declare (ignore type))
! #'(lambda (&rest trace-args)
! (funcall handler fun trace-args)))
#+Maclisp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wolfgang
--
wjenkner@inode.at