我试图运行hy手册(https://docs.hylang.org/en/stable/language/api.html?highlight=with-decorator#with-decorator)中的“去皮质激素”示例:
(defn inc-decorator [func]
(fn [value-1 value-2] (func (+ value-1 1) (+ value-2 1))))
(with-decorator inc-decorator (defn addition [a b] (+ a b)))
(setv foo (addition 1 1))
(print foo)但我有个例外:
line 4, in <module>
(with-decorator inc-decorator (defn addition [a b] (+ a b)))
NameError: name 'with_decorator' is not defined带有下划线的with_decorator。我在尝试最新的稳定版本的hy。同样的情况也发生在任何带有-装饰符的代码中。
发布于 2022-05-18 12:10:09
,我正在尝试使用最新的稳定版本的hy。
with-decorator最近在master中被移除,而它在0.20.0中仍然存在,所以我认为您弄错了。检查hy --version。
发布于 2022-05-18 20:23:32
我找到文件了。
(with-decorator (app.route "/") (defn index [] "Hello World !"))在早期版本中起作用的操作现在如下所示:
(defn [(.route app "/")] index [] "Hello World !")和
(with-decorator (inc-decorator (defn addition [a b] (+ a b)))是现在
(defn [inc-decorator] addition [a b] (+ a b))https://stackoverflow.com/questions/72285808
复制相似问题