Clojure - Lists nth
This function returns the item in the nth position in the list.
Syntax
Following is the syntax.
(nth lst index)
Parameters − lst is the list of items. index is the index position of the element, which needs to be returned.
Return Value − The value at the index position from the list.
Example
Following is an example of nth in Clojure.
(ns clojure.examples.example (:gen-class)) (defn example [] (println (nth (list 1 2,3) 0)) (println (nth (list 1 2,3) 2))) (example)
Output
The above program produces the following output.
1 3
clojure_lists.htm
Advertisements