Edwin Woollett wrote:
>
> trying to reproduce David Touretzky's (Common Lisp)
> example (p. 272: Lisp Toolkit: The Debugger), but get
> a Lisp error (w/ Window's gcl maxima binary):
> ----------------------------------------------------------
> (%i1) to_lisp();
> Type (to-maxima) to restart, ($quit) to quit Maxima.
>
> MAXIMA> (defun fact (n)
> (cond ((zerop n) 1)
> (t (* n (fact (- n 1))))))
>
> FACT
> MAXIMA> (fact 5)
>
> 120
So it works OK
> MAXIMA> (defun fact (n)
> (cond ((zerop n) (break "N is zero."))
> (t (* n (fact (- n 1))))))
>
> FACT
> MAXIMA> (fact 5)
>
> Maxima encountered a Lisp error:
This is fine, n decreases to 0 and then the break is issued, which goes into
the lisp debugger. However on your system you don't get the debugger prompt
for whatever reason.
On my system (mac os, sbcl) i get
debugger invoked on a SIMPLE-CONDITION: N is zero.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [CONTINUE ] Return from COMMON-LISP:BREAK.
1: [MACSYMA-QUIT] Maxima top-level
2: Ignore runtime option --eval "(cl-user::run)".
3: [ABORT ] Skip rest of --eval and --load options.
4: Skip to toplevel READ/EVAL/PRINT loop.
5: [QUIT ] Quit SBCL (calling #'QUIT, killing the process).
(COMMON-LISP:BREAK "N is zero.")
If one chooses 0, the program crashes because fact(0) is not defined. The
solution is simple replace the line with break by
(cond ((zerop n) (break "N is zero.") 1)
so that returning from break sets fact(0)=1, and then one gets (fact 5) -> 120
choosing the restart 0 above.
>
> N is zero.
>
> Automatically continuing.
> To reenable the Lisp debugger set *debugger-hook* to nil.
> -------------------------------------------------
> Is this a syntax problem or a lisp version problem
> or a Windows binary problem?
>
> Ted Woollett
--
Michel Talon