•
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
<!--[if ppt]-->
•<!--[endif]-->
<!--[if ppt]-->
•<!--[endif]-->
<!--[if ppt]-->
•<!--[endif]-->
<!--[if ppt]-->
•<!--[endif]-->