Skip to content

Commit 1e6151a

Browse files
committed
Renamed variables
1 parent 4c553af commit 1e6151a

File tree

1 file changed

+65
-67
lines changed

1 file changed

+65
-67
lines changed

src/libcollections/list.rs

Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
//! A standard, garbage-collected linked list.
1212
13-
14-
1513
#[deriving(Clone, Eq)]
1614
#[allow(missing_doc)]
1715
pub enum List<T> {
@@ -33,30 +31,30 @@ pub fn from_vec<T:Clone + 'static>(v: &[T]) -> @List<T> {
3331
*
3432
* # Arguments
3533
*
36-
* * ls - The list to fold
34+
* * list - The list to fold
3735
* * z - The initial value
3836
* * f - The function to apply
3937
*/
40-
pub fn foldl<T:Clone,U>(z: T, ls: @List<U>, f: |&T, &U| -> T) -> T {
38+
pub fn foldl<T:Clone,U>(z: T, list: @List<U>, f: |&T, &U| -> T) -> T {
4139
let mut accum: T = z;
42-
iter(ls, |elt| accum = f(&accum, elt));
40+
iter(list, |element| accum = f(&accum, element));
4341
accum
4442
}
4543

4644
/**
4745
* Search for an element that matches a given predicate
4846
*
49-
* Apply function `f` to each element of `ls`, starting from the first.
47+
* Apply function `f` to each element of `list`, starting from the first.
5048
* When function `f` returns true then an option containing the element
5149
* is returned. If `f` matches no elements then none is returned.
5250
*/
53-
pub fn find<T:Clone>(ls: @List<T>, f: |&T| -> bool) -> Option<T> {
54-
let mut ls = ls;
51+
pub fn find<T:Clone>(list: @List<T>, f: |&T| -> bool) -> Option<T> {
52+
let mut list = list;
5553
loop {
56-
ls = match *ls {
57-
Cons(ref hd, tl) => {
58-
if f(hd) { return Some((*hd).clone()); }
59-
tl
54+
list = match *list {
55+
Cons(ref head, tail) => {
56+
if f(head) { return Some((*head).clone()); }
57+
tail
6058
}
6159
Nil => return None
6260
}
@@ -66,71 +64,71 @@ pub fn find<T:Clone>(ls: @List<T>, f: |&T| -> bool) -> Option<T> {
6664
/**
6765
* Returns true if a list contains an element that matches a given predicate
6866
*
69-
* Apply function `f` to each element of `ls`, starting from the first.
67+
* Apply function `f` to each element of `list`, starting from the first.
7068
* When function `f` returns true then it also returns true. If `f` matches no
7169
* elements then false is returned.
7270
*/
73-
pub fn any<T>(ls: @List<T>, f: |&T| -> bool) -> bool {
74-
let mut ls = ls;
71+
pub fn any<T>(list: @List<T>, f: |&T| -> bool) -> bool {
72+
let mut list = list;
7573
loop {
76-
ls = match *ls {
77-
Cons(ref hd, tl) => {
78-
if f(hd) { return true; }
79-
tl
74+
list = match *list {
75+
Cons(ref head, tail) => {
76+
if f(head) { return true; }
77+
tail
8078
}
8179
Nil => return false
8280
}
8381
};
8482
}
8583

8684
/// Returns true if a list contains an element with the given value
87-
pub fn has<T:Eq>(ls: @List<T>, elt: T) -> bool {
85+
pub fn has<T:Eq>(list: @List<T>, element: T) -> bool {
8886
let mut found = false;
89-
each(ls, |e| {
90-
if *e == elt { found = true; false } else { true }
87+
each(list, |e| {
88+
if *e == element { found = true; false } else { true }
9189
});
9290
return found;
9391
}
9492

9593
/// Returns true if the list is empty
96-
pub fn is_empty<T>(ls: @List<T>) -> bool {
97-
match *ls {
94+
pub fn is_empty<T>(list: @List<T>) -> bool {
95+
match *list {
9896
Nil => true,
9997
_ => false
10098
}
10199
}
102100

103101
/// Returns the length of a list
104-
pub fn len<T>(ls: @List<T>) -> uint {
102+
pub fn len<T>(list: @List<T>) -> uint {
105103
let mut count = 0u;
106-
iter(ls, |_e| count += 1u);
104+
iter(list, |_e| count += 1u);
107105
count
108106
}
109107

110108
/// Returns all but the first element of a list
111-
pub fn tail<T>(ls: @List<T>) -> @List<T> {
112-
match *ls {
113-
Cons(_, tl) => return tl,
109+
pub fn tail<T>(list: @List<T>) -> @List<T> {
110+
match *list {
111+
Cons(_, tail) => return tail,
114112
Nil => fail!("list empty")
115113
}
116114
}
117115

118116
/// Returns the first element of a list
119-
pub fn head<T:Clone>(ls: @List<T>) -> T {
120-
match *ls {
121-
Cons(ref hd, _) => (*hd).clone(),
117+
pub fn head<T:Clone>(list: @List<T>) -> T {
118+
match *list {
119+
Cons(ref head, _) => (*head).clone(),
122120
// makes me sad
123121
_ => fail!("head invoked on empty list")
124122
}
125123
}
126124

127125
/// Appends one list to another
128-
pub fn append<T:Clone + 'static>(l: @List<T>, m: @List<T>) -> @List<T> {
129-
match *l {
130-
Nil => return m,
131-
Cons(ref x, xs) => {
132-
let rest = append(xs, m);
133-
return @Cons((*x).clone(), rest);
126+
pub fn append<T:Clone + 'static>(list: @List<T>, other: @List<T>) -> @List<T> {
127+
match *list {
128+
Nil => return other,
129+
Cons(ref head, tail) => {
130+
let rest = append(tail, other);
131+
return @Cons((*head).clone(), rest);
134132
}
135133
}
136134
}
@@ -144,27 +142,27 @@ fn push<T:Clone>(ll: &mut @list<T>, vv: T) {
144142
*/
145143

146144
/// Iterate over a list
147-
pub fn iter<T>(l: @List<T>, f: |&T|) {
148-
let mut cur = l;
145+
pub fn iter<T>(list: @List<T>, f: |&T|) {
146+
let mut cur = list;
149147
loop {
150148
cur = match *cur {
151-
Cons(ref hd, tl) => {
152-
f(hd);
153-
tl
149+
Cons(ref head, tail) => {
150+
f(head);
151+
tail
154152
}
155153
Nil => break
156154
}
157155
}
158156
}
159157

160158
/// Iterate over a list
161-
pub fn each<T>(l: @List<T>, f: |&T| -> bool) -> bool {
162-
let mut cur = l;
159+
pub fn each<T>(list: @List<T>, f: |&T| -> bool) -> bool {
160+
let mut cur = list;
163161
loop {
164162
cur = match *cur {
165-
Cons(ref hd, tl) => {
166-
if !f(hd) { return false; }
167-
tl
163+
Cons(ref head, tail) => {
164+
if !f(head) { return false; }
165+
tail
168166
}
169167
Nil => { return true; }
170168
}
@@ -191,11 +189,11 @@ mod tests {
191189

192190
#[test]
193191
fn test_from_vec() {
194-
let l = from_vec([0, 1, 2]);
192+
let list = from_vec([0, 1, 2]);
195193

196-
assert_eq!(head(l), 0);
194+
assert_eq!(head(list), 0);
197195

198-
let tail_l = tail(l);
196+
let tail_l = tail(list);
199197
assert_eq!(head(tail_l), 1);
200198

201199
let tail_tail_l = tail(tail_l);
@@ -211,9 +209,9 @@ mod tests {
211209
#[test]
212210
fn test_foldl() {
213211
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
214-
let l = from_vec([0, 1, 2, 3, 4]);
212+
let list = from_vec([0, 1, 2, 3, 4]);
215213
let empty = @list::Nil::<int>;
216-
assert_eq!(list::foldl(0u, l, add), 10u);
214+
assert_eq!(list::foldl(0u, list, add), 10u);
217215
assert_eq!(list::foldl(0u, empty, add), 0u);
218216
}
219217

@@ -222,50 +220,50 @@ mod tests {
222220
fn sub(a: &int, b: &int) -> int {
223221
*a - *b
224222
}
225-
let l = from_vec([1, 2, 3, 4]);
226-
assert_eq!(list::foldl(0, l, sub), -10);
223+
let list = from_vec([1, 2, 3, 4]);
224+
assert_eq!(list::foldl(0, list, sub), -10);
227225
}
228226

229227
#[test]
230228
fn test_find_success() {
231229
fn match_(i: &int) -> bool { return *i == 2; }
232-
let l = from_vec([0, 1, 2]);
233-
assert_eq!(list::find(l, match_), option::Some(2));
230+
let list = from_vec([0, 1, 2]);
231+
assert_eq!(list::find(list, match_), option::Some(2));
234232
}
235233

236234
#[test]
237235
fn test_find_fail() {
238236
fn match_(_i: &int) -> bool { return false; }
239-
let l = from_vec([0, 1, 2]);
237+
let list = from_vec([0, 1, 2]);
240238
let empty = @list::Nil::<int>;
241-
assert_eq!(list::find(l, match_), option::None::<int>);
239+
assert_eq!(list::find(list, match_), option::None::<int>);
242240
assert_eq!(list::find(empty, match_), option::None::<int>);
243241
}
244242

245243
#[test]
246244
fn test_any() {
247245
fn match_(i: &int) -> bool { return *i == 2; }
248-
let l = from_vec([0, 1, 2]);
246+
let list = from_vec([0, 1, 2]);
249247
let empty = @list::Nil::<int>;
250-
assert_eq!(list::any(l, match_), true);
248+
assert_eq!(list::any(list, match_), true);
251249
assert_eq!(list::any(empty, match_), false);
252250
}
253251

254252
#[test]
255253
fn test_has() {
256-
let l = from_vec([5, 8, 6]);
254+
let list = from_vec([5, 8, 6]);
257255
let empty = @list::Nil::<int>;
258-
assert!((list::has(l, 5)));
259-
assert!((!list::has(l, 7)));
260-
assert!((list::has(l, 8)));
256+
assert!((list::has(list, 5)));
257+
assert!((!list::has(list, 7)));
258+
assert!((list::has(list, 8)));
261259
assert!((!list::has(empty, 5)));
262260
}
263261

264262
#[test]
265263
fn test_len() {
266-
let l = from_vec([0, 1, 2]);
264+
let list = from_vec([0, 1, 2]);
267265
let empty = @list::Nil::<int>;
268-
assert_eq!(list::len(l), 3u);
266+
assert_eq!(list::len(list), 3u);
269267
assert_eq!(list::len(empty), 0u);
270268
}
271269

0 commit comments

Comments
 (0)