为什么 clojure 允许小于 () 运算符/函数的单个参数?
我想知道为什么它只是返回 'true' 而不是强制至少 2 个参数?

来源:

(defn >
  "Returns non-nil if nums are in monotonically decreasing order,
  otherwise false."
  {:inline (fn [x y] `(. clojure.lang.Numbers (gt ~x ~y)))
   :inline-arities #{2}
   :added "1.0"}
  ([x] true)
  ([x y] (. clojure.lang.Numbers (gt x y)))
  ([x y & more]
   (if (> x y)
     (if (next more)
       (recur y (first more) (next more))
       (> y (first more)))
     false)))

最佳答案

如果您认为“单调递减”与“第一个值之后是否有任何值大于前一个值(我们将其作为单调递减序列拒绝)”,那么 >(和< 如果你说增加/小于)满足这个定义。

关于clojure - 为什么 clojure 允许小于 (<) 或大于 (>) 运算符/函数的单个参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34057900/

10-10 01:04
查看更多