# Examples 6.43 and 6.44 require 'continuation' def foo(i, c) A printf "start %d; ", i B if i < 3 then foo(i+1, c) else c.call(i) end C printf "end %d; ", i D end E v = callcc { |d| foo(1, d) } F printf "got %d\n", v G puts "----------------" H def here I return callcc { |a| return a } J end K def bar(i) L printf "start %d; ", i M b = if i < 3 then bar(i+1) else here end N printf "end %d; ", i O return b P end n = 3 Q c = bar(1) R n -= 1 S puts T if n > 0 then c.call(c) end U puts "done" V execution F sets up callc with { |d| foo(1,d) }