sci

john 2023-06-12T00:24:57.471669Z

Hi, I'm curious about embedding sci (or cherry or squint) into a custom node runtime (Google App Script). Wondering where I should start. I've got a self-hosted CLJS running on GAS, so you can run code in formulas in Google Sheets and what not, which is interesting. But it's a bit heavy weight, having the whole self host in there. And 99% of your GAS code is going to be interop with GAS libs, so even squint might be a fit.

john 2023-06-12T00:26:48.498869Z

I noticed this: https://github.com/babashka/sci/blob/master/src/sci/impl/js.cljs

john 2023-06-12T00:28:43.281539Z

So that might work. But is it possible to share a namespace/context environment across different evalString calls, so that diffrent sheet cells can refer to the same definitions?

john 2023-06-12T00:30:00.236469Z

Still figuring out how to send cells in as parameters to clojure functions defined in a cell formula, but it might be an interesting tool

john 2023-06-12T00:30:47.517659Z

Using the whole self hosted compiler on every call is too heavyweight though and slows the call down

john 2023-06-12T00:34:22.189449Z

The great thing about Google App Script, by the way, is that 1) it's free, and 2) https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app, which you can use to build a bot that can scrape the internet and store results in google sheets, for free, so that's pretty sweet

john 2023-06-12T00:34:47.508199Z

GAS is serverless node before serverless was even a thing lol

john 2023-06-12T00:35:51.954509Z

Anyway, no reason to write scripts on there in an uncivilized manner, so I figure I'll try one of these slimmer alternatives to cljs for wrapping GAS

john 2023-06-12T00:52:48.964329Z

And with https://developers.google.com/apps-script/guides/clasp you can just deploy from the cli. So a cljs->gs build/deploy pipeline would be easy. There's no reason we shouldn't be just firing off scripts to the cloud using our personal hosted google node servers using our google accounts. It's a free lambda. Maybe that's what I should turn my clgs project into. A tool like nbb, but sends it to GAS. Not sure how a repl would work - it's ephemeral, like a lambda 🤔

john 2023-06-12T01:02:35.242599Z

Would probably be pretty easy to host a free ngrok/pagekite thing, for getting repls out from behind firewalls, etc

john 2023-06-12T01:10:07.292479Z

And it could probably be as easy as nbb -e '(+ 1 2 3)', but it just runs it on gas

john 2025-04-08T18:31:12.530459Z

hmm. Not sure where that pointed. But essentially, you just start a project that has a Javasript.html file in it. Then you can just use script tags in it, with something like:

<script src="" type="application/javascript"></script>
<script type="application/x-scittle">
  (defn my-alert []
    (-> js/google
        .-script
        .-run
        (.withSuccessHandler #(println :contents %))
        (.doMyFn #js {"id" 12}))
    (js/alert "You clicked!"))
  ;; export function to use from JavaScript:
  (set! (.-my_alert js/window) my-alert)
</script>
Where doMyFn is some js fn you've defined in your file. Then in your index.html file you can have something like:
<button onclick="my_alert()">
  Click me!
</button>

john 2025-04-08T18:34:22.390149Z

That's for frontend logic using scittle. Using it on the backend, in a .gs file is a different workflow, IIRC

john 2025-04-08T18:47:56.376079Z

Oh yeah, for that workflow, I'd advance compile a self-hosted version of CLJS, which IIRC was like 1.5 megs of JS. I pasted that into a file in the app script project. Then, in some other file or whatever, add a function to call the CLJS compiler:

function evalStr(s) {
  clgs.core.evalCljs("(ns cljs.user)");
  var res = clgs.core.evalCljs(s);
  //Logger.log("output: " + res);
  return res;
}
And then you can eval cljs forms directly in spreadsheet cells using evalStr. And you could probably use that eval in other places where app script code interfaces with. I played with that before sci was out I believe. But the idea there is to just put the whole js artifact in a gs file - not sure sci has a singular js artifact that exposes an eval call - probably does.

2025-04-10T06:02:21.915979Z

thanks @john 👍

2025-04-03T15:12:48.171809Z

Hi - apols for being almost 2 years late... I am interested in sci on GAS. I can't access this link bc permissions. What tooling setup did you use in the end for clojure and GAS? anything on github I could see? thanks

john 2023-06-12T01:49:36.897419Z

Has that ugly ToS banner bar at the top, but good enough to get stuff done for free

borkdude 2023-06-12T09:11:45.451459Z

> Hi, I'm curious about embedding sci (or cherry or squint) into a custom node runtime (Google App Script). Wondering where I should start. I guess you figured it out?

john 2023-06-12T19:22:43.276459Z

Well, I guess a number of different paths could work. Sorry about the longwindedness above, kinda pitching it and ruminating options at the same time

borkdude 2023-06-12T19:28:30.917919Z

google cloud functions play well with nbb btw

borkdude 2023-06-12T19:28:47.163619Z

no custom runtime necessary

john 2023-06-12T19:29:23.117489Z

And I guess there's a free threshold there too yeah?

borkdude 2023-06-12T19:29:39.836759Z

not sure, but I would assume so

borkdude 2023-06-12T19:30:26.360049Z

first two million are free

borkdude 2023-06-12T19:31:32.796499Z

Cloud Functions provides a perpetual free tier for compute-time resources, which includes an allocation of both GB-seconds and GHz-seconds. In addition to the 2 million invocations, the free tier provides 400,000 GB-seconds, 200,000 GHz-seconds of compute time and 5GB of Internet egress traffic per month.

john 2023-06-12T19:33:16.377229Z

Wow

john 2023-06-12T23:19:22.434789Z

That's probably even more than the GAS quotas anyway

john 2023-06-12T23:20:25.269069Z

GAS is an interesting stack though, with the webservices and docs integration

john 2023-06-12T23:21:27.048709Z

You could spin up a form from the CLI to take community comments that auto populated a google sheet