Fork me on GitHub
#sci
<
2022-09-17
>
djblue06:09:56

Quick question about sci.core/ns . If I eval an expression that changes the namespace, such as (ns foo) , should that information be available in sci.core/ns? Given what I'm seeing for the https://github.com/babashka/babashka.nrepl/blob/master/src/babashka/nrepl/impl/server.clj#L121, I would expect so but in cljs I can't seem to get it working :thinking_face:

borkdude06:09:37

Yes but with eval-string ns is reset to the original binding, similar to load-string in Clojure

borkdude06:09:49

The sci.async ns has an eval-string+ function which returns the last ns binding as well. Sci/parse-next + eval-form allows you to save the last ns binding in case you are at the end of the stream

borkdude06:09:29

Eval-form doesn't reset the ns binding and requires you to bind ns yourself

djblue06:09:04

Ohh, that makes sense. Thanks for the help! 🙏

djblue06:09:48

How would I setup *1, *2, *3 and *e with eval-string+?

borkdude07:09:51

With sci/binding

borkdude07:09:45

Or in cljs maybe just use sci/alter-var-root

borkdude07:09:02

Since when using async those bindings go out of scope which sucks

☝️ 1
djblue07:09:40

I think parse-next + eval-form is what I'm looking for 👌

borkdude07:09:13

If you want sync eval, then use parse-next + eval-form. We could introduce a sci.core/eval-string+ as well

djblue07:09:06

That would be nice, but I'm also cool with the more manual way

djblue07:09:15

Everything is working perfectly!!! Thanks for the help ❤️

borkdude07:09:19

Cool! What are you doing, portal?

djblue07:09:33

Yeah, working on exposing sci in portal via nrepl / socket repl

borkdude07:09:02

ah nice! you can check out nbb for nrepl / socket repl examples as well

👍 1
borkdude07:09:42

also scittle (in browser nREPL)

djblue07:09:16

So I'm adding middleware to an existing nrepl server, how does scittle do it?

borkdude07:09:36

scittle implements an nrepl server from scratch, so does nbb

borkdude07:09:51

but I'm curious to learn what you are doing, it sounds like it's something I haven't explored

djblue07:09:00

Wait, how do clients connect to the browser?

djblue07:09:23

Is there a proxy involved?

borkdude08:09:12

yes, there is a tiny proxy which is running in a bb process

djblue08:09:07

Interesting :thinking_face: I went the piggieback/shadow-cljs route and implemented nrepl middleware that intercepts evals 😆

borkdude08:09:03

I hadn't even considered that. I'm sure there are interesting trade-offs

djblue08:09:36

Yeah, I'm not a big fan of middleware but I did get something working. Might try https://github.com/babashka/sci.nrepl instead.