(examples-for list-single-element ("returns nothing from an empty list" (list-single-element nil) nil) ("returns first item from a list with one item" (list-single-element '(x)) x) ("returns nothing from a list with more than one item" (list-single-element '(x y z)) nil)) (examples-for iso ("(nil) is not the same as nil" (iso '(nil) nil) nil)) (examples-for pair? (" t for a cons" (pair? '(1 a 2 b 3 c)) t) ("nil for a number" (pair? 1) nil) ("nil for a string" (pair? "werwe") nil) ("nil for a hash" (pair? {a 1 b 2}) nil) ("nil for a symbol" (pair? 'foo) nil)) (examples-for pairs ("'pair breaks a list into pairs" (pairs '(1 a 2 b 3 c)) ((1 a) (2 b) (3 c)))) (examples-for rev ("'rev reverses a list" (rev '(a b c)) (c b a)) ("'rev reverses a list, appending another list" (rev '(a b c) '(x y z)) (c b a x y z)) ("'rev reverses a list, appending an improper ending" (rev '(a b c) 'surprise) (c b a . surprise)) ("'rev handles nil" (rev nil) nil) ("'rev doesn't recurse" (rev '(a b (c d e) f g)) (g f (c d e) b a))) (examples-for flatten ("removes empty lists and nil" (flatten '(a b nil (c d () e nil) f ())) (a b c d e f)) ("returns a flat list of things" (flatten '((poo (x) (* x x)) (1 2 3))) (poo x * x x 1 2 3))) (examples-for joinlists ("joins one list to another" (joinlists '(a b c) '(x y z)) (a b c x y z)) ("joins three lists" (joinlists '(a b c) '(x y z) '(1 2 3)) (a b c x y z 1 2 3)) ("nil disappears" (apply joinlists '( (a b c) (d e f) nil (j k l) ) ) (a b c d e f j k l)) ("joins three lists without recursing" (joinlists '(a b c) '(x (y1 y2 y3) z) '(1 2 (3 3 3))) (a b c x (y1 y2 y3) z 1 2 (3 3 3)))) (examples-for firstn ("returns no items for n = 0" (firstn 0 '(a b c d)) nil) ("returns first n items for n > 0 and n < size of list" (firstn 3 '(a b c d e)) (a b c)) ("returns all items for n > size of list" (firstn 33 '(a b c d e)) (a b c d e))) (examples-for nthcdr ("returns all items for n = 0" (nthcdr 0 '(a b c d)) (a b c d)) ("returns nth cdr of list for n > 0 and n < size of list" (nthcdr 3 '(a b c d e)) (d e)) ("returns nothing for n = size of list" (nthcdr 5 '(a b c d e)) nil) ("returns nothing for n > size of list" (nthcdr 33 '(a b c d e)) nil)) (examples-for caar ("caar of list" (caar '((x y) (1 2))) x ) ("caar of nil" (caar nil) nil )) (examples-for cadr ("cadr of list" (cadr '((x y) (1 2))) (1 2) ) ("cadr of nil" (cadr nil) nil )) (examples-for cdar ("cdar of list" (cdar '((x y) (1 2))) (y) ) ("cdar of nil" (cdar nil) nil )) (examples-for cddr ("cddr of list" (cddr '(x y 1 2)) (1 2) ) ("cddr of nil" (cddr nil) nil )) (examples-for cadar ("cadar of list" (cadar '((x y) (1 2))) y ) ("cadar of nil" (cadar nil) nil )) (examples-for caddr ("caddr of list" (caddr '(x y 1 2)) 1 ) ("caddr of nil" (caddr nil) nil )) (examples-for cdddr ("cdddr of list" (cdddr '(x y 1 2)) (2) ) ("cdddr of nil" (cdddr nil) nil )) (examples-for cadddr ("cadddr of list" (cadddr '(x y 1 2 3)) 2 ) ("cadddr of nil" (cadddr nil) nil )) (examples-for proper? ("t for a proper list" (proper? '(a b c d)) t) ("t for a proper list, even if we write it funny" (proper? '(a b . (c d))) t) ("t for a proper list, even if we write it funny with nil" (proper? '(a b . nil)) t) ("nil for an improper list" (proper? '(a b . c)) nil) ("nil for a very improper list" (proper? '(a b . (c . d))) nil)) (examples-for list-slices ("just the list if small" (list-slices '(a b c d e) 12) ((a b c d e))) ("nothing but the list if the list is exactly the length of the page" (list-slices '(a b c) 3) ((a b c))) ("exactly three lists" (list-slices '(a b c d e f g h i) 3) ((a b c) (d e f) (g h i))) ("three lists and an extra big" (list-slices '(a b c d e f g h i j k) 3) ((a b c) (d e f) (g h i) (j k)))) (examples-for assoc ("finds nothing in an empty list" (assoc 'foo nil) nil) ("finds nothing in a non-list" (assoc 'foo 'bar) nil) ("finds nothing for nonexistent key" (assoc 'z '((a b) (c d))) nil) ("finds value corresponding to given key" (assoc 'c '((a b) (c d))) (c d))) (examples-for alref ("finds nothing in an empty list" (alref 'foo nil) nil) ("finds nothing for nonexistent key" (alref 'z '((a b) (c d))) nil) ("finds value corresponding to given key" (alref 'c '((a b) (c d))) d)) (examples-for list/fill ("returns an overfull list unchanged" (list/fill '(a b c) λ(just 'x) 2) (a b c)) ("returns a full list unchanged" (list/fill '(a b c) λ(just 'x) 3) (a b c)) ("returns an unfull list with extra items" (list/fill '(a b c) λ(just 'x) 4) (a b c x)) ("returns an unfull list with extra items" (let idx 0 (list/fill '(a b c) λ(++ idx) 10)) (a b c 1 2 3 4 5 6 7))) (examples-for list/index-of ("returns nil if thing is not found in an empty list" (list/index-of 5 '()) nil) ("returns nil if thing is not found" (list/index-of 5 '(1 2 3 4)) nil) ("returns 0 if thing is first in the list" (list/index-of 'a '(a b c d a b c d)) 0) ("returns 1 if thing is second in the list" (list/index-of 'b '(a b c d a b c d)) 1) ("returns 2 if thing is third in the list" (list/index-of 'c '(a b c d a b c d)) 2)) (examples-for list/around-thing ("returns nil,nil if item is not in the empty list" (list/around-thing 6 '()) (nil nil)) ("returns nil,nil if item is not in the list" (list/around-thing 6 '(1 2 3 4 5)) (nil nil)) ("returns nil,next if item is at the start of the list" (list/around-thing 1 '(1 2 3 4 5)) (nil 2)) ("returns prev,nil if item is at the end of the list" (list/around-thing 5 '(1 2 3 4 5)) (4 nil)) ("returns nil,nil if item is the only element of the list" (list/around-thing 42 '(42)) (nil nil)) ("returns prev,next if item is the second element of a longer list list" (list/around-thing 2 '(1 2 3 4 5)) (1 3)) ("returns prev,next if item is the second-last element of a longer list list" (list/around-thing 4 '(1 2 3 4 5)) (3 5)) ("returns prev,next if item is anywhere in the middle of a longer list list" (list/around-thing 3 '(1 2 3 4 5)) (2 4))) (examples-for list/around ("returns nil,nil if index is nil" (list/around nil '(a b c d e)) (nil nil)) ("returns nil,nil if index is nil and list is empty" (list/around nil '()) (nil nil)) ("returns nil,nil if index is negative" (list/around -1 '(a b c d e)) (nil nil)) ("returns nil,nil if index is negative and list is empty" (list/around -1 '()) (nil nil)) ("returns nil,nil if index is out of range" (list/around 10 '(a b c d e)) (nil nil)) ("returns nil,nil if index is out of range and list is empty" (list/around 10 '()) (nil nil)) ("returns nil,nil if index is even slightly out of range" (list/around 5 '(a b c d e)) (nil nil)) ("returns nil,next if index is zero" (list/around 0 '(a b c d e)) (nil b)) ("returns nil,nil if index is zero and list is empty" (list/around 0 '()) (nil nil)) ("returns nil,nil if index is one and list is empty" (list/around 1 '()) (nil nil)) ("returns prev,nil index is at the end of the list" (list/around 4 '(a b c d e)) (d nil)) ("returns nil,nil if index is 0 and list has only one item" (list/around 0 '(xxx)) (nil nil)) ("returns prev,next if index is 1" (list/around 1 '(a b c d e)) (a c)) ("returns prev,next if index corresponds to the second-last element of a longer list" (list/around 3 '(a b c d e)) (c e)) ("returns prev,next if index is anywhere in the middle of a longer list" (list/around 2 '(a b c d e)) (b d))) (examples-for list/last ("returns the thing if it's nil" (list/last nil) nil) ("returns the thing if it's not a pair" (list/last 42) 42) ("is not tricked when the last item is itself a list" (list/last '(1 2 3 (a b c))) (a b c)) ;; (1 2 3 . (a b c)) is equivalent to '(1 2 3 a b c) ("is not tricked by tricky syntax" (list/last '(1 2 3 . (a b c))) c) ("is not tricked when the last list-item is a list but there is also a last-cdr" (list/last '(1 2 3 (a b c) . foo)) foo) ("returns the cdr if it's not a pair" (list/last '(x . y)) y) ("returns the cdr if it's not a pair" (list/last '(x nil . y)) y) ("dot nil is not real" (list/last '(x q . nil)) q) ("returns the last item in the list" (list/last '(x y z)) z) ("returns nil if it's the last item in the list" (list/last '(x nil y z nil)) nil))