core: Make some functions pure

This commit is contained in:
Brian Anderson 2012-03-15 13:57:26 -07:00
parent 561511e628
commit 844fbd83da
12 changed files with 21 additions and 21 deletions

View file

@ -31,11 +31,11 @@ fn range(lo: i16, hi: i16, it: fn(i16)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: i16) -> i16 { pure fn compl(i: i16) -> i16 {
u16::compl(i as u16) as i16 u16::compl(i as u16) as i16
} }
#[doc = "Computes the absolute value"] #[doc = "Computes the absolute value"]
fn abs(i: i16) -> i16 { pure fn abs(i: i16) -> i16 {
if negative(i) { -i } else { i } if negative(i) { -i } else { i }
} }

View file

@ -31,11 +31,11 @@ fn range(lo: i32, hi: i32, it: fn(i32)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: i32) -> i32 { pure fn compl(i: i32) -> i32 {
u32::compl(i as u32) as i32 u32::compl(i as u32) as i32
} }
#[doc = "Computes the absolute value"] #[doc = "Computes the absolute value"]
fn abs(i: i32) -> i32 { pure fn abs(i: i32) -> i32 {
if negative(i) { -i } else { i } if negative(i) { -i } else { i }
} }

View file

@ -31,11 +31,11 @@ fn range(lo: i64, hi: i64, it: fn(i64)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: i64) -> i64 { pure fn compl(i: i64) -> i64 {
u64::compl(i as u64) as i64 u64::compl(i as u64) as i64
} }
#[doc = "Computes the absolute value"] #[doc = "Computes the absolute value"]
fn abs(i: i64) -> i64 { pure fn abs(i: i64) -> i64 {
if negative(i) { -i } else { i } if negative(i) { -i } else { i }
} }

View file

@ -31,11 +31,11 @@ fn range(lo: i8, hi: i8, it: fn(i8)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: i8) -> i8 { pure fn compl(i: i8) -> i8 {
u8::compl(i as u8) as i8 u8::compl(i as u8) as i8
} }
#[doc = "Computes the absolute value"] #[doc = "Computes the absolute value"]
fn abs(i: i8) -> i8 { pure fn abs(i: i8) -> i8 {
if negative(i) { -i } else { i } if negative(i) { -i } else { i }
} }

View file

@ -37,7 +37,7 @@ pure fn nonnegative(x: int) -> bool { ret x >= 0; }
// FIXME: Make sure this works with negative integers. // FIXME: Make sure this works with negative integers.
#[doc = "Produce a uint suitable for use in a hash table"] #[doc = "Produce a uint suitable for use in a hash table"]
fn hash(x: int) -> uint { ret x as uint; } pure fn hash(x: int) -> uint { ret x as uint; }
#[doc = "Iterate over the range `[lo..hi)`"] #[doc = "Iterate over the range `[lo..hi)`"]
fn range(lo: int, hi: int, it: fn(int)) { fn range(lo: int, hi: int, it: fn(int)) {
@ -107,7 +107,7 @@ fn pow(base: int, exponent: uint) -> int {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: int) -> int { pure fn compl(i: int) -> int {
uint::compl(i as uint) as int uint::compl(i as uint) as int
} }

View file

@ -15,7 +15,7 @@ Get the value out of a successful result
If the result is an error If the result is an error
"] "]
fn get<T: copy, U>(res: result<T, U>) -> T { pure fn get<T: copy, U>(res: result<T, U>) -> T {
alt res { alt res {
ok(t) { t } ok(t) { t }
err(_) { err(_) {
@ -33,7 +33,7 @@ Get the value out of an error result
If the result is not an error If the result is not an error
"] "]
fn get_err<T, U: copy>(res: result<T, U>) -> U { pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
alt res { alt res {
err(u) { u } err(u) { u }
ok(_) { ok(_) {

View file

@ -1,14 +1,14 @@
fn first<T:copy, U:copy>(pair: (T, U)) -> T { pure fn first<T:copy, U:copy>(pair: (T, U)) -> T {
let (t, _) = pair; let (t, _) = pair;
ret t; ret t;
} }
fn second<T:copy, U:copy>(pair: (T, U)) -> U { pure fn second<T:copy, U:copy>(pair: (T, U)) -> U {
let (_, u) = pair; let (_, u) = pair;
ret u; ret u;
} }
fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) { pure fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) {
let (t, u) = pair; let (t, u) = pair;
ret (u, t); ret (u, t);
} }

View file

@ -31,6 +31,6 @@ fn range(lo: u16, hi: u16, it: fn(u16)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: u16) -> u16 { pure fn compl(i: u16) -> u16 {
max_value ^ i max_value ^ i
} }

View file

@ -26,7 +26,7 @@ fn range(lo: u32, hi: u32, it: fn(u32)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: u32) -> u32 { pure fn compl(i: u32) -> u32 {
max_value ^ i max_value ^ i
} }

View file

@ -82,6 +82,6 @@ fn from_str(buf: str, radix: u64) -> option<u64> {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: u64) -> u64 { pure fn compl(i: u64) -> u64 {
max_value ^ i max_value ^ i
} }

View file

@ -28,7 +28,7 @@ fn range(lo: u8, hi: u8, it: fn(u8)) {
} }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: u8) -> u8 { pure fn compl(i: u8) -> u8 {
max_value ^ i max_value ^ i
} }

View file

@ -74,7 +74,7 @@ is either `x/y` or `x/y + 1`.
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; } pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
#[doc = "Produce a uint suitable for use in a hash table"] #[doc = "Produce a uint suitable for use in a hash table"]
fn hash(x: uint) -> uint { ret x; } pure fn hash(x: uint) -> uint { ret x; }
#[doc = "Iterate over the range [`lo`..`hi`)"] #[doc = "Iterate over the range [`lo`..`hi`)"]
#[inline(always)] #[inline(always)]
@ -188,7 +188,7 @@ fn to_str(num: uint, radix: uint) -> str {
fn str(i: uint) -> str { ret to_str(i, 10u); } fn str(i: uint) -> str { ret to_str(i, 10u); }
#[doc = "Computes the bitwise complement"] #[doc = "Computes the bitwise complement"]
fn compl(i: uint) -> uint { pure fn compl(i: uint) -> uint {
max_value ^ i max_value ^ i
} }