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

Language idea: Generators (yield fn, yield ret, yield break) #26

Open
alexrp opened this issue Feb 19, 2023 · 0 comments
Open

Language idea: Generators (yield fn, yield ret, yield break) #26

alexrp opened this issue Feb 19, 2023 · 0 comments
Assignees
Labels
area: language Issues related to the design of the language. state: approved Feature requests and housekeeping tasks that have been approved. type: feature Issues that are classified as feature requests.
Milestone

Comments

@alexrp
Copy link
Sponsor Member

alexrp commented Feb 19, 2023

The keyword is already reserved.

Something like:

yield fn range(x, y) {
    if y >= x {
        yield break;
    };
    let mut i = x;
    while i < y {
        yield ret i;
        i = i + 1;
    };
}
  • yield fns may use yield ret and yield break; normal fns may not.
  • yield fns must have at least one yield ret or yield break expression.
  • yield fns may not use raise expressions, normal ret expressions, and error-propagating calls.
  • yield fns do not have an implicit return value like normal fns.
  • yield fn is mutually exclusive with ext fn and err fn.
  • yield fn lambdas are supported.

The transformation into a state machine will happen when the module is loaded by the runtime. If a yield fn passes semantic analysis, it must be transformable.

This is tentatively approved for 2.0.

@alexrp alexrp added state: deliberation Issues that require considerable deliberation and/or discussion before a resolution can be found. type: feature Issues that are classified as feature requests. area: language Issues related to the design of the language. labels Feb 19, 2023
@alexrp alexrp added this to the v2.0 milestone Feb 19, 2023
@alexrp alexrp self-assigned this Feb 19, 2023
@alexrp alexrp changed the title Language idea: Generators (yield) Language idea: Generators (yield fn, yield ret, yield break) Feb 19, 2023
@alexrp alexrp added state: approved Feature requests and housekeeping tasks that have been approved. and removed state: deliberation Issues that require considerable deliberation and/or discussion before a resolution can be found. labels Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: language Issues related to the design of the language. state: approved Feature requests and housekeeping tasks that have been approved. type: feature Issues that are classified as feature requests.
Development

No branches or pull requests

1 participant