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.