Next: A few more Up: Sather Lisp Previous: Function definition

Error recovery

Currently, after a parse_ or run_time, the interpreter only prints out a short error message and returns to the read_eval_write loop. If the error hapens during file input (i.e., during the evaluation of a (readFile arg) expression, also the file name (arg) is displayed. However, the Lisp tracing facility can be used to simplify the location of bugs. The function tracer is turned on by evaluating (tracer on), and turned off by evaluating (tracer off). When on, the interpreter prints out the every (predefined and user_defined) function call together with its arguments and the return value. The following shows the trace of the expression (sum 3) (sum is defined in Section 8):


> (tracer on)
on
> (sum 3)
[sum] called with (3)
   [cond] called with (((<= #0 0) 0) (t (+ #0 (sum (- #0 1)))))
      [<=] called with (#0 0)
      [<=] returns nil
      [+] called with (#0 (sum (- #0 1)))
         [sum] called with ((- #0 1))
            [-] called with (#0 1)
            [-] returns 2
            [cond] called with (((<= #0 0) 0) (t (+ #0 (sum (- #0 1)))))
               [<=] called with (#0 0)
               [<=] returns nil
               [+] called with (#0 (sum (- #0 1)))
                  [sum] called with ((- #0 1))
                     [-] called with (#0 1)
                     [-] returns 1
                     [cond] called with (((<= #0 0) 0) (t (+ #0 (sum (- #0
1)))))
                        [<=] called with (#0 0)
                        [<=] returns nil
                        [+] called with (#0 (sum (- #0 1)))
                           [sum] called with ((- #0 1))
                              [-] called with (#0 1)
                              [-] returns 0
                              [cond] called with (((<= #0 0) 0) (t (+ #0 (sum
(- #0 1)))))
                                 [<=] called with (#0 0)
                                 [<=] returns t
                              [cond] returns 0
                           [sum] returns 0
                        [+] returns 1
                     [cond] returns 1
                  [sum] returns 1
               [+] returns 3
            [cond] returns 3
         [sum] returns 3
      [+] returns 6
   [cond] returns 6
[sum] returns 6
6
>
Function names (i.e., the symbols to which the functions are bound to) are shown in brackets []. If there is no name for a particular function (i.e., in case of a anonymous lambda expression), the function definition is printed out instead. Parameters are denoted by #i, starting with i = 0 for the first parameter of a lambda expression. If the same function sum is called with a wrong argument, e.g., a string, the run_time error can be located easily:


> (sum "illegal argument")
[sum] called with ("illegal argument")
   [cond] called with (((<= #0 0) 0) (t (+ #0 (sum (- #0 1)))))
      [<=] called with (#0 0)
error in [sum]: 0 is not a string
>
Obviously, the error occured in the user_defined function sum (error messages refer to user_defined function names only). Within sum, the last function called was [<=] with the arguments #0 and 0. Since #0 refers to the string "illegal argument", the expression to be evaluated is (<= "illegal argument" 0) which results in a run_time error, since [<=] requires all arguments to be either numbers or strings.


borisv@ICSI.Berkeley.EDU
Thu Jul 20 19:01:07 PDT 1995