Clojure 宏以查找包含该窗体的顶级窗体
有没有办法用宏访问顶级窗体?大意是:Clojure 宏以查找包含该窗体的顶级窗体,clojure,Clojure,有没有办法用宏访问顶级窗体?大意是: (defmacro which-defn [] ....) (defn hello [] (which-defn)) (defn world [] (which-defn)) (hello) => 'hello (world) => 'world 已经存在于中。您不需要宏: (ns tst.demo.core (:use tupelo.core tupelo.test) (:require [tupelo.mis
(defmacro which-defn []
....)
(defn hello []
(which-defn))
(defn world []
(which-defn))
(hello) => 'hello
(world) => 'world
已经存在于中。您不需要宏:
(ns tst.demo.core
(:use tupelo.core tupelo.test)
(:require [tupelo.misc :as misc]))
(defn hello []
(misc/fn-info))
(dotest
(is= (hello)
{:class-name "tst.demo.core$hello",
:file-name "core.clj",
:method-name "invokeStatic",
:line-num 6,
:ns-name "tst.demo.core",
:fn-name "hello"}))
虽然宏在编译时可以访问特殊&env变量,这使您可以访问本地绑定,但到目前为止还是空的。它必须是宏吗?强制和捕捉错误并检查堆栈跟踪是要考虑的事情吗?如果您想在宏扩展时间使用它,这对您没有什么好处。我更喜欢宏,但这对我来说是有效的。谢谢