{"id":16658565,"url":"https://github.com/mveytsman/delimr","last_synced_at":"2026-04-20T08:33:26.149Z","repository":{"id":18604901,"uuid":"21809945","full_name":"mveytsman/DelimR","owner":"mveytsman","description":"Delimited continuations for Ruby","archived":false,"fork":false,"pushed_at":"2014-07-14T20:50:27.000Z","size":128,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-26T20:11:50.558Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mveytsman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-14T06:39:26.000Z","updated_at":"2017-09-27T19:45:02.000Z","dependencies_parsed_at":"2022-09-25T01:02:08.423Z","dependency_job_id":null,"html_url":"https://github.com/mveytsman/DelimR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mveytsman/DelimR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mveytsman%2FDelimR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mveytsman%2FDelimR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mveytsman%2FDelimR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mveytsman%2FDelimR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mveytsman","download_url":"https://codeload.github.com/mveytsman/DelimR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mveytsman%2FDelimR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32040205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T10:05:56.411Z","updated_at":"2026-04-20T08:33:26.126Z","avatar_url":"https://github.com/mveytsman.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DelimR\n\n*For background information, see this [blog post](http://blog.ontoillogical.com/blog/2014/07/12/delimited-continuations-in-ruby/).*\n\nImplements [delimited continuations](https://en.wikipedia.org/wiki/Delimited_continuation) in Ruby. This is a direct port of Oleg Kselyov's Scheme [implementation](http://okmij.org/ftp/continuations/implementations.html#delimcc-scheme).\n\nThis is an experiment. Ruby continuations are [considered harmful](http://www.atdot.net/~ko1/pub/ContinuationFest-ruby.pdf). By the way, I want to take a minute to point out that this talk was at something called \"Continuation Fest 2008\", and calls Matz out for being a \"criminal.\"\n\nTL;DR: Don't use this for anything \"serious.\"\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'delimr'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install delimr\n\n## Usage\n\nTODO: make this clearer\n\nDelimited continuations can be a bit tricky. Basically, `DelimR.prompt` takes a block and marks the boundary of the continuation. Inside `DelimR.prompt`, you can call `DelimR.control` which takes a block with a single argument. That argument is a *function* which represents the rest of the computation around the `DelimR.control` block. The results of the `DelimR.control` block, or of calling the continuation, will be returned to where the `DelimR.prompt` was declared.\n\n## Examples\n\n```ruby\n# k represents the computation outside of it\nDelimR.prompt { 1 + DelimR.control { |k| k.call(3) } + 7}\n# =\u003e 11\n\n# If we don't call k, the computation is lost, and simply the value is returned\nDelimR.prompt { 1 + DelimR.control { |k| 3 } + 7}\n# =\u003e 3\n\n# Delmited computations are composable! We can keep applying k to itself\nDelimR.prompt { 1 + DelimR.control { |k| k.call(k.call(3)) } + 7}\n# (1 + (1 + 3 + 7) + 7)\n# =\u003e 19\n```\n\n## A more involved example\n\nBack in 1.8.7, Ruby core had an implementation of generators using plain old continuations. You can see it [here](https://github.com/ruby/ruby/blob/ruby_1_8_7/lib/generator.rb).\n\nBelow, we implement Python style generators using delimited continuations.\n\n```ruby\nclass Generator\n  def initialize(\u0026block)\n    @results = []\n    DelimR.prompt do\n      block.call(self)\n    end\n  end\n  \n  def next\n    r = @results.pop\n    if r.nil?\n      raise \"Iterator finished\"\n    end\n    @k.call(nil)\n    r\n  end\n  \n  def yield(result)\n    @results \u003c\u003c result\n    DelimR.control do |k| \n      @k = k\n    end\n  end\nend\n```\n\nand use it:\n\n```ruby\ncounter = Generator.new do |g| \n  ctr = 0\n  while true\n    g.yield(ctr)\n    ctr += 1\n  end\nend\n\ncounter.next\n# =\u003e 0\ncounter.next\n# =\u003e 1\ncounter.next\n# =\u003e 2\n# ...\n```\n\n\nFor more information on delimited continuations\n\n1. http://community.schemewiki.org/?composable-continuations-tutorial\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/delimr/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmveytsman%2Fdelimr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmveytsman%2Fdelimr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmveytsman%2Fdelimr/lists"}