📅  最后修改于: 2020-11-05 04:01:06             🧑  作者: Mango
列表是用于存储数据项集合的结构。在Clojure中,列表实现ISeq接口。使用list函数在Clojure中创建列表。
以下是在Clojure中创建数字列表的示例。
(ns clojure.examples.example
(:gen-class))
(defn example []
(println (list 1 2 3 4)))
(example)
上面的代码产生以下输出。
(1 2 3 4)
以下是在Clojure中创建字符列表的示例。
(ns clojure.examples.example
(:gen-class))
(defn example []
(println (list 'a 'b 'c 'd)))
(example)
上面的代码产生以下输出。
(a b c d)
以下是Clojure中可用的列表方法。
Sr.No. | Lists & Description |
---|---|
1 | list*
Creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence. |
2 | first
This function returns the first item in the list. |
3 | nth
This function returns the item in the ‘nth’ position in the list. |
4 | cons
Returns a new list wherein an element is added to the beginning of the list. |
5 | conj
Returns a new list wherein the list is at the beginning and the elements to be appended are placed at the end. |
6 | rest
Returns the remaining items in the list after the first item. |