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
如何从文本文件中读取字符串并在clojure中转换为映射?_Clojure_Seesaw - Fatal编程技术网

如何从文本文件中读取字符串并在clojure中转换为映射?

如何从文本文件中读取字符串并在clojure中转换为映射?,clojure,seesaw,Clojure,Seesaw,我试图使用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 :n

我试图使用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中的字符串,然后用它创建地图。所需的输出应该是 电影:电影名称 价格:5元 身份证号码:1 数量:2

但在某种程度上,如果我说,:movie,它会引用电影的名字

有人能帮忙吗?感谢您的帮助

一, 2. 我可以用这个吗 但不是用这个 文件:

传递给
show的参数错误
看起来你好像在向跷跷板/秀!传递大量的参数

文件说明

用法:(显示!目标)

显示框架、对话框或小部件

如果目标是一个模式对话框,调用将阻塞并显示!将 返回对话框的结果。请参阅(seesaw.core/从对话框返回)

返回其输入


我尝试过使用它,我认为reade实际上是reader,但找不到reader,并在CLI中导致错误。您使用的是什么版本的Clojure?它也应该是clojure.core/read-string,有什么错误?
(def movies-as-map
  (let [lines (with-open [rdr (reade "amovies.txt")]
                (line-seq rdr))]
    (binding [*read-eval* false]
      (map read-string lines))))
user> (def movie
        (binding [*read-eval* false]
          (read-string 
           "{:id 1 :qty 4 :name \"movie1\" :price 3.50}")))

#'user/movie
user> (keys movie)
(:id :qty :name :price)
(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)