This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-04
Channels
- # adventofcode (129)
- # announcements (1)
- # babashka (7)
- # beginners (30)
- # calva (42)
- # cider (2)
- # clj-commons (2)
- # clj-on-windows (27)
- # clj-yaml (4)
- # clojure (69)
- # clojure-belgium (4)
- # clojure-europe (5)
- # clojure-norway (4)
- # clr (1)
- # css (3)
- # datomic (19)
- # dev-tooling (2)
- # events (1)
- # humbleui (1)
- # hyperfiddle (17)
- # introduce-yourself (4)
- # java (1)
- # joyride (3)
- # kaocha (1)
- # lsp (4)
- # malli (10)
- # mount (1)
- # nbb (34)
- # off-topic (37)
- # pathom (1)
- # ring (4)
- # tools-deps (12)
Is there a way to configure nbb with sci options from JavaScript? I'm experimenting using nbb (or maybe just sci) for embedded scripting in our app, and would like to limit things that could create infinite loops.
After looking at the nbb code and seeing how it uses sci, I suppose another option is to use sci directly. I'd only need to evaluate a single short file (maybe with some common functions injected), no async. Maybe I could do a simplified version of eval-next
https://github.com/babashka/nbb/blob/main/src/nbb/core.cljs#L383
@U066LQXPZ In this case, you might just want to use SCI directly in a bespoke CLJS project and compile it to JS with the interface you like
Ah, right, all of that API isn't available to JS.
Ah, I guess that's why those docs are commented out in the README
. They still show up on https://www.npmjs.com/package/@borkdude/sci
No, probably not, though I see now that it's pretty old compared to the latest sci release.
Maybe add some notice?
I don't know, haven't worked with it from that end.
Looks like it meets the criteria for being unpublished: https://docs.npmjs.com/policies/unpublish
It said there were zero dependents.
oh I think it's ok ;) https://github.com/babashka/sci/network/dependents
anyway, one should probably upgrade to the newest SCI instead of using one from 3 years ago
Back to the original question...would you anticipate any problems pushing sci options through something like nbb.loadFile
?
That's not what I plan to support, but what I would support is this:
(nbb.loadString `(require '[sci.core :as sci]) (sci/eval-string "{yourProgram}")`)
or so. Not sure if that would help you and what the requirements of yourProgram
are - e.g. should it have access to the environment?
Another thing you could use is a Node vm which you can kill after x time. I've used this in the nbb REPL. E.g. when you evaluate (range)
you can do ctrl-c without losing your previous stateI'll have to think about it. It's just a simple script returning one function and some data, and then the potential execution of the function. I'm trying to pitch this as giving a really easy user experience (despite being Clojure 😜). But I'm just in the initial stages of thinking about this, so there's opportunity to adapt. For selling it to the team, it would be a big win if it was "just a library". If we're going to go full VM or similar, we'd probably just go JS for this.
Just try npx nbb
, then (range)
and then hit ctrl-c. This is implemented with the Node.js vm library
Ah, cool, will check that out. Thanks!
That's good to know about, though I think it comes back to the same thing, where if that's the only safety mechanism we might as well just use JS. I'll see where I can get calling sci from inside nbb.
yeah, I think we could maybe support load-string
or so with extra SCI opts but maybe not exposed via the normal namespace. Feel free to experiment locally and see how far you get
From nbb running jacked-in from calva:
(require '[sci.core :as sci])
(sci/eval-string "(inc 1)") ; => Could not resolve symbol: sci/eval-string
require
worked, so this is puzzling.Actually, maybe require didn't work. I tried it again and the first time it gave Could not resolve symbol: -invoke
, subsequently nil
.
$ nbb
Welcome to nbb v1.1.150!
user=> (require '[sci.core :as sci])
"Error: Could not find namespace: sci.core"