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?
@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
Note that Clojure eval
is not compatible with GraalVM native-image
, so if that is a requirement, sci may be a good alternative
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?
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
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.
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
If you want something more isolated, then sci is a good option
I see. Thank's a lot.
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?
Thx. That makes sense.