Clojure - 邏輯運算子



邏輯運算子用於評估布林表示式。以下是 Groovy 中可用的邏輯運算子。

運算子 描述 示例
and 這是邏輯“與”運算子 (or true true) 將返回 true
or 這是邏輯“或”運算子 (and true false) 將返回 false
not 這是邏輯“非”運算子 (not false) 將返回 true

以下程式碼片段顯示瞭如何使用各種運算子。

示例

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

;; This program displays Hello World
(defn Example []
   (def x (or true true))
   (println x)
   
   (def x (and true false))
   (println x)
   
   (def x (not true))
   (println x))
(Example)

以上程式產生以下輸出。

輸出

true
false
false
clojure_operators.htm
廣告
© . All rights reserved.