讓我們來看看condp
documentation:
=> (doc condp) ; in my REPL
-------------------------
clojure.core/condp
([pred expr & clauses])
Macro
Takes a binary predicate, an expression, and a set of clauses.
Each clause can take the form of either:
test-expr result-expr
test-expr :>> result-fn
Note :>> is an ordinary keyword.
For each clause, (pred test-expr expr) is evaluated. If it returns
logical true, the clause is a match. If a binary clause matches, the
result-expr is returned, if a ternary clause matches, its result-fn,
which must be a unary function, is called with the result of the
predicate as its argument, the result of that call being the return
value of condp. A single default expression can follow the clauses,
and its value will be returned if no clause matches. If no default
expression is provided and no clause matches, an
IllegalArgumentException is thrown.
所以,:>>
只是在condp
宏作爲某種syntactic sugar一個普通的關鍵字:
=> (class :>>)
clojure.lang.Keyword
=> (name :>>)
">>"
:>>
關鍵字在condp
宏中使用以表示以下事物是調用(pred test-expr expr)
調用結果的函數,而不是要返回的值。