Fork me on GitHub
#sci
<
2021-06-15
>
Artem04:06:49

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 🙏

borkdude07:06:15

@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.

borkdude12:06:22

@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.

Artem14:06:35

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 🙂

borkdude14:06:32

Sci doesn't have anything for this at the moment

👍 3
mauricio.szabo17:06:46

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 🙂

mkvlr18:06:57

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

borkdude19:06:51

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