Fork me on GitHub
#sci
<
2022-02-03
>
respatialized18:02:03

Are there examples of using scittle with other JS libraries besides the bundled ones? (I'm thinking of D3 here but any examples of requiring an external JS lib from scittle will probably help me get started)

borkdude18:02:55

@afoltzm scittle currently doesn't support loading JS libraries in the ns form. The way this would work is just by loading d3 in a script tag and then using js/D3.whatever

borkdude18:02:14

@afoltzm Example:

<html>
  <head>
    <script src="" type="application/javascript"></script>
    <script src=""></script>
    <script type="application/x-scittle">
      (-> (js/d3.selectAll "p") (.style "color" "blue"))
    </script>
  </head>
  <body>
    <p>This is a paragraph</p>
    <p>This is another paragraph</p>
  </body>
</html>

1
šŸ™ 1
teodorlu22:02:08

Wanted to say that sci is exceptionally cool. I'm not aware of anything similar in other languages.

teodorlu22:02:59

Also, I have a question. Does sci self host? In other words, can sci use sci to eval clojure code isolated from the outer sci layer? Just curious for now. It's like... We've got this Docker for Clojure, just without tons and tons of copied stuff, containers, images, versions, one might say bloat.

borkdude22:02:36

@teodorlu SCI cannot evaluate itself, but what is evaluated in a SCI context, created with (sci/init {...}), does not, or should not affect the host. E.g. creating vars in a context does not create vars in the Clojure runtime.

šŸ‘ 1
teodorlu22:02:20

So I cannot use sci as a library from a Babashka script?

borkdude22:02:47

we could expose SCI itself in babashka, but so far I haven't done this

borkdude22:02:57

it is possible

teodorlu22:02:15

I don't have a particular use case in mind, just curious

borkdude22:02:37

some people use SCI in the JVM to evaluate programs coming from web requests. SCI gives a form of isolation and you can control what vars are or are not allowed. One thing SCI doesn't do is protect you from long-running or never-ending loops, but both JVM and Node.js have lower level primitives for this

šŸ‘ 1
borkdude22:02:27

About the ANSI escape codes, are you looking for colored output?

teodorlu22:02:10

Yeah - deleted because I figured I could just experiment myself

teodorlu22:02:22

Thanks, exactly what I was looking for šŸ‘

borkdude22:02:10

In #nbb (SCI on Node.js) I've used something to kill for-ever running loops. E.g. if you type (range)in the REPL and then press ctrl-c, you're still in the REPL and the eval loop is killed.

šŸ‘ 1
teodorlu22:02:41

On the JVM, would threads and .stop() be the way to achieve reliable interrupts?

borkdude22:02:12

in the JVM, CIDER uses .stop() on Threads to do the same. Unfortunately GraalVM doesn't support it, since they have decided not to implement the deprecated method

šŸ‘ 1
borkdude22:02:58

but if you're running SCI in a non-Graal JVM you could use .stop()

šŸ‘ 1
teodorlu22:02:48

Ok, thanks šŸ‘

phronmophobic22:02:32

as a note, cider uses .interrupt , wait, then .stop, https://github.com/nrepl/nrepl/blob/d875260afcecd6bfc2ff53a0be437cf2972250f4/src/clojure/nrepl/middleware/session.clj#L176 This allows tasks that do support interruption to property clean up.

šŸ‘ 2
teodorlu22:02:00

Ahh, nice, thanks for the link. So... First try to kill "nicely", then permit 5 seconds for cleanup, then stop forcibly?

phronmophobic22:02:02

Yes, it seems like a reasonable balance which is good enough for trusted code in a dev environment. If you need true isolation, you probably want to run it in a separate process with appropriate sandboxing.

šŸ‘ 1
teodorlu22:02:21

Right - and then you could just use OS interrupts instead?

šŸ‘ 1
teodorlu22:02:33

https://clojurians.slack.com/archives/C015LCR9MHD/p1643925719149929 Does that mean that the answer to my original question is that ā€¢ It's not really necessary to stack two sci interpreters for isolation because they can run "next to each other" ā€¢ And the same isolation guarantees could be provided with an interface to sci/init and sci/eval from Babashka ? Just that it hasn't been needed so far?

borkdude22:02:08

yes

šŸ’Æ 1
teodorlu22:02:14

I guess running sci inside sci inside sci..... Is going to perform poorly at some point šŸ˜„

teodorlu22:02:26

Ok, that makes sense šŸ‘

borkdude22:02:56

GraalVM has a JVM bytecode Truffle interpreter which can run inside of itself

šŸ‘ 1
borkdude22:02:33

but unfortunately loading Clojure in that thing takes 30 seconds or so

teodorlu22:02:40

Defeating babashka's primary selling point :)

borkdude22:02:48

Exactly. I've tried initializing the clojure loading in a static initializer with espresso (the name of the bytecode interpreter) but that didn't work out

šŸ‘ 1