What is the get() method in Clojure?
What is a set in Clojure?
A set is a data structure that stores data in an unsorted manner. It contains a collection of unique data values.
What is a get method in Clojure?
A get method returns the selected element of a set.
Syntax
(get setofelements element)
Parameter(s)
The get method receives two parameters:
setofelement: the setelement: the element
Return Value
The get method returns an element from the set.
Example
(ns clojure.examples.example(:gen-class))(defn gett [](println (get (set '(4 6 8)) 4))(println (get (set '(3 2 1)) 1)))(gett)
Explanation
From the code above:
-
Line 3: We define a function
gett. -
Line 4: We print the element returned using the
println. Thegetmethod is used to get data value4from theset. -
Line 5: We print the element returned using the
println. Thegetmethod is used to get data value1from theset. -
Line 6: We call the
gettfunction.