Clojure core environment and runtime library providing a dynamic, general-purpose programming language on the JVM.
—
Fundamental language constructs including data structures, control flow, functions, and macros that form the foundation of Clojure programming.
Create the core immutable data structures that are central to Clojure programming.
(list & items)
;; Creates a new list containing the items
;; Returns: clojure.lang.IPersistentList
(vector & args)
;; Creates a vector containing the arguments
;; Returns: clojure.lang.IPersistentVector
(hash-map & keyvals)
;; Creates a hash map from alternating keys and values
;; keyvals must be even number of arguments: key1 val1 key2 val2 ...
;; Returns: clojure.lang.IPersistentMap
(hash-set & keys)
;; Creates a hash set containing the keys
;; Returns: clojure.lang.IPersistentSet
(sorted-map & keyvals)
;; Creates a sorted map from alternating keys and values
;; Returns: clojure.lang.IPersistentMap
(sorted-set & keys)
;; Creates a sorted set containing the keys
;; Returns: clojure.lang.IPersistentSetCore functions for working with sequences - the fundamental abstraction in Clojure.
(first coll)
;; Returns the first item in the collection
;; Returns nil if coll is nil or empty
;; Returns: Object
(rest coll)
;; Returns a seq of the items after the first
;; Returns empty seq if no more items
;; Returns: clojure.lang.ISeq
(next coll)
;; Returns a seq of the items after the first
;; Returns nil if no more items
;; Returns: clojure.lang.ISeq
(cons x seq)
;; Returns a new seq where x is the first element and seq is the rest
;; Returns: clojure.lang.ISeq
(conj coll & xs)
;; Returns a new collection with the xs added
;; Addition placement depends on collection type
;; Returns: same type as coll
(count coll)
;; Returns the number of items in the collection
;; Returns: long
(empty? coll)
;; Returns true if coll has no items
;; Returns: boolean
(seq coll)
;; Returns a seq on the collection, nil if empty
;; Returns: clojure.lang.ISeq or nilFunctions to test the type of values.
(nil? x)
;; Returns true if x is nil
;; Returns: boolean
(some? x)
;; Returns true if x is not nil
;; Returns: boolean
(boolean? x)
;; Returns true if x is a Boolean
;; Returns: boolean
(number? x)
;; Returns true if x is a Number
;; Returns: boolean
(string? x)
;; Returns true if x is a String
;; Returns: boolean
(keyword? x)
;; Returns true if x is a Keyword
;; Returns: boolean
(symbol? x)
;; Returns true if x is a Symbol
;; Returns: boolean
(fn? x)
;; Returns true if x is a function
;; Returns: boolean
(coll? x)
;; Returns true if x is a collection
;; Returns: boolean
(sequential? x)
;; Returns true if x is a sequential collection
;; Returns: booleanSpecific predicates for collection types.
(list? x)
;; Returns true if x is a list
;; Returns: boolean
(vector? x)
;; Returns true if x is a vector
;; Returns: boolean
(map? x)
;; Returns true if x is a map
;; Returns: boolean
(set? x)
;; Returns true if x is a set
;; Returns: boolean
(seq? x)
;; Returns true if x implements ISeq
;; Returns: booleanCore constructs for defining functions.
(fn name? [params*] exprs*)
;; Creates a function
;; name is optional for recursion
;; Multiple arity overloads supported: (fn ([x] ...) ([x y] ...))
;; Returns: clojure.lang.IFn
(defn name doc-string? attr-map? [params*] exprs*)
;; Defines a function and binds it to a var
;; Supports multiple arity: (defn f ([x] ...) ([x y] ...))
;; Returns: clojure.lang.Var
(defn- name doc-string? attr-map? [params*] exprs*)
;; Defines a private function
;; Returns: clojure.lang.VarVariable definition and binding constructs.
(def symbol doc-string? init?)
;; Creates a global var
;; Returns: clojure.lang.Var
(let [bindings*] exprs*)
;; Creates local bindings
;; bindings are [name init-expr name init-expr ...]
;; Returns: result of last expr
(binding [bindings*] exprs*)
;; Dynamically binds vars during execution
;; bindings are [var-symbol value var-symbol value ...]
;; Returns: result of last exprBoolean logic and comparison operations.
(not x)
;; Returns true if x is logical false (nil or false)
;; Returns: boolean
(and exprs*)
;; Evaluates exprs left to right, returns first falsy or last value
;; Returns: Object
(or exprs*)
;; Evaluates exprs left to right, returns first truthy value
;; Returns: Object
(= x y & more)
;; Returns true if all arguments are equal
;; Returns: boolean
(not= x y & more)
;; Returns true if arguments are not all equal
;; Returns: boolean
(< x y & more)
;; Returns true if numbers/strings are in monotonically increasing order
;; Returns: boolean
(> x y & more)
;; Returns true if numbers/strings are in monotonically decreasing order
;; Returns: boolean
(<= x y & more)
;; Returns true if numbers/strings are in monotonically non-decreasing order
;; Returns: boolean
(>= x y & more)
;; Returns true if numbers/strings are in monotonically non-increasing order
;; Returns: booleanUsage Examples:
;; Creating data structures
(def my-list (list 1 2 3 4))
(def my-vector [1 2 3 4]) ; literal syntax
(def my-map {:name "Alice" :age 30}) ; literal syntax
(def my-set #{1 2 3 4}) ; literal syntax
;; Working with sequences
(first my-vector) ; => 1
(rest my-vector) ; => (2 3 4)
(cons 0 my-vector) ; => (0 1 2 3 4)
(conj my-vector 5) ; => [1 2 3 4 5]
;; Type checking
(vector? [1 2 3]) ; => true
(map? {:a 1}) ; => true
(nil? nil) ; => true
(number? 42) ; => true
;; Function definition
(defn greet [name]
(str "Hello, " name "!"))
(defn add
([x y] (+ x y))
([x y z] (+ x y z)))
;; Local bindings
(let [x 10
y 20]
(+ x y)) ; => 30Install with Tessl CLI
npx tessl i tessl/maven-org-clojure--clojure