[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:

http://psg.com/~dlamkins/sl/chapter23.html

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

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)))))
;DEVICE-UNRESPONSIVE
  (defun send-query (device query)
    (format t "~&Sending ~S ~S~%" device query))
;SEND-QUERY
  (defun accept-response (device)
    ;; For the example, the device always fails. 
    nil)
;ACCEPT-RESPONSE
  (defun reset-device (device)
    (format t "~&Resetting ~S~%" device))
;RESET-DEVICE
  (defun query-device (device)
    (restart-bind ((nil #'(lambda () (reset-device device))
                        :report-function
                        #'(lambda (stream)
                            (format stream "Reset device.")))
                   (nil #'(lambda ()
                            (format t "~&New device: ")
                            (finish-output)
                            (setq device (read)))
                        :report-function
                        #'(lambda (stream)
                            (format stream "Try a different device.")))
                   (nil #'(lambda ()
                            (return-from query-device :gave-up))
                        :report-function
                        #'(lambda (stream)
                            (format stream "Give up."))))
      (loop
        (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