What is the pop vector method in Clojure?

Overview

A vector is a Clojure data structure that stores data in a sequentially indexed manner. The pop method is used to return a new vector with all the elements of the vector except the last one.

Syntax

(pop vec)
Syntax of pop method

Parameter

We pass one parameter to this method:

vec: This represents the set of vector elements.

Return value

This method returns a new set of vector elements without the last element.

Example

(ns clojure.examples.example
(:gen-class))
(defn popp []
(println (pop (vector 3 2 1 4 5 6 7 8 0))))
(popp)

Explanation

  • Line 3: We define a function, Pop.
  • Line 4: We use println to print the new sets of vector elements. The pop method removes the last element of the vector set which is 0.
  • Line 5: We call the popp function.