git @ Cat's Eye Technologies Dipple / master ruby / continuations3.rb
master

Tree @master (Download .tar.gz)

continuations3.rb @masterraw · history · blame

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

def rcall(fun)
  callcc do |continuation|
    fun.call(continuation)
  end
end

def a
  puts "a"
  rcall lambda { |k| b k }
  puts "a"
end

def b(continuation)
  puts "b"
  c continuation  #  instead of: rcall lambda { |k| c k }
  puts "b"
  continuation.call()
end

def c(continuation)
  puts "c"
  continuation.call()
end

a