Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果向量大小小于一定量,则连接到clojure向量_Clojure - Fatal编程技术网

如果向量大小小于一定量,则连接到clojure向量

如果向量大小小于一定量,则连接到clojure向量,clojure,Clojure,我有三个向量: (def v1 ["one" "two" "three"]) (def v2 ["one" "two" "three" "four"]) (def v3 ["one" "two" "three" "four" "five"]) 我需要确保向量的大小始终为5个元素。我想要一个函数传递给每个函数,当大小小于5时,该函数将检查大小并将空字符串作为占位符连接,这样我可以得到: (def new-v1 ["one" "two" "three" "" ""]) (def new-v2 ["

我有三个向量:

(def v1 ["one" "two" "three"])
(def v2 ["one" "two" "three" "four"])
(def v3 ["one" "two" "three" "four" "five"])
我需要确保向量的大小始终为5个元素。我想要一个函数传递给每个函数,当大小小于5时,该函数将检查大小并将空字符串作为占位符连接,这样我可以得到:

(def new-v1 ["one" "two" "three" "" ""])
(def new-v2 ["one" "two" "three" "four" ""])
(def new-v3 ["one" "two" "three" "four" "five"])

谢谢。

您可以为vector++重复的空字符串创建一个惰性seq,并从中提取5个元素:

(defn process [items]
  (into [] (take 5 (concat items (repeat "")))))

user> (process ["a" "b"])
["a" "b" "" "" ""]

您可以为vector++重复的空字符串创建一个惰性seq,并从中获取5个元素:

(defn process [items]
  (into [] (take 5 (concat items (repeat "")))))

user> (process ["a" "b"])
["a" "b" "" "" ""]

太完美了!谢谢,太完美了!谢谢