Python 等同于 Ruby 的延续

标签 python ruby continuations

Ruby 中以下代码的 Python 等价物是什么?

def loop
  cont=nil
  for i in 1..4
    puts i
    callcc {|continuation| cont=continuation} if i==2
  end
  return cont
end

> c=loop
1
2
3
4
> c.call
3
4

引用:Secrets of lightweight development success, Part 9: Continuations-based frameworks

最佳答案

您引用的文章包含指向 Continuations Made Simple And Illustrated 的链接在引用资料部分,讨论 Python 语言中的延续。

关于Python 等同于 Ruby 的延续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/312794/

相关文章:

haskell - 我怎样才能继续实现这个monad转换器?

python - 为什么网站上的简单模型链示例正在计算负交流功率?

ruby - 在不同服务器上执行多项任务的作业

ruby - Ruby 中的阴阳拼图

css - 如何在 nokogiri css 选择器中使用 ruby​​ 表达式插值 "#{var}"?

ruby - Sinatra 与 Postgres 和 ActiveRecord |推送到 Heroku 时出错是 : Invalid DATABASE_URL

Scala 延续 : many shifts in sequence

python - 如何有效地对 Pandas 中的列和分组进行分类?

python - Django 提示查询必须在子查询中使用,当它在子查询中使用时

python - 非唯一索引上的 Index._join_level 未实现