静态类型如何限制宏?
我正在读保罗·格雷厄姆的《百年语言》文章。
http://www.paulgraham.com/hundred.html
在那里他声称静态输入“排除真正的宏”。
例如,类型似乎是 取之不尽、用之不竭的研究资源 论文,尽管事实上静态 打字似乎排除了真正的宏—— 在我看来,没有它,就没有 语言是值得使用的。
这怎么是真的呢?论文在哪里?我尝试在谷歌上搜索但没有成功。
I was reading Paul Graham's "The Hundred-Year Language" article.
http://www.paulgraham.com/hundred.html
In there he makes a claim that static typing "preclude[s] true macros".
For example, types seem to be an
inexhaustible source of research
papers, despite the fact that static
typing seems to preclude true macros--
without which, in my opinion, no
language is worth using.
How is this true? Where are the papers? I tried searching on Google without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
静态类型并不排除宏。例如,静态类型的 Boo 语言具有宏。 Nemerle 也是如此。
然而,这取决于格雷厄姆所说的“真正的”宏是什么意思。也许 Boo 和 Nemerle 宏按照他的标准是“错误的”。
Static typing doesn't preclude macros. For example, the static-typed Boo language has macros. So does Nemerle.
However, it depends on what Graham means by "true" macros. Maybe Boo and Nemerle macros are "false" by his standards.
静态类型排除宏的说法并不正确,但它通常确实意味着宏系统需要比许多人熟悉的不卫生的文本替换宏更复杂。我不太确定格雷厄姆在这里想表达什么,或者他所说的“真正的”宏是什么意思。
请参阅本文了解一下关于静态类型上下文中的卫生宏。
(顺便说一句,我也不同意如果没有宏,任何语言都不值得使用。我认为一流的函数与一些更复杂的现代类型系统相结合可以优雅地解决宏所解决的大多数问题传统上都是针对的。)
It isn't really true that static typing precludes macros, but it generally does mean that the macro system needs to be more complicated than the unhygienic text-substitution macros familiar to many. I'm not exactly sure what Graham is trying to get at here, or what he means by "true" macros.
See this paper for one take on hygienic macros in a statically typed context.
(Incidentally, I also don't agree that no language is worth using if it doesn't have macros. I think that first-class functions coupled with some of the more sophisticated modern type systems can elegantly solve most of the problems at which macros have traditionally been aimed.)
如果没有“真正的宏”的定义,这是一个毫无意义的主张,但在 Paul Graham 写下这一点之前,OCaml 就拥有静态类型和(AST 重写)宏。他本可以很容易地自己发现这一点,但显然没有。我什至没有看到任何逻辑理由相信静态类型会排除宏。
我不知道有什么。 Lisp 风格的宏现在已经不流行了。
请记住,Paul Graham 是一名哲学专业学生,他用 Lisp 编写了一个购物车,该购物车被雅虎收购并随后重写。他赚到了金子,年轻时就退休了,然后花了数年时间写这样的东西。
Without a definition of "true macros" it is a meaningless claim but OCaml had both static typing and (AST-rewriting) macros before Paul Graham wrote that. He could easily have discovered that for himself but apparently did not. I don't even see a logical reason to believe that static typing precludes macros.
I do not know of any. Lisp-style macros are unfashionable these days.
Bear in mind that Paul Graham is a philosophy major who wrote a shopping cart in Lisp that was bought by Yahoo and subsequently rewritten. He struck gold, retired young and then spent years writing stuff like this.
Paul Graham 是“始终存在整个语言”的支持者:
因此,他可能指的是在运行时用一种期望在编译时拥有所有类型信息的语言定义新类型实际上是不可能的,正如 Daniel Ribeiro 在他的博客上指出:
我确信您会毫不费力地找到那些质疑这种功能是否值得放弃从静态类型中获得的好处的程序员。
Paul Graham is a proponent of having "the whole language there all the time":
So he may be referring to the practical impossibility of defining new types at runtime in a language that expects to have all the type information at compile time, as Daniel Ribeiro points out on his blog:
I am sure that you would have no trouble finding programmers who dispute that this capability is worth giving up the benefits that they derive from static typing.
静态类型(系统不推断类型)阻止了真正的通用宏,因为宏的输出必须在非常严格的意义上保持类型安全。
Static typing, in which the system does not infer types, prevents truly general-purpose macros as the output of macros must remain type-safe in a very restrictive sense.