You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are two forms of generator and async syntax that could be helpful to have:
Define a generator or async function
Run a generator or async block of code
Proto has taken an ES-style approach to solving the second type with either IIFEs or comprehensions.
// Type 1
async foo() :{
var value = await bar(3);
// ...
}
// Type 2 with IIFE
(async :{
var value = await bar(3);
// ...
})();
// Type 2 with comprehension
{:
var value = await bar(3);
// ...
};
Proposal
Add a dedicated syntactic form for type 2 that's more prominent than the existing comprehension syntax.
Impetus
I expect type 2 to be pretty common, and the IIFE is ugly while the comprehension is too easy to miss when skimming code (looks like a regular block unless you really look closely). We can do better.
Pros
Clean, readable syntax
Can drop comprehensions (they're already closer to type 2 than ES or Python comprehensions).
Extensible. We can easily add new forms without having to make syntax crazier and crazier. Just use a keyword like gen, async, or array to specify the kind of block. We could potentially want to add more kinds of blocks. Maybe block types could even be user-defined?
Syntax Options
The form async :{ } will probably be used for either type 1 or type 2. Both seem to be reasonable options.
Favoring Type 1
// Type 1 (function)
async foo(bar) :{
// ...
}
// Type 2 (block)
do async :{
// ...
}
Pros
Harder for someone to accidentally use a block instead of a function. If we use the option below, I can see people typing var foo = async :{ }; and expecting foo to be a function when really (under the option below) it would be a promise, just because they forgot fn. This could be an annoyance. If the option above is chosen, I think it's less likely that people will forget the do. I'm not sure why, but it just seems that way...
Cons
This option would look really weird for array blocks:
var x = do array :{
for i of 0 .. 10:
each i ^ 2;
}
Favoring Type 2
// Type 1 (function)
async fn foo(bar) :{
// ...
}
// Type 2 (block)
async :{
}
Pros
This option looks much better for array blocks.
var x = array :{
for i of 0 .. 10:
each i ^ 2;
}
Cons
See the pros for the first syntax option. It seems too easy for someone to forget fn when they intend to write a function.
The text was updated successfully, but these errors were encountered:
Background
There are two forms of generator and async syntax that could be helpful to have:
Proto has taken an ES-style approach to solving the second type with either IIFEs or comprehensions.
Proposal
Add a dedicated syntactic form for type 2 that's more prominent than the existing comprehension syntax.
Impetus
I expect type 2 to be pretty common, and the IIFE is ugly while the comprehension is too easy to miss when skimming code (looks like a regular block unless you really look closely). We can do better.
Pros
gen
,async
, orarray
to specify the kind of block. We could potentially want to add more kinds of blocks. Maybe block types could even be user-defined?Syntax Options
The form
async :{ }
will probably be used for either type 1 or type 2. Both seem to be reasonable options.Favoring Type 1
Pros
var foo = async :{ };
and expectingfoo
to be a function when really (under the option below) it would be a promise, just because they forgotfn
. This could be an annoyance. If the option above is chosen, I think it's less likely that people will forget thedo
. I'm not sure why, but it just seems that way...Cons
Favoring Type 2
Pros
Cons
fn
when they intend to write a function.The text was updated successfully, but these errors were encountered: