gpt4 book ai didi

scala - 为什么定界的延续原语名为 “shift”和 “reset”?

转载 作者:行者123 更新时间:2023-12-03 08:49:33 29 4
gpt4 key购买 nike

我想我大致了解shiftreset的含义。但是我不明白为什么要这样命名?作为分隔连续原语的shiftreset与英语中的“shift”和“reset”单词有什么关系?

最佳答案

之所以这样称呼它们是因为它们的实现方式(通常)。

引用Direct Implementation of Shift and Reset in the MinCaml Compiler

By interpreting a program using the continuation semantics, we can regard the state of the program as a continuation stack. Then, reset can be thought of as marking the continuation stack, and shift capturing the continuation stack up to the nearest mark created by reset. Here is the overview of the implementation:

  • When calling reset, set a reset mark to the stack
  • When calling shift (fun k -> M), move a part of the stack frames up to the nearest reset mark to the heap
  • When calling a continuation k, set a reset mark to the stack and copy the corresponding frames from the heap to the stack top.

A reset mark is inserted when k is called, because captured continuations are executed in an empty continuation.

关于scala - 为什么定界的延续原语名为 “shift”和 “reset”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5989961/

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