Clojure——序列取反



选取序列中最后的列表元素。

语法

以下是语法。

(take-last num seq1)

**参数**“seq1”是元素的序列列表。“num”是序列中需要从末尾包含的元素数。

**返回值**包含仅末尾指定数的元素的新元素序列。

示例

以下是Clojure中take-last的示例。

(ns clojure.examples.example
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def seq1 (seq [5 4 3 2 1]))
   (def seq2 (take-last 2 seq1))
   (println seq2))
(Example)

输出

以上程序产生以下输出。

(2 1)
clojure_sequences.htm
广告
© . All rights reserved.