本文介绍了seq和seq之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-------------------------
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。空的区别是什么?和nil?我很抱歉。
Obviously empty? is based on seq. what is the difference between empty? and nil? I'm soooo confused.
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
推荐答案
-
seq
将集合转换为序列,如果集合为空,则返回nil;如果参数为nil,也返回nil。 -
seq?
如果参数是序列则返回true(实现ISeq接口)。 -
如果参数为nil,
将返回true。
空?
将返回true。 seq
converts collection to sequence and returns nil if the collection is empty; also returns nil if the argument is nil.seq?
returns true if the argument is a sequence (implements the ISeq interface).empty?
will return true if the argument is either nil or an empty collection.nil?
will return true if the argument is nil.
> > > c $ c>这样:
I guess the bit about the (seq x)
idiom in the docstring for empty?
applies to common practice of using if-let
like so:
(defn print-odd-numbers [coll]
(if-let [x (seq (filter odd? coll))]
(println "Odd numbers:" x)
(println "No odd numbers found.")))
这篇关于seq和seq之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!