提交 d9bc3cb1 编写于 作者: T Tim Chevalier

Change "pred" to "pure fn" in all libraries and test cases

上级 1cb85015
pred is_whitespace(c: char) -> bool { pure fn is_whitespace(c: char) -> bool {
const ch_space: char = '\u0020'; const ch_space: char = '\u0020';
const ch_ogham_space_mark: char = '\u1680'; const ch_ogham_space_mark: char = '\u1680';
const ch_mongolian_vowel_sep: char = '\u180e'; const ch_mongolian_vowel_sep: char = '\u180e';
......
...@@ -73,12 +73,12 @@ fn is_ascii(s: &istr) -> bool { ...@@ -73,12 +73,12 @@ fn is_ascii(s: &istr) -> bool {
} }
/// Returns true if the string has length 0 /// Returns true if the string has length 0
pred is_empty(s: &istr) -> bool { pure fn is_empty(s: &istr) -> bool {
for c: u8 in s { ret false; } ret true; for c: u8 in s { ret false; } ret true;
} }
/// Returns true if the string has length greater than 0 /// Returns true if the string has length greater than 0
pred is_not_empty(s: &istr) -> bool { pure fn is_not_empty(s: &istr) -> bool {
!is_empty(s) !is_empty(s)
} }
......
...@@ -10,17 +10,17 @@ ...@@ -10,17 +10,17 @@
fn rem(x: uint, y: uint) -> uint { ret x % y; } fn rem(x: uint, y: uint) -> uint { ret x % y; }
pred lt(x: uint, y: uint) -> bool { ret x < y; } pure fn lt(x: uint, y: uint) -> bool { ret x < y; }
pred le(x: uint, y: uint) -> bool { ret x <= y; } pure fn le(x: uint, y: uint) -> bool { ret x <= y; }
pred eq(x: uint, y: uint) -> bool { ret x == y; } pure fn eq(x: uint, y: uint) -> bool { ret x == y; }
pred ne(x: uint, y: uint) -> bool { ret x != y; } pure fn ne(x: uint, y: uint) -> bool { ret x != y; }
pred ge(x: uint, y: uint) -> bool { ret x >= y; } pure fn ge(x: uint, y: uint) -> bool { ret x >= y; }
pred gt(x: uint, y: uint) -> bool { ret x > y; } pure fn gt(x: uint, y: uint) -> bool { ret x > y; }
fn max(x: uint, y: uint) -> uint { if x > y { ret x; } ret y; } fn max(x: uint, y: uint) -> uint { if x > y { ret x; } ret y; }
......
...@@ -77,13 +77,13 @@ fn from_mut<@T>(v: &[mutable T]) -> [T] { ...@@ -77,13 +77,13 @@ fn from_mut<@T>(v: &[mutable T]) -> [T] {
} }
// Predicates // Predicates
pred is_empty<T>(v: &[mutable? T]) -> bool { pure fn is_empty<T>(v: &[mutable? T]) -> bool {
// FIXME: This would be easier if we could just call len // FIXME: This would be easier if we could just call len
for t: T in v { ret false; } for t: T in v { ret false; }
ret true; ret true;
} }
pred is_not_empty<T>(v: &[mutable? T]) -> bool { ret !is_empty(v); } pure fn is_not_empty<T>(v: &[mutable? T]) -> bool { ret !is_empty(v); }
// Accessors // Accessors
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
type bubu = {x: int, y: int}; type bubu = {x: int, y: int};
pred less_than(x: int, y: int) -> bool { ret x < y; } pure fn less_than(x: int, y: int) -> bool { ret x < y; }
type ordered_range = {low: int, high: int} : less_than(low, high); type ordered_range = {low: int, high: int} : less_than(low, high);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
fn print_even(y: int) : even(y) { log y; } fn print_even(y: int) : even(y) { log y; }
pred even(y: int) -> bool { true } pure fn even(y: int) -> bool { true }
fn main() { fn main() {
let y: int = 42; let y: int = 42;
......
// error-pattern:Unsatisfied precondition constraint // error-pattern:Unsatisfied precondition constraint
pred even(x: uint) -> bool { pure fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
ret false; ret false;
} else if x == 2u { ret true; } else { ret even(x - 2u); } } else if x == 2u { ret true; } else { ret even(x - 2u); }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
fn g() { } fn g() { }
pred f(q: int) -> bool { g(); ret true; } pure fn f(q: int) -> bool { g(); ret true; }
fn main() { fn main() {
let x = 0; let x = 0;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// error-pattern: Constraint args must be // error-pattern: Constraint args must be
pred f(q: int) -> bool { ret true; } pure fn f(q: int) -> bool { ret true; }
fn main() { fn main() {
// should fail to typecheck, as pred args must be slot variables // should fail to typecheck, as pred args must be slot variables
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
fn f(a: int, b: int) : lt(a, b) { } fn f(a: int, b: int) : lt(a, b) { }
pred lt(a: int, b: int) -> bool { ret a < b; } pure fn lt(a: int, b: int) -> bool { ret a < b; }
fn main() { fn main() {
let a: int = 10; let a: int = 10;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
fn f(a: int, b: int) : lt(a, b) { } fn f(a: int, b: int) : lt(a, b) { }
pred lt(a: int, b: int) -> bool { ret a < b; } pure fn lt(a: int, b: int) -> bool { ret a < b; }
fn main() { fn main() {
let a: int = 10; let a: int = 10;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
fn f(a: int, b: int) : lt(a, b) { } fn f(a: int, b: int) : lt(a, b) { }
pred lt(a: int, b: int) -> bool { ret a < b; } pure fn lt(a: int, b: int) -> bool { ret a < b; }
fn main() { fn main() {
let a: int = 10; let a: int = 10;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
fn print_even(y: int) : even(y) { log y; } fn print_even(y: int) : even(y) { log y; }
pred even(y: int) -> bool { true } pure fn even(y: int) -> bool { true }
fn main() { fn main() {
......
// error-pattern:Number is odd // error-pattern:Number is odd
pred even(x: uint) -> bool { pure fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
ret false; ret false;
} else if x == 2u { ret true; } else { ret even(x - 2u); } } else if x == 2u { ret true; } else { ret even(x - 2u); }
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
// error-pattern:Predicate lt(b, a) failed // error-pattern:Predicate lt(b, a) failed
fn f(a: int, b: int) { } fn f(a: int, b: int) { }
pred lt(a: int, b: int) -> bool { ret a < b; } pure fn lt(a: int, b: int) -> bool { ret a < b; }
fn main() { let a: int = 10; let b: int = 23; check (lt(b, a)); f(b, a); } fn main() { let a: int = 10; let b: int = 23; check (lt(b, a)); f(b, a); }
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
import std::str::*; import std::str::*;
import std::uint::*; import std::uint::*;
pred fails(a: uint) -> bool { fail; } pure fn fails(a: uint) -> bool { fail; }
fn main() { let b: uint = 4u; claim (fails(b)); } fn main() { let b: uint = 4u; claim (fails(b)); }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
type bubu = {x: int, y: int}; type bubu = {x: int, y: int};
pred less_than(x: int, y: int) -> bool { ret x < y; } pure fn less_than(x: int, y: int) -> bool { ret x < y; }
type ordered_range = {low: int, high: int} : less_than(*.low, *.high); type ordered_range = {low: int, high: int} : less_than(*.low, *.high);
......
pred even(x: uint) -> bool { pure fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
ret false; ret false;
} else if x == 2u { ret true; } else { ret even(x - 2u); } } else if x == 2u { ret true; } else { ret even(x - 2u); }
......
pred even(x: uint) -> bool { pure fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
ret false; ret false;
} else if x == 2u { ret true; } else { ret even(x - 2u); } } else if x == 2u { ret true; } else { ret even(x - 2u); }
......
// -*- rust -*- // -*- rust -*-
pred f(q: int) -> bool { ret true; } pure fn f(q: int) -> bool { ret true; }
fn main() { let x = 0; check (f(x)); } fn main() { let x = 0; check (f(x)); }
// FIXME should be in run-pass
// -*- rust -*- // -*- rust -*-
// error-pattern: Non-boolean return type // error-pattern: Non-boolean return type
......
// -*- rust -*- // -*- rust -*-
fn f(a: int, b: int) { } fn f(a: int, b: int) { }
pred lt(a: int, b: int) -> bool { ret a < b; } pure fn lt(a: int, b: int) -> bool { ret a < b; }
fn main() { fn main() {
let a: int = 10; let a: int = 10;
......
pred p(i: int) -> bool { true } pure fn p(i: int) -> bool { true }
fn f(i: int) : p(i) -> int { i } fn f(i: int) : p(i) -> int { i }
......
...@@ -40,7 +40,7 @@ fn hammertime() -> int { ...@@ -40,7 +40,7 @@ fn hammertime() -> int {
} }
fn canttouchthis() -> uint { fn canttouchthis() -> uint {
pred p() -> bool { true } pure fn p() -> bool { true }
let _a = (assert (true)) == (check (p())); let _a = (assert (true)) == (check (p()));
let _c = (check (p())) == (); let _c = (check (p())) == ();
let _b = (log 0) == (ret 0u); let _b = (log 0) == (ret 0u);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
fn square_alias(n: &uint) -> uint { ret n * n; } fn square_alias(n: &uint) -> uint { ret n * n; }
pred is_three(n: &uint) -> bool { ret n == 3u; } pure fn is_three(n: &uint) -> bool { ret n == 3u; }
fn square_if_odd(n: &uint) -> option::t<uint> { fn square_if_odd(n: &uint) -> option::t<uint> {
ret if n % 2u == 1u { some(n * n) } else { none }; ret if n % 2u == 1u { some(n * n) } else { none };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册