What is the list method in Clojure?

Overview

A list is a data storage structure that holds a collection of data objects. The list method in Clojure builds lists.

The list method in Clojure

The list method in Clojure creates lists by appending data items to a list and sequencing the list’s last data.

Syntax

(list* listitems [lst])

Parameter

From the syntax above, there are basically two parameters passed to a list method:

  1. listitems: These are data items we want to add to a list.
  2. lst: This is the list to which we will add data items. Let’s see an example

Code

(ns clojure.listt.listt
(:gen-class))
(defn listt []
(println (list* 1 [5,9])))
(listt)

Explanation

Line 3: We define a function, list.

Line 4: We print the list items of the newly created list using println. We then create a list using the list* method.

Line 5: We call the list function.