Multiple return values...

Manu turkeyman at gmail.com
Fri Mar 9 00:55:19 PST 2012


On 9 March 2012 02:59, Mantis <mail.mantis.88 at gmail.com> wrote:

> 09.03.2012 2:23, Manu пишет:
>
>> On 9 March 2012 01:56, Mantis <mail.mantis.88 at gmail.com <mailto:
>> mail.mantis.88 at gmail.**com <mail.mantis.88 at gmail.com>>> wrote:
>>
>>    [...]
>>
>>    Is tuple required to be anonymous struct? I thought it's
>>    implementation details that may be done the other way if tuples
>>    implemented in language rather then library. There's another
>>    problem with non-named return values, as this:
>>    auto (sin_a, cos_a) = sincos( a );
>>    is not equivalent to this:
>>    auto (cos_a, sin_a) = sincos( a );
>>
>>
>> I can't imagine a syntax that's non-destructive to the existing grammar
>> where order is not important, but order would be clearly stated in the
>> auto-complete pop-up, and in the reference. Also mismatching types would
>> throw errors.
>>
>
> You can't mess with the parameters order in this case:
> http://dl.dropbox.com/u/**36715190/Images/par_order.jpg<http://dl.dropbox.com/u/36715190/Images/par_order.jpg>
> Is it impossible to make efficient multiple return values without the need
> to trade off the help from tools?
>

Eh? How so?

Visual studio show's the return value and function name in the same tooltip
(not just the argument list as your image shows). Tools may need to tweak
their popup if they don't present the return values already.
Also, tools can do the usual red-squiggly underline thing on return
assignments with mismatching result count or types easily.


On 9 March 2012 03:24, bearophile <bearophileHUGS at lycos.com> wrote:

> I understand. But in other languages tuples are used for such purpose, so
> there is some risk people will think of them as a third kind of tuples,
> despite they are a different thing.
>

I really don't think so. The only language I know of that behaves like you
say is lua (oh, and python?); scripting languages, not too interested with
ABI expression, and bear virtually no relation whatsoever to any c-like
language.
I think the comparison might be drawn to something more like Go. Octave
does it with an interesting syntax, but these are not compatible with D in
a non-breaking way.

What kind of syntax do you suggest?
>

I detailed my initial idea in my post prior to yours, but perhaps other
more interesting syntax might also exist:

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?
> int x; ... (x, float y) = func(); // assign to predeclared variable(/s)?
> (x, , z) = func(); // ignore the second result value, intuitive and
> visible (elimination of the second result's code path)
>
> I'm sure other more bizarre syntax could be possible too to help reduce
> bracket spam. Ideas from things like lambda syntax?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120309/c1fc052b/attachment.html>


More information about the Digitalmars-d mailing list