如何阅读 Clojure 的规范:宏语法检查错误

How to read Clojure's spec :macro-syntax-check errors

我从 "Joy of Closure" 第 12.2.1 章

复制了以下 joy.gui.DynaFrame 定义
(ns joy.gui
  (:gen-class
   :name joy.gui.DynaFrame
   :extends javax.swing.JFrame
   :implements [clojure.lang.IMeta]
   :prefix df-
   :state state
   :init init
   :constructors {[String] [String]
                  [] [String]}
   :methods [[display [java.awt.Container] void]
   ^{:static true} [version [] String]]
   )
  (:import (javax.swing JFrame JPanel JComponent)
           (java.awt BorderLayout Container)))

不幸的是,:prefix 的语法自 2014 年以来显然发生了变化,因此第 6 行应显示为 :prefix "df-"

评估上面的错误代码我收到以下错误消息:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling src/dipping_feet/gui.clj at (1:1)
   #:clojure.error{:phase :macro-syntax-check,
                   :line 1,
                   :column 1,
                   :source

1. Caused by clojure.lang.ExceptionInfo
   Call to clojure.core/ns did not conform to spec.
   #:clojure.spec.alpha{:problems
                        [{:path [],
                          :reason "Extra input",
                          :pred
                          (clojure.spec.alpha/cat
                           :docstring
                           (clojure.spec.alpha/? clojure.core/string?)
                           :attr-map
                           (clojure.spec.alpha/? clojure.core/map?)
                           :ns-clauses
                           :clojure.core.specs.alpha/ns-clauses),
                          :val
                          ((:gen-class
                            :name
                            joy.gui.DynaFrame
                            :extends
                            javax.swing.JFrame
                            :implements
                            [clojure.lang.IMeta]
                            :prefix
                            df-
                            :state
                            state
                            :init
                            init
                            :constructors
                            {[String] [String], [] [String]}
                            :methods
                            [[display [java.awt.Container] void]
                             [version [] String]])
                           (:import
                            (javax.swing JFrame JPanel JComponent)
                            (java.awt BorderLayout Container))),
                          :via [:clojure.core.specs.alpha/ns-form],
                          :in [1]}],
                        :spec
                        #object[clojure.spec.alpha$regex_spec_impl$reify__2509 0x3b982314 "clojure.spec.alpha$regex_spec_impl$reify__2509@3b982314"],
                        :value
                        (joy.gui
                         (:gen-class
                          :name
                          joy.gui.DynaFrame
                          :extends
                          javax.swing.JFrame
                          :implements
                          [clojure.lang.IMeta]
                          :prefix
                          df-
                          :state
                          state
                          :init
                          init
                          :constructors
                          {[String] [String], [] [String]}
                          :methods
                          [[display [java.awt.Container] void]
                           [version [] String]])
                         (:import
                          (javax.swing JFrame JPanel JComponent)
                          (java.awt BorderLayout Container))),
                        :args
                        (joy.gui
                         (:gen-class
                          :name
                          joy.gui.DynaFrame
                          :extends
                          javax.swing.JFrame
                          :implements
                          [clojure.lang.IMeta]
                          :prefix
                          df-
                          :state
                          state
                          :init
                          init
                          :constructors
                          {[String] [String], [] [String]}
                          :methods
                          [[display [java.awt.Container] void]
                           [version [] String]])
                         (:import
                          (javax.swing JFrame JPanel JComponent)
                          (java.awt BorderLayout Container)))}

我在这里省略了堆栈跟踪。

我的问题是:错误消息中是否有引用可以指出代码中错误的确切位置?我不得不基本上猜测我的定义的哪一部分是不正确的。

是的,我同意,这是一条令人困惑的错误消息。这似乎是规范中的一个错误,所以不幸的是,我认为此时您无法做任何事情来改善错误。

https://clojure.atlassian.net/browse/CLJ-2013?oldIssueView=true