Clojure-relational-operators

提供:Dev Guides
移動先:案内検索

Clojure-関係演算子

関係演算子を使用すると、オブジェクトを比較できます。 Clojureで使用できる関係演算子は次のとおりです。

Operator Description Example
= Tests the equality between two objects (= 2 2) will give true
not= Tests the difference between two objects (not = 3 2) will give true
< Checks to see if the left object is less than the right operand (< 2 3) will give true
Checks to see if the left object is less than or equal to the right operand (⇐ 2 3) will give true
> Checks to see if the left object is greater than the right operand (> 3 2) will give true
>= Checks to see if the left object is greater than or equal to the right operand (>= 3 2) will give 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