Pergunta

Probably just showcasing my ignorance of lisp(s) here, but I have some slightly odd results with ClojureScript's and function:

(and true false) ; false
(and false true) ; false
(and 1 0)        ; 0
(and 0 1)        ; 1 !?

What's going on here? I'd at least expect symmetry; is this something to do with the bit-storage of true and false?

Foi útil?

Solução

and returns its last argument if all the arguments are truthy, otherwise it returns false (it also stops evaluating the arguments as soon as it reaches the first falsey one). In Clojure, unlike Javascript, 0 and 1 are both truthy. The only falsey values in Clojure are false and nil.

http://blog.jayfields.com/2011/02/clojure-truthy-and-falsey.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top