与海边延续合作

Mar*_*cin 2 continuations smalltalk callcc squeak seaside

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

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

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

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

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

Jul*_*ian 7

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

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

如果您正在尝试使用Continuation除了编写Seaside应用程序之外的其他操作,请查看WAComponent>>call:使用示例.

或试试这个.打开Transcript窗口.现在,在Workspace中,立即选择所有这些代码并执行操作:

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

Transcript show: result.
Run Code Online (Sandbox Code Playgroud)

您应该看到1在Transcript窗口中显示.现在,在工作区中,执行:

continuation value: 2
Run Code Online (Sandbox Code Playgroud)

然后:

continuation value: 3
Run Code Online (Sandbox Code Playgroud)

您应该看到传递给continuationTranscript的每个值都显示,因为传递给#value的每个值都会导致延续上下文并分配新值result.

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