@john You might want to use load-string or scittle.core.eval_string
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.what makes you think eval-string takes an additional SCI configuration?
From the README (sci/eval-string "(println \"hello\")" {:namespaces {'clojure.core {'println println}}})
That is SCI, not scittle
aaaah
Didn't realize they were different
scittle is made with SCI to evaluate code from browser tags. if you want to have full control, you can just use SCI directly
From within scittle?
No I meant, write a CLJS project using SCI?
ah k
@john if you want to alter println you can evaluate (alter-var-root #'println ...) within a SCI context
It could be that this currently doesn't work, due to a safety setting that should be enabled, but this is an easy change
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)
hmm okay
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
Kinda almost like the bookmarklet code editor
But I'm not able to do requires and whatnot in that bookmarklet context
There was a similar thing recently, I forgot the name...
I did it once a few years ago with a self hosted cljs
"Repl on a git stick"
Might be cleaner with a sci-like thing though
I mean this one: https://github.com/NickCellino/clj-browser-eval and this one: https://nickcellino.com/blog/2022-08-07-clojure-bandits.html
Beast!
@john The benefit of going directly with SCI (or a fork of scittle) is that you can add in your own libraries too
and then advance-compile them
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.
do you mean CLJS code snippets?
yeah, SCI compatible CLJS
yeah, why not
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
you could do that. you can disallow eval and all access to js/ (in fact, that's not even enabled by default)
SCI aims to be safe out of the box for sandboxing
the only thing it cannot do is pause/cancel running code
this has to be controlled by the host (by killing worker/thread)
yeah, that's what I'd do. I'm thinking 3 seconds of execution time every 8 seconds
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
I'd think that's long enough to get some task done
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
Hook it up to some utility coin and let content consumers and producers collect coin for resources provided, etc
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?
It would be opt-in anyway, so the consumer could decide how much execution time to contribute
Anyway, the idea is like a distributed computation platform for building backend services for distributed apps
sounds very futuristic, if SCI can help with that, why not :)
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.
Just need a way to lock down and fully instrument and meter the runtime
Seems like a sci-like thing is a lot of the way there
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.
Dude, sci is future-sauce. This is amazing https://github.com/babashka/sci/blob/master/doc/async.md
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
sci is amazing, I can't believe we have an embedded, isolated, safe clojure in clojure
it's like python's eval only good rather than terribly scary
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.
And being serializable... The distributed computing applications are fascinating
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?