Module: ShiftReset
- Included in:
- Ruby::Reflection::ThreadMirror
- Defined in:
- lib/ruby/reflection/support/shift_reset.rb
Overview
Modeled after Andrzej Filinski’s article “Representing Monads” at POPL’94, and a Scheme implementation of it. citeseer.ist.psu.edu/filinski94representing.html
Copyright 2004–2011 Christian Neukirchen
Constant Summary collapse
- @@metacont =
lambda do |x| raise RuntimeError, "You forgot the top-level reset..." end
Instance Method Summary collapse
Instance Method Details
#reset(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby/reflection/support/shift_reset.rb', line 12 def reset(&block) mc = @@metacont callcc do |k| @@metacont = lambda do |v| @@metacont = mc k.call v end x = block.call @@metacont.call x end end |
#shift(&block) ⇒ Object
24 25 26 27 28 |
# File 'lib/ruby/reflection/support/shift_reset.rb', line 24 def shift(&block) callcc do |k| @@metacont.call block.call(lambda {|*v| reset { k.call *v } }) end end |