Unofficial wish list status.(Nov 2008)

Robert Fraser fraserofthenight at gmail.com
Mon Nov 3 08:42:49 PST 2008


downs wrote:
> Denis Koroskin wrote:
>> On Sat, 01 Nov 2008 19:33:01 +0300, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>>> Denis Koroskin wrote:
>>>> On Sat, 01 Nov 2008 19:04:16 +0300, Andrei Alexandrescu
>>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>>
>>>>> KennyTM~ wrote:
>>>>>> ore-sama wrote:
>>>>>>> 4tuu4k002 at sneakemail.com Wrote:
>>>>>>>
>>>>>>>> 105  Multiple return values (tuples (#28)
>>>>>>>> int, int getPoint();
>>>>>>>> int a,b;
>>>>>>>> a,b = getPoint();
>>>>>>> Provided we have lvalue array literals, this can fit to general
>>>>>>> array operations rules:
>>>>>>> int[] getPoint();
>>>>>>> int a,b;
>>>>>>> [a,b]=getPoint();
>>>>>>  int code;
>>>>>> string msg;
>>>>>>  [code, msg] = getError();
>>>>> Tuple!(int, "code", string, "msg") getError();
>>>>> auto e = getError;
>>>>>
>>>>>
>>>>> Andrei
>>>>  Imagine 'code' and 'msg' are already there as local variables and
>>>> you want to reuse them. How should you do this?
>>> I've been thinking of defining a simple function that binds to
>>> variable addresses and allows assignment from a tuple, in which case
>>> the code would be:
>>>
>>> group(&code, &msg) = getError;
>>>
>>> In "the future" we'll have variadic ref arguments, in which case the
>>> "&"s can be dropped:
>>>
>>> group(code, msg) = getError;
>>>
>>> Also in "the future" variable definitions will be expressions, in
>>> which case the code to define and assign code and msg becomes:
>>>
>>> group(int code, string msg) = getError;
>>>
>>>
>>> Andrei
>> Hmmm, this is almost as nice (inspired by jQuery):
>>
>> $(code, msg) = getError(); // :)
> 
> Sure.
> 
> $ is not an identifier, but this will work.
> 
> import tools.base;
> 
> alias ptuple _;
> 
> Stuple!(int, string) test() { return stuple(4, "foo"); }
> 
> void main() { int a; string b; _(a, b) = test(); }
> 
> :)

$(a, b);
_(a, b);

*has flashbacks to his days in the jungles of Perl*



More information about the Digitalmars-d mailing list