Plaster

common-lisp
(defmacro retrying (n &body body) (alexandria:with-gensyms (i out loop) (alexandria:once-only (n) `(block ,out (loop :named ,(gensym) :for ,i :from 0 :below ,n :do (block ,loop (format t "Try ~a~%" ,i) (handler-bind ((error (lambda (c) (declare (ignore c)) (return-from ,loop)))) (return-from ,out (progn ,@body))))) (format t "Exceeded!~%") nil)))) (retrying (+ 1 2) (when (zerop (random 2)) (format t "Signaling an error!~%") (error "Error")) (format t "Hi!~%") 123)