[Ecls-list] restart-bind

Chui Tey teyc at bluebottle.com
Wed Aug 16 04:44:27 UTC 2006

Hi, I'm working through examples on Lamkin's book:


Why doesn't the debugger (ecl win32 msvc) provide a list of possible

Here's the code:

  (define-condition device-unresponsive ()
                    ((device :initarg :device :reader device))
    (:report (lambda (condition stream)
               (format stream "Device ~A is unresponsive."
                       (device condition)))))
  (defun send-query (device query)
    (format t "~&Sending ~S ~S~%" device query))
  (defun accept-response (device)
    ;; For the example, the device always fails. 
  (defun reset-device (device)
    (format t "~&Resetting ~S~%" device))
  (defun query-device (device)
    (restart-bind ((nil #'(lambda () (reset-device device))
                        #'(lambda (stream)
                            (format stream "Reset device.")))
                   (nil #'(lambda ()
                            (format t "~&New device: ")
                            (setq device (read)))
                        #'(lambda (stream)
                            (format stream "Try a different device.")))
                   (nil #'(lambda ()
                            (return-from query-device :gave-up))
                        #'(lambda (stream)
                            (format stream "Give up."))))
        (send-query device 'query)
        (let ((answer (accept-response device)))
          (if answer
            (return answer)
            (cerror "Try again."
                    'device-unresponsive :device device))))))

; Test code
(query-device "foobar")

More information about the ecl-devel mailing list