Clojure - conj



Appends an element to the set and returns the new set of elements.

Syntax

Following is the syntax.

(conj setofelements x)

Parameters − ‘setofelements’ is the set of elements. ‘x’ is the element which needs to be appended to the set of elements.

Return Value − Returns the new set with the appended element.

Example

Following is an example of conj in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (conj (set '(3 2 1)) 5)))
(example)

Output

The above code produces the following output.

#{1 3 2 5}
clojure_sets.htm
Advertisements