parent
d58a9c7346
commit
d8d35e7c40
@ -356,11 +356,10 @@ fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {
|
||||
}
|
||||
|
||||
fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) {
|
||||
let loc_pos =
|
||||
alt list::car(sc) {
|
||||
scope_block(_, _, pos) { pos }
|
||||
_ { @mutable 0u }
|
||||
};
|
||||
let loc_pos = alt list::head(sc) {
|
||||
scope_block(_, _, pos) { pos }
|
||||
_ { @mutable 0u }
|
||||
};
|
||||
alt d.node {
|
||||
decl_local(locs) {
|
||||
for (_, loc) in locs { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
|
||||
|
@ -105,20 +105,20 @@ fn len<T>(ls: list<T>) -> uint {
|
||||
}
|
||||
|
||||
/*
|
||||
Function: cdr
|
||||
Function: tail
|
||||
|
||||
Returns all but the first element of a list
|
||||
*/
|
||||
fn cdr<T>(ls: list<T>) -> list<T> {
|
||||
fn tail<T>(ls: list<T>) -> list<T> {
|
||||
alt ls { cons(_, tl) { ret *tl; } nil. { fail "list empty" } }
|
||||
}
|
||||
|
||||
/*
|
||||
Function: car
|
||||
Function: head
|
||||
|
||||
Returns the first element of a list
|
||||
*/
|
||||
fn car<T>(ls: list<T>) -> T {
|
||||
fn head<T>(ls: list<T>) -> T {
|
||||
alt ls { cons(hd, _) { ret hd; } nil. { fail "list empty" } }
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ pure fn nonempty_list<T>(ls: list<T>) -> bool { pure_length(ls) > 0u }
|
||||
// knowledge that ls is a cons node. Future work.
|
||||
// Also, this is pretty contrived since nonempty_list
|
||||
// could be a "tag refinement", if we implement those.
|
||||
fn safe_head<T>(ls: list<T>) : nonempty_list(ls) -> T { car(ls) }
|
||||
fn safe_head<T>(ls: list<T>) : nonempty_list(ls) -> T { head(ls) }
|
||||
|
||||
fn main() {
|
||||
let mylist = cons(@1u, @nil);
|
||||
|
@ -22,7 +22,7 @@ pure fn nonempty_list<T>(ls: list<T>) -> bool { pure_length(ls) > 0u }
|
||||
// knowledge that ls is a cons node. Future work.
|
||||
// Also, this is pretty contrived since nonempty_list
|
||||
// could be a "tag refinement", if we implement those.
|
||||
fn safe_head<T>(ls: list<T>) : nonempty_list(ls) -> T { car(ls) }
|
||||
fn safe_head<T>(ls: list<T>) : nonempty_list(ls) -> T { head(ls) }
|
||||
|
||||
fn main() {
|
||||
let mylist = cons(@1u, @nil);
|
||||
|
@ -1,25 +1,25 @@
|
||||
|
||||
use std;
|
||||
import std::list;
|
||||
import std::list::car;
|
||||
import std::list::cdr;
|
||||
import std::list::head;
|
||||
import std::list::tail;
|
||||
import std::list::from_vec;
|
||||
import std::option;
|
||||
|
||||
#[test]
|
||||
fn test_from_vec() {
|
||||
let l = from_vec([0, 1, 2]);
|
||||
assert (car(l) == 0);
|
||||
assert (car(cdr(l)) == 1);
|
||||
assert (car(cdr(cdr(l))) == 2);
|
||||
assert (head(l) == 0);
|
||||
assert (head(tail(l)) == 1);
|
||||
assert (head(tail(tail(l))) == 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_vec_mut() {
|
||||
let l = from_vec([mutable 0, 1, 2]);
|
||||
assert (car(l) == 0);
|
||||
assert (car(cdr(l)) == 1);
|
||||
assert (car(cdr(cdr(l))) == 2);
|
||||
assert (head(l) == 0);
|
||||
assert (head(tail(l)) == 1);
|
||||
assert (head(tail(tail(l))) == 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user