sci

respatialized 2022-02-03T18:28:03.421339Z

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)

borkdude 2022-02-03T18:38:55.501979Z

@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

borkdude 2022-02-03T18:45:14.953549Z

@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
teodorlu 2022-02-03T22:00:08.842609Z

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

teodorlu 2022-02-03T22:01:59.149929Z

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.

borkdude 2022-02-03T22:04:36.584499Z

@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
teodorlu 2022-02-03T22:05:20.165799Z

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

borkdude 2022-02-03T22:05:47.527919Z

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

borkdude 2022-02-03T22:05:57.046439Z

it is possible

teodorlu 2022-02-03T22:06:00.625089Z

Ok

teodorlu 2022-02-03T22:06:15.729039Z

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

borkdude 2022-02-03T22:07:37.717849Z

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
borkdude 2022-02-03T22:09:27.999189Z

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

teodorlu 2022-02-03T22:11:10.062149Z

Yeah - deleted because I figured I could just experiment myself

teodorlu 2022-02-03T22:11:22.721559Z

Thanks, exactly what I was looking for 👍

borkdude 2022-02-03T22:12:10.735969Z

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
teodorlu 2022-02-03T22:13:41.280659Z

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

borkdude 2022-02-03T22:14:12.381759Z

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
borkdude 2022-02-03T22:14:58.458009Z

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

👍 1
teodorlu 2022-02-03T22:16:48.577579Z

Ok, thanks 👍

phronmophobic 2022-02-03T22:19:32.945819Z

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
teodorlu 2022-02-03T22:22:00.384229Z

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

phronmophobic 2022-02-03T22:25:02.153049Z

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
teodorlu 2022-02-03T22:27:21.178939Z

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

👍 1
teodorlu 2022-02-03T22:19:33.042609Z

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?

borkdude 2022-02-03T22:20:08.644799Z

yes

💯 1
teodorlu 2022-02-03T22:20:14.366969Z

I guess running sci inside sci inside sci..... Is going to perform poorly at some point 😄

teodorlu 2022-02-03T22:20:26.239419Z

Ok, that makes sense 👍

borkdude 2022-02-03T22:20:56.967009Z

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

👍 1
borkdude 2022-02-03T22:21:33.647229Z

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

teodorlu 2022-02-03T22:22:40.647609Z

Defeating babashka's primary selling point :)

borkdude 2022-02-03T22:23:48.778979Z

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