为什么clojurescript宏不能在clojurescript中写? [英] Why clojurescript macros can't be written in clojurescript?

查看:131
本文介绍了为什么clojurescript宏不能在clojurescript中写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然clojure和clojurescript功能基本相同(除了明显的差异),宏不是。当我想要一个宏在clojurescript我必须写在clojure和需要它与require-macros。这是JavaScript的技术限制还是只是一个设计决定?为什么两者不能相同?

While clojure and clojurescript features are basically the same (apart from obvious differences), macros are not. When I want a macro in clojurescript I have to write it in clojure and require it with require-macros. Is that a technical limitation of javascript or just a design decision? Why can't both be the same?

推荐答案

ClojureScript:Up and Running by Stuart Sierra and Luker VanderHart,page 69:

From ClojureScript: Up and Running by Stuart Sierra and Luker VanderHart, page 69:


宏在编译过程中应用。它们在运行时不存在
。因为
ClojureScript编译器在Clojure中实现,ClojureScript宏必须在Clojure中写为
,而不是ClojureScript。幸运的是,当涉及到操作数据结构时,Clojure和ClojureScript几乎是相同的,所以在两种语言之间切换是
并不困难。

Macros are applied during the compilation process. They do not exist at runtime. Because the ClojureScript compiler is implemented in Clojure, ClojureScript macros must be written in Clojure, not ClojureScript. Fortunately, Clojure and ClojureScript are almost identical when it comes to manipulating data structures, so switching between the two languages is not difficult.

这意味着宏代码在Clojure世界中执行,而不是在浏览器中执行,所以它必须以Clojure的纯文本编写。

What that means is that macro code gets executed in Clojure world and not in the browser, so it must be written in plain Clojure.

这篇关于为什么clojurescript宏不能在clojurescript中写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆