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: Allow loop to take parameters #6

Open
porky11 opened this issue Oct 24, 2022 · 0 comments
Open

Idea: Allow loop to take parameters #6

porky11 opened this issue Oct 24, 2022 · 0 comments

Comments

@porky11
Copy link

porky11 commented Oct 24, 2022

Blocks will take parameters, for example by specifying them using with before them.

For example now a factorial would look like this:

fn factorial(x: i32)
{
    var result: i32 = 1;
    var i = x;

    {
        if i == 0
            goto return;
        result = result * i;
        i = i - 1
        loop;
    }
    
    return: result
}

When loop takes parameters, it could look like this:

fn factorial(x: i32)
{
    with result: i32 = 1, i = x;
    {
        if i == 0
            goto return;
        loop result * i, i - 1;
    }
    
    return: result
}

(I don't think, these with-parameters should be exposed after the loop, but if return parameters are not exposed, but then we would need other features like #3 to make it useful)

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

1 participant