- Clojure Tutorial
- Clojure - Home
- Clojure - Overview
- Clojure - Environment
- Clojure - Basic Syntax
- Clojure - REPL
- Clojure - Data Types
- Clojure - Variables
- Clojure - Operators
- Clojure - Loops
- Clojure - Decision Making
- Clojure - Functions
- Clojure - Numbers
- Clojure - Recursion
- Clojure - File I/O
- Clojure - Strings
- Clojure - Lists
- Clojure - Sets
- Clojure - Vectors
- Clojure - Maps
- Clojure - Namespaces
- Clojure - Exception Handling
- Clojure - Sequences
- Clojure - Regular Expressions
- Clojure - Predicates
- Clojure - Destructuring
- Clojure - Date & Time
- Clojure - Atoms
- Clojure - Metadata
- Clojure - StructMaps
- Clojure - Agents
- Clojure - Watchers
- Clojure - Macros
- Clojure - Reference Values
- Clojure - Databases
- Clojure - Java Interface
- Clojure - Concurrent Programming
- Clojure - Applications
- Clojure - Automated Testing
- Clojure - Libraries
- Clojure Useful Resources
- Clojure - Quick Guide
- Clojure - Useful Resources
- Clojure - Discussion
Clojure - Relational Operators
Relational operators allow comparison of objects. Following are the relational operators available in 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 |
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 (= 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)
The above program produces the following output.
Output
true true true true true true
clojure_operators.htm
Advertisements