sci

https://github.com/babashka/SCI - also see #babashka and #nbb
Artem 2021-06-15T04:25:49.101300Z

hi there! I’ve been playing with with SCI recently in my small ClojureScript toy project (a kind of a computational notebook) and it was exactly what I needed and super easy to integrate. Really impressive work! 😍 It made me wonder: would the current design of SCI allow for passing bindings that execute asynchronously, but appear synchronous (blocking) to the caller? E.g., a program like (do (sleep 2000) (js/alert "Here")) . This is, of course, trivial in Clojure where one can dereference a future (or use the <!! macro in core.async), but it could be possible in ClojureScript if SCI could interrupt on certain bindings, returning control to the caller and providing a continuation. Does this make sense? I’d love a synchronous scripting language that runs in a browser. (I’m more familiar with Clojure than ClojureScript so maybe there’s already a way to achieve this somehow via creative use of core.async or native promises). Any pointers would be welcome 🙏

borkdude 2021-06-15T07:26:15.102200Z

@chistyakov.artem I think @mauricio.szabo has done something similar in his #chlorine-clover project where he implemented a kind of let macro that accepts promises as bindings. Maybe he could tell you more.

borkdude 2021-06-15T12:53:22.103600Z

@chistyakov.artem I extracted a working example here: https://gist.github.com/borkdude/e926d02b0d44dde04d74364201172e9b It doesn't even use the promesa library, it's just pure promises.

Artem 2021-06-15T14:27:35.109200Z

oh wow, thank you so much @borkdude! I’ll look into this more tonight. The gist you shared is much better than what I have right now. I guess, your answer also implies that currently there’s no way to “abstract the async away” from the user like in my original sleep/alert example, is that correct? I realize it might be out of scope for SCI, but it’s one of those things that seem possible in abstract 🙂

borkdude 2021-06-15T14:30:32.109500Z

Sci doesn't have anything for this at the moment

👍 1
mauricio.szabo 2021-06-15T17:35:46.111500Z

Yeah, what I did was to simulate the p/let from promesa into SCI. I was thinking if it should be possible to eval form by form and, if one return promises, await for it to resolve. This would remove the need for the let binding for SCI too 🙂

mkvlr 2021-06-15T18:11:57.112400Z

reminds me of a thing I’ve promised you @borkdude

borkdude 2021-06-15T19:52:51.112800Z

@mkvlr No worries, it's not a trivial problem to achieve a solution for ;)