What is the first method in Clojure?
Overview
What is a list?
A list is a data storage structure that holds a collection of data objects. The list method in Clojure is used to build lists. You can see this shot for more information on creating a list.
The first method in Clojure
The first method is a list method used to fetch the first item of a list.
Syntax
(first lst)
Parameter
One parameter is passed to the first method, where lst in the syntax above represents the list.
Let’s look at an example.
(ns clojure.Test.example(:gen-class))(defn Firstt [](println (first (list 1 2,3))))(Firstt)
Explanation
In the code above, we’ll print the first item of a list.
Line 3: We define a function Firstt.
Line 4: We print the return value of the first method using the println. Then, we fetch the first item of the list using the list method first.
Line 5: We call the Firstt function.