Clojure无法解析符号

Clojure无法解析符号,clojure,functional-programming,Clojure,Functional Programming,我对Clojure不熟悉。我试图运行此程序,但找不到符号解析到dict (ns noobfile (:require '[clojure.string :as str] '[noobfile])) (def my_str "1|John Smith|123 Here Street|456-4567 2|Sue Jones|43 Rose Court Street|345-7867 3|Fan Yuhong|165 Happy Lane|345-4533") (def

我对Clojure不熟悉。我试图运行此程序,但找不到符号解析到dict

(ns noobfile
  (:require '[clojure.string :as str]
            '[noobfile]))

(def my_str "1|John Smith|123 Here Street|456-4567
2|Sue Jones|43 Rose Court Street|345-7867
3|Fan Yuhong|165 Happy Lane|345-4533")
(def my_dict (str/split my_str #"\n"))
(defn pasre-to-dict [x] (str ":" x))
(apply parse-to-dict my_dict)
错误如下所示:

CompilerException java.lang.Exception: Found lib name 'clojure.string' containing period with prefix 'quote'.  lib names inside prefix lists must not contain periods, compiling:(/tmp/form-init6237588243498764600.clj:16:1)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: parse-to-dict in this context, compiling:(/tmp/form-init6237588243498764600.clj:28:1) 
  • require
    子句中不应该有引号
  • 没有理由需要
    noobfile
  • 您在
    中有一个打字错误(定义为dict[x](str:“x))
  • 在这种情况下使用是没有意义的。您可能需要修改
    parse to dict
    函数,具体取决于您想要实现的功能
  • 因此,您可以在这里继续:

    (ns noobfile
      (:require [clojure.string :as str]))
    
    (def my_str "1|John Smith|123 Here Street|456-4567
      2|Sue Jones|43 Rose Court Street|345-7867
      3|Fan Yuhong|165 Happy Lane|345-4533")
    (def my_dict (str/split my_str #"\n"))
    (defn parse-to-dict [x] (str ":" x))
    (parse-to-dict my_dict)
    
    下次提问之前,请自己做更多的研究

  • require
    子句中不应该有引号
  • 没有理由需要
    noobfile
  • 您在
    中有一个打字错误(定义为dict[x](str:“x))
  • 在这种情况下使用是没有意义的。您可能需要修改
    parse to dict
    函数,具体取决于您想要实现的功能
  • 因此,您可以在这里继续:

    (ns noobfile
      (:require [clojure.string :as str]))
    
    (def my_str "1|John Smith|123 Here Street|456-4567
      2|Sue Jones|43 Rose Court Street|345-7867
      3|Fan Yuhong|165 Happy Lane|345-4533")
    (def my_dict (str/split my_str #"\n"))
    (defn parse-to-dict [x] (str ":" x))
    (parse-to-dict my_dict)
    

    下次提问之前,请自己做更多的研究。

    你想要的是
    map
    ,而不是
    apply

    (map parse-to-dict my_dict)
    

    读入你想要的是
    map
    而不是
    apply

    (map parse-to-dict my_dict)
    

    读一读

    我会说这样的话:

    (require '[clojure.string :as cs])
    
    (reduce #(let [[x & xs] (cs/split (cs/trim %2) #"\|")]
               (assoc %1 x xs))
            {}
            (cs/split-lines my_str))
    
    ;; => {"1" ("John Smith" "123 Here Street" "456-4567"), 
    ;;     "2" ("Sue Jones" "43 Rose Court Street" "345-7867"), 
    ;;     "3" ("Fan Yuhong" "165 Happy Lane" "345-4533")}
    

    但实际上,正如大家所建议的那样,在开始之前,你应该先读一些clojure的基础知识。

    我会说这样的话:

    (require '[clojure.string :as cs])
    
    (reduce #(let [[x & xs] (cs/split (cs/trim %2) #"\|")]
               (assoc %1 x xs))
            {}
            (cs/split-lines my_str))
    
    ;; => {"1" ("John Smith" "123 Here Street" "456-4567"), 
    ;;     "2" ("Sue Jones" "43 Rose Court Street" "345-7867"), 
    ;;     "3" ("Fan Yuhong" "165 Happy Lane" "345-4533")}
    

    但实际上,正如大家所建议的那样,在开始之前,你应该先阅读一些clojure的基础知识。

    你把它称为
    pasre to dict
    而不是
    parse to dict
    str
    也被
    clojure.string
    别名所掩盖。不要用核心函数的名字来别名任何东西(除非你真的知道你在做什么)@leetwinski不,它没有阴影。这是。您将其称为
    pasre to dict
    而不是
    parse to dict
    str
    也被
    clojure.string
    别名隐藏。不要用核心函数的名字来别名任何东西(除非你真的知道你在做什么)@leetwinski不,它没有阴影。这是我第一次投反对票。这似乎是尝试Clojure的合理尝试,而“请做更多的研究”对我来说并没有任何帮助。这似乎是尝试Clojure的合理尝试,而“请做更多的研究”并没有帮助