gpt4 book ai didi

scheme - R6RS 的 `letrec` 、 `letrec*` 和 Racket 的 `letrec` 有什么区别?

转载 作者:行者123 更新时间:2023-12-04 17:49:37 26 4
gpt4 key购买 nike

两者 letrecletrec*在 R6RS 中,但有 only letrec在 Racket 中,没有 letrec* .这些之间有什么区别?

最佳答案

总之 Racket letrec和 R6RS letrec*是一样的。
评估顺序是为这些指定的。
在 R5RS letrec订单未指定。

由于R5RS的订单letrec是未指定的实现可以选择
一个固定的顺序(例如从左到右)或者他们可以让编译器
为每次使用选择不同的顺序(以获得更快的代码)。

来自 Racket 文档。

R5RS letrec :

Semantics: The < variable>s are bound to fresh locations holding undefined values, the < init>s are evaluated in the resulting environment (in some unspecified order), each < variable> is assigned to the result of the corresponding < init>, the < body> is evaluated in the resulting environment, and the value(s) of the last expression in < body> is(are) returned. Each binding of a < variable> has the entire letrec expression as its region, making it possible to define mutually recursive procedures.



Racket letrec :

Like let, including left-to-right evaluation of the val-exprs, but the locations for all ids are created first and filled with #< undefined>, all ids are bound in all val-exprs as well as the bodys, and each id is set immediately after the corresponding val-expr is evaluated. The ids must be distinct according to bound-identifier=?.



R6RS letrec* :

Semantics: The < variable>s are bound to fresh locations, each < variable> is assigned in left-to-right order to the result of evaluating the corresponding < init>, the < body> is evaluated in the resulting environment, and the values of the last expression in < body> are returned. Despite the left-to-right evaluation and assignment order, each binding of a < variable> has the entire letrec* expression as its region, making it possible to define mutually recursive procedures.

关于scheme - R6RS 的 `letrec` 、 `letrec*` 和 Racket 的 `letrec` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20440688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com