So, :echo
is dead, long live :read
!
cool, seems clearer to me
I like that it's explicit - it gives you a window into how unrepl works behind the scenes (with distinct read, eval, print phases)
A sample
> "hello";comment
< [:read {:from [1 1], :to [1 8], :offset 0, :len 7} 1]
< [:started-eval {:actions {:interrupt (unrepl.repl/interrupt! :session337 1), :background (unrepl.repl/background! :session337 1)}} 1]
< [:eval "hello" 1]
< [:read {:from [1 8], :to [2 1], :offset 7, :len 9} nil]
< [:prompt {:file "unrepl-session", :line 2, :column 1, :offset 16, clojure.core/*warn-on-reflection* false, clojure.core/*ns* <#C4C63FWP5|unrepl>/ns user}]
two reads (one for which the id is nil
: it’s the comment)
I love the idea of displaying inline results for a whole buffer using this system.
Actually repl is a bit of misnomer. It should be PREPL: prompt, read, eval, print, loop 🙂
With pervasive offset reporting a client may determine if it is up-to-date
so it can determine when it is safe to send “meta commands” on the main channel
like set-source
Now, how to prevent commands from messing with *1 and friends?
• tag them with some meta e.g. ^:unrepl (....)
• have commands impl set a flag
• return special value/throw specal exception
I prefer the 1st one because it’s declarative
how does the meta work?
after read, before evaluating the form, look whether the meta is present, if yes don’t update \*[123e]
but metadata is not canon edn
so a tagged element rather #unrepl/do (set-source ...)
there could also be a macro,
(unrepl/incognito (set-source ...))
true
not sure how easy tagged elements are to implement in cljs
easy
I think (?!) the normal reader doesn't support tagged literals
registering custom tags I mean
maybe I'm wrong?
cljs.user=> #inst “2017-04-01”
#inst “2017-04-01T00:00:00.000-00:00"
that's not a custom tag, it's built in
cljs.user=> (binding [cljs.reader/*default-data-reader-fn* (atom tagged-literal)] (cljs.reader/read-string “<#C4C63FWP5|unrepl>/do bidoo”))
<#C4C63FWP5|unrepl>/do bidoo
hm true, although that doesn't affect the reader that reads .cljs source files
(or *tag-table*
for specific tags)
I'm talking about jvm-based cljs here, so I imaging self-hosted works differently
this one we are in control of
ah
so simply wrapping in (unrepl/do ...)
and it’s not even a macro, it doesn’t exist
hehe that could work too 🙂
lisps are great
@pesterhazy thanks it removed a complex piece (:pre-prompt queue)
>66
< [:read {:from [1 1], :to [2 1], :offset 0, :len 3} 1]
< [:started-eval {:actions {:interrupt (unrepl.repl/interrupt! :session339 1), :background (unrepl.repl/background! :session339 1)}} 1]
< [:eval 66 1]
< [:prompt {:file “unrepl-session”, :line 2, :column 1, :offset 3, clojure.core/*warn-on-reflection* false, clojure.core/*ns* <#C4C63FWP5|unrepl>/ns user}]
>(unrepl/do (unrepl.repl/set-file-line-col :session339 “foo.clj” 42 63))
< [:read {:from [2 1], :to [3 1], :offset 3, :len 72} 2]
< [:prompt {:file “foo.clj”, :line 42, :column 63, :offset 75, clojure.core/*warn-on-reflection* false, clojure.core/*ns* <#C4C63FWP5|unrepl>/ns user}]
>*1
< [:read {:from [42 63], :to [43 1], :offset 75, :len 3} 3]
< [:started-eval {:actions {:interrupt (unrepl.repl/interrupt! :session339 3), :background (unrepl.repl/background! :session339 3)}} 3]
< [:eval 66 3]
< [:prompt {:file “foo.clj”, :line 43, :column 1, :offset 78, clojure.core/*warn-on-reflection* false, clojure.core/*ns* <#C4C63FWP5|unrepl>/ns user}]
Does *1 trigger re-evaluation? I thought it grabbed the result only
it grabs the result, the eval you see is the evaluation of “grab the value of *1”
ah