Skip to content

Instantly share code, notes, and snippets.

@bhb
Created March 20, 2018 00:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/f637ef589ef3ac3d2ca5a883fafc2c12 to your computer and use it in GitHub Desktop.
Save bhb/f637ef589ef3ac3d2ca5a883fafc2c12 to your computer and use it in GitHub Desktop.
Expound examples
;; There is still a ton of work to do wrt to formatting, testing, and improving examples,
;; but here's a proof-of-concept of Expound printing examples.
;; 'defn' examples are adapted from "Improving Clojure's Error Messages with Grammars"
;; https://youtu.be/kt4haSH2xcs?t=10m20s
;; Changing types
(defn "foo" [] 1)
;; -- Example ------------------------
;; (<f> foo [] 1)
;; (Note that clojure.spec does not currently include the macro name in `explain-data`,
;; so Expound can only print placeholder <f>
;; (https://dev.clojure.org/jira/browse/CLJ-2271))
;; Adding a form
(defn foo)
;; -- Example ------------------------
;; (<f> foo [])
;; Wrapping forms
(defn foo (arg1 arg2))
;; -- Example ------------------------
;; (<f> foo ([arg1] arg2))
;; Changing collection type
(defn foo (arg1 arg2) arg2)
;; -- Example ------------------------
;; (<f> foo [arg1 arg2] arg2)
;; Wrapping form (again)
(defn foo a)
;; -- Example ------------------------
;; (<f> foo [a])
;; Reordering form
(defn "bad docstring" foo [arg1 arg2])
;; -- Example ------------------------
;; (<f> foo "bad docstring" [arg1 arg2])
@bhb
Copy link
Author

bhb commented Mar 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment