Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

evalhook

evalhook

type: function (subr)
location: built-in
source file: xlbfun.c  and  xleval.c
Common LISP compatible: related
supported on: all machines

SYNTAX

(evalhook  <expr> <eval-expr> <apply-expr> [ <env> ] )
        <expr>          -       an expression to evaluate
        <eval-expr>     -       an expression for the evaluation routine
        <apply-expr>    -       an expression for APPLY - not used
        <env>           -       an environment expression - default is NIL

DESCRIPTION

EVALHOOK is a function that performs evaluation. The routine specified by <eval-expr> is called with the <expr> and <env> parameters. If <eval-expr> is NIL, then the normal system evaluator is called. The <apply-hook> is a dummy parameter that is not used in the current XLISP system. The <expr> contains the expression to be evaluated. If the <env> argument to EVALHOOK is not specified, NIL is used, which specifies to use the current global environment. The <env>, if specified, is a structure composed of dotted pairs constructed of the symbol and its value which have the form ((( (<sym1> . <val1> ) (<sym2> . <val2> ) ... ))).

EXAMPLES

(setq a 100)    (setq b 200)            ; set up global values
(evalhook '(+ a b) NIL NIL)             ; returns 300   - no <env>
(evalhook '(+ a b) NIL NIL              ; eval with a=1 and b=2
          '((((a . 1)(b . 2)))))        ;   returns 3
(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 XEVALHOOK 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.


Go to the first, previous, next, last section, table of contents.