我写了一个宏来处理http响应
(defmacro defhandler
[name & args]
(let [[docstring args] (if (string? (first args))
[(first args) (next args)]
[nil args])
args (apply hash-map :execute-if true (vec args))]
`(do
(def ~name
(with-meta (fn [scope# promise#]
(let [e# (:execute-if ~args)
ei# (if (fn? e#)
(e# scope#)
(boolean e#))]
(when ei#
(.then promise# (fn [result#]
(let [{:strs [http-status# value#]} result#
the-func# ((keyword http-status#) ~args)]
(the-func# scope# value#))))))) {:structure ~args}))
(alter-meta! (var ~name) assoc :doc ~docstring))))
所以我可以做到
(defhandler my-handler
:200 (fn [$scope value] (set! (.-content $scope) value)))
但是在第1行抛出“UnmatchedDelimiter”,但如果我尝试使用命名函数:
(defn my-func [$scope value] (set! (.-content $scope) value))
(defhandler my-handler
:200 my-func)
一切正常。我只是好奇,这是正常的行为吗?
答案 0 :(得分:0)
这不是我在尝试你的例子时看到的行为,也不是很可能。我建议检查您粘贴的表单完全产生错误的表单;我怀疑你的实际匿名函数包含了太多)
s。