Added (last) function to core language
This commit is contained in:
parent
3d41630219
commit
cbd942fd02
@ -243,6 +243,10 @@
|
||||
"Return true if x is an iterator"
|
||||
(isinstance x collections.Iterator))
|
||||
|
||||
(defn last [coll]
|
||||
"Return last item from `coll`"
|
||||
(nth coll (- (len coll) 1)))
|
||||
|
||||
(defn list* [hd &rest tl]
|
||||
"Return a dotted list construed from the elements of the argument"
|
||||
(if (not tl)
|
||||
@ -416,7 +420,7 @@
|
||||
dec distinct disassemble drop drop-last drop-while empty? even?
|
||||
every? first filter filterfalse flatten float? gensym identity
|
||||
inc input instance? integer integer? integer-char? interleave
|
||||
interpose iterable? iterate iterator? keyword keyword? list*
|
||||
interpose iterable? iterate iterator? keyword keyword? last list*
|
||||
macroexpand macroexpand-1 map merge-with name neg? nil? none?
|
||||
nth numeric? odd? pos? range read remove repeat repeatedly
|
||||
rest reduce second some string string? symbol? take take-nth
|
||||
|
@ -382,6 +382,11 @@
|
||||
;; should not work for an int
|
||||
(assert-false (iterator? 5)))
|
||||
|
||||
(defn test-last []
|
||||
"NATIVE: testing the last function"
|
||||
(assert-equal (last [1 2 3 4]) 4)
|
||||
(assert-equal (last [5]) 5))
|
||||
|
||||
(defn test-neg []
|
||||
"NATIVE: testing the neg? function"
|
||||
(assert-true (neg? -2))
|
||||
|
Loading…
Reference in New Issue
Block a user