In this guide, we will discuss Clojure Lists cons. 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)
Next Topic : Click Here
Pingback: Clojure - Lists nth | Adglob Infosystem Pvt Ltd
Pingback: Clojure - Lists | Adglob Infosystem Pvt Ltd