sci

borkdude 2022-08-28T09:36:34.161549Z

@john You might want to use load-string or scittle.core.eval_string

👀 1
john 2022-08-28T15:31:25.811239Z

I tried both like so:

...
       :on-click #(let [res (js/scittle.core.eval_string
                             #_load-string
                             code-str
                             {:namespaces {'clojure.core {'println (partial println :new-stuff)}}})]
                    (swap! results-atom assoc :result res))
       ...
And when I evaluate (do (println :original) 2) it returns 2 but it prints :original, with no :new-stuff.

borkdude 2022-08-28T15:33:07.705809Z

what makes you think eval-string takes an additional SCI configuration?

john 2022-08-28T15:33:45.771309Z

From the README (sci/eval-string "(println \"hello\")" {:namespaces {'clojure.core {'println println}}})

borkdude 2022-08-28T15:33:55.322139Z

That is SCI, not scittle

john 2022-08-28T15:33:58.770779Z

aaaah

john 2022-08-28T15:34:15.733679Z

Didn't realize they were different

borkdude 2022-08-28T15:34:45.297809Z

scittle is made with SCI to evaluate code from browser tags. if you want to have full control, you can just use SCI directly

john 2022-08-28T15:34:58.700829Z

From within scittle?

borkdude 2022-08-28T15:35:37.112019Z

No I meant, write a CLJS project using SCI?

john 2022-08-28T15:35:51.272379Z

ah k

borkdude 2022-08-28T15:37:46.262239Z

@john if you want to alter println you can evaluate (alter-var-root #'println ...) within a SCI context

borkdude 2022-08-28T15:38:37.853609Z

It could be that this currently doesn't work, due to a safety setting that should be enabled, but this is an easy change

borkdude 2022-08-28T15:39:27.787319Z

a wait, this probably also doesn't work, because scittle has no reified vars (due to an optimization setting, I thought I could save some bundle size by leaving out docstrings, etc)

john 2022-08-28T15:39:49.491059Z

hmm okay

john 2022-08-28T15:42:32.232829Z

My idea for my weekend project was to build a little blog thing where you can edit your scittle coded blog in scittle. So like a component that can hide and show and edit your other components in

john 2022-08-28T15:42:52.168419Z

Kinda almost like the bookmarklet code editor

john 2022-08-28T15:43:12.892639Z

But I'm not able to do requires and whatnot in that bookmarklet context

borkdude 2022-08-28T15:44:00.884259Z

There was a similar thing recently, I forgot the name...

john 2022-08-28T15:44:37.820909Z

I did it once a few years ago with a self hosted cljs

john 2022-08-28T15:45:07.902699Z

https://pepl.io/admin

john 2022-08-28T15:45:20.930419Z

"Repl on a git stick"

john 2022-08-28T15:45:45.751709Z

Might be cleaner with a sci-like thing though

john 2022-08-28T15:47:09.916479Z

Beast!

borkdude 2022-08-28T15:51:14.385139Z

@john The benefit of going directly with SCI (or a fork of scittle) is that you can add in your own libraries too

borkdude 2022-08-28T15:51:28.287629Z

and then advance-compile them

john 2022-08-28T15:55:26.795039Z

Yeah, that would be necessary eventually. I'm also curious about the idea of bringing in deps at runtime, written in sci. Maybe sci snippets from gh gists or something, imported in via some declaration or something, so a blog author can extend from the browser editor and then just commit the change from the browser. Basically a pure browser build and deploy scenario.

borkdude 2022-08-28T15:57:53.654619Z

do you mean CLJS code snippets?

john 2022-08-28T15:58:14.024369Z

yeah, SCI compatible CLJS

borkdude 2022-08-28T15:58:19.770679Z

yeah, why not

john 2022-08-28T15:59:47.077859Z

I'm also curious about an impl of sci that is more locked down, which can pull in approved deps/plugins, but can't call js/eval or js/alert or other stuff, maybe sandboxed in a iframed web worker, for the purposes of semi-trusted distributed computations

borkdude 2022-08-28T16:01:05.624839Z

you could do that. you can disallow eval and all access to js/ (in fact, that's not even enabled by default)

borkdude 2022-08-28T16:01:21.943399Z

SCI aims to be safe out of the box for sandboxing

borkdude 2022-08-28T16:01:36.920459Z

the only thing it cannot do is pause/cancel running code

borkdude 2022-08-28T16:01:54.326139Z

this has to be controlled by the host (by killing worker/thread)

john 2022-08-28T16:02:27.547289Z

yeah, that's what I'd do. I'm thinking 3 seconds of execution time every 8 seconds

john 2022-08-28T16:04:38.645259Z

3 seconds split across a per-host worker pool. Time spent in workers waiting on results would not go against the time quota, so they could spread across all 8 seconds, but 8 seconds would be the cutoff

john 2022-08-28T16:05:00.287749Z

I'd think that's long enough to get some task done

john 2022-08-28T16:06:51.381759Z

Pull data from IPFS, do something, put the result up. And then an author can construct larger computations by putting together circuits of these 3 second computations

john 2022-08-28T16:08:07.938579Z

Hook it up to some utility coin and let content consumers and producers collect coin for resources provided, etc

john 2022-08-28T16:09:59.458429Z

Donating 1 webworker/process thread for 3 seconds of execution time every 8 seconds doesn't seem too egregious. Maybe it could be larger than 8 seconds. 16, 32?

john 2022-08-28T16:12:16.329819Z

It would be opt-in anyway, so the consumer could decide how much execution time to contribute

john 2022-08-28T16:13:51.977119Z

Anyway, the idea is like a distributed computation platform for building backend services for distributed apps

borkdude 2022-08-28T16:14:23.373029Z

sounds very futuristic, if SCI can help with that, why not :)

john 2022-08-28T16:16:43.959789Z

Yeah, imagine an email client you could use for 10 bucks a month, or just enable a light-weight compute sharing thing and get it for free! Would be sweet.

john 2022-08-28T16:17:55.426929Z

Just need a way to lock down and fully instrument and meter the runtime

john 2022-08-28T16:18:21.793459Z

Seems like a sci-like thing is a lot of the way there

john 2022-08-28T16:24:39.517779Z

It's pretty much the missing piece for a lot of these blockchains. You can't do most of the compute on these networks, because every node has to compute everything. So what you need is a separate set of partitions where small groups of "lite clients" can split off and do the work and then put the result back on-chain.

john 2022-08-28T19:39:01.808529Z

Dude, sci is future-sauce. This is amazing https://github.com/babashka/sci/blob/master/doc/async.md

🔥 1
🎉 1
teodorlu 2022-08-30T09:25:43.015719Z

and you can even make that serializable function perform well. Simply provide well-performing functions from the "host" and provide them to the sci environment

teodorlu 2022-08-29T11:52:38.702019Z

sci is amazing, I can't believe we have an embedded, isolated, safe clojure in clojure

teodorlu 2022-08-29T11:53:04.034879Z

it's like python's eval only good rather than terribly scary

john 2022-08-29T14:54:51.629079Z

Yeah, pretty amazing. The async thing is sweet too. Especially how require can go async and park the interpreter until the async job finishes - That's amazing. You could impl simulated blocking takes and all kinds of stuff with that.

john 2022-08-29T14:55:45.039489Z

And being serializable... The distributed computing applications are fascinating

💯 1
âž• 1
john 2022-08-28T00:15:16.002999Z

Hey all. I'm playing around with a sci evaluator in sci/scljs in sci/cljs. So like, a scittle page with a textarea which can be evaluated in browser, with an evaluate button like:

...
       :on-click #(let [res (eval (read-string code-str))]
                    (swap! results-atom assoc :result res))
       ...
Which seems to work, but when I put code in there that for instance has a r/atom, I'm getting the error: Could not resolve symbol: r/atom And doing something like: (ns self (:require [reagent.core :as r])) causes an error like: Can't change/establish root binding of #'*ns* with set Can I somehow pass through bindings from the parent sci context to the inner one?