I was thinking something like struct Foo { x: int, y: int }
fn f(foo: &mut Foo) { (foo.x, foo.y) = g(); } (I actually get an ICE building this (with with appropriate g() and main()) using rustc 0.8 eb55348.) I kind of like this idea of letting arbitrary lvalues appear in the "variable" position in pattern syntax. But I don't know if it would turn out to be a can of worms. keegan ----- Original Message ----- From: "Matthew McPherrin" <mozi...@mcpherrin.ca> To: "Benjamin Striegel" <ben.strie...@gmail.com> Cc: rust-dev@mozilla.org Sent: Wednesday, September 25, 2013 12:10:29 PM Subject: Re: [rust-dev] Some suggestions of Rust language Maybe if you were writing code like this: let mut a = 1; let mut b = 2; loop { ... (a, b) = F(); ... } (b, a) On Wed, Sep 25, 2013 at 11:29 AM, Benjamin Striegel <ben.strie...@gmail.com> wrote: > 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 > > > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev > _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev