首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

clojure API学习(二) 比较操作

2012-10-10 
clojure API学习(2) 比较操作注:本文基于jdk1.6,clojure1.2比较操作等于??? clojure中的等于和java中的eq

clojure API学习(2) 比较操作

注:本文基于jdk1.6,clojure1.2

比较操作等于=

??? clojure中的等于和java中的equals方法类似,但是clojure中的=还能够作用于nil、数字和集合上面。看看例子:

??? 从上面的例子来看,=应该是做的值比较,那我们再来验证一下看看:

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

?

?

热点排行