•
cond
(cond & clauses)
后跟一组测试求值表达式
/
表达式对(
test/expr pairs
),逐次一次一个的求值。如果某个测试求值表达式
返回逻辑真,返回对应表达式的值,并且不再对下面剩下的测试求值表达式或对应表达式求值。如果
没有指定任何测试求值表达式
/
表达式对(
test/expr pairs
),也就是这种形式:
(cond)
,将返回
nil
。
例子:
user=> (def i 100)
#'user/i
user=> (cond
#_=> (< i 0) (str i " < 0")
#_=> (and (>= i 0) (< i 10)) (str i " >= 0 and " i " < 10")
#_=> (and (>= i 10) (< i 100)) (str i " >= 10 and " i " < 100")
#_=> (and (>= i 100) (< i 1000)) (str i " >= 100 and " i " < 1000")
#_=> true (str i " >= 1000"))
"100 >= 100 and 100 < 1000
«
user=> (cond)
nil
(ns clojure.wf.core.SimpleScalaControlFlow (:gen-class :implements [com.wf.core.AbstractControlFlow] :init constructor :constructors {[String] []})) (import java.util.function.Function) (import com.wf.core.internal.ScalaEngine) (def script nil) (defn -constructor [_script] (println *ns*) (def script _script) [[] (atom {:location "default"})]) (defn result ;; [Input] (def engine (ScalaEngine/get)) (.put engine "input" Input) ;(def value (.eval engine (str "var _input = \"test\"\n" "_input == input"))) (def value (.eval engine script)) (println "the class of value:", (.getClass value)) (cond (= value nil) false (not (.isInstance Boolean value)) false :else (.booleanValue value))) (defn -getFunctionExpress ;; fn .getFunctionExpress [this] (let [functionExpress (proxy [Function] [] (apply [t] (result t)))] functionExpress))
(ns clojure.wf.core.SimpleScalaControlFlowTest (:require [clojure.test :refer :all])) (import clojure.wf.core.SimpleScalaControlFlow) (deftest getFunctionExpress (println "testing getFunctionExpress") (def simplescala (SimpleScalaControlFlow. (str "var _input = \"test\"\n" "_input == input"))) (def functionExpress (.getFunctionExpress simplescala)) (println (.getClass functionExpress)) ; call fn apply (def result (.apply functionExpress "what...")) (println result) (testing "the eval result of process of flow:control is false!" (is (not result))))
>lein test :only clojure.wf.core.SimpleScalaControlFlowTest lein test clojure.wf.core.SimpleScalaControlFlowTest testing getFunctionExpress #object[clojure.lang.Namespace 0x31920ade user] clojure.wf.core.SimpleScalaControlFlow.proxy$java.lang.Object$Function$ac181173 log4j:WARN No appenders could be found for logger (com.wf.core.internal.ScalaEngine). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. input: Object = what... the class of value: java.lang.Boolean false Ran 1 tests containing 1 assertions. 0 failures, 0 errors.