开发者

Clojure -- is the dispatch macro special?

开发者 https://www.devze.com 2023-03-14 12:29 出处:网络
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

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 fo开发者_开发知识库r similar questions better.


The # dispatch macro is a reader macro, and reader macros cannot be implemented using regular macros; they're interpreted by (read) instead of (eval).

0

精彩评论

暂无评论...
验证码 换一张
取 消