Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Florian Weimer
* austin seipp: > On Mon, Feb 28, 2011 at 1:09 PM, Florian Weimer wrote: >> * Sebastian Sylvan: >> >>> I think that if Haskell allows it, it's unlikely to be an issue even for >>> purists. :-) >> >> Haskell has potential side effects at every pattern match, so it can >> hardly be used as a refere

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread David Herman
In my experience, trying to give universal definitions for terms like "pure" or "referentially transparent" that cut across multiple programming languages is near impossible to do precisely, and devolves into philosophical "angels and pinheads" territory pretty quickly. Speaking of which, I thin

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread austin seipp
On Mon, Feb 28, 2011 at 1:09 PM, Florian Weimer wrote: > * Sebastian Sylvan: > >> I think that if Haskell allows it, it's unlikely to be an issue even for >> purists. :-) > > Haskell has potential side effects at every pattern match, so it can > hardly be used as a reference point for purity. > __

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Sebastian Sylvan
On Mon, Feb 28, 2011 at 7:09 PM, Florian Weimer wrote: > * Sebastian Sylvan: > > > I think that if Haskell allows it, it's unlikely to be an issue even for > > purists. :-) > > Haskell has potential side effects at every pattern match, so it can > hardly be used as a reference point for purity. >

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Florian Weimer
* Sebastian Sylvan: > I think that if Haskell allows it, it's unlikely to be an issue even for > purists. :-) Haskell has potential side effects at every pattern match, so it can hardly be used as a reference point for purity. ___ Rust-dev mailing list

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Sebastian Sylvan
On Mon, Feb 28, 2011 at 2:32 PM, Graydon Hoare wrote: > > A word on *that* concept might be in order: at the moment our effect system > considers a function "pure" if it mutates local variables. Depending on your > opinion, this might be fudging the notion of "purity" or might be capturing > its e

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Graydon Hoare
On 28/02/2011 12:41 AM, Peter Hull wrote: On Sun, Feb 27, 2011 at 10:19 PM, Graydon Hoare wrote: Yeah. You want vec[mutable int]. We'll probably wind up with a 'swap' primitive at some point down the line when unique ownership and move semantics are more thoroughly worked out. Thanks. To be mo

Re: [rust-dev] Swapping elements in a vec

2011-02-28 Thread Marijn Haverbeke
> A 'swap' primitive is, like 'move', able to skip the step of refcounting its > referent (and zero-checking, conditionally branching to drop glue). It knows > that the referent has exactly as many references before the swap (or move) > as after. Fair enough. Still, if swap can be implemented on t

Re: [rust-dev] Swapping elements in a vec

2011-02-27 Thread Graydon Hoare
On 27/02/2011 11:44 PM, Marijn Haverbeke wrote: We'll probably wind up with a 'swap' primitive at some point down the line when unique ownership and move semantics are more thoroughly worked out. This would be a great use case for syntactic extensions. Seems neater to do something like this in

Re: [rust-dev] Swapping elements in a vec

2011-02-27 Thread Marijn Haverbeke
> We'll probably wind up with a 'swap' > primitive at some point down the line when unique ownership and move > semantics are more thoroughly worked out. This would be a great use case for syntactic extensions. Seems neater to do something like this in the standard library than in the core. (Conte

Re: [rust-dev] Swapping elements in a vec

2011-02-27 Thread Graydon Hoare
On 27/02/2011 1:51 PM, Peter Hull 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. Yeah. You want vec[mutable int]. We'll pr

Re: [rust-dev] Swapping elements in a vec

2011-02-27 Thread Brian Anderson
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 wrote

[rust-dev] Swapping elements in a vec

2011-02-27 Thread Peter Hull
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 Chi