Racket 与Scheme 有何不同?
Racket 是Scheme 的后代。 Racket 与 R6RS 有何不同?它添加了什么,删除了什么,或者只是有所不同?
我知道 Racket 不仅仅是一种语言,它还是一个语言平台。但我指的是主要的 Racket 方言。
Racket is a descendant of Scheme. How is Racket different than R6RS? What did it add, or take away, or is just different?
I understand that Racket is more than a language, it's a platform for languages. But I'm referring to the main Racket dialect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Racket 最终基于 R5RS,而不是 R6RS,也不是两者的严格超集。我不认为它可以被称为“Scheme”,因为它不向后兼容任何Scheme 标准。
大多数实现都提供扩展,但在其他方面都向后兼容,当然,Racket 附带的编译器也可以在 R5RS 或 R6RS 模式下运行。在球拍模式下运行的有效 R5/6RS 方案可能会被拒绝、导致运行时错误或行为与应有的不同。话虽如此,它不向后兼容的要点是:
set-cdr!
和set-car!
,而是set-mcar!
仅适用于专门创建为可变的对。letrec
在R6RS中称为letrec*
,在R5RS中不存在,R5RS和R6RS中调用的letrec
在R5RS中不存在球拍。最重要的是空列表。( ... )
和[ ... ]
视为等效,R5RS 不这样做,但 R6RS 这样做。可能还有更多,但在大多数其他部分,racket 是Scheme 的超集。
Racket is ultimately based on R5RS, and not R6RS and not a strict superset of either. I don't think it can be called 'Scheme' because it's not backwards compatible with any Scheme standard.
Most implementations offer extensions, but are otherwise backwards compatible, of course, the compiler that comes with Racket can also run in R5RS or R6RS mode. Valid R5/6RS Scheme that runs in racket mode may either be rejected, cause runtime errors, or behave differently than it should. With that said, the main points where it is not backwards compatible are:
set-cdr!
andset-car!
, ratherset-mcar!
which only works on pairs specifically created as mutable.letrec
is calledletrec*
in R6RS and doesn't exist in R5RS, what R5RS and R6RS callletrec
doesn't exist in Racket.most importantly the empty list.( ... )
and[ ... ]
as equivalent, R5RS does not, but R6RS does.There are probably more, but on most other parts racket is a superset of Scheme.
如上所述,它包含不可变列表。它还包含一个比 R6RS 记录系统更干净的结构系统。它有一个面向对象的类和对象系统。它具有对合同设计的本机支持。它有一个让人想起ML模块系统的单元系统,以及一个很像R6RS模块系统的模块系统。我确信我已经忘记了我提到过的很多事情。
我不确定重命名除了营销噱头之外还有什么用处,但球拍绝对是一种独特的方案方言。
It contains immutable lists, as mentioned above. It also contains a structure system that is a bit cleaner than the R6RS record system. It has an object oriented class and object system. It has native support for design by contract. It has a unit system reminiscent of the ML module system, as well as a module system much like the R6RS module system. I'm sure I've forgotten as many things as I've mentioned.
I'm not sure that the rename was useful as anything other than a marketing gimmick, but racket is definitely a distinct dialect of scheme.
Racket 网站讨论了从 PLT 方案更名为 Racket 的理由。
The rationale for the name-change from PLT Scheme to Racket is discussed on the Racket site.
Scheme编程语言的语言规范R5RS基于多个Scheme实现者之间的共识。这意味着该语言非常稳定。这也意味着许多有用的功能并不属于 R5RS 标准的一部分。
Racket 以 R5RS 为基础,并对其进行了极大的扩展。有些扩展被定义为宏,但有些功能需要运行时系统的支持。
Racket 中的功能不能单独通过宏实现:
模块和宏系统比 RnRS 规范更通用。
与
#lang
阅读器/语言规范一起,可以定义自定义语言(使用自定义语法)并将其与普通 Racket 程序一起使用。在少数情况下,Racket 的构造的行为与 R5RS 不同。最明显的一个是让
cons
构造一个不可变对(mcons
构造一个可变对)。具有不可变对的一个优点是length
现在运行时间为 O(1) 摊销时间。The language specification R5RS on the Scheme programming language is based on consensus between the multiple Scheme implementors. This imply that the language is very stable. It also implies that many useful features are not part of the R5RS standard.
Racket has built upon R5RS and extended it greatly. Some extensions are defined as macros, but some features require the support of the runtime system.
Features in Racket not implementable by macros alone:
The module and macro system are much more general than the RnRS specification.
Together with
#lang
reader/language specification makes it possible to define custom languages (with custom syntax) and use them with normal Racket programs.In a few cases Racket has constructs whose behaviour deviates from R5RS. The most obvious one is making
cons
construct an immutable pair (mcons
constructs a mutable pair). One advantage of a having immutable pairs, is thatlength
now runs in O(1) amortized time.Racket 包含许多 R6RS 方案中未包含的非常好的语言结构,例如 "match"。
Racket includes a lot of really nice language constructs not included in R6RS scheme, like "match".
举一个重要的例子,默认情况下,Racket 列表是不可变的,而 Scheme 列表是可变的。 Racket还包括许多其他Scheme没有的标准库(例如Web Server)。
For one big example, Racket lists are immutable by default whereas Scheme's are mutable. Racket also includes a lot of standard libraries (e.g. Web Server) that other Schemes do not.