Browse code
chore: add utilities for binding and managing restarts
Showing 1 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,17 @@ |
1 |
+(in-package :fwoar-lisputils.restarts) |
|
2 |
+ |
|
3 |
+(defmacro with-retry (form &body restart-cases) |
|
4 |
+ `(loop (restart-case (return ,form) |
|
5 |
+ (continue ()) |
|
6 |
+ ,@restart-cases))) |
|
7 |
+ |
|
8 |
+(defmacro with-retry* (bindings &body body) |
|
9 |
+ `(loop |
|
10 |
+ (restart-bind (,@bindings) |
|
11 |
+ ,@(butlast body) |
|
12 |
+ ,(cons 'return (last body))))) |
|
13 |
+ |
|
14 |
+(defmacro safely-invoke-restart (name condition &rest args) |
|
15 |
+ (alexandria:with-gensyms (restart) |
|
16 |
+ `(alexandria:when-let ((,restart (find-restart ,name ,condition))) |
|
17 |
+ (invoke-restart ,restart ,@args)))) |