Ricerca…
truthiness
In Clojure tutto ciò che non è nil o false è considerato logico vero.
Esempi:
(boolean nil) ;=> false
(boolean false) ;=> false
(boolean true) ;=> true
(boolean :a) ;=> true
(boolean "false") ;=> true
(boolean 0) ;=> true
(boolean "") ;=> true
(boolean []) ;=> true
(boolean '()) ;=> true
(filter identity [:a false :b true]) ;=> (:a :b true)
(remove identity [:a false :b true]) ;=> (false)
booleani
Qualsiasi valore in Clojure è considerato vero a meno che non sia false o nil . Puoi trovare la verità di un valore con (boolean value) . Puoi trovare la veridicità di un elenco di valori usando (or) , che restituisce true se qualsiasi argomento è true, o (and) che restituisce true se tutti gli argomenti sono veri.
=> (or false nil)
nil ; none are truthy
=> (and '() [] {} #{} "" :x 0 1 true)
true ; all are truthy
=> (boolean "false")
true ; because naturally, all strings are truthy
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow