[ANN] dont-give-up: Common Lisp style interactive restarts
I've been playing around a little bit with Common Lisp lately, and I've found the interactive restarts to be pretty amazing. So, I've implemented something similar to them in Clojure/Cider!
https://github.com/czan/dont-give-up
I don't really know my way around nrepl/Cider, but I managed to hack something together that works! If you know anything about nrepl middleware or writing extensions to Cider I would really appreciate your help!
Here's an example of what it looks like (taken from the readme):
(require '[dont-give-up.core :refer (with-restarts with-handlers read-unevaluated-value use-restart)])
(defn div [n d]
(with-restarts [(:use-value [value]
:arguments #'read-unevaluated-value
:describe "Provide a value to use."
value)
(:use-denominator [value]
:arguments #'read-unevaluated-value
:describe "Provide a new denominator and retry."
(div n value))]
(/ n d)))
(div 3 0)
;; ArithmeticException: Divide by zero
;;
;; The following restarts are available:
;; [1] use-value - Provide a value to use instead.
;; [2] use-denominator - Provide a value to use as the denominator.
;; [q] abort - Rethrow the exception.
;;
;; ----------------------
;; java.lang.ArithmeticException: Divide by zero
;; at clojure.lang.Numbers.divide(Numbers.java:158)
;; ...
The restarts can also be triggered programmatically. See the readme for an example.
Posted Apr 6, 2018, 3:50 AM UTC
Cool. I’ve been using Common Lisp (SBCL) too, and as a newcomer to both languages I’ve found the experience so much nicer than Clojure when hitting exceptions. Nice stack trace, readable error message, the chance to correct your mistake and continue as if nothing happened.
Clojure’s a beautiful language with so much going for it, but there’s a lot of room for improvement on the ergonomics of errors.