The Clojure (or Lisp) Equivalent of a Compound Boolean Test

后端 未结 4 1558
暗喜
暗喜 2021-02-05 06:25

In C++ I\'d write something like this:

if (a == something && b == anotherthing)
{
   foo();
}

Am I correct in thinking the Clojure equi

4条回答
  •  天涯浪人
    2021-02-05 07:19

    It's really cool! (and x y) is a macro -- you can check the source code at clojure.org -- that expands to (if x y false) equivalent to:

    if (x) {
      if (y) {
        ...
      }
    } else {
      false
    }
    

    (or x y) is similar but reversed.

提交回复
热议问题