📅  最后修改于: 2020-11-05 04:03:32             🧑  作者: Mango
序列是通过“ seq”命令创建的。以下是一个简单的序列创建示例。
(ns clojure.examples.example
(:gen-class))
;; This program displays Hello World
(defn Example []
(println (seq [1 2 3])))
(Example)
上面的程序产生以下输出。
(1 2 3)
以下是可用于序列的各种方法。
Sr.No. | Methods & Description |
---|---|
1 | cons
Returns a new sequence where ‘x’ is the first element and ‘seq’ is the rest. |
2 | conj
Returns a new sequence where ‘x’ is the element that is added to the end of the sequence. |
3 | concat
This is used to concat two sequences together. |
4 | distinct
Used to only ensure that distinct elements are added to the sequence. |
5 | reverse
Reverses the elements in the sequence. |
6 | first
Returns the first element of the sequence. |
7 | last
Returns the last element of the sequence. |
8 | rest
Returns the entire sequence except for the first element. |
9 | sort
Returns a sorted sequence of elements. |
10 | drop
Drops elements from a sequence based on the number of elements, which needs to be removed. |
11 | take-last
Takes the last list of elements from the sequence. |
12 | take
Takes the first list of elements from the sequence. |
13 | split-at
Splits the sequence of items into two parts. A location is specified at which the split should happen. |