我有很多“乐趣”,试图理解为什么以下内容不起作用。src
在我的项目目录中启动 nREPL 会话后lein
,我执行了以下操作:
user> (require 'animals.core)
nil
user> (animals.core/-main)
"Welcome to Animals!"
nil
user> (require 'animals.animal)
nil
user> (extends? animals.animal/Animal animals.animal/Dog)
CompilerException java.lang.RuntimeException: No such var: animals.animal/Dog, compiling:(NO_SOURCE_PATH:1:1)
阅读 Lein 教程,我的基本理解是我应该像这样放置我的源代码:
- src/
|____ animals/
|_______ core.clj
|_______ animal.clj
下面动物的内容如下所示:
(ns animals.animal)
(defprotocol Animal
"A protocol for animal move behavior."
(move [this] "Method to move."))
(defrecord Dog [name species]
Animal
(move [this] (str "The " (:name this) " walks on all fours.")))
(defrecord Human [name species]
Animal
(move [this] (str "The " (:name this) " walks on two legs.")))
(defrecord Arthropod [name species]
Animal
(move [this] (str "The " (:name this) " walks on eight legs.")))
(defrecord Insect [name species]
Animal
(move [this] (str "The " (:name this) " walks on six legs.")))
Dog
为什么在评估没有错误时尝试评估会Animal
导致运行时异常?如何正确地做到这一点?