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

Make a gather/take construct #241

Open
masak opened this issue Aug 8, 2017 · 0 comments
Open

Make a gather/take construct #241

masak opened this issue Aug 8, 2017 · 0 comments

Comments

@masak
Copy link
Owner

masak commented Aug 8, 2017

I would be fine with having it be lexical rather than dynamic as in Perl 6. Lexical seems to rhyme better with what we can reasonably do with macros, and the dynamic part was never a dealbreaker anyway.

my values = gather {
    take 1;
    for [2, 3, 4] -> v {
        take v;
    }
}

Would desugar to something like

my _tmp_array;
_tmp_array.push(1);
for [2, 3, 4] -> v {
    _tmp_array.push(v);
}
my values = _tmp_array;

I also don't mind if the gather construct is not lazy, since we don't really have lazy lists/arrays in 007. The important thing is that everything works out nicely with a take finding its appropriate surrounding gather.

Note that there are bound to be some cases where a take is lexically inside the gather, but the `gather has completed already;

sub foo() {
    gather {
        take 1;
        return sub() { take 2 };
    }
}

foo()();    # ERROR: the `take 2` tried to take against a `gather` that has already finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant