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
Graph Clojure创建表示较大列表边缘的子列表的方法_Graph_Clojure_Edges - Fatal编程技术网

Graph Clojure创建表示较大列表边缘的子列表的方法

Graph Clojure创建表示较大列表边缘的子列表的方法,graph,clojure,edges,Graph,Clojure,Edges,鉴于此: ["a" "bunch" "of" "words"] 我想要一个函数,它可以产生: [["a" "bunch"] ["a" "of"] ["a" "words"] ["bunch" "of"] ["bunch" "words"] ["of" "words"]] 我基本上是想列举第一个向量中单词的边缘 类似这样的情况很接近: (for [i lst, j (rest lst) :when (not= i j)] (conj [] i j)) 但它当然会倒退。换句话说,当它们在第

鉴于此:

["a" "bunch" "of" "words"]
我想要一个函数,它可以产生:

[["a" "bunch"] ["a" "of"] ["a" "words"]
 ["bunch" "of"] ["bunch" "words"]
 ["of" "words"]]
我基本上是想列举第一个向量中单词的边缘

类似这样的情况很接近:

(for [i lst, j (rest lst) :when (not= i j)] (conj [] i j))
但它当然会倒退。换句话说,当它们在第一次传递中被捕获时,我最终得到了[“单词”“串”][“单词”或“]等等

也许这需要通过loop recur手动完成?但首先,我想检查一下我是否缺少一些明显的功能或已经存在的一个好的核心功能。

尝试以下方法:

(def lst ["a" "bunch" "of" "words"])

(let [cnt (count lst) r (range cnt)]
  (for [a r b r :when (< a b)]
    [(lst a) (lst b)]))


;=> (["a" "bunch"] ["a" "of"] ["a" "words"] ["bunch" "of"] ["bunch" "words"] ["of" "words"])
(def lst[“一串”字])
(让[cnt(count lst)r(range cnt)]
(对于[a r b:when(([“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”][“一串”])
这似乎与打印4x4矩阵的上三角形相同

如果希望结果是向量,那么

(apply vector 
       (let [cnt (count lst) r (range cnt)]
         (for [a r b r :when (< a b)]
           [(lst a) (lst b)])))
(应用向量
(让[cnt(count lst)r(range cnt)]
(对于[a r b:when(
一种简单的递归方式:

(defn edges [[f & r]]
  (when f (concat (map #(do [f %]) r) (edges r))))

我收到一个错误LazySeq无法转换为IFn。我没有遵循(WA)(WB)是什么。w标识符是什么?@Scott
w
应该更改为
lst
。我更新了答案。很抱歉输入错误。
(lst a)
表示
lst
的第个元素
a
。由于向量也作为函数工作,因此在这种情况下不必使用
nth
(lsta)
(nth lsta)
实际上是相同的。您还可以使用:
(对于[b r a(范围b)][(lsta)(lst b)]