lib/ambit.rb
# Given an enumerator, begin a generate-and-test process.
#
# Returns with the first member of the enumerator.  A later call to #fail!
# on the same generator will backtrack and try the next value in the
# enumerator, continuing from the point of this #choose as if that value
# had been chosen originally.
#
# Multiple calls to #choose will nest, so that backtracking forms
# a tree-like execution path
#
# calling #choose with no argument or an empty iterator 
# is equivalent to calling #fail!
Given an enumerator, begin a generate-and-test process.
Returns with the first member of the enumerator.  A later call to #fail.
on the same generator will backtrack and try the next value in the
enumerator, continuing from the point of this #choose as if that value
had been chosen originally.

Multiple calls to #choose will nest, so that backtracking forms
a tree-like execution path

calling #choose with no argument or an empty iterator
is equivalent to calling #fail!
Given an enumerator begin a generate - and - test process . Returns with the first member of the enumerator . A later call to #fail . on the same generator will backtrack and try the next value in the enumerator continuing from the point of this #choose as if that value had been chosen originally . Multiple calls to #choose will nest so that backtracking forms a tree - like execution path calling #choose with no argument or an empty iterator is equivalent to calling #fail!
def choose choices = []
      ch = choices.clone          
      ch.each do |choice|
        callcc do |cc|
          STDERR.print "choosing from " + choices.inspect + ": " if @trace > 0
          @paths.unshift cc
          STDERR.puts choice.inspect if @trace > 0
          return choice
        end
      end
      self.fail!                  
    end
def choose choices = [ ] ch = choices . clone ch . each do | choice | callcc do | cc | STDERR . print "choosing from " + choices . inspect + ": " if @trace > 0 @paths . unshift cc STDERR . puts choice . inspect if @trace > 0 return choice end end self . fail! end
Given an enumerator, begin a generate-and-test process.
Given an enumerator begin a generate - and - test process .
# clone it in case it's modified by the caller # if we get here, we've exhausted the choices
choices
<not_specific>