amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0 amb.assert x >= 3 puts x # prints '4'
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0 amb.assert x >= 3 puts x # prints '4'
amb = Amb.new x = amb.choose(1,2,3,4)
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0
amb = Amb.new x = amb.choose(1,2,3,4)
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0 amb.assert x >= 3
amb = Amb.new x = amb.choose(1,2,3,4)
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0
amb = Amb.new x = amb.choose(1,2,3,4)
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0 amb.assert x >= 3
amb = Amb.new x = amb.choose(1,2,3,4) amb.assert (x % 2) == 0 amb.assert x >= 3 puts x # prints '4'
class Amb class ExhaustedError < RuntimeError; end def initialize @back = [ lambda { fail ExhaustedError, "amb tree exhausted" } ] end def choose(*choices) choices.each { |choice| callcc { |fk| @back << fk return choice } } failure end def failure @back.pop.call end def assert(cond) failure unless cond end end