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

后端 未结 4 1615
暗喜
暗喜 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:09

    In Clojure I would normally use something like:

    (if 
      (and (= a something) (= b anotherthing))
      (foo))
    

    It is clearly possible to be more concise (e.g. Doug's answer) but I think this approach is more natural for people to read - especially if future readers of the code have a C++ or Java background!

提交回复
热议问题