📜  Clojure-矢量

📅  最后修改于: 2020-11-05 04:01:38             🧑  作者: Mango


向量是由连续整数索引的值的集合。使用Clojure中的vector方法创建一个vector。

以下是在Clojure中创建向量的示例。

(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (println (vector 1 2 3)))
(example)

输出

上面的代码产生以下输出。

[1 2 3]

以下是Clojure中可用的方法。

Sr.No. Vectors & Description
1 vector-of

Creates a new vector of a single primitive type ‘t’, where ‘t’ is one of :int :long :float :double :byte :short :char or :boolean.

2 nth

This function returns the item in the nth position in the vector.

3 get

Returns the element at the index position in the vector.

4 conj

Appends an element to the vector and returns the new set of vector elements.

5 pop

For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item.

6 subvec

Returns a sub vector from a starting and ending index.