我有以下代码,当我在Cider中执行并逐步执行它时它会起作用,但是当我在命令行上直接运行时,我收到以下错误:
Exception in thread "main" java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure-todo.todo/execute-todo-cmd, compiling:(/private/var/folders/d_/b8gmsvl16sgdg70m15gx20l40000gn/T/form-init6080372317525706515.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure-todo.todo/execute-todo-cmd
这是代码。我想这是一个名称空间错误,但如果它在苹果酒中工作,我会对它如何成为名称空间问题感到困惑。
(ns clojure-todo.todo
(:gen-class))
///// Other Code here
(defn print-msg-list [list]
(doseq [item list] (print-msg item)))
(defn create-todo [todo-string] (hash-map :todo-content todo-string :checked false))
(defn list-todos [todos]
(doseq [single-todo todos]
(do
(print (get single-todo :todo-content))
(let [is-checked (get single-todo :checked)]
(if is-checked
(print-msg :is-checked)
(print-msg :is-unchecked))))))
(defn add-todo []
(do
(print-msg :add-todo-message)
(let [todo-string (read-line) the-todo-created (create-todo todo-string)]
(def the-todos (conj the-todos the-todo-created))
(list-todos the-todos)))
(def todo-fns {"1" add-todo "2" delete-todo "3" list-todos "4" check-todo})
(defn execute-todo-cmd [command]
(get todo-fns command nil)))
(defn take-todo-command [backup-fn]
(let [command (read-line)]
(if (= command "q")
(print-msg :goodbye)
(let [todo-fn (execute-todo-cmd command)]
(if todo-fn
(todo-fn)
(do
(print-msg :sorry)
(print-msg :border)
(backup-fn)))))))
(defn run-app []
(do
(print-msg :welcome)
(print-msg-list '(:add-todo :list-todos :delete-todo :check-todo :quit))
;; The take-todo-command fn takes a backup in case the user types in
;; a command that's not supported by the application. In this case we just
;; want the app to restart
(take-todo-command run-app)))
答案 0 :(得分:1)
这只是在add-todo中错过了一个关闭的paren,并且在execute-todo-cmd中有一个额外的关闭。因此,在运行add-todo之前,execute-todo-cmd不存在,这就是它产生unbound-fn错误的原因。