Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Idea] with blocks instead of defer #10

Open
Weltspear opened this issue Jul 28, 2022 · 6 comments
Open

[Idea] with blocks instead of defer #10

Weltspear opened this issue Jul 28, 2022 · 6 comments

Comments

@Weltspear
Copy link
Contributor

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();
}
@mustafaquraish
Copy link
Owner

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.

@Weltspear
Copy link
Contributor Author

Weltspear commented Jul 29, 2022

Instead of doing nested blocks we can do something like this:

with let a = ..., let b = ... {
    ...
}

@mustafaquraish
Copy link
Owner

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.

@Weltspear
Copy link
Contributor Author

Okay

@Weltspear
Copy link
Contributor Author

We can implement those as syntatic sugar to defer basically. Does defer support multiple defers per block?

@mustafaquraish
Copy link
Owner

We can implement those as syntatic sugar to defer basically. Does defer support multiple defers per block?

Yep, you can have multiple defers in a block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants