[Idea] `with` blocks instead of `defer`
Maybe instead of using defer statements we can use with blocks:
struct A{
a: i32,
}
fn new_a(): A*{
...
}
method A::close(){
...
}
fn main(){
with let foo: A* = new_a(){
...
}
}
Which essentially means:
struct A{
a: i32,
}
fn new_a(): A*{
...
}
method A::close(){
...
}
fn main(){
let foo: A* = new_a();
...
foo::close();
}
I've considered this, but I'm not really sure how much I like the proposed idea. The problem for me is really that this forces everything to be indented one level, which I'm not a fan of. So, if I were to open 3 files at once, I would have 3 nested with blocks and code keeps moving to the right.
If you have any ideas on how we can avoid this, maybe there's another variation of this idea we can add.
Instead of doing nested blocks we can do something like this:
with let a = ..., let b = ... {
...
}
Instead of doing nested blocks we can do something like this:
Sounds reasonable. I have nothing against this, but I would prefer if we had these alongside defer instead of replacing it.
Okay
We can implement those as syntatic sugar to defer basically. Does defer support multiple defers per block?
We can implement those as syntatic sugar to
deferbasically. Doesdefersupport multipledefers per block?
Yep, you can have multiple defers in a block.