Clojure - 关系运算符



关系运算符允许比较对象。以下是 Clojure 中可用的关系运算符。

运算符 描述 示例
= 测试两个对象之间的相等性 (= 2 2) 将返回 true
not= 测试两个对象之间的差异 (not= 3 2) 将返回 true
< 检查左侧对象是否小于右侧操作数 (< 2 3) 将返回 true
<= 检查左侧对象是否小于或等于右侧操作数 (<= 2 3) 将返回 true
> 检查左侧对象是否大于右侧操作数 (> 3 2) 将返回 true
>= 检查左侧对象是否大于或等于右侧操作数 (>= 3 2) 将返回 true

以下代码片段展示了如何使用各种运算符。

示例

(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def x (= 2 2))
   (println x)
   
   (def x (not= 3 2))
   (println x)
   
   (def x (< 2 3))
   (println x)
   
   (def x (<= 2 3))
   (println x)
   
   (def x (> 3 2))
   (println x)
   
   (def x (>= 3 2))
   (println x))
(Example)

以上程序产生以下输出。

输出

true
true
true
true
true
true
clojure_operators.htm
广告

© . All rights reserved.