The less-familiar parts of Lisp for beginners — restart-case

Having just talked about restart-bind, we’ll now look at restart-case.  The restart-bind might be used to implement restart-case, but there are differences between the syntax and behaviour for these two macros.  The most obvious difference from the programmer’s perspective is in what happens after a restart is invoked.  In the case of restart-bind, the execution continues after the invoke-restart call.  In the case of restart-case, the entire restart-case form exits, and the values returned by the restart, if any, are returned.  Here is a simple example of the two different behaviours:
*slime-repl sbcl*

CL-USER> (restart-bind
             ((say-hi #'(lambda ()
                          (format t "Hello~%")
                          (values 1 2 3))))
           (progn
             (format t "Printing before the restart~%")
             (invoke-restart 'say-hi)
             (format t "Printing after the restart~%")
             (format t "Returning the value 10~%")
             10))
Printing before the restart
Hello
Printing after the restart
Returning the value 10
10
CL-USER> (restart-case
             (progn
               (format t "Printing before the restart~%")
               (invoke-restart 'say-hi)
               (format t "Printing after the restart~%")
               (format t "Returning the value 10~%")
               10)
           (say-hi ()
             (format t "Hello~%")
             (values 1 2 3)))

Printing before the restart
Hello
1
2
3

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

反垃圾邮件 / Anti-spam question * Time limit is exhausted. Please reload CAPTCHA.