Fork me on GitHub
#clojurescript
<
2022-08-02
>
john00:08:28

What's the simplest way in Clojurescript to spawn a subrepl such that every time you evaluate something, "Yay!" is printed before the result is returned? Either via macro or in cljs directly? Preferably without bringing in all the self-host machinery?

john00:08:35

I basically want to wrap the evaluation context in an extra function that ships the evaluation to a specific webworker

john00:08:06

Also, I'd like to be able to do this to easily create sub-sub repls, so that I can evaluate code in the context of a stepping dbg evaluation context

john00:08:53

With inmesh's blocking semantics, I have a basic stepping debugger working, where you just wrap your code in (dbg ... and then when it halts, you can check the value of local vals with (dbg-> ..., But it'd be nice to be able to not have to use dbg-> and just automatically get a sub-repl that has the dbg-> built in, until you exit out of it

thheller07:08:55

@john not possible in any of the default REPL impls, not even self-hosted if by REPL you mean evaluating something from your editor. You'd basically have to build your own from scratch.

john17:08:27

@thheller hmm, okay thanks

john17:08:48

Might try to cannibalize some rebel-readline bits

thheller17:08:03

I mean the challenge is that in all regular REPLs the RL happens in CLJ but EP in JS

john17:08:26

It would be nice to not have to wrap the repl though, and instead do something like set-pre-eval-hook-fn! so you could just reuse the existing repl

john17:08:52

Meaning RL=Read Loop and EP=Eval Print?

thheller17:08:39

its more of a read -> compile to js -> send to runtime -> eval in runtime -> print in runtime -> send to server -> print in server -> loop loop 😉

john17:08:59

set-print-fn! works, allowing me instrument the P step, to catch prints and send them to a particular worker. I essentially want that for instrumenting the E step

john17:08:59

I could probably wrap either the R or E step and have the same effect

john17:08:07

Would just be different kinds of impl

john17:08:50

nrepl middleware might be an option, for those using nrepl

john17:08:41

Or maybe just a macro that blocks for user input. Would be nice if there was a line-number-push-back reader thing built right in, that unblocked after a form is closed. And then I could handle the looping on the CLJS side

john17:08:45

No, the CLJS side can't reinvoke the blocking macro :thinking_face: would have to loop on the CLJ side, but then releasing forms to the CLJS repl on each loop becomes a problem, hmm

john18:08:31

Interesting thing about the debugger, it inverts control of the loop to the CLJS side, inside the worker, so:

(dbg
 (let [x 1 y 3 z 5]
   (println :starting)
   (dotimes [i z]
     (break (= i y))
     (println :i i))
   (println :done)
   4))
;:starting
;:i 0
;:i 1
;:i 2
;=> :starting-dbg
It'll then just hang at the break, waiting for messages from other workers. Sending it a message like (in? i) makes it send back 3 and it just keeps looping, letting you inspect the locals. Finally,
(in? :in/exit)
;:i 3
;:i 4
;:done
;=> 4
And it exits. So most of the REPL parts are there. I just need a way to tie the existing repl to it, essentially wrapping the result of the existing Read with a (in? ...)

john18:08:04

I guess you don't need the outer dbg . That's just a convenience thing. You could drop breaks into regular worker code and it'll enter the break loop, waiting for messages, and after exit it'll continue normal execution

winsome18:08:42

I want to start investigating how to reduce my bundle size - is there a way to get the post-closure-compiler size for each of my dependencies? What sort of size analysis tools are available?

winsome18:08:11

My deps are a mix of npm deps and clj/s deps.

john19:08:20

@thheller, something like npx shadow-cljs run shadow.cljs.build-report app output.html ?

👍 1
winsome03:08:55

These build reports are a godsend! Thank you for adding that, I've now got some low-hanging fruit to saw off : )

👍 2
Michaël Salihi19:08:34

Arf not fast enough compare to @thheller 😁

winsome19:08:40

Unfortunately I'm not currently using shadow-cljs, though this may be an inducement to switch

ag21:08:03

I need to import and re-use some react components from a vanilla .js lib. Unfortunately, it's a closed-source project otherwise I'd share a link. I'm trying to require things directly in my project (shadow-cljs), but it chokes on sass imports. The .js code has lines like import "./Accordion.scss". Does that mean that I have to prep this lib somehow, re-bundle it with webpack or something (I dunno), to be able to use it in cljs project?

thheller07:08:52

yes, this requires webpack. you can use it to bundle all your JS dependencies via this https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html#option-2-js-provider-external

👀 1
Sameer Thajudin23:08:03

I am running lein uberjar on a reagent project and am getting the following error. How can I fix this?

winsome03:08:55

These build reports are a godsend! Thank you for adding that, I've now got some low-hanging fruit to saw off : )

👍 2