为什么大多数 S-Expression 语言都是动态类型的?

发布于 2024-09-03 14:30:30 字数 55 浏览 1 评论 0原文

为什么大多数Lisp 和Scheme 都是动态类型的? 静态类型不会与它们的一些常见功能混合吗?

How come most Lisps and Schemes are dynamically typed?
Does static typing not mix with some of their common features?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

永不分离 2024-09-10 14:30:30

键入和 s 表达式可以一起使用,请参阅键入方案

s-表达式语言是动态类型的,部分原因是历史巧合。这些语言往往更加依赖,并且 s 表达式易于解析和模式匹配使得宏处理变得更加容易。大多数对复杂宏的研究都是在 s 表达式语言中进行的。

类型卫生宏很难。

Typing and s-expressions can be made to work together, see typed scheme.

Partly it is a historical coincidence that s-expression languages are dynamically typed. These languages tend to rely more heavily on macros, and the ease of parsing and pattern-matching on s-expressions makes macro processing much easier. Most research on sophisticated macros happens in s-expression languages.

Typed Hygienic Macros are hard.

海夕 2024-09-10 14:30:30

当 Lisp 在 1958 年到 1960 年间发明时,它引入了许多作为语言和实现的功能(垃圾收集、自托管编译器……)。一些功能是从其他语言继承的(有一些改进)(列表处理,...)。该语言通过函数实现计算。 s-表达式更多的是一个实现细节(当时),而不是一个语言功能。类型系统不是语言的一部分。以交互方式使用该语言也是早期的实现功能。

当时尚未发明适用于函数式语言的有用类型系统。直到今天,以交互方式使用静态类型语言仍然相对困难。有许多静态类型语言的实现也提供了一些交互界面 - 但大多数情况下它们不提供与典型 Lisp 系统相同级别的交互使用支持。在交互式 Lisp 系统中编程意味着许多事情可以即时更改,如果类型更改必须通过此类交互式 Lisp 系统中的整个程序和数据传播,则可能会出现问题。请注意,一些策划者对这些事情有不同的看法。 R6RS 主要是一种批处理语言,通常不太符合 Lisp 的精神...

后来通过静态类型系统发明的函数式语言也获得了非 s 表达式语法 - 它们不提供对宏或相关功能的支持。后来,其中一些语言/实现使用了预处理器来进行语法扩展。

When Lisp was invented in the years from 1958 to 1960 it introduced a lot of features both as a language and an implementation (garbage collection, a self-hosting compiler, ...). Some features were inherited (with some improvements) from other languages (list processing, ...). The language implemented computation with functions. The s-expressions were more an implementation detail ( at that time ), than a language feature. A type system was not part of the language. Using the language in an interactive way was also an early implementation feature.

The useful type systems for functional languages were not yet invented at that time. Still until today it is also relatively difficult to use statically typed languages in an interactive way. There are many implementations of statically typed languages which also provide some interactive interface - but mostly they don't offer the same level of support of interactive use as a typical Lisp system. Programming in an interactive Lisp system means that many things can be changed on the fly and it could be problematic if type changes had to be propagated through whole programs and data in such an interactive Lisp system. note that Some Schemers have a different view about these things. R6RS is mostly a batch language generally not that much in the spirit of Lisp...

The functional languages that got invented later with static type systems then also got a non-s-expression syntax - they did not offer support for macros or related features. later some of these languages/implementations used a preprocessor for syntactic extensions.

如此安好 2024-09-10 14:30:30

静态类型是词法的,这意味着有关类型的所有信息都可以从阅读源代码中推断出来,而无需评估任何表达式或计算任何东西,条件在这里最重要。静态类型语言的设计就是为了实现这种情况,更好的术语是“词法类型”,例如,编译器可以通过单独读取源代码来证明不会发生类型错误。

就 lisp 而言,这是一个尴尬的不同,因为 lisp 的源代码本身不是静态的,lisp 是同源标志的,它使用数据作为代码,并且可以在某种程度上动态编辑自己的运行源代码。

Lisp 是第一个动态类型语言,可能正是因为这个原因,程序代码本身在 Lisp 中不再是词法的。

编辑:一个更强大的原因,在静态类型的情况下,你必须输入列表。您可以为每个包含所有元素的列表设置极其复杂的类型,要求每个元素具有相同的类型并将其键入为该列表。前一个选项会产生列表列表的地狱。后一个选项要求源代码仅包含每个数据的相同类型,这意味着您甚至无法构建表达式,因为列表无论如何都是与整数不同的类型。

所以我敢说这是完全不可能实现的。

Static typing is lexical, it means that all information about types can be inferred from reading source code without evaluating any expressions or computing any things, conditionals being most important here. A statically typed language is designed so that this can happen, a better term would be 'lexically typed', as in, a compiler can prove from reading the source alone that no type errors will occur.

In the case of lisp, this is awkwardly different because lisp's source code itself is not static, lisp is homo-iconic, it uses data as code and can to some extend dynamically edit its own running source.

Lisp was the first dynamically typed language, and probably for this reason, program code itself is no longer lexical in Lisp.

Edit: a far more powerful reason, in the case of static typing you'd have to type lists. You can either have extremely complex types for each lists which account for all elements, of demand that each element has the same type and type it as a list of that. The former option will produce hell with lists of lists. The latter option demands that source code only contains the same type for each datum, this means that you can't even build expressions as a list is anyhow a different type than an integer.

So I dare say that it is completely and utterly infeasible to realize.

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