*evalhook* is a system variable whose value is user code that will
intercept evaluations either through normal system evaluation or through
calls to evalhook. The default value for
*evalhook* is 
(((sym1 . val1) (sym2 . val2) ... )))
(defun myeval (exp env)           ; define MYEVAL routine
  (princ "exp: ") (print exp)
  (princ "env: ") (print env)
  (evalhook exp #'myeval NIL env))
(defun foo (a) (+ a a))           ; create simple function
(setq *evalhook* #'myeval)        ; and install MYEVAL as hook
(foo 1)                           ; prints exp: (FOO 1) env:NIL
                                  ;        exp: 1       env:NIL
                                  ;        exp: (+ A A) env:((((A . 1))))
                                  ;        exp: A       env:((((A . 1))))
                                  ;        exp: A       env:((((A . 1))))
                                  ; returns 2
(top-level)                       ; to clean up *evalhook*
Note: The evalhook function and *evalhook* system variable are very useful in the construction of debugging facilities within XLISP. The trace and untrace functions use evalhook and *evalhook* to implement their functionality. The other useful aspect of evalhook and *evalhook* is to help in understanding how XLISP works to see the expressions, their environment and how they are evaluated.
Caution: Be careful when using *evalhook* and evalhook. If you put in a bad definition into *evalhook*, you might not be able to do anything and will need to exit XLISP.
Unusual behaviour: The evalhook function and *evalhook* system variable, by their nature, cause some unusual things to happen. After you have set *evalhook* to some non-NIL value, your function will be called. However, when you are all done and set *evalhook* to NIL or some other new routine, it will never be set. This is because the evalhook function [in the 'xlbfun.c' source file] saves the old value of *evalhook* before calling your routine, and then restores it after the evaluation. The mechanism to reset *evalhook* is to execute the top-level function, which sets *evalhook* to NIL.
See the
*evalhook*
system variable in the