Clojure-snips: Equality in Clojure


Clojure allows you to test for equality using the equals(=) sign.

;you can compare two things
(= 1 1) ;true

;you can compare multiple things
(= 1 1 1) ;true 

;if any of them are not equal then we get false
(= 1 1 2) ;false

;if something is not strictly equal then we get false
(= 2 2.0) ;false

;but we can also check for loose equality (Notice two equals)
(== 2 2.0) ;true

;and it's not just numbers that can be compared
;see? didn't need anything special for strings
(= "abc" (str "a" "b" "c")) ;true

;nil (other languages call it null) can be compared the same way
(= nil nil)
Advertisements

One thought on “Clojure-snips: Equality in Clojure

  1. Pingback: Writing about Clojure | ansh bansal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s