Skip to content

Instantly share code, notes, and snippets.

@cgrand cgrand/ednrepl.clj
Last active Mar 28, 2018

Embed
What would you like to do?
What if a REPL out was a stream of EDN forms?
;; some sample interaction with a clojure socket repl whose output stream consists only of valid edn forms.
;; the edn stream is not meant for the end user but for the client UI.
;; it demoes several features:
;; • prompt, out, err, eval and exceptions are demultiplexed; unstructred ones (err & out) are just text but the others give data.
;; • elided content (because data too deep or wide) is replaced by a tagged literal (which optionally contains the expr to evaluate to get more items)
;; this last point makes possible navigation
;; lines are prefixed by > or < to tell what is sent to the repl (>) and what is received from it (<)
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
> (+ 1 2)
< [:eval 3]
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
> (println "hello")
< [:out "hello\n"]
< [:eval nil]
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
> (range)
< [:eval (0 1 2 3 4 5 6 7 8 9 #ednrepl/... {:get (ednrepl/get :G__8407)})]
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
> (ednrepl/get :G__8407)
< [:eval (10 11 12 13 14 15 16 17 18 19 #ednrepl/... {:get (ednrepl/get :G__8426)})]
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
> (nil)
< [:exception #error {:cause "Can't call nil, form: (nil)", :via [{#ednrepl/... {:get (ednrepl/get :G__8402)} #ednrepl/pad} {#ednrepl/... {:get (ednrepl/get :G__8403)} #ednrepl/pad}], :trace [[clojure.lang.Compiler analyzeSeq "Compiler.java" 6860] [clojure.lang.Compiler analyze "Compiler.java" 6669] [clojure.lang.Compiler analyze "Compiler.java" 6625] [clojure.lang.Compiler$BodyExpr$Parser parse "Compiler.java" 6001] [clojure.lang.Compiler$FnMethod parse "Compiler.java" 5380] [clojure.lang.Compiler$FnExpr parse "Compiler.java" 3972] [clojure.lang.Compiler analyzeSeq "Compiler.java" 6866] [clojure.lang.Compiler analyze "Compiler.java" 6669] [clojure.lang.Compiler eval "Compiler.java" 6924] [clojure.lang.Compiler eval "Compiler.java" 6890] #ednrepl/... {:get (ednrepl/get :G__8404)}]}]
< [:prompt {:ns richrepl.core, :*warn-on-reflection* nil}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.