Clojure - Lists cons


Advertisements

Returns a new list wherein an element is added to the beginning of the list.

Syntax

Following is the syntax.

(cons element lst)

Parameters − ‘element’ is the element which needs to be added to the list. ‘lst’ is the list of items.

Return Value − The list with the appended value.

Example

Following is an example of cons in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (cons 0 (list 1 2,3))))
(example)

Output

The above program produces the following output.

(0 1 2 3)
clojure_lists.htm
Advertisements