从lein run执行此功能时,程序按预期执行。但我正在尝试使用atom.io的proto-repl包,当我使用proto-repl调用该函数时,它会给出一个" CompilerException java.lang.RuntimeException:无法解析符号:can-vote在这种情况下。" 这是我的功能:
(defn can-vote
[]
(println "Enter age: ")
(let [age (read-line)]
(let [new-age (read-string age)]
(if (< new-age 18) (println "Not old enough")))
(println "Yay! You can vote")))
答案 0 :(得分:11)
当你的repl启动时,它可能会让你进入user
命名空间。您需要移动到clojure-noob.core
命名空间或使用完全限定符号调用它。
如果要切换名称空间
(ns clojure-noob.core) ;; switch to the correct namespace
(can-vote) ;; call the function
如果您想使用用户名称空间中的完全限定符号
进行调用(require 'clojure-noob.core) ;; first require the namespace
(clojure-noob.core/can-vote) ;; call the fully qualified function
您可以阅读更多关于名称空间和从其他名称空间和库here调用函数的内容。