class Rbprolog::Evaluation

Attributes

args[RW]

FIXME the design is not good to have an empty array as args

Public Class Methods

new(expression) click to toggle source
# File lib/rbprolog/evaluation.rb, line 6
def initialize(expression)
  @args = []
  @expression = expression
end

Public Instance Methods

each_deduce(context, rules, id) { |binds| ... } click to toggle source
# File lib/rbprolog/evaluation.rb, line 11
def each_deduce(context, rules, id)
  #print "#{"\t" * id.size}#{id.join('.')} #{@expression}?)"

  context.scope(self) do |scoped_args|
    kclass = Class.new
    kclass.send(:define_singleton_method, :const_missing) do |sym|
      context.deduce(Var.new(sym))
    end

    evaluation = kclass.class_eval(@expression)
    #puts " => #{evaluation}"

    yield context.binds if evaluation
  end
end