我是 Clojure 初学者。我有以下代码
(let [products "abc"]
(let [my-year (try
(if (or (nil? passed-in-year) (empty? passed-in-year))
(.get (java.util.Calendar/getInstance) java.util.Calendar/YEAR)
(let [year-num (Integer/parseInt passed-in-year)]
(if (and (>= year-num 1900) (<= year-num 2300))
year-num
(throw (RuntimeException. "Invalid Year input. Must be between 1900 and 2300.")))))
(catch Exception e
(r/bad-request (.getMessage e))))]
(r/created (.process (service/getProductProcessor) products my-year))))
基本上,它的作用是检查传入的年份字符串。如果为零,我们将使用当前年份。否则,尝试将其转换为整数以及年份数字是否有效(1900-2300)。如果不是,则响应错误请求 400。
但是,当我构建项目时,出现错误
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: my-year in this context, compiling:(com/my/code/my-service.clj:395:40)
java.lang.RuntimeException: Unable to resolve symbol: my-year in this context
有什么想法吗?
您的代码结构如下所示:
(let [a (let [b c] d)]
e)
错误消息抱怨
b
在 e
中未定义。这是真的,因为它只存在于 d
的乐谱中。
要解决这个问题,请将您的代码重写为类似的人
(let [a d,
b c]
e)