我在 Clojure 中有一个简单但令人沮丧的问题,我有一个函数(我们称之为 read-function),它可以从他的输入中找出用户想要做什么,然后调用另一个执行该操作的函数(我们称之为 action-function)。此操作函数在完成后调用读取函数,以便用户可以执行另一个任务。
现在我的问题是,如果我将 read-function 的代码放在 action-function 的代码之前,我会在 read-function 中得到一个错误,说它不知道 action-function 是什么(因为它的代码更进一步下),如果我做相反的事情,那么我显然会收到类似的错误,说无法解析读取功能等。
有没有简单的方法来解决这个问题?
实际代码:
(defn ajout [botin]
(def botin botin)
(readCmd botin)
)
(defn readCmd [botin]
(println "Entrez une commande svp ")
(def botin botin)
(let [cmd (read-line)]
(if (.equals cmd "a") ((println "Ajout 8o") (ajout botin))
(if (.equals cmd "e") ((println "Elim 8o") (eliminer botin))
(if (.equals cmd "i") ((println "Imprim 8o") (imprimer botin))
((println "Commande invalide, nous vous rapellons que les commandes possibles sont : ") (print-les-cmd) (readCmd))))))
)
像这样,我在 ajout 函数的 (readCmd botin) 行收到错误消息:无法解析符号:在此上下文中的 readCmd
如果我将这两个函数的代码以相反的顺序放置,我会收到一条错误消息:无法解析符号:在此上下文中的 ajout