寻求人为的示例代码:延续!
所以我相信我现在至少在某种程度上理解了延续,这要归功于 社区计划维基 和 在固定天数内学习方案。
但我想要更多的练习——也就是说,我可以在脑海中完成更多的示例代码(最好是人为的,这样就不会出现无关的东西来分散对概念的注意力)。
具体,我想通过恢复和/或协程来解决更多问题,而不是仅仅使用它们来退出循环或其他什么(这相当简单)。
不管怎样,如果你知道除了我上面链接的教程之外的好教程,或者如果你愿意发布你写的一些东西,这将是一个很好的练习,我将非常感激!
So I believe I understand continuations now, at least on some level, thanks to the community scheme wiki and Learn Scheme in Fixnum Days.
But I'd like more practice -- that is, more example code I can work through in my head (preferably contrived, so there's not extraneous stuff to distract from the concept).
Specifically, I'd like to work through more problems with continuations that resume and/or coroutines, as opposed to just using them to exit a loop or whatever (which is fairly straightforward).
Anyway, if you know of good tutorials besides the ones I linked above, or if you'd care to post something you've written that would be a good exercise, I'd be very appreciative!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,继续下去可能会非常令人费解。 这是我不久前发现的一个很好的谜题 - 尝试找出打印的内容和原因:
解释它是如何工作的(包含剧透!):
call/cc
存储返回它自己的延续并存储它在k
中。1
被写入屏幕。1
再次写入screen2
被写入屏幕1
再次写入屏幕3
被写入屏幕因此,正确的输出是
11213
。 我用粗体文本表示的最常见的症结是 - 重要的是要注意,当您使用延续来“重置” k 的值时,它不会影响原始延续中的 k 值。 一旦你知道了,它就会变得更容易理解。Yeah, continuations can be pretty mind-bending. Here's a good puzzle I found a while back - try to figure out what's printed and why:
Explanation of how this works (contains spoilers!):
call/cc
stores returns it's own continuation and stores it ink
.1
is written to the screen.1
is written again to the screen2
is written to the screen1
is written again to the screen3
is written to the screenTherefore, the correct output is
11213
. The most common sticking point I've put in bold text - it's important to note that when you use continuations to 'reset' the value of k that it doesn't affect the value of k back in the original continuation. Once you know that it becomes easier to understand.布朗大学的编程语言课程有一个关于延续的问题 公开可用。
Brown University's programming languages course has a problem set on continuations publicly available.