Clojure - Sequences conj

Returns a new sequence where ‘x’ is the element that is added to the end of the sequence.


Following is the syntax.

(conj seq x)

Parameters − ‘x’ is the element which needs to be added to the sequence. ‘seq’ is the sequence list of elements.

Return Value − The new sequence with the appended element.


Following is an example of conj in Clojure. Note that in the following program, we are also seeing the shorter version of creating a sequence, which can simply be done by using the square brackets [].

(ns clojure.examples.example

;; This program displays Hello World
(defn Example []
   (println (conj [1 2 3] 4)))


The above program produces the following output.

(1 2 3 4)
Kickstart Your Career

Get certified by completing the course

Get Started