Why is there no non-zero? in Clojure?

In clojure I noticed functions with logical opposites like [[if x if-not] [every? x not every]]. I wonder why [non-zero?] Not included, is it on purpose or because it is too trivial.

Sorry, I have to ask this.

+3


source to share


2 answers


There some?

is since Clojure 1.6:

clojure.core/some?
([x])
Returns true if x is not nil, false otherwise.

      



https://clojuredocs.org/clojure.core/some_q

+3


source


In Clojure, false and nil are false (treated as "false"), everything else is true (treated as "true").

As an example,

(if-not nil
        true
        false)

      

is true and



(if-not false
        true
        false)

      

also evaluates to true. In most cases, you shouldn't explicitly check for null, but rather use forms that work with false / rights values.

If you only have to check for null, you can use some?

derivatives as well.

+1


source







All Articles