The stately := operator feature proposal

Byron Heads byron.heads at gmail.com
Fri May 31 05:54:14 PDT 2013


On Friday, 31 May 2013 at 00:50:56 UTC, bearophile wrote:
> Manu:
>
>> I've raised the topic of multiple-return-values a whole heap 
>> of times. It's
>> usually shot down because it would create ambiguities in 
>> existing syntax.
>
> Solving only that small problem is a bad idea. A language meant 
> to support some functional programming should be able to 
> support tuples well enough. Your problem is a special case of 
> tuple usage. Don't you agree?
>
> Bye,
> bearophile

The question is which is more optimal for the MRV style of 
programming

// here the compiler can decide the best way to return the two 
ints,
// probably in two registers, maybe even better for inlining
(int, int) positionMRV() { return 1, 2; }

// here the compiler is making a tuple and returning it may not 
be optimal
#(int, int) positionTuple() { return #(1, 2); } //assuming #() 
for tuples

I agree tuples cover more cases, but maybe hard to optimize for 
MRV.

a side note := could be use to extract tuples as well.

Would be nice if _ was not a valid identifier, could have been 
used it for value skipping:

x, _ := positionMRV(); // only care about x value, optimize away




More information about the Digitalmars-d mailing list