-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
This proposal is an alternative to the rejected multiple expression values proposal (#83). It affects inline assembly improvements (#215). It depends on or at least is related to my comment in #346.
- Add ability for functions to have multiple return values.
fn div(numerator: i32, denominator: i32) -> i32, i32 {
return numerator / denominator, numerator % denominator;
}
- If you want an error, it's recommended to use a struct:
error DivByZero;
const DivResult = struct {quotient: i32, remainder: i32 };
fn div(numerator: i32, denominator: i32) -> %DivResult {
if (denominator == 0) return error.DivByZero;
return DivResult {
.quotient = numerator / denominator,
.remainder = numerator % denominator,
};
}
return
statements can have multiple return values:
fn foo(condition: bool) {
const x, const y = div(3, 1);
const a, const b = if (condition) {
return :this false, 1234;
} else {
return :this true, 5678;
};
}
This is not general-purpose tuples. This is multiple assignment and multiple return values.
Real Actual Use Case: https://github.com/zig-lang/zig/blob/cba4a9ad4a149766c650e3f3d71435cef14867a3/std/os/child_process.zig#L237-L246
moosichu, ethernetsellout, prajwalch, Karmylr, seandewar and 7 morewatzon, demizer, igotfr, prajwalch and matteobir12
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.