merge #547 - keyword?

This commit is contained in:
Tuukka Turto 2014-04-28 21:56:32 +03:00
commit bdd8e3c82e
2 changed files with 17 additions and 1 deletions

View File

@ -44,6 +44,11 @@
"Check whether c can be used as a cons object"
(instance? HyCons c))
(defn keyword? [k]
"Check whether k is a keyword"
(and (instance? (type :foo) k)
(.startswith k (get :foo 0))))
(defn cycle [coll]
"Yield an infinite repetition of the items in coll"
(setv seen [])
@ -354,7 +359,7 @@
(def *exports* '[calling-module-name coll? cons cons? cycle dec distinct
disassemble drop drop-while empty? even? every? first filter
flatten float? gensym identity inc instance? integer
integer? integer-char? iterable? iterate iterator?
integer? integer-char? iterable? iterate iterator? keyword?
list* macroexpand macroexpand-1 neg? nil? none? nth
numeric? odd? pos? remove repeat repeatedly rest second
some string string? take take-nth take-while zero? zipwith])

View File

@ -478,3 +478,14 @@
(assert-equal (list res) [4 4 4])
(setv res (zipwith operator.sub [3 7 9] [1 2 4]))
(assert-equal (list res) [2 5 5]))
(defn test-is-keyword []
"NATIVE: testing the keyword? function"
(assert (keyword? ':bar))
(assert (keyword? ':baz))
(assert (keyword? :bar))
(assert (keyword? :baz))
(assert (not (keyword? "foo")))
(assert (not (keyword? ":foo")))
(assert (not (keyword? 1)))
(assert (not (keyword? nil))))