Fork me on GitHub
#unrepl
<
2017-06-15
>
cgrand09:06:44

@richiardiandrea hmm find-ns happens to trigger an interesting shadowing bug, opened https://dev.clojure.org/jira/browse/CLJS-2088

richiardiandrea14:06:27

cgrand: just woken up saw the fix and patch thanks! I patched inf-clojure with lumo.core and was wondering why $macros is now in there and not core only anymore

cgrand14:06:51

(btw David applied my patch)

cgrand14:06:54

“was wondering why $macros should it find either way” ?

richiardiandrea14:06:15

cgrand: lol let me rephrase

richiardiandrea14:06:29

Why did you switch to detecting core$macros instead of core

cgrand14:06:02

because in self-hosted cljs, (find-ns 'lumo.repl) cripples access to this ns macros (open lumo, enter this find-ns and after that try to use doc)

richiardiandrea14:06:18

Oh gotcha temporary fix before your patch is officially in

cgrand14:06:31

and until non-patched cljs are rare enough

cgrand10:06:41

Identifying a repl:

(cond
  (find-ns ') :clj
  (find-ns ') :cljr
  (find-ns 'lumo.repl$macros) :lumo
  (find-ns 'planck.repl$macros) :planck
  (find-ns 'cljs.core$macros) :cljs-js
  (find-ns 'cljs.core) :cljs-jvm
  :else :unknown)

thheller11:06:26

@cgrand find-ns is bootstrap only

cgrand11:06:27

for repl sniffing it works enough in non-bootstrap

thheller11:06:27

says so in the docs at least

cgrand11:06:14

don’t use that in a lib though (advanced compilation...)

thheller11:06:56

hmm you are right, actually works in normal as well

thheller11:06:11

but sending that before every interaction would suck

pesterhazy11:06:25

why not once per connection?

thheller13:06:08

rlwrap nc localhost 8201
shadow-cljs - REPL - see (help), :repl/quit to exit
[13:0]~shadow.user=> (shadow/node-repl)
[13:1]~cljs.user=> :repl/quit
:repl/quit
[13:0]~shadow.user=>

thheller13:06:28

@pesterhazy starts out as CLJ, then becomes CLJS, then CLJ again

cgrand13:06:03

if only there was a protocol which clearly tells when an upgrade occurs 😇

thheller13:06:19

I know right? 🙂

thheller13:06:19

any ideas how to do the upgrade process properly for cljs yet?

thheller13:06:30

not self-hosted that is

thheller13:06:08

still not totally on-board with unrepl yet but thats mostly due to tool support

thheller13:06:27

guess I can’t get around nrepl for now

cgrand13:06:48

Some ideas start to click together. The current cljs repl infrastructure is not ok but it can be remixed (that is: reuse environments and so on but recreate an upgradable infrastructure to replace https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/repl.cljc)

thheller13:06:12

shadow-cljs doesn’t use any of that, maybe its simpler to integrate there

thheller13:06:29

is there an unrepl client I could test this with?

cgrand13:06:30

my current idea is to consider the loop on the js-side as its own repl

cgrand13:06:21

it starts as a framed JS repl but is upgradable

thheller13:06:30

this is the loop for the CLJS REPL at the moment

thheller13:06:57

it reads off *in* and prints to *out*

thheller13:06:03

the actual JS eval is RPC

pesterhazy13:06:13

@thheller I'd test with netcat first

thheller13:06:28

so it should be really simple to add the upgrade

pesterhazy13:06:28

once you have a working protocol, you can try unravel

pesterhazy13:06:46

it's not updated yet to use the "official" unrepl blob

cgrand13:06:09

and the blob is only for clj

cgrand13:06:19

bootstrap soon

pesterhazy13:06:19

of course the blob would have to be completely replaced

thheller13:06:24

yeah still not sold on the blob idea

thheller13:06:47

I’m fine with just having a dependency in the server

cgrand13:06:16

@thheller how do you handle the print part in shadow repl?

thheller13:06:42

the client decides how to print

thheller13:06:46

currently it just does pr-str but I could make that configurable

thheller13:06:03

it does not send a wrapped form over the wire

thheller13:06:25

so if you eval (js/alert "foo") the client actually just evals alert("foo") nothing else

thheller13:06:21

not the wrapped stuff the normal CLJS REPL sends

pesterhazy13:06:39

@cgrand, I did a presentation on unrepl/unravel here in Berlin yesterday. Here are the slides: http://pesterhazy.karmafish.net/unravel-your-repl.pdf

cgrand13:06:16

How was it received?

pesterhazy13:06:13

pretty well. I had a few people express interest in contributing after the talk, which is awesome

volrath13:06:03

^ yes, pretty well 🙂

cgrand13:06:27

great! welcome @volrath

volrath13:06:15

cgrand: thanks! I really like the whole idea. I told @pesterhazy yesterday that I went through the documentation two nights ago, to prepare for the talk, and I think I can contribute a very small PR with some minor fixes to the README (commas, and a couple typos) and then maybe I can help with documenting more stuff (missing tags like :started-eval, and so on)

volrath13:06:29

that would help with my understanding of the protocol as well

volrath13:06:32

if that's ok with you

cgrand13:06:04

that’s more than totally ok

cgrand13:06:45

Don’t hesitate pinging me (in private or on the channel)

volrath13:06:36

thank you! will do

cgrand13:06:15

> Rich capabilities, frugal dependencies I like this wording!

cgrand13:06:09

bonus points for using “transclusion”

thheller13:06:25

[15:1]~cljs.user=> [1 2 3]
(] 3   2   1 [)
[15:1]~cljs.user=> (set! shadow.cljs.devtools.client.env/repl-print-fn #(reverse (pr-str %))
)
(] " }
 ; ) ) _ P R A H S _ 5 2 6 5 4 _ _ 1 p , l l u n ( l l a c . r t s _ r p . e r o c . s j l c , l l u n ( l l a c . e s r e v e r . e r o c . s j l c   n r u t e r
 { ) _ P R A H S _ 5 2 6 5 4 _ _ 1 p (   n o i t c n u f "   n o i t c n u F [ t c e j b o #)
[15:1]~cljs.user=> [1 2 3]
(] 3   2   1 [)

thheller13:06:35

not the result I had in mind but fun 😛

pesterhazy13:06:57

@cgrand, yup, I've learned a new word 🙂

thheller13:06:26

[15:1]~cljs.user=> (set! shadow.cljs.devtools.client.env/repl-print-fn #(clojure.string/upper-case (pr-str %)))
#OBJECT[FUNCTION "FUNCTION (P1__45626_SHARP_){
RETURN CLOJURE.STRING.UPPER_CASE.CALL(NULL,CLJS.CORE.PR_STR.CALL(NULL,P1__45626_SHARP_));
}"]
[15:1]~cljs.user=> [:hello :world]
[:HELLO :WORLD]

thheller13:06:49

is there a CLJS impl for the unrepl print style yet?

cgrand13:06:30

I plan to merge it when I got time

thheller13:06:14

[15:1]~cljs.user=> (load-file "/Users/zilence/code/shadow-cljs/src/dev/unrepl/print.cljc")
[:result {:type :repl/error, :message "cond-splice not in list", :data {:type :reader-exception, :line 15, :column 5, :file "unrepl/print.cljc"}, :causes []}]

cgrand13:06:02

indeed, remove the @

cgrand13:06:20

and add a do

thheller13:06:54

another one at 170

cgrand13:06:39

reader discrpencies: LispReader is ok with that, tools.reader not

cgrand08:06:03

I guess @plexus tested it against cljs-js-repl on lumo

plexus08:06:03

print.cljc is completely untested. I got as far as making sure the forms evaluated without errors on Lumo. That's it. It almost certainly is incomplete, it's just a first pass addressing the most obvious differences.

cgrand13:06:08

async-reader should be fine too

cgrand13:06:17

tools.reader issue?

thheller13:06:19

it cannot print itself

thheller13:06:22

[18:0]~shadow.user=> (shadow/dev :browser)
[18:1]~cljs.user=> (require 'unrepl.print)
[18:1]~cljs.user=> (set! shadow.cljs.devtools.client.env/repl-print-fn unrepl.print/edn-str)
nil
[18:1]~cljs.user=> {:foo "bar"}
{:foo "bar"}

thheller13:06:37

TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of undefined
    at cljs.core.MultiFn.cljs$core$IFn$_invoke$arity$1 (cljs.core.cljs:10295)
    at Function.unrepl.print.ednize.cljs$core$IFn$_invoke$arity$3 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:457:119)
    at Function.unrepl.print.ednize.cljs$core$IFn$_invoke$arity$2 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:425:28)
    at Object.unrepl$print$print_on [as print_on] (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:610:33)

thheller13:06:43

doesn’t seem to work really

cgrand13:06:44

I haven’t had time to test it, I was doing some preliminary work on the upgradable cljs repl

thheller13:06:01

(range 0 10000) also fails

thheller13:06:30

TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of undefined
    at cljs.core.MultiFn.cljs$core$IFn$_invoke$arity$1 (cljs.core.cljs:10295)
    at Function.unrepl.print.ednize.cljs$core$IFn$_invoke$arity$3 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:457:119)
    at Function.unrepl.print.ednize.cljs$core$IFn$_invoke$arity$2 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:425:28)
    at unrepl$print$print_on (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:610:33)
    at Function.unrepl.print.print_vs.cljs$core$IFn$_invoke$arity$5 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:571:113)
    at Function.unrepl.print.print_vs.cljs$core$IFn$_invoke$arity$3 (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:516:30)
    at Object.unrepl$print$print_on [as print_on] (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:653:23)
    at unrepl$print$edn_str (eval at shadow$cljs$devtools$client$browser$do_js_load (shadow.cljs.devtools.client.browser.cljs:48), <anonymous>:698:18)

thheller13:06:37

damn js stack traces are ugly

thheller13:06:10

ah wait I have a debugger for that 😉

cgrand13:06:17

i may have an idea, in the clojure version you need to set some dynvars around it

cgrand13:06:36

(keep calm it’s synchronous so plain binding is ok)

cgrand13:06:03

it would explain the undefined

thheller13:06:47

*ednize* seems unbound

cgrand14:06:25

(defmulti default-ednize-fn class) <- no class in cljs

thheller14:06:14

why isn’t that a protocol?

cgrand14:06:40

trying to remember — I dislike multimethods so there must be a reason

thheller14:06:45

Error: No method in multimethod 'unrepl.print/default-ednize-fn' for dispatch value: function Function() { [native code] }

thheller14:06:58

just changed it to type

thheller14:06:16

uhm (try try try try try try try try try try #unrepl/... nil) 😛

thheller14:06:40

[20:1]~cljs.user=> (range 0 1000)
(try try try try try try try try try try #unrepl/... nil)

thheller14:06:03

where does the try come from? 😛

cgrand14:06:43

re: protocol, really I don’t see why anymore, maybe to have the opportunity to prefer impls in case of conflicts?

cgrand14:06:56

there are only two “try” one in the expansion of a macro, I think it’s the one

thheller14:06:46

ok .. I gotta do some other stuff .. will try again later

cgrand14:06:41

on line 234 blame-seq which is a macro is called like a function (because cljs) and then its head (`try`) is used for v

thheller14:06:13

[20:1]~cljs.user=> (range 0 1000)
(0 1 2 3 4 5 6 7 8 9 #unrepl/... nil

thheller14:06:35

#?(:cljs (:require-macros [unrepl.print :refer (blame-seq)])) in ns

thheller14:06:46

#?(:clj
   (defmacro ^:private blame-seq [& body]
     `(try (seq ~@body)
           (catch Throwable t#
             (list (tagged-literal 'unrepl/lazy-error t#))))))

cgrand14:06:35

oh noes, you just broke it for self-hosted

cgrand14:06:29

macrovich to the rescue!

richiardiandrea14:06:27

cgrand: just woken up saw the fix and patch thanks! I patched inf-clojure with lumo.core and was wondering why $macros is now in there and not core only anymore

richiardiandrea14:06:49

@thheller I think @plexus was writing an Emacs mode