Multiple return values...

Timon Gehr timon.gehr at gmx.ch
Fri Mar 9 06:27:14 PST 2012


On 03/09/2012 01:23 AM, Manu wrote:
> I can imagine syntax using parentheses, but I don't think I'm qualified
> to propose a robust syntax, I don't know enough about the finer details
> of the grammar.
> Perhaps if other people agree with me, they could present some creative
> solutions to the syntax?
>
> I imagine something like:
> auto (x, y) = func(); // specify auto for all results?
> float (x, y) = func(); // specify explicit type for all results?
> (int x, float y) = func; // explicitly type each result?

This works, and Kenji Hara has already implemented appropriate parser 
extensions.

> int x; ... (x, float y) = func(); // assign to predeclared variable(/s)?
> (x, , z) = func(); // ignore the second result value (elimination of the
> second result's code path)
>

Those two would work, but (x,y) = func(); conflicts with the comma 
operator. (I'd prefer (,) to be a tuple constructor though.)



More information about the Digitalmars-d mailing list