nbb

Benjamin 2022-12-04T15:04:48.494809Z

is j/call not a macro?

[applied-science.js-interop :as j]
also
(j/lit {-b 10})
ah now I see it nbb readme it says it is not supported

borkdude 2022-12-04T15:06:44.533989Z

Those macros are only there for externs I think, in nbb you can just directly call those things

sparkofreason 2022-12-04T01:14:23.045389Z

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.

borkdude 2022-12-04T10:57:45.670709Z

we could just expose the SCI API to nbb

sparkofreason 2022-12-04T14:22:21.686069Z

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

borkdude 2022-12-04T14:24:25.704769Z

@dave.dixon 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

sparkofreason 2022-12-04T14:26:41.862059Z

Ah, right, all of that API isn't available to JS.

borkdude 2022-12-04T14:30:18.633509Z

There used to be a JS api, but it was a pain to maintain

sparkofreason 2022-12-04T14:42:58.345939Z

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

borkdude 2022-12-04T14:50:18.196659Z

it's not a good habit to remove npm packages, is it? ;)

sparkofreason 2022-12-04T14:58:51.279709Z

No, probably not, though I see now that it's pretty old compared to the latest sci release.

sparkofreason 2022-12-04T14:59:24.084209Z

Maybe add some notice?

borkdude 2022-12-04T15:04:56.626089Z

Does npm support archiving / deprecating a project?

sparkofreason 2022-12-04T15:49:53.436919Z

I don't know, haven't worked with it from that end.

sparkofreason 2022-12-04T16:20:06.843479Z

Looks like it meets the criteria for being unpublished: https://docs.npmjs.com/policies/unpublish

borkdude 2022-12-04T16:34:26.606219Z

done

1
borkdude 2022-12-04T16:40:26.010349Z

I wonder who will start complaining...

borkdude 2022-12-04T16:40:40.381709Z

maybe I should have checked the usages first :/

sparkofreason 2022-12-04T16:41:27.745679Z

It said there were zero dependents.

borkdude 2022-12-04T16:41:30.153419Z

oh I think it's ok ;) https://github.com/babashka/sci/network/dependents

borkdude 2022-12-04T16:42:04.290329Z

anyway, one should probably upgrade to the newest SCI instead of using one from 3 years ago

👍🏼 1
sparkofreason 2022-12-04T16:45:15.337249Z

Back to the original question...would you anticipate any problems pushing sci options through something like nbb.loadFile?

borkdude 2022-12-04T16:48:04.858759Z

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 state

sparkofreason 2022-12-04T16:54:27.569999Z

I'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.

borkdude 2022-12-04T16:57:27.803959Z

I didn't mean VM as in a dedicated virtual machine

borkdude 2022-12-04T16:57:37.866459Z

I meant a Node.js vm, it's an built-in sandboxing-like thing

borkdude 2022-12-04T16:58:20.282599Z

Just try npx nbb, then (range) and then hit ctrl-c. This is implemented with the Node.js vm library

sparkofreason 2022-12-04T17:00:44.096119Z

Ah, cool, will check that out. Thanks!

sparkofreason 2022-12-04T17:22:03.132029Z

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.

borkdude 2022-12-04T17:24:54.793049Z

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

👍🏼 1
sparkofreason 2022-12-04T18:23:17.042789Z

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.

sparkofreason 2022-12-04T18:29:43.039479Z

Actually, maybe require didn't work. I tried it again and the first time it gave Could not resolve symbol: -invoke, subsequently nil.

borkdude 2022-12-04T18:42:13.527899Z

$ nbb
Welcome to nbb v1.1.150!
user=> (require '[sci.core :as sci])
"Error: Could not find namespace: sci.core"

borkdude 2022-12-04T18:42:21.868619Z

sci itself needs to be exposed through the sci options