Skip to content

Instantly share code, notes, and snippets.

@bhb
Last active May 15, 2023 01:28
Show Gist options
  • Save bhb/2686b023d074ac052dbc21f12f324f18 to your computer and use it in GitHub Desktop.
Save bhb/2686b023d074ac052dbc21f12f324f18 to your computer and use it in GitHub Desktop.

Revisions

  1. bhb revised this gist Jan 15, 2022. 3 changed files with 13 additions and 16 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,18 +3,18 @@
    A beginner-friendly REPL that combines

    * [rebel-readline](https://github.com/bhauman/rebel-readline)
    * [Pyro](https://github.com/venantius/pyro)
    * [Expound](https://github.com/bhb/expound)
    * [Speculative](https://github.com/borkdude/speculative)

    ## Usage

    JVM 8:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -M -m friendly`
    `clojure -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -X friendly/run`

    JVM 9 or newer:

    `clj -J --add-modules=java.xml.bind -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -M -m friendly`
    `clojure -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -X friendly/run`

    ## Credits

    7 changes: 3 additions & 4 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    {:paths ["."]
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
    venantius/pyro {:mvn/version "0.1.2"}
    expound {:mvn/version "0.9.0"}
    expound/expound {:mvn/version "0.9.0"}
    org.clojure/core.specs.alpha {:mvn/version "0.2.62"}
    speculative {:git/url "https://github.com/borkdude/speculative.git"
    :sha "4e773794a4065a84bdadd997516e52c76ab51b1f"}}}
    speculative/speculative {:git/url "https://github.com/borkdude/speculative.git"
    :sha "4e773794a4065a84bdadd997516e52c76ab51b1f"}}}
    16 changes: 7 additions & 9 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,13 @@
    (ns friendly
    (:require [pyro.printer :as pyro]
    [rebel-readline.clojure.main]
    (:require [rebel-readline.clojure.main]
    [expound.alpha :as expound]
    [clojure.spec.alpha :as s]
    [clojure.spec.test.alpha :as st]
    [clojure.stacktrace]
    [clojure.main]
    ;; for specs
    [speculative.core :as speculative]))
    [speculative.instrument :as speculative]))

    (expound/defmsg ::speculative/ifn "should be a function (or a value that can be *treated* like a function e.g. a set or keyword)")
    (expound/defmsg :speculative.specs/ifn "should be a function (or a value that can be *treated* like a function e.g. a set or keyword)")

    (def printer (expound/custom-printer {:print-specs? false
    :show-valid-values? true
    @@ -44,8 +42,8 @@
    "[trace missing]")))))))))


    (defn -main []
    (set! s/*explain-out* printer)
    (st/instrument)
    (pyro/swap-stacktrace-engine!)
    (speculative/instrument)
    (set! s/*explain-out* printer)

    (defn run [_opts]
    (rebel-readline.clojure.main/repl :caught repl-caught))
  2. bhb revised this gist Jan 15, 2022. No changes.
  3. bhb revised this gist Jan 15, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,11 @@ A beginner-friendly REPL that combines

    JVM 8:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "418bf66fd96851cc55398b55d5a8aff65692f565"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -M -m friendly`

    JVM 9 or newer:

    `clj -J --add-modules=java.xml.bind -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "418bf66fd96851cc55398b55d5a8aff65692f565"}}}' -m friendly`
    `clj -J --add-modules=java.xml.bind -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "d532662414376900c13bed9c920181651e1efeff"}}}' -M -m friendly`

    ## Credits

  4. bhb revised this gist Jan 15, 2022. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    {:paths ["."]
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
    venantius/pyro {:mvn/version "0.1.2"}
    expound {:mvn/version "0.7.1"}}}
    expound {:mvn/version "0.9.0"}
    org.clojure/core.specs.alpha {:mvn/version "0.2.62"}
    speculative {:git/url "https://github.com/borkdude/speculative.git"
    :sha "4e773794a4065a84bdadd997516e52c76ab51b1f"}}}
  5. bhb revised this gist Jan 15, 2022. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion friendly.clj
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,11 @@
    [clojure.spec.alpha :as s]
    [clojure.spec.test.alpha :as st]
    [clojure.stacktrace]
    [clojure.main]))
    [clojure.main]
    ;; for specs
    [speculative.core :as speculative]))

    (expound/defmsg ::speculative/ifn "should be a function (or a value that can be *treated* like a function e.g. a set or keyword)")

    (def printer (expound/custom-printer {:print-specs? false
    :show-valid-values? true
  6. bhb revised this gist Jan 15, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    {:paths ["."]
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
    venantius/pyro {:mvn/version "0.1.2"}
    expound {:mvn/version "0.7.1"}}}
    expound {:mvn/version "0.9.0"}}}
  7. bhb revised this gist Sep 7, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,14 @@ A beginner-friendly REPL that combines

    ## Usage

    JVM 8:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "418bf66fd96851cc55398b55d5a8aff65692f565"}}}' -m friendly`

    JVM 9 or newer:

    `clj -J --add-modules=java.xml.bind -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "418bf66fd96851cc55398b55d5a8aff65692f565"}}}' -m friendly`

    ## Credits

    Inspired by https://github.com/slipset/friendly
  8. bhb revised this gist Jul 9, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ A beginner-friendly REPL that combines

    ## Usage

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "a6a6727f68d52d9024079bdd93fab87222993ae5"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "418bf66fd96851cc55398b55d5a8aff65692f565"}}}' -m friendly`

    ## Credits

  9. bhb revised this gist Jul 9, 2018. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,19 @@
    el (when-not (zero? (count tr)) (aget tr 0))
    ex-m (Throwable->map ex)]
    (binding [*out* *err*]
    ;; If the output is a clojure spec issue...
    (if (::s/problems (:data ex-m))
    (cond
    ;; If the output is a clojure spec issue...
    (::s/problems (:data ex-m))
    ;; print expound output
    (do
    (println (str (re-find #"Call to .* did not conform to spec\:" (.getMessage ex))
    "\n"
    (with-out-str (printer (:data ex-m))))))

    (instance? clojure.lang.LispReader$ReaderException e)
    (println (:cause (Throwable->map e)))

    :else
    ;; otherwise print exception
    (println (str (if (instance? clojure.lang.Compiler$CompilerException ex)
    (str
  10. bhb revised this gist Jul 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ A beginner-friendly REPL that combines

    ## Usage

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "2686b023d074ac052dbc21f12f324f18"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "a6a6727f68d52d9024079bdd93fab87222993ae5"}}}' -m friendly`

    ## Credits

  11. bhb revised this gist Jul 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ A beginner-friendly REPL that combines

    ## Usage

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "c6b0b7cb0a30e2edbf7050c0119ef038cf0f0ac2"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "2686b023d074ac052dbc21f12f324f18"}}}' -m friendly`

    ## Credits

  12. bhb revised this gist Jul 8, 2018. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,17 @@
    # Friendly

    A beginner-friendly REPL that combines

    Inspired by https://github.com/slipset/friendly
    * [rebel-readline](https://github.com/bhauman/rebel-readline)
    * [Pyro](https://github.com/venantius/pyro)
    * [Expound](https://github.com/bhb/expound)

    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
    ## Usage

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "c6b0b7cb0a30e2edbf7050c0119ef038cf0f0ac2"}}}' -m friendly`

    Usage:
    ## Credits

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "bb5806bd655d743f3b48b36ce83c0085a8d7c54a"}}}' -m friendly`
    Inspired by https://github.com/slipset/friendly

    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
  13. bhb revised this gist Jul 8, 2018. 3 changed files with 6 additions and 2 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@


    Inspired by https://github.com/slipset/friendly

    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
    3 changes: 2 additions & 1 deletion deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    {:paths ["."]
    :deps {venantius/pyro {:mvn/version "0.1.2"}
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
    venantius/pyro {:mvn/version "0.1.2"}
    expound {:mvn/version "0.7.1"}}}
    3 changes: 2 additions & 1 deletion friendly.clj
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    (ns friendly
    (:require [pyro.printer :as pyro]
    [rebel-readline.clojure.main]
    [expound.alpha :as expound]
    [clojure.spec.alpha :as s]
    [clojure.spec.test.alpha :as st]
    @@ -37,4 +38,4 @@
    (set! s/*explain-out* printer)
    (st/instrument)
    (pyro/swap-stacktrace-engine!)
    (clojure.main/repl :caught repl-caught))
    (rebel-readline.clojure.main/repl :caught repl-caught))
  14. bhb revised this gist Jul 6, 2018. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    Inspired by https://github.com/slipset/friendly
    # Usage

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "c6b0b7cb0a30e2edbf7050c0119ef038cf0f0ac2"}}}' -m friendly`

    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
    # Credits

    Usage:
    Inspired by https://github.com/slipset/friendly

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "bb5806bd655d743f3b48b36ce83c0085a8d7c54a"}}}' -m friendly`
    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202
  15. bhb revised this gist Jul 6, 2018. 2 changed files with 36 additions and 8 deletions.
    4 changes: 2 additions & 2 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    {:paths ["."]
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.3"}
    expound {:mvn/version "0.7.0"}}}
    :deps {venantius/pyro {:mvn/version "0.1.2"}
    expound {:mvn/version "0.7.1"}}}
    40 changes: 34 additions & 6 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,40 @@
    (ns friendly
    (:require [rebel-readline.main]
    (:require [pyro.printer :as pyro]
    [expound.alpha :as expound]
    [clojure.spec.alpha :as s]
    [clojure.spec.test.alpha :as st]))
    [clojure.spec.test.alpha :as st]
    [clojure.stacktrace]
    [clojure.main]))

    (def printer (expound/custom-printer {:print-specs? false
    :show-valid-values? true
    :theme :figwheel-theme}))

    (defn repl-caught [e]
    (let [ex (clojure.main/repl-exception e)
    tr (.getStackTrace ex)
    el (when-not (zero? (count tr)) (aget tr 0))
    ex-m (Throwable->map ex)]
    (binding [*out* *err*]
    ;; If the output is a clojure spec issue...
    (if (::s/problems (:data ex-m))
    ;; print expound output
    (do
    (println (str (re-find #"Call to .* did not conform to spec\:" (.getMessage ex))
    "\n"
    (with-out-str (printer (:data ex-m))))))
    ;; otherwise print exception
    (println (str (if (instance? clojure.lang.Compiler$CompilerException ex)
    (str
    (-> ex class .getSimpleName)
    " " (.getMessage ex) " ")
    (str " " (if el
    (clojure.stacktrace/print-stack-trace ex)
    "[trace missing]")))))))))


    (defn -main []
    (set! s/*explain-out* (expound/custom-printer {:print-specs? false
    :show-valid-values? true
    :theme :figwheel-theme}))
    (set! s/*explain-out* printer)
    (st/instrument)
    (rebel-readline.main/-main))
    (pyro/swap-stacktrace-engine!)
    (clojure.main/repl :caught repl-caught))
  16. bhb revised this gist May 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,4 @@ I learned the technique of loading code via a gist from https://gist.github.com/

    Usage:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "9bd01f28522a0083c6a7428a871aa5fbb8070d1d"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "bb5806bd655d743f3b48b36ce83c0085a8d7c54a"}}}' -m friendly`
  17. bhb revised this gist May 29, 2018. 2 changed files with 6 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    {:paths ["."]
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.2"}
    expound {:mvn/version "0.6.0"}}}
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.3"}
    expound {:mvn/version "0.7.0"}}}
    6 changes: 4 additions & 2 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@
    [clojure.spec.test.alpha :as st]))

    (defn -main []
    (set! s/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true}))
    (set! s/*explain-out* (expound/custom-printer {:print-specs? false
    :show-valid-values? true
    :theme :figwheel-theme}))
    (st/instrument)
    (rebel-readline.main/-main))
    (rebel-readline.main/-main))
  18. bhb revised this gist Apr 27, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,4 @@ I learned the technique of loading code via a gist from https://gist.github.com/

    Usage:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "cbc5b3c73d4788a25570f125e5f2de23a3d2bf5f"}}}' -m friendly`
    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "9bd01f28522a0083c6a7428a871aa5fbb8070d1d"}}}' -m friendly`
  19. bhb revised this gist Apr 27, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    {:paths ["."]
    :deps {rebel-readline {:mvn/version "0.1.1-SNAPSHOT"}
    expound {:mvn/version "0.5.0"}}}
    :deps {com.bhauman/rebel-readline {:mvn/version "0.1.2"}
    expound {:mvn/version "0.6.0"}}}
  20. bhb revised this gist Feb 28, 2018. 2 changed files with 7 additions and 4 deletions.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Inspired by https://github.com/slipset/friendly

    I learned the technique of loading code via a gist from https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202

    Usage:

    `clj -Sdeps '{:deps {friendly {:git/url "https://gist.github.com/bhb/2686b023d074ac052dbc21f12f324f18" :sha "cbc5b3c73d4788a25570f125e5f2de23a3d2bf5f"}}}' -m friendly`
    4 changes: 0 additions & 4 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,3 @@
    ;; Inspired by https://github.com/slipset/friendly
    ;; I learned the technique of loading code via a gist from
    ;; https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202

    (ns friendly
    (:require [rebel-readline.main]
    [expound.alpha :as expound]
  21. bhb revised this gist Feb 28, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    ;; Inspired by https://github.com/slipset/friendly
    ;; I learned the technique of loading code via a gist from
    ;; https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202

    (ns friendly
    (:require [rebel-readline.main]
    [expound.alpha :as expound]
  22. bhb revised this gist Feb 28, 2018. No changes.
  23. bhb created this gist Feb 28, 2018.
    3 changes: 3 additions & 0 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    {:paths ["."]
    :deps {rebel-readline {:mvn/version "0.1.1-SNAPSHOT"}
    expound {:mvn/version "0.5.0"}}}
    11 changes: 11 additions & 0 deletions friendly.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ;; Inspired by https://github.com/slipset/friendly
    (ns friendly
    (:require [rebel-readline.main]
    [expound.alpha :as expound]
    [clojure.spec.alpha :as s]
    [clojure.spec.test.alpha :as st]))

    (defn -main []
    (set! s/*explain-out* (expound/custom-printer {:print-specs? false :show-valid-values? true}))
    (st/instrument)
    (rebel-readline.main/-main))