Is there a use case that necessitates such a feature? The following code
works today:

    let a = 1;
    let b = 2;
    let (a, b) = (b, a);

Not sure why that wouldn't be sufficient.


On Wed, Sep 25, 2013 at 2:50 PM, Marvin Löbel <loebel.mar...@gmail.com>wrote:

> On 09/25/2013 06:37 PM, Diggory Hardy wrote:
>
>> Hi,
>>
>> On Wednesday 25 September 2013 08:29:17 Patrick Walton wrote:
>>
>>> On 9/25/13 6:32 AM, Alexander Sun wrote:
>>>
>>>> Multiple return values
>>>> if has a function like this:
>>>>
>>>> fn addsub(x : int, y : int) -> (int, int) {
>>>>
>>>>         return (x+y,x-y);
>>>>
>>>> }
>>>>
>>>> them, this is valid:
>>>>
>>>> let (b,c) = addsub(x, y);
>>>>
>>>> but this is invalid;
>>>>
>>>> let b:int =0;
>>>> let c:int =0;
>>>> (b,c) = addsub(x, y);
>>>>
>>>> also invalid:
>>>>
>>>> let (b,c)  = (0, 0);
>>>> (b,c) = addsub(x, y);
>>>>
>>> If we did this, we wouldn't know whether to parse a pattern or an
>>> expression when starting a statement. This isn't fixable without trying
>>> to define some sort of cover grammar that covers both expressions and
>>> patterns, like ECMAScript 6 does. I don't know if this would work in
>>> Rust.
>>>
>> Are there any plans to support something like:
>>
>> assign (b,c) = addsub(x,y);
>>
>> for existing b,c? The best I could come up with is:
>>
>>      match two_nums(2) {
>>          (x,y) => {a=x;b=y;}
>>      }
>>
>> Not that I need this; just curious.
>>
> I had the idea once to reuse the `in` keyword for that:
>
> let mut a = 0; let mut b = 1;
> in (a, b) = (b, a);
>
> No idea how feasible that would be, though.
>
> ______________________________**_________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to