In article <87lja1hcee.fsf@...>,
Teemu Likonen <tlikonen@...> wrote:
> There is something in Common Lisp's (or SBCL's) conditions and restarts
> which I don't understand. Here's some background and an example code. I
> made a simple tool "sbcl-eval" which evaluates its command-line
> arguments as Lisp expressions and prints the results:
> $ sbcl-eval "" '(* 123 2)' blah pi '(foo)'
> ; No value
> ; The variable BLAH is unbound.
> ; undefined function: FOO
> The code is here:
> --8<---------------cut here---------------start------------->8---
> #!/home/dtw/local/bin/sbcl --script
> (defun handler-eof (condition)
> (declare (ignore condition))
> (invoke-restart 'continue-eval "No value"))
> (defun handler-t (condition)
> (invoke-restart 'continue-eval condition))
> (handler-bind ((end-of-file #'handler-eof)
> (t #'handler-t))
> (dolist (arg (rest sb-ext:*posix-argv*))
> (restart-case (format *standard-output* "~&~S~%"
> (eval (read-from-string arg)))
> (continue-eval (msg)
> (format *error-output* "~&; ~A~%" msg)))))
> --8<---------------cut here---------------end--------------->8---
> The code does what I want but then I tried to test more its error
> handling. At least this works:
> $ sbcl-eval "(error 'error)"
> ; Condition ERROR was signalled.
> The following expression with SIMPLE-ERROR condition doesn't work. My
> restart is not active any more and I don't understand why.
> $ sbcl-eval "(error 'simple-error)"
> [See the backtrace below]
> There is some "unbound condition slot" error in the backtrace. What is
If you M-. on simple-error in Slime, you'll be brought
into src/code/condition.lisp; unfortunately not to the right
toplevel-form, the definition of SIMPLE-ERROR, but the macro
definition of DEFINE-CONDITION -- my memory currently fails
for the exact reason for that mismatch, but iirc it's due to
some ordering issues during compilation of SBCL itself.
Anyway, you can just search for "simple-error" in that file,
and you'll see: SIMPLE-ERROR is a SIMPLE-CONDITION which consists
of two slots, in particular its FORMAT-CONTROL slot has no initform.
If you know look into its reporter, SIMPLE-CONDITION-PRINTER, you'll
see that printing SIMPLE-ERRORs depends on the presence of a
Indeed, if you try (ERROR 'SIMPLE-ERROR) at the REPL, you'll see
SBCL complain for
Unable to display error condition: unbound condition slot:
As SIMPLE-ERROR and SIMPLE-CONDITION are condition specified by
the standard (they're external symbols of the CL package), you
can actually look up their specifications via C-c C-d h in Slime.
Arguably, the definition of SIMPLE-CONDITION should have a
:INITFORM (SB-INT:MISSING-ARGUMENT :FORMAT-CONTROL) in the
slot definition of FORMAT-CONTROL to bail out early.