【问题标题】:Syntax error macroexpanding clojure.core/let宏扩展 clojure.core/let 的语法错误
【发布时间】:2019-03-08 22:02:20
【问题描述】:

我正在使用 shadowcljs,我正在尝试使用基于示例代码的代码在服务器上创建一个突变。我有一个非常小的突变,总是抛出这个错误。这是为什么呢?

[jchat.server-components.pathom-wrappers :refer [defmutation defresolver]]

(defmutation reset-users-db
             "Removes all users"
             []
             {::pc/output [:message]}
             {:message "ok"})

在 (user.clj:47:1) 处宏扩展 clojure.core/let 时出现语法错误。无 - 失败:简单符号?在: [:bindings :form :local-symbol] 规范: :clojure.core.specs.alpha/local-name nil - 失败:向量?在: [:bindings :form :seq-destructure] 规范: :clojure.core.specs.alpha/seq-binding-form nil - 失败:映射?在: [:bindings :form :map-destructure] 规范: :clojure.core.specs.alpha/map-bindings nil - 失败:地图?在: [:bindings :form :map-destructure] 规范: :clojure.core.specs.alpha/map-special-binding

第 47 行是 defmutation 的起始行。

macroexpand:

(macroexpand '(defmutation reset-users-db
                           "Removes all users"
                           []
                           {::pc/output [:message]}
                           {:message "ok"}))
=>
(do
 (com.wsscode.pathom.connect/defmutation
  reset-users-db
  [env__26870__auto__ params__26871__auto__]
  #:com.wsscode.pathom.connect{:output [:message]}
  (clojure.core/let [nil env__26870__auto__ nil params__26871__auto__] {:message "ok"}))
 (jchat.server-components.pathom-wrappers/register! reset-users-db))

【问题讨论】:

  • 尝试将其封装在对macroexpand 的调用中,看看它是否会扩展为一些奇怪的东西。我以前从未听说过那个宏。
  • 我已经用宏扩展更新了我的问题。
  • 可能是(clojure.core/let [nil env__26870...(let [nil ""]) 在 1.7.0 中导致 <CompilerException java.lang.Exception: Unsupported binding form: , compiling:(Clojure REPL:2:1)>。我不知道为什么 nil 会出现在扩展包中,但这是你的问题。
  • 哦,它需要 2 in params。这就是为什么那些nil 在那里。谢谢。
  • 我很高兴你知道了。如果可以,请发布一个快速答案,解释问题所在。

标签: clojure


【解决方案1】:

感谢 Carcigenicate 帮助我调试和理解调试我们发现突变需要 2 in params。

如:

(defmutation reset-users-db
             "Removes all users"
             [env params]
             {::pc/output [:message]}
             (println "test"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 2014-03-28
    • 2015-05-08
    相关资源
    最近更新 更多