我正在尝试使用 Clojure - Seesaw 从文件中读取并将字符串转换为映射(变量),以便我可以使用它们打印到 GUI。以下是我当前的代码:
(ns store.core
(:gen-class)
(:require [seesaw.core :as seesaw]))
(defn -main
[& args]
(seesaw/show!
(spit "amovies.txt" "")
;(spit "amovies.txt" (pr-str [{:id 1 :qty 4 :name "movie1" :price 3.50}
; {:id 2 :qty 5 :name "movie2" :price 3.00}]) :append true)
(spit "amovies.txt" "movie: Movie_Name\nprice: 5\nid: 1\nquantity: 2" :append true)
(print (read-string (slurp "amovies.txt")))
(with-open [rdr (reade "amovies.txt")]
(doseq [line (line-seq rdr)]
(println-str line)))
我一直在弄清楚如何逐行读取 amovies.txt 中的字符串,然后用它创建一个地图。所需的输出应该类似于电影: Movie_Name 价格:5 id:1 数量:2
但在某种程度上,如果我说 :movie,它会引用电影的名称。
有人可以帮忙吗?感谢所有帮助!