Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 宏以查找包含该窗体的顶级窗体_Clojure - Fatal编程技术网

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变量,这使您可以访问本地绑定,但到目前为止还是空的。它必须是宏吗?强制和捕捉错误并检查堆栈跟踪是要考虑的事情吗?如果您想在宏扩展时间使用它,这对您没有什么好处。我更喜欢宏,但这对我来说是有效的。谢谢