我想按号码删除房间。如您所见,房间是原子列表并包含原子。我遇到了一个异常:IllegalArgumentException 不知道如何从以下位置创建 ISeq:core.main$delete_room_by_id$fn__7541 clojure.lang.RT.seqFrom (RT.java:487)
我有这个代码:
(comment ------------- * DATA * ----------------- )
(def rooms "atomic list of atoms - rooms" (atom '()))
(comment ------------- * UTILS * ----------------- )
(defn enter-value [message]
(do (println message) (read-line)))
(comment ------------- * ADD ROOM * ----------------- )
(defn save-room "The function that will save provided room."
[number num-of-beds price]
(swap! rooms conj (atom {:number number
:num-of-beds num-of-beds
:price price
:is-ocupated false})))
(defn enter-room "This function will create room based on user input." []
(let [number (enter-value "Number...")
num-of-beds (enter-value "Number of beds...")
price (enter-value "Price...")]
(save-room number num-of-beds price)))
(comment ------------- * DELETE ROOM * ----------------- )
(defn delete-room-by-number "Delete room by number."
[number]
(swap! rooms remove #(not (= (:number @%) number))))
我认为交换!函数不要像我想要的那样为删除函数设置参数。我认为最后的命令是:(删除房间#(不是(=(:数字@%)数字)))。这不好,因为我必须取消引用 @rooms 之类的房间并将其作为删除函数的第二个参数传递。
感谢您阅读本文。