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 the standard library than in the core.
(Context: Common Lisp's rotatef is a generalization of swap
implemented simply as a macro.
http://www.lispworks.com/documentation/HyperSpec/Body/m_rotate.htm )
In this case, I'm afraid I meant 'primitive' in the more-primitive sense
than you'd be able to implement via syntax extension; the issue has to
do with whether you're dealing with copy-semantics or move-semantics.
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.
(Here I'm getting into territory we haven't even fully sketched yet, are
still discussing on IRC and in person, so please forgive me if it sounds
very unexpected! We haven't implemented any of the planned
move-semantics stuff yet at all.)
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev