目录

Show 例子

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

操作者 描述
= 测试两个对象之间的相等性 (= 2 2)将给出真实
not= 测试两个对象之间的差异 (不是= 3 2)会给出真实的
< 检查左对象是否小于右操作数 (<2 3)将给出真实
<= 检查左对象是否小于或等于右操作数 (<= 2 3)将给出真实
> 检查左对象是否大于右操作数 (> 3 2)将给出真实
>= 检查左对象是否大于或等于右操作数 (> = 3 2)将给出真实

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

例子 (Example)

(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)

上述程序产生以下输出。

输出 (Output)

true
true
true
true
true
true
↑回到顶部↑
WIKI教程 @2018