Trusted answers to developer questions

What is the list method in Clojure?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

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.

RELATED TAGS

clojure
list method

CONTRIBUTOR

Chinweuba Elijah Azubuike
Did you find this helpful?