This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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?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
.From the README (sci/eval-string "(println \"hello\")" {:namespaces {'clojure.core {'println println}}})
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 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)
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
I mean this one: https://github.com/NickCellino/clj-browser-eval and this one: https://nickcellino.com/blog/2022-08-07-clojure-bandits.html
@john The benefit of going directly with SCI (or a fork of scittle) is that you can add in your own libraries too
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.
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)
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
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
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.
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
sci is amazing, I can't believe we have an embedded, isolated, safe clojure in clojure
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.