如何在Squeak中获得BlockClosure(我想使用BlockClosure>> callCC)?

当我写[#foo]这是一个BlockContext时,这是什么交易?

更新:我已经知道BlockClosure主要是新编译器。

相反,我如何使用海边Continuations?我遇到了问题,任何例子都会受到赞赏。

进一步更新:这样做的目的不是使用海边(至少不是直接),而是以比滚动我自己的状态跟踪迭代器更容易的方式编写遍历和其他类似的东西。

有帮助吗?

解决方案

通常情况下,在Seaside,您根本不需要自己处理Continuations。

您只需在组件中使用 #call: #answer:

如果您尝试使用 Continuation 执行其他操作,而不是编写Seaside应用程序,请查看 WAComponent>> call:以获取使用示例

或试试这个。打开Transcript窗口。现在,在Workspace中,一次选择所有这些代码,然后选择Do-it:

continuation := nil.
result := Continuation currentDo: [:cc |
   "store the continuation, cc, somewhere for later use"
   continuation := cc.
   1 ].

Transcript show: result.

您应该会在Transcript窗口中看到 1 。现在,在工作区中,执行:

continuation value: 2

然后:

continuation value: 3

您应该看到传递给Transcript中的 continuation 传递的每个值,因为传递给#value的每个值都会导致继续的上下文被恢复,并且新的值被赋值给结果

希望这有助于......

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top