sci

https://github.com/babashka/SCI - also see #babashka and #nbb
henrik42 2021-04-25T13:10:03.020900Z

sci newbie here. Why would I use sci instead of just clojure java interop when using clojure expressions as an embedded dsl in a java app?

borkdude 2021-04-25T13:11:13.021500Z

@henrikheine If you can just use Clojure eval and you do not need to control which classes you have access to, by all means, use it

borkdude 2021-04-25T13:11:44.022Z

Note that Clojure eval is not compatible with GraalVM native-image, so if that is a requirement, sci may be a good alternative

henrik42 2021-04-25T13:16:21.022200Z

Ok. The sci readme mentions bindings for eval-string which I like as it lets me define a context for name resolution. Do you think it's worth pulling in sci as a dep'y for this or is there a clojure equivalent you know of?

borkdude 2021-04-25T13:18:30.022400Z

You could just evaluate an expression in Clojure in the context of a namespace which has the names you need.

user=> (ns foo)
nil
foo=> (def x 1)
#'foo/x
foo=> (ns bar)
nil
bar=> (binding [*ns* (the-ns 'foo)] (eval 'x))
1

henrik42 2021-04-25T13:23:14.022600Z

Good idea. Since this would be a server app I would have to give each user (session? service-call?) a dedicated namespace. Isolation is my concern here.

borkdude 2021-04-25T13:24:17.022800Z

Namespaces in Clojure are global, but you could generate the name using some uuid. You don't get any isolation in the level of security though, users could always iterate over all the available namespaces and ruin it for others for example or ruin your running up, call (System/exit 1), etc

👍 1
borkdude 2021-04-25T13:24:25.023Z

If you want something more isolated, then sci is a good option

henrik42 2021-04-25T13:31:43.023400Z

I see. Thank's a lot.

henrik42 2021-04-25T13:54:58.023600Z

From an older sci cljdoc I had the impression that some parts may have been aot compiled in the past. Is there some kind of java api for sci? Or would I just go through java-interop?

henrik42 2021-04-25T18:49:21.024500Z

Thx. That makes sense.