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.
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
