Re-implemented last function so that it also supports iterators. Added a test to reflect this.

This commit is contained in:
Antony Woods 2015-04-07 10:30:52 +01:00
parent 0496b7f7b6
commit d1ed8f49d3
2 changed files with 3 additions and 1 deletions

View File

@ -245,7 +245,7 @@
(defn last [coll] (defn last [coll]
"Return last item from `coll`" "Return last item from `coll`"
(nth coll (- (len coll) 1))) (get (list coll) -1))
(defn list* [hd &rest tl] (defn list* [hd &rest tl]
"Return a dotted list construed from the elements of the argument" "Return a dotted list construed from the elements of the argument"

View File

@ -386,6 +386,8 @@
"NATIVE: testing the last function" "NATIVE: testing the last function"
(assert-equal (last [1 2 3 4]) 4) (assert-equal (last [1 2 3 4]) 4)
(assert-equal (last [5]) 5)) (assert-equal (last [5]) 5))
(import itertools)
(assert-equal (last (take 5 (itertools.count 10))) 14)
(defn test-neg [] (defn test-neg []
"NATIVE: testing the neg? function" "NATIVE: testing the neg? function"