Clojure中的" if-do" 表达式用于允许为" if"语句的每个分支执行多个表达式。

If/do Expression - 语法

if(condition) (
   statement #1
   statement #1.1
)

(
   statement #2
   statement #2.1
)

以下是"if condition" 语句的示例。

(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello Learnfk
(defn Example [] (
   if (= 2 2)
      (do(println "Both the values are equal")
         (println "true"))
      (do(println "Both the values are not equal")
         (println "false"))))
(Example)

在上面的示例中," if"条件用于判断2和2的值是否相等。

上面的代码产生以下输出。

Both the values are equal
true

参考链接

https://www.learnfk.com/clojure/clojure-if-do-expression.html