Clojure - Logical Operators



Logical operators are used to evaluate Boolean expressions. Following are the logical operators available in Groovy.

Operator Description Example
and This is the logical “and” operator (or true true) will give true
or This is the logical “or” operator (and true false) will give false
not This is the logical “not” operator (not false) will give true

The following code snippet shows how the various operators can be used.

Example

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

The above program produces the following output.

Output

true
false
false
clojure_operators.htm
Advertisements