Clojure - 列表 nth



此函式返回列表中“第 n 個”位置的專案。

語法

以下是語法。

(nth lst index)

引數 - ‘lst’ 是專案列表。‘index’ 是需要返回的元素的索引位置。

返回值 - 列表中索引位置的值。

示例

以下是 Clojure 中 nth 的示例。

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (nth (list 1 2,3) 0))
   (println (nth (list 1 2,3) 2)))
(example)

輸出

以上程式產生以下輸出。

1
3
clojure_lists.htm
廣告
© . All rights reserved.