dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
516 stars 97 forks source link

Feat: Improve concrete syntax for eliminating `async ? T` #2287

Open matthewhammer opened 3 years ago

matthewhammer commented 3 years ago

Are all of these parens really needed, or am I missing something? https://github.com/dfinity/cancan/blob/8c9034ccd0c799664e4aa5ce061f488a0430b3f0/service/CanCan.mo#L97

rossberg commented 3 years ago

Yes, that's what you get when mixing prefix and postfix elimination syntax -- a problem well-known back from C.

We'd need to use some postfix alternative to await to fix this, but prefix await is widely used standard practice. The only alternative I've seen is Rust's .await, which is odd. Does anybody have a better idea?

In practice, I'd probably avoid inlining await too much and rather let-bind its result to increase visibility of the interleaving point.

crusso commented 3 years ago

Actually, I don't think the parens around the arg to await are necessary.

buf.add((await (getVideoResult(vid)))!)

Try:

buf.add((await getVideoResult(vid))!)
matthewhammer commented 3 years ago

Ah, okay.

The alternation of prefixed await and postfixed ! remains, but it's perhaps not so bad, since that's also the order of the operations.

matthewhammer commented 3 years ago

I'd probably avoid inlining await too much and rather let-bind its result to increase visibility of the interleaving point.

Add to a conventions spec somewhere? (For library authors?)