Clojure

Print

(println "Hello World")

Variables

(def x 4)
(def x "hello")
(def x true)

Data types

;; Integer
(def x 4)

;; Float
(def x 4.5)

;; String
(def x "hello")

;; List
(list 1 2 3)

;; Set
(set '(1 2 3))

;; Vector
(vector 1 2 3)

;; Map
(hash-map "a" 1 "b" 2 "a" 3)

Operators

;; Arithmetic operators
(+ 1 2) ;; addition
rem ;; modulo (remainder)

;; Logical operators
= ;; equal
not= ;; not equal
and ;; AND
or ;; OR
not ;; NOT

;; Bitwise operators
bit-and ;; AND
bit-or ;; OR
bit-xor ;; XOR
bit-not ;; NOT

Control flow

;; if-else
(if (= a b)
    (println "equal")
    (println "not equal"))

Functions

(defn my_function [x y] (+ x y))

;; Call function
(my_function)

;; Anonymous function
(fn [x y] (+ x y))

Error handling

(try
    (def content (slurp "my_file.txt"))
    (println content)
    (catch Exception e (println (str "Can't open file: " (.getMessage e)))))