静态类型如何限制宏?

发布于 2024-08-07 14:54:26 字数 331 浏览 2 评论 0原文

我正在读保罗·格雷厄姆的《百年语言》文章。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

摘星┃星的人 2024-08-14 14:54:26

静态类型并不排除宏。例如,静态类型的 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.

夜未央樱花落 2024-08-14 14:54:26

静态类型排除宏的说法并不正确,但它通常确实意味着宏系统需要比许多人熟悉的不卫生的文本替换宏更复杂。我不太确定格雷厄姆在这里想表达什么,或者他所说的“真正的”宏是什么意思。

请参阅本文了解一下关于静态类型上下文中的卫生宏。

(顺便说一句,我也不同意如果没有宏,任何语言都不值得使用。我认为一流的函数与一些更复杂的现代类型系统相结合可以优雅地解决宏所解决的大多数问题传统上都是针对的。)

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.)

风吹雪碎 2024-08-14 14:54:26

“静态类型似乎排除了真正的宏”
这是怎么回事?

如果没有“真正的宏”的定义,这是一个毫无意义的主张,但在 Paul Graham 写下这一点之前,OCaml 就拥有静态类型和(AST 重写)宏。他本可以很容易地自己发现这一点,但显然没有。我什至没有看到任何逻辑理由相信静态类型会排除宏。

论文在哪里?

我不知道有什么。 Lisp 风格的宏现在已经不流行了。

请记住,Paul Graham 是一名哲学专业学生,他用 Lisp 编写了一个购物车,该购物车被雅虎收购并随后重写。他赚到了金子,年轻时就退休了,然后花了数年时间写这样的东西。

"static typing seems to preclude true macros"
How is this true?

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.

Where are the papers?

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.

失与倦" 2024-08-14 14:54:26

Paul Graham 是“始终存在整个语言”的支持者:

读取时、编译时和运行时之间没有真正的区别
运行时。您可以在阅读、读取或运行代码的同时编译或运行代码
编译时,并在运行时读取或编译代码。

在读取时运行代码可以让用户重新编程 Lisp 的语法;跑步
编译时的代码是宏的基础;运行时编译是
Lisp 在类似程序中用作扩展语言的基础
Emacs;在运行时读取使程序能够使用
s-表达式,最近被重新发明为 XML 的一个想法。

因此,他可能指的是在运行时用一种期望在编译时拥有所有类型信息的语言定义新类型实际上是不可能的,正如 Daniel Ribeiro 在他的博客上指出

请注意,您无法在中进行类型安全的运行时元编程
一般的。例如:尽管某些语言允许您创建
编译时不存在的接口,调用的唯一方法
这些方法是通过非类型安全的方式(例如反射)实现的。

我确信您会毫不费力地找到那些质疑这种功能是否值得放弃从静态类型中获得的好处的程序员。

Paul Graham is a proponent of having "the whole language there all the time":

There is no real distinction between read-time, compile-time, and
runtime. You can compile or run code while reading, read or run code
while compiling, and read or compile code at runtime.

Running code at read-time lets users reprogram Lisp's syntax; running
code at compile-time is the basis of macros; compiling at runtime is
the basis of Lisp's use as an extension language in programs like
Emacs; and reading at runtime enables programs to communicate using
s-expressions, an idea recently reinvented as XML.

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:

Note that you cannot make type-safe runtime metaprogramming in
general. For instance: even though some languages allow you to create
interfaces that do not exist on compile time, the only way to invoke
methods from these is through non type-safe ways (such as reflection).

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.

拥抱我好吗 2024-08-14 14:54:26

静态类型(系统不推断类型)阻止了真正的通用宏,因为宏的输出必须在非常严格的意义上保持类型安全。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文