How does this proposal relate to the do block and explicit resource management proposals? I'm noticing that the basic functionality of both of these proposals can trivially be implemented with this proposal. I know this proposal has had a bit of a rocky start (as stated in #35), but perhaps if we're able to resolve some of its core issues (with break/continue/etc) and simplify it, it may have a chance. And, considering that this single proposal is powerful enough to potentially replace two other proposals, it may be to our advantage to really give this proposal another chance.
The do-block proposal can be simulated by providing a built-in identity function that will simply call the expression-block passed into it.
// The do-block proposal
const result = do {
let x = Math.random()
x * x
}
// This proposal, with a built-in identity function called "run".
const result = run {
let x = Math.random()
x * x
}
Earlier versions of the resource-management proposal let you create a block using with, and allocate a resource for the duration of that block, like this:
with (const connection = openDbConnection()) {
connection.createUser(username)
}
If we provide a built-in withResource() function that operates on an object that implemented a particular protocol, we could get similar results:
withResource (openDbConnection()) do (connection) {
...
}
They also had the ability to do resource-management logic with declarations, because it was a little more powerful this way (you could reuse the existing block), then later decided to drop the with syntax altogether to simplify things. While we can't simulate the declaration version of this proposal, we can still provide the with version, and that could be good enough to make it so we don't need the resource-management proposal at all.
How does this proposal relate to the do block and explicit resource management proposals? I'm noticing that the basic functionality of both of these proposals can trivially be implemented with this proposal. I know this proposal has had a bit of a rocky start (as stated in #35), but perhaps if we're able to resolve some of its core issues (with break/continue/etc) and simplify it, it may have a chance. And, considering that this single proposal is powerful enough to potentially replace two other proposals, it may be to our advantage to really give this proposal another chance.
The do-block proposal can be simulated by providing a built-in identity function that will simply call the expression-block passed into it.
Earlier versions of the resource-management proposal let you create a block using
with
, and allocate a resource for the duration of that block, like this:If we provide a built-in withResource() function that operates on an object that implemented a particular protocol, we could get similar results:
They also had the ability to do resource-management logic with declarations, because it was a little more powerful this way (you could reuse the existing block), then later decided to drop the
with
syntax altogether to simplify things. While we can't simulate the declaration version of this proposal, we can still provide thewith
version, and that could be good enough to make it so we don't need the resource-management proposal at all.