hy 内置装饰器抛出名称错误:未定义名称'with_decorator'



我试图从我的手册运行with-decorator的例子(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 with下划线。我正在尝试使用hy的最新稳定版本。同样的事情发生在任何带有with-decorator的代码中。

我找到文档了。

(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))

我正在尝试使用最新的稳定版本。

with-decorator最近在master中被删除了,而它在0.20.0中仍然存在,所以我认为你错了。检查hy --version

最新更新