What is the rest list method in Clojure?

Overview

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

What is the rest list method in Clojure?

The rest method is a list method that returns all the items in a list except the first element.

Syntax

(rest lst)

Parameter

The rest method receives a list represented by lst in the syntax.

Return value

The rest method returns the list of items without the first item of the passed list. Let's see an example to understand this further.

Example

(ns clojure.examples.example
(:gen-class))
(defn restlist []
(println (rest (list 1 2,40,80,12,34))))
(restlist)

Code explanation

In the code above:

  • In line 3, we create a function restlist
  • In line 4, we print the output of the rest method using the println, and pass a list of items to the rest method.
  • In line 5, we call our function restlist.

Free Resources