Fork me on GitHub

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)


@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


@afoltzm Example:

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

šŸ™ 1

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


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.


@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

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


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


it is possible


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


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

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


Yeah - deleted because I figured I could just experiment myself


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


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

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


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

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

šŸ‘ 1

Ok, thanks šŸ‘


as a note, cider uses .interrupt , wait, then .stop, This allows tasks that do support interruption to property clean up.

šŸ‘ 2

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


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

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

šŸ‘ 1
teodorlu22:02:33 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?



šŸ’Æ 1

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


Ok, that makes sense šŸ‘


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

šŸ‘ 1

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


Defeating babashka's primary selling point :)


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