Skip to content

De and fn #10563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/po/ja/tutorial-tasks.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
Expand Down
8 changes: 4 additions & 4 deletions doc/po/ja/tutorial.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -3509,13 +3509,13 @@ msgstr "## 所有クロージャ"
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
"particularly for spawning [tasks][tasks]."
msgstr ""
"`~` ポインタ型と同様に `~fn` 型 で書き表される所有クロージャは安全にプロセス"
"`~` `proc` で書き表される所有クロージャは安全にプロセス"
"間で送信することができます。所有クローじゃはマネージドクロージャと全く同じよ"
"うに閉じ込める値をコピーしますが、値を所有します。つまり、他のコードは閉じ込"
"められた値にアクセスできなくなります。所有クロージャは並列プログラム、特に "
Expand Down Expand Up @@ -3666,11 +3666,11 @@ msgstr ""
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""
"`task::spawn` 関数を用いてタスクを生成する場合、 `do` を用いると便利です。"
"`spawn` は、 `spawn(fn: ~fn())` という方を持っています。言い換えると、"
"`spawn` は、 `spawn(fn: proc())` という方を持っています。言い換えると、"
"`spawn` は「引数をとらない所有クロージャ」を引数としてとる関数ということで"
"す。"

Expand Down
2 changes: 1 addition & 1 deletion doc/po/tutorial-tasks.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial-tasks.md:102
msgid ""
"The `spawn` function has a very simple type signature: `fn spawn(f: ~fn())`. "
"The `spawn` function has a very simple type signature: `fn spawn(f: proc())`. "
"Because it accepts only owned closures, and owned closures contain only "
"owned data, `spawn` can safely move the entire closure and all its "
"associated state into an entirely different task for execution. Like any "
Expand Down
4 changes: 2 additions & 2 deletions doc/po/tutorial.md.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ msgstr ""
#. type: Plain text
#: doc/tutorial.md:1510
msgid ""
"Owned closures, written `~fn` in analogy to the `~` pointer type, hold on to "
"Owned closures, written `proc`, hold on to "
"things that can safely be sent between processes. They copy the values they "
"close over, much like managed closures, but they also own them: that is, no "
"other code can access them. Owned closures are used in concurrent code, "
Expand Down Expand Up @@ -2808,7 +2808,7 @@ msgstr ""
#: doc/tutorial.md:1582
msgid ""
"`do` is a convenient way to create tasks with the `task::spawn` function. "
"`spawn` has the signature `spawn(fn: ~fn())`. In other words, it is a "
"`spawn` has the signature `spawn(fn: proc())`. In other words, it is a "
"function that takes an owned closure that takes no arguments."
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _owned types_. The language leaves the implementation details to the standard
library.

The `spawn` function has a very simple type signature: `fn spawn(f:
~fn())`. Because it accepts only owned closures, and owned closures
proc())`. Because it accepts only owned closures, and owned closures
contain only owned data, `spawn` can safely move the entire closure
and all its associated state into an entirely different task for
execution. Like any closure, the function passed to `spawn` may capture
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ pervasively in Rust code.

## Owned closures

Owned closures, written `~fn` in analogy to the `~` pointer type,
Owned closures, written `proc`,
hold on to things that can safely be sent between
processes. They copy the values they close over, much like managed
closures, but they also own them: that is, no other code can access
Expand Down Expand Up @@ -1484,7 +1484,7 @@ parentheses, where it looks more like a typical block of
code.

`do` is a convenient way to create tasks with the `task::spawn`
function. `spawn` has the signature `spawn(fn: ~fn())`. In other
function. `spawn` has the signature `spawn(fn: proc())`. In other
words, it is a function that takes an owned closure that takes no
arguments.

Expand Down
24 changes: 11 additions & 13 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<T:Send> MutexArc<T> {
* blocked on the mutex) will also fail immediately.
*/
#[inline]
pub unsafe fn unsafe_access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
pub unsafe fn unsafe_access<U>(&self, blk: |x: &mut T| -> U) -> U {
let state = self.x.get();
// Borrowck would complain about this if the function were
// not already unsafe. See borrow_rwlock, far below.
Expand All @@ -234,8 +234,7 @@ impl<T:Send> MutexArc<T> {
/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
#[inline]
pub unsafe fn unsafe_access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
blk: |x: &mut T, c: &Condvar| -> U)
-> U {
let state = self.x.get();
do (&(*state).lock).lock_cond |cond| {
Expand Down Expand Up @@ -284,15 +283,14 @@ impl<T:Freeze + Send> MutexArc<T> {
* unsafe_access_cond.
*/
#[inline]
pub fn access<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
pub fn access<U>(&self, blk: |x: &mut T| -> U) -> U {
unsafe { self.unsafe_access(blk) }
}

/// As unsafe_access_cond but safe and Freeze.
#[inline]
pub fn access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
blk: |x: &mut T, c: &Condvar| -> U)
-> U {
unsafe { self.unsafe_access_cond(blk) }
}
Expand Down Expand Up @@ -389,7 +387,7 @@ impl<T:Freeze + Send> RWArc<T> {
* poison the Arc, so subsequent readers and writers will both also fail.
*/
#[inline]
pub fn write<U>(&self, blk: &fn(x: &mut T) -> U) -> U {
pub fn write<U>(&self, blk: |x: &mut T| -> U) -> U {
unsafe {
let state = self.x.get();
do (*borrow_rwlock(state)).write {
Expand All @@ -403,7 +401,7 @@ impl<T:Freeze + Send> RWArc<T> {
/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline]
pub fn write_cond<U>(&self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
blk: |x: &mut T, c: &Condvar| -> U)
-> U {
unsafe {
let state = self.x.get();
Expand All @@ -427,7 +425,7 @@ impl<T:Freeze + Send> RWArc<T> {
* Failing will unlock the Arc while unwinding. However, unlike all other
* access modes, this will not poison the Arc.
*/
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
unsafe {
let state = self.x.get();
do (*state).lock.read {
Expand Down Expand Up @@ -457,7 +455,7 @@ impl<T:Freeze + Send> RWArc<T> {
* }
* ```
*/
pub fn write_downgrade<U>(&self, blk: &fn(v: RWWriteMode<T>) -> U) -> U {
pub fn write_downgrade<U>(&self, blk: |v: RWWriteMode<T>| -> U) -> U {
unsafe {
let state = self.x.get();
do (*borrow_rwlock(state)).write_downgrade |write_mode| {
Expand Down Expand Up @@ -539,7 +537,7 @@ pub struct RWReadMode<'self, T> {

impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
/// Access the pre-downgrade RWArc in write mode.
pub fn write<U>(&mut self, blk: &fn(x: &mut T) -> U) -> U {
pub fn write<U>(&mut self, blk: |x: &mut T| -> U) -> U {
match *self {
RWWriteMode {
data: &ref mut data,
Expand All @@ -555,7 +553,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {

/// Access the pre-downgrade RWArc in write mode with a condvar.
pub fn write_cond<U>(&mut self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
blk: |x: &mut T, c: &Condvar| -> U)
-> U {
match *self {
RWWriteMode {
Expand All @@ -580,7 +578,7 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {

impl<'self, T:Freeze + Send> RWReadMode<'self, T> {
/// Access the post-downgrade rwlock in read mode.
pub fn read<U>(&self, blk: &fn(x: &T) -> U) -> U {
pub fn read<U>(&self, blk: |x: &T| -> U) -> U {
match *self {
RWReadMode {
data: data,
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Arena {
}

#[inline]
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
unsafe {
let tydesc = get_tydesc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Arena {
}

#[inline]
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
fn alloc_nonpod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
unsafe {
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
Expand All @@ -263,7 +263,7 @@ impl Arena {

// The external interface
#[inline]
pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T {
unsafe {
// XXX: Borrow check
let this = transmute_mut(self);
Expand Down
24 changes: 12 additions & 12 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl SmallBitv {
pub fn bits_op(&mut self,
right_bits: uint,
nbits: uint,
f: &fn(uint, uint) -> uint)
f: |uint, uint| -> uint)
-> bool {
let mask = small_mask(nbits);
let old_b: uint = self.bits;
Expand Down Expand Up @@ -140,7 +140,7 @@ impl BigBitv {
pub fn process(&mut self,
b: &BigBitv,
nbits: uint,
op: &fn(uint, uint) -> uint)
op: |uint, uint| -> uint)
-> bool {
let len = b.storage.len();
assert_eq!(self.storage.len(), len);
Expand All @@ -161,7 +161,7 @@ impl BigBitv {
}

#[inline]
pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
pub fn each_storage(&mut self, op: |v: &mut uint| -> bool) -> bool {
self.storage.mut_iter().advance(|elt| op(elt))
}

Expand Down Expand Up @@ -512,7 +512,7 @@ impl Bitv {
true
}

pub fn ones(&self, f: &fn(uint) -> bool) -> bool {
pub fn ones(&self, f: |uint| -> bool) -> bool {
range(0u, self.nbits).advance(|i| !self.get(i) || f(i))
}

Expand Down Expand Up @@ -542,7 +542,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv {
* Create a `Bitv` of the specified length where the value at each
* index is `f(index)`.
*/
pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv {
pub fn from_fn(len: uint, f: |index: uint| -> bool) -> Bitv {
let mut bitv = Bitv::new(len, false);
for i in range(0u, len) {
bitv.set(i, f(i));
Expand All @@ -557,7 +557,7 @@ impl ops::Index<uint,bool> for Bitv {
}

#[inline]
fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
if bits == 0 {
return true;
}
Expand Down Expand Up @@ -675,7 +675,7 @@ impl BitvSet {
}

#[inline]
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
fn other_op(&mut self, other: &BitvSet, f: |uint, uint| -> uint) {
fn nbits(mut w: uint) -> uint {
let mut bits = 0;
for _ in range(0u, uint::bits) {
Expand Down Expand Up @@ -722,7 +722,7 @@ impl BitvSet {
BitvSetIterator {set: self, next_idx: 0}
}

pub fn difference(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
pub fn difference(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 & !w2, |b| f(&b)) {
return false
Expand All @@ -734,8 +734,8 @@ impl BitvSet {
)
}

pub fn symmetric_difference(&self, other: &BitvSet,
f: &fn(&uint) -> bool) -> bool {
pub fn symmetric_difference(&self, other: &BitvSet, f: |&uint| -> bool)
-> bool {
for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 ^ w2, |b| f(&b)) {
return false
Expand All @@ -744,11 +744,11 @@ impl BitvSet {
self.outlier_iter(other).advance(|(_, i, w)| iterate_bits(i, w, |b| f(&b)))
}

pub fn intersection(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
pub fn intersection(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
self.common_iter(other).advance(|(i, w1, w2)| iterate_bits(i, w1 & w2, |b| f(&b)))
}

pub fn union(&self, other: &BitvSet, f: &fn(&uint) -> bool) -> bool {
pub fn union(&self, other: &BitvSet, f: |&uint| -> bool) -> bool {
for (i, w1, w2) in self.common_iter(other) {
if !iterate_bits(i, w1 | w2, |b| f(&b)) {
return false
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl<T> DList<T> {
/// or at the end.
///
/// O(N)
pub fn insert_when(&mut self, elt: T, f: &fn(&T, &T) -> bool) {
pub fn insert_when(&mut self, elt: T, f: |&T, &T| -> bool) {
{
let mut it = self.mut_iter();
loop {
Expand All @@ -339,7 +339,7 @@ impl<T> DList<T> {
/// put `a` in the result if `f(a, b)` is true, else `b`.
///
/// O(max(N, M))
pub fn merge(&mut self, mut other: DList<T>, f: &fn(&T, &T) -> bool) {
pub fn merge(&mut self, mut other: DList<T>, f: |&T, &T| -> bool) {
{
let mut it = self.mut_iter();
loop {
Expand Down
Loading