-------------------------
clojure.core/seq
([coll])
Returns a seq on the collection. If the collection is
empty, returns nil. (seq nil) returns nil. seq also works on
Strings, native Java arrays (of reference types) and any objects
that implement Iterable.
-------------------------
clojure.core/seq?
([x])
Return true if x implements ISeq
-----
显然是空的?基于seq。空的区别是什么?没有?我很困惑。
clojure.core/empty?
([coll])
Returns true if coll has no items - same as (not (seq coll)).
Please use the idiom (seq x) rather than (not (empty? x))
还有更多:
(not (seq? ())) ;;false
(not (seq ())) ;;true
(not nil) ;;true
答案 0 :(得分:10)
seq
将集合转换为序列,如果集合为空,则返回nil;如果参数为nil,则返回nil。 seq?
返回true。empty?
将返回true。nil?
将返回true。我想(seq x)
文档字符串中empty?
成语的含义适用于使用if-let
这样的常规做法:
(defn print-odd-numbers [coll]
(if-let [x (seq (filter odd? coll))]
(println "Odd numbers:" x)
(println "No odd numbers found.")))