【发布时间】:2019-05-30 00:04:11
【问题描述】:
我想在全班维护一个向量副本。我必须在递归中多次更新向量。
;this is to update cell in vector
(defn to-plus [data x y]
(update data y (fn [row] (apply str (assoc (vec row) x \+)))))
;here i am getting values in board and calling to-plus to update board
;now i need to maintain a single copy of board
(let [board (read-in-board "map.txt")]
(print-maze board)
(println(str (get-in board [1 4])))
(print-maze (to-plus board 1 4))
(println(to-plus board 1 4)))
我正在尝试使用递归和随机游走来解决迷宫问题。我是 Clojure 的新手。
;Data is of type
---#--###----
-#---#----##-
####-#-#-#-##
---#---#-#---
-+-####---##-
-#------#----
-############
------------@
【问题讨论】:
-
你不能。 Clojure 向量是不可变的。您可以使用 Java 风格的 数组。 Clojure 为这些提供了帮助函数: [
make-array][clojuredocs.org/clojure_core/clojure.core/make-array] 可以制作您想要的东西。您可以使用aget和某种形式的aset...来操作数组。
标签: clojure