list is a structure used to store a collection of data items. in clojure, the list implements the iseq interface. lists are created in clojure by using the list function.
example
following is an example of creating a list of numbers in clojure.
(ns clojure.examples.example (:gen-class)) (defn example [] (println (list 1 2 3 4))) (example)
output
the above code produces the following output.
(1 2 3 4)
following is an example of creating a list of characters in clojure.
(ns clojure.examples.example (:gen-class)) (defn example [] (println (list 'a 'b 'c 'd))) (example)
the above code produces the following output.
(a b c d)
following are the list methods available in clojure.
| sr.no. | lists & description |
|---|---|
| 1 |
list*
creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence. |
| 2 |
first
this function returns the first item in the list. |
| 3 |
nth
this function returns the item in the ‘nth’ position in the list. |
| 4 |
cons
returns a new list wherein an element is added to the beginning of the list. |
| 5 |
conj
returns a new list wherein the list is at the beginning and the elements to be appended are placed at the end. |
| 6 |
rest
returns the remaining items in the list after the first item. |