mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
std: Camel case list
This commit is contained in:
parent
d3e75ea375
commit
3764fe3f2a
@ -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);
|
||||
|
||||
|
@ -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,21 +43,21 @@ 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; }
|
||||
}
|
||||
@ -65,49 +65,49 @@ fn has<T: copy Eq>(ls: @list<T>, +elt: T) -> bool {
|
||||
}
|
||||
|
||||
/// 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,7 +233,7 @@ 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>);
|
||||
}
|
||||
@ -241,7 +241,7 @@ mod tests {
|
||||
#[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);
|
||||
}
|
||||
|
@ -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,7 +157,7 @@ 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
|
||||
}
|
||||
@ -165,7 +165,7 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
|
||||
|
||||
// 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}),
|
||||
|
@ -103,7 +103,7 @@ fn replace_bound_regions_in_fn_ty(
|
||||
ty::re_bound(br) => {
|
||||
match isr.find(br) {
|
||||
Some(_) => isr,
|
||||
None => @cons((br, to_r(br)), isr)
|
||||
None => @Cons((br, to_r(br)), isr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ use result::Result;
|
||||
use result::{Ok, Err};
|
||||
use std::map::{hashmap, uint_hash};
|
||||
use std::cell::{Cell, empty_cell};
|
||||
use std::list::{list, nil, cons};
|
||||
use std::list::{List, Nil, Cons};
|
||||
|
||||
use ty::{region, region_vid, hash_region};
|
||||
use region::is_subregion_of;
|
||||
|
@ -133,7 +133,7 @@ impl Sub: combine {
|
||||
// First, we instantiate each bound region in the subtype with a fresh
|
||||
// region variable.
|
||||
let {fn_ty: a_fn_ty, _} = {
|
||||
do replace_bound_regions_in_fn_ty(self.infcx.tcx, @nil,
|
||||
do replace_bound_regions_in_fn_ty(self.infcx.tcx, @Nil,
|
||||
None, a) |br| {
|
||||
// N.B.: The name of the bound region doesn't have
|
||||
// anything to do with the region variable that's created
|
||||
@ -153,7 +153,7 @@ impl Sub: combine {
|
||||
// Second, we instantiate each bound region in the supertype with a
|
||||
// fresh concrete region.
|
||||
let {fn_ty: b_fn_ty, _} = {
|
||||
do replace_bound_regions_in_fn_ty(self.infcx.tcx, @nil,
|
||||
do replace_bound_regions_in_fn_ty(self.infcx.tcx, @Nil,
|
||||
None, b) |br| {
|
||||
// FIXME: eventually re_skolemized (issue #2263)
|
||||
ty::re_bound(br)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std;
|
||||
|
||||
import std::list::{list, cons, nil};
|
||||
import std::list::{List, Cons, Nil};
|
||||
import std::time::precise_time_s;
|
||||
|
||||
fn main() {
|
||||
@ -25,7 +25,7 @@ fn run(repeat: int, depth: int) {
|
||||
}
|
||||
}
|
||||
|
||||
type nillist = list<()>;
|
||||
type nillist = List<()>;
|
||||
|
||||
// Filled with things that have to be unwound
|
||||
enum st {
|
||||
@ -56,13 +56,13 @@ fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||
let st = match st {
|
||||
None => {
|
||||
st_({
|
||||
box: @nil,
|
||||
unique: ~nil,
|
||||
fn_box: fn@() -> @nillist { @nil::<()> },
|
||||
fn_unique: fn~() -> ~nillist { ~nil::<()> },
|
||||
tuple: (@nil, ~nil),
|
||||
vec: ~[@nil],
|
||||
res: r(@nil)
|
||||
box: @Nil,
|
||||
unique: ~Nil,
|
||||
fn_box: fn@() -> @nillist { @Nil::<()> },
|
||||
fn_unique: fn~() -> ~nillist { ~Nil::<()> },
|
||||
tuple: (@Nil, ~Nil),
|
||||
vec: ~[@Nil],
|
||||
res: r(@Nil)
|
||||
})
|
||||
}
|
||||
Some(st) => {
|
||||
@ -70,14 +70,14 @@ fn recurse_or_fail(depth: int, st: Option<st>) {
|
||||
let fn_unique = st.fn_unique;
|
||||
|
||||
st_({
|
||||
box: @cons((), st.box),
|
||||
unique: ~cons((), @*st.unique),
|
||||
fn_box: fn@() -> @nillist { @cons((), fn_box()) },
|
||||
fn_unique: fn~() -> ~nillist { ~cons((), @*fn_unique()) },
|
||||
tuple: (@cons((), st.tuple.first()),
|
||||
~cons((), @*st.tuple.second())),
|
||||
vec: st.vec + ~[@cons((), st.vec.last())],
|
||||
res: r(@cons((), st.res._l))
|
||||
box: @Cons((), st.box),
|
||||
unique: ~Cons((), @*st.unique),
|
||||
fn_box: fn@() -> @nillist { @Cons((), fn_box()) },
|
||||
fn_unique: fn~() -> ~nillist { ~Cons((), @*fn_unique()) },
|
||||
tuple: (@Cons((), st.tuple.first()),
|
||||
~Cons((), @*st.tuple.second())),
|
||||
vec: st.vec + ~[@Cons((), st.vec.last())],
|
||||
res: r(@Cons((), st.res._l))
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ fn check_log<T>(exp: ~str, v: T) {
|
||||
|
||||
fn main() {
|
||||
let x = list::from_vec(~[a(22u), b(~"hi")]);
|
||||
let exp = ~"@cons(a(22), @cons(b(~\"hi\"), @nil))";
|
||||
let exp = ~"@Cons(a(22), @Cons(b(~\"hi\"), @Nil))";
|
||||
assert fmt!("%?", x) == exp;
|
||||
check_log(exp, x);
|
||||
}
|
||||
|
@ -2,21 +2,21 @@ use std;
|
||||
|
||||
import std::list::*;
|
||||
|
||||
pure fn pure_length_go<T: copy>(ls: @list<T>, acc: uint) -> uint {
|
||||
match *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
|
||||
pure fn pure_length_go<T: copy>(ls: @List<T>, acc: uint) -> uint {
|
||||
match *ls { nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
|
||||
}
|
||||
|
||||
pure fn pure_length<T: copy>(ls: @list<T>) -> uint { pure_length_go(ls, 0u) }
|
||||
pure fn pure_length<T: copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
|
||||
|
||||
pure fn nonempty_list<T: copy>(ls: @list<T>) -> bool { pure_length(ls) > 0u }
|
||||
pure fn nonempty_list<T: copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
||||
|
||||
fn safe_head<T: copy>(ls: @list<T>) -> T {
|
||||
fn safe_head<T: copy>(ls: @List<T>) -> T {
|
||||
assert is_not_empty(ls);
|
||||
return head(ls);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mylist = @cons(@1u, @nil);
|
||||
let mylist = @Cons(@1u, @Nil);
|
||||
assert (nonempty_list(mylist));
|
||||
assert (*safe_head(mylist) == 1u);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user