This works, but the "mutable 1" notation sure seems odd.
impure fn main() {
let vec[mutable int] a = vec(mutable 1,2,3);
let int t = a.(0);
a.(0) = a.(1);
a.(1) = t;
log a.(0);
log a.(1);
check (a.(0) == 2);
check (a.(1) == 1);
}
On Sun, Feb 27, 2011 at 4:51 PM, Peter Hull <[email protected]> wrote:
> Is it possible to swap elements in a vec? I tried
> let mutable vec[int] a = vec(1,2,3);
> let int t = a.(0);
> a.(0) = a.(1);
> a.(1) = t;
> but rustboot says (quite rightly I suppose) that int is not mutable.
>
> Pete
> ps. hope you're not too disappointed I stuck to ASCII for my
> identifiers, what's Chinese for 'a' anyway?!?
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev