class Rbprolog::Rule
when fail at one predicate, the output values need be reset, and remove from the parent rule/s context
Attributes
args[RW]
sym[RW]
Public Class Methods
new(sym, *args, deductions)
click to toggle source
# File lib/rbprolog/rule.rb, line 6 def initialize(sym, *args, deductions) @sym = sym @args = args @deductions = [deductions].flatten.map {|deduction| Deduction === deduction ? deduction : Evaluation.new(deduction.call)} end
Public Instance Methods
each_match(rules, *args, id) { |binds| ... }
click to toggle source
# File lib/rbprolog/rule.rb, line 12 def each_match(rules, *args, id) #print "#{"\t" * id.size}#{id.join('.')} #{@sym}(#{@args.join(', ')}).deduce(#{args.join(', ')})" context = Context.new context.scope(self) do |scoped_args| if self.match!(context, args) #puts " => #{@sym}(#{@args.map {|arg| context.deduce(arg)}.join(', ')})" deduce_deductions(context, rules, *@deductions, id) do yield context.binds end else #print "\n" end end end
match!(context, args)
click to toggle source
# File lib/rbprolog/rule.rb, line 32 def match!(context, args) match = match?(context, args) @args.zip(args).each {|v1, v2| context.match!(v1, v2)} if match match end
match?(context, args)
click to toggle source
# File lib/rbprolog/rule.rb, line 28 def match?(context, args) @args.size == args.size && @args.zip(args).all? {|v1, v2| context.match?(v1, v2)} end
Private Instance Methods
deduce_deductions(context, rules, *deductions, id) { || ... }
click to toggle source
# File lib/rbprolog/rule.rb, line 39 def deduce_deductions(context, rules, *deductions, id, &block) if deductions.empty? yield else deduction = deductions.shift deduction.each_deduce(context, rules, id + [@deductions.size - deductions.size - 1]) do |hash| deduce_deductions(context, rules, *deductions, id, &block) end end end