Clojure——调度宏特殊吗?
我想将调度宏包装在另一个中以保持清洁。然而,Clojure 似乎以不同的方式对待它......或者也许我误解了什么?让我们看一下简单地为#
创建别名的情况。
这可行:
(defmacro mkDef [x y] `~(list 'def x y))
但这不行:
(defmacro mkDispatch [x] `~(list '# x))
谢谢!!
PS 有足够代表的人:请创建一个语法宏标签;我希望能够更好地搜索类似的问题。
I wanted to wrap the dispatch macro in another for cleanliness. However, Clojure seems to treat it differently ... or perhaps I am misunderstanding something? Let's look at the case of simply making an alias for #
.
This works:
(defmacro mkDef [x y] `~(list 'def x y))
But this doesn't:
(defmacro mkDispatch [x] `~(list '# x))
Thanks!!
P.S. someone with enough rep: please create a syntax-macros tag; I'd love to be able to search for similar questions better.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#dispatch宏是一个reader宏,reader宏不能使用常规宏实现;它们由 (read) 而不是 (eval) 解释。
The # dispatch macro is a reader macro, and reader macros cannot be implemented using regular macros; they're interpreted by (read) instead of (eval).