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"
|
"Return true if x is an iterator"
|
||||||
(isinstance x collections.Iterator))
|
(isinstance x collections.Iterator))
|
||||||
|
|
||||||
|
(defn last [coll]
|
||||||
|
"Return last item from `coll`"
|
||||||
|
(nth coll (- (len 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"
|
||||||
(if (not tl)
|
(if (not tl)
|
||||||
@ -416,7 +420,7 @@
|
|||||||
dec distinct disassemble drop drop-last drop-while empty? even?
|
dec distinct disassemble drop drop-last drop-while empty? even?
|
||||||
every? first filter filterfalse flatten float? gensym identity
|
every? first filter filterfalse flatten float? gensym identity
|
||||||
inc input instance? integer integer? integer-char? interleave
|
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?
|
macroexpand macroexpand-1 map merge-with name neg? nil? none?
|
||||||
nth numeric? odd? pos? range read remove repeat repeatedly
|
nth numeric? odd? pos? range read remove repeat repeatedly
|
||||||
rest reduce second some string string? symbol? take take-nth
|
rest reduce second some string string? symbol? take take-nth
|
||||||
|
@ -382,6 +382,11 @@
|
|||||||
;; should not work for an int
|
;; should not work for an int
|
||||||
(assert-false (iterator? 5)))
|
(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 []
|
(defn test-neg []
|
||||||
"NATIVE: testing the neg? function"
|
"NATIVE: testing the neg? function"
|
||||||
(assert-true (neg? -2))
|
(assert-true (neg? -2))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user