Fork me on GitHub
#cljs-dev
<
2021-10-21
>
borkdude15:10:42

What is the chance that CLJS will ever have bespoke syntax around async/await: higher or equal to zero? I'm not advocating for it or against it, I just want to know the (current) likelihood.

neumann16:10:08

@borkdude The <p! macro has been a near drop-in replacement for await for me. Are you looking for something different?

borkdude16:10:08

I'm not looking for anything. I just want to know exactly what I'm asking. Not looking for solutions :-).

neumann16:10:52

Ah, OK. 🙂

dnolen16:10:25

@borkdude I don't see how this wouldn't be some kind of syntactical change - so the likelihood is pretty low - I haven't encountered a single situation it is necessary - nor have heard as of yet convincing arguments otherwise

dnolen16:10:43

not enough to introduce new syntax

1
dnolen16:10:08

also semantic change seems to me - since it would necessarily generate functions w/o Clojure semantics

dnolen16:10:05

if something like this existed it probably would not be allowed to interact w/ fn syntax - at which point - why bother?

borkdude16:10:19

from an implementation perspective, would it be far more complex than generating the words await and async at the right spots and let JS deal with the complexity?

dnolen16:10:54

And Closure can handle it as well

dnolen16:10:32

But that's the thing - if you really need this stuff, I just don't see how it isn't solved by writing some JavaScript - we made that relatively easy long ago

Karol Wójcik17:10:35

Could you please clarify what do you mean "by writing some JavaScript". Do you mean using *js in cljs or literally write Javascript?

nwjsmith17:10:03

Literally write JavaScript and import it, compile using the bundle target.

borkdude17:10:29

I suspect more like this:

import { readFile } from 'fs'
const foo = await Promise.resolve(100);

export default foo
---
(ns foo
  (:require ["./foo.mjs" :refer [default] :rename {default foo}]))

(.log js/console foo)

thheller17:10:16

that type of require is shadow-cljs only 😉

borkdude17:10:54

And #nbb :)

borkdude17:10:20

Since it directly uses dynamic import this just works

Karol Wójcik17:10:12

async/await is one of the biggest wins for the JS ecosystem since it makes code more readable compared to promises/callbacks. I know we can use channels. I am aware of their existence and use them regularly. However, there are types of applications e.g. puppeteer tests, AsyncLocalStorage + fibers that require the usage of pure Promises. Using channels the user might shoot itself in the foot quickly. I am aware that async/await for Clojurescript on the browser has a little sense, but for Node.js is essential.

borkdude17:10:26

Here is a puppeteer test with promesa. https://github.com/borkdude/nbb/blob/main/examples/puppeteer/example.cljs Promesa is just a bunch of short macros that translate in chained promises. I like it.

borkdude17:10:08

One could argue that because macros aren't a thing you need a committee to add things to a language like JS

Karol Wójcik17:10:59

I'm aware of other alternatives, but thanks anyway 😄

dnolen17:10:13

I used Puppeteer w/ core.async 3 years ago - it just works and works great, I still have my feet 🙂

dnolen17:10:38

anyways - it ain't gonna happen until somebody comes with an incredible reason that hasn't been considered yet

dnolen17:10:20

re: just writing JavaScript ...

dnolen17:10:46

you can write modern JavaScript and Closure can process it along w/ your ClojureScript

dnolen17:10:08

you can write modern JavaScript in files w/ goog.provide

dnolen17:10:36

again some of these things were validated by transit-js even more years ago

dnolen17:10:58

IMO absolutely nothing of interest has happened as far as ClojureScript is concerned to JavaScript since 2001 - which is more or less the version of JS we generate

borkdude17:10:30

@dnolen yep. I was just wondering, I'm not particularly interested in adding stuff to the language myself, but for #nbb I would like to be compatible. If I were to introduce some kind of mode for the REPL where it would await top level expressions, I wanted to make sure I didn't miss anything going in in CLJS.

dnolen17:10:12

yeah no plans

dnolen17:10:33

the only proposed features for JS that I've felt anything enthusiasm for - real 64 bit ints, and fast multimethod arithmetic to make it work

👍 1
lilactown22:10:21

I think there are things we win by generating async/await: potentially better efficiency and error handling, and avoiding the core.async macro pains if we know we're working with just promises. is that worth the cost to developing it into the language? sounds like that's been answered. but there are second-order wins, to me

lilactown22:10:35

we've hashed this all out before, IIRC the biggest impediment is that we use a lot of IIFEs to handle do and similar expressions and those conflict with async needing to be at the function boundary

lilactown22:10:46

so it's not a matter of "just emit async / await" and be done, since it would break strangely when used with let or any number of expressions that implicitly wrap the body in a function in order to return as an expression. and that problem would have to be solved before letting it into the language. then as dnolen alluded to there's the problem of syntax and breaking from Clojure more

dnolen22:10:28

yep, expression oriented language and access to async await primitive just isn't going to work

dnolen22:10:58

I was alluding to that above in the adding such a constructs is just creating a lot of trouble and absolutely minimal value

lilactown23:10:47

at some point this might just be fixed for us in the language if certain proposals get accepted, i.e. do-notation

lilactown23:10:32

but those are such pie-in-the-sky proposals IMO

lilactown23:10:06

and there always ends up being some weirdness that makes it awkward. design-by-committee has its shortfalls....

dnolen23:10:32

Fortunately JS optimizers came before all this stuff