Permalink
Browse files

std: Camel case list

  • Loading branch information...
brson committed Sep 4, 2012
1 parent d3e75ea commit 3764fe3f2a7d04d99d7c69137b7a7724a6546bcb
View
@@ -24,7 +24,7 @@
export Arena, arena_with_size;
-use list::{list, cons, nil};
+use list::{List, Cons, Nil};
use unsafe::reinterpret_cast;
use sys::TypeDesc;
use libc::size_t;
@@ -53,7 +53,7 @@ struct Arena {
// access the head.
priv mut head: Chunk;
priv mut pod_head: Chunk;
- priv mut chunks: @list<Chunk>;
+ priv mut chunks: @List<Chunk>;
drop {
unsafe {
destroy_chunk(self.head);
@@ -73,7 +73,7 @@ fn chunk(size: uint, is_pod: bool) -> Chunk {
fn arena_with_size(initial_size: uint) -> Arena {
return Arena {mut head: chunk(initial_size, false),
mut pod_head: chunk(initial_size, true),
- mut chunks: @nil};
+ mut chunks: @Nil};
}
fn Arena() -> Arena {
@@ -134,7 +134,7 @@ impl &Arena {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.pod_head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
- self.chunks = @cons(copy self.pod_head, self.chunks);
+ self.chunks = @Cons(copy self.pod_head, self.chunks);
self.pod_head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -176,7 +176,7 @@ impl &Arena {
// Allocate a new chunk.
let chunk_size = at_vec::capacity(self.head.data);
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
- self.chunks = @cons(copy self.head, self.chunks);
+ self.chunks = @Cons(copy self.head, self.chunks);
self.head =
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
View
@@ -7,14 +7,14 @@ use core::option;
use option::*;
use option::{Some, None};
-enum list<T> {
- cons(T, @list<T>),
- nil,
+enum List<T> {
+ Cons(T, @List<T>),
+ Nil,
}
-/// Create a list from a vector
-fn from_vec<T: copy>(v: &[T]) -> @list<T> {
- vec::foldr(v, @nil::<T>, |h, t| @cons(h, t))
+/// Cregate a list from a vector
+fn from_vec<T: copy>(v: &[T]) -> @List<T> {
+ vec::foldr(v, @Nil::<T>, |h, t| @Cons(h, t))
}
/**
@@ -30,7 +30,7 @@ fn from_vec<T: copy>(v: &[T]) -> @list<T> {
* * z - The initial value
* * f - The function to apply
*/
-fn foldl<T: copy, U>(+z: T, ls: @list<U>, f: fn((&T), (&U)) -> T) -> T {
+fn foldl<T: copy, U>(+z: T, ls: @List<U>, f: fn((&T), (&U)) -> T) -> T {
let mut accum: T = z;
do iter(ls) |elt| { accum = f(&accum, &elt);}
accum
@@ -43,71 +43,71 @@ fn foldl<T: copy, U>(+z: T, ls: @list<U>, f: fn((&T), (&U)) -> T) -> T {
* When function `f` returns true then an option containing the element
* is returned. If `f` matches no elements then none is returned.
*/
-fn find<T: copy>(ls: @list<T>, f: fn((&T)) -> bool) -> Option<T> {
+fn find<T: copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
let mut ls = ls;
loop {
ls = match *ls {
- cons(hd, tl) => {
+ Cons(hd, tl) => {
if f(&hd) { return Some(hd); }
tl
}
- nil => return None
+ Nil => return None
}
};
}
/// Returns true if a list contains an element with the given value
-fn has<T: copy Eq>(ls: @list<T>, +elt: T) -> bool {
+fn has<T: copy Eq>(ls: @List<T>, +elt: T) -> bool {
for each(ls) |e| {
if e == elt { return true; }
}
return false;
}
/// Returns true if the list is empty
-pure fn is_empty<T: copy>(ls: @list<T>) -> bool {
+pure fn is_empty<T: copy>(ls: @List<T>) -> bool {
match *ls {
- nil => true,
+ Nil => true,
_ => false
}
}
/// Returns true if the list is not empty
-pure fn is_not_empty<T: copy>(ls: @list<T>) -> bool {
+pure fn is_not_empty<T: copy>(ls: @List<T>) -> bool {
return !is_empty(ls);
}
/// Returns the length of a list
-fn len<T>(ls: @list<T>) -> uint {
+fn len<T>(ls: @List<T>) -> uint {
let mut count = 0u;
iter(ls, |_e| count += 1u);
count
}
/// Returns all but the first element of a list
-pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
+pure fn tail<T: copy>(ls: @List<T>) -> @List<T> {
match *ls {
- cons(_, tl) => return tl,
- nil => fail ~"list empty"
+ Cons(_, tl) => return tl,
+ Nil => fail ~"list empty"
}
}
/// Returns the first element of a list
-pure fn head<T: copy>(ls: @list<T>) -> T {
+pure fn head<T: copy>(ls: @List<T>) -> T {
match *ls {
- cons(hd, _) => hd,
+ Cons(hd, _) => hd,
// makes me sad
_ => fail ~"head invoked on empty list"
}
}
/// Appends one list to another
-pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
+pure fn append<T: copy>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l {
- nil => return m,
- cons(x, xs) => {
+ Nil => return m,
+ Cons(x, xs) => {
let rest = append(xs, m);
- return @cons(x, rest);
+ return @Cons(x, rest);
}
}
}
@@ -121,45 +121,45 @@ pure fn push<T: copy>(ll: &mut @list<T>, +vv: T) {
*/
/// Iterate over a list
-fn iter<T>(l: @list<T>, f: fn(T)) {
+fn iter<T>(l: @List<T>, f: fn(T)) {
let mut cur = l;
loop {
cur = match *cur {
- cons(hd, tl) => {
+ Cons(hd, tl) => {
f(hd);
tl
}
- nil => break
+ Nil => break
}
}
}
/// Iterate over a list
-fn each<T>(l: @list<T>, f: fn(T) -> bool) {
+fn each<T>(l: @List<T>, f: fn(T) -> bool) {
let mut cur = l;
loop {
cur = match *cur {
- cons(hd, tl) => {
+ Cons(hd, tl) => {
if !f(hd) { return; }
tl
}
- nil => break
+ Nil => break
}
}
}
-impl<T:Eq> list<T> : Eq {
- pure fn eq(&&other: list<T>) -> bool {
+impl<T:Eq> List<T> : Eq {
+ pure fn eq(&&other: List<T>) -> bool {
match self {
- cons(e0a, e1a) => {
+ Cons(e0a, e1a) => {
match other {
- cons(e0b, e1b) => e0a == e0b && e1a == e1b,
+ Cons(e0b, e1b) => e0a == e0b && e1a == e1b,
_ => false
}
}
- nil => {
+ Nil => {
match other {
- nil => true,
+ Nil => true,
_ => false
}
}
@@ -172,7 +172,7 @@ mod tests {
#[test]
fn test_is_empty() {
- let empty : @list::list<int> = from_vec(~[]);
+ let empty : @list::List<int> = from_vec(~[]);
let full1 = from_vec(~[1]);
let full2 = from_vec(~['r', 'u']);
@@ -200,15 +200,15 @@ mod tests {
#[test]
fn test_from_vec_empty() {
- let empty : @list::list<int> = from_vec(~[]);
- assert (empty == @list::nil::<int>);
+ let empty : @list::List<int> = from_vec(~[]);
+ assert (empty == @list::Nil::<int>);
}
#[test]
fn test_foldl() {
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
let l = from_vec(~[0, 1, 2, 3, 4]);
- let empty = @list::nil::<int>;
+ let empty = @list::Nil::<int>;
assert (list::foldl(0u, l, add) == 10u);
assert (list::foldl(0u, empty, add) == 0u);
}
@@ -233,15 +233,15 @@ mod tests {
fn test_find_fail() {
fn match_(_i: &int) -> bool { return false; }
let l = from_vec(~[0, 1, 2]);
- let empty = @list::nil::<int>;
+ let empty = @list::Nil::<int>;
assert (list::find(l, match_) == option::None::<int>);
assert (list::find(empty, match_) == option::None::<int>);
}
#[test]
fn test_has() {
let l = from_vec(~[5, 8, 6]);
- let empty = @list::nil::<int>;
+ let empty = @list::Nil::<int>;
assert (list::has(l, 5));
assert (!list::has(l, 7));
assert (list::has(l, 8));
@@ -251,7 +251,7 @@ mod tests {
#[test]
fn test_len() {
let l = from_vec(~[0, 1, 2]);
- let empty = @list::nil::<int>;
+ let empty = @list::Nil::<int>;
assert (list::len(l) == 3u);
assert (list::len(empty) == 0u);
}
View
@@ -61,7 +61,6 @@ mod comm;
mod bitv;
mod deque;
mod fun_treemap;
-#[allow(non_camel_case_types)] // XXX
mod list;
#[allow(non_camel_case_types)] // XXX
mod map;
@@ -223,7 +223,7 @@ use syntax::codemap::span;
use util::ppaux::{ty_to_str, region_to_str, explain_region};
use std::map::{int_hash, hashmap, set};
use std::list;
-use std::list::{list, cons, nil};
+use std::list::{List, Cons, Nil};
use result::{Result, Ok, Err};
use syntax::print::pprust;
use util::common::indenter;
@@ -59,7 +59,7 @@ use str::{connect, split_str};
use vec::pop;
use syntax::parse::token::ident_interner;
-use std::list::{cons, list, nil};
+use std::list::{Cons, List, Nil};
use std::map::{hashmap, int_hash, uint_hash};
use str_eq = str::eq;
@@ -19,7 +19,7 @@
use std::map::hashmap;
use std::list;
-use std::list::{list, cons, nil};
+use std::list::{List, Cons, Nil};
use driver::session::session;
use metadata::csearch;
use syntax::ast::*, syntax::ast_util, syntax::visit;
@@ -122,14 +122,14 @@ fn type_needs(cx: ctx, use: uint, ty: ty::t) {
// Optimization -- don't descend type if all params already have this use
for vec::each_mut(cx.uses) |u| {
if *u & use != use {
- type_needs_inner(cx, use, ty, @nil);
+ type_needs_inner(cx, use, ty, @Nil);
return;
}
}
}
fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
- enums_seen: @list<def_id>) {
+ enums_seen: @List<def_id>) {
do ty::maybe_walk_ty(ty) |ty| {
if ty::type_has_params(ty) {
match ty::get(ty).struct {
@@ -143,7 +143,7 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
| ty::ty_trait(_, _, _) => false,
ty::ty_enum(did, substs) => {
if option::is_none(list::find(enums_seen, |id| *id == did)) {
- let seen = @cons(did, enums_seen);
+ let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| {
let t = ty::subst(cx.ccx.tcx, &substs, aty);
@@ -64,7 +64,7 @@ use util::ppaux::{ty_to_str, tys_to_str, region_to_str,
bound_region_to_str, vstore_to_str};
use util::common::{indent, indenter};
use std::list;
-use list::{list, nil, cons};
+use list::{List, Nil, Cons};
export check_crate;
export infer;
@@ -157,15 +157,15 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
indirect_ret_ty: None,
purity: ast::pure_fn,
mut region_lb: region_bnd,
- in_scope_regions: @nil,
+ in_scope_regions: @Nil,
inh: blank_inherited(ccx),
ccx: ccx
}
}
// a list of mapping from in-scope-region-names ("isr") to the
// corresponding ty::region
-type isr_alist = @list<(ty::bound_region, ty::region)>;
+type isr_alist = @List<(ty::bound_region, ty::region)>;
trait get_and_find_region {
fn get(br: ty::bound_region) -> ty::region;
@@ -225,7 +225,7 @@ fn check_fn(ccx: @crate_ctxt,
// the node_id of the body block.
let {isr, self_info, fn_ty} = {
- let old_isr = option::map_default(old_fcx, @nil,
+ let old_isr = option::map_default(old_fcx, @Nil,
|fcx| fcx.in_scope_regions);
replace_bound_regions_in_fn_ty(tcx, old_isr, self_info, fn_ty,
|br| ty::re_free(body.node.id, br))
@@ -917,7 +917,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
match structure_of(fcx, sp, in_fty) {
ty::ty_fn(ref fn_ty) => {
replace_bound_regions_in_fn_ty(
- fcx.ccx.tcx, @nil, None, fn_ty,
+ fcx.ccx.tcx, @Nil, None, fn_ty,
|_br| fcx.infcx().next_region_var(sp,
call_expr_id)).fn_ty
}
@@ -1237,7 +1237,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
Some(ty::ty_fn(ref fn_ty)) => {
let {fn_ty, _} =
replace_bound_regions_in_fn_ty(
- tcx, @nil, None, fn_ty,
+ tcx, @Nil, None, fn_ty,
|br| ty::re_bound(ty::br_cap_avoid(expr.id, @br)));
(Some({inputs:fn_ty.inputs,
output:fn_ty.output}),
Oops, something went wrong.

0 comments on commit 3764fe3

Please sign in to comment.