Class: Rbprolog::Deduction
- Inherits:
-
Object
- Object
- Rbprolog::Deduction
- Includes:
- Enumerable
- Defined in:
- lib/rbprolog/deduction.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#sym ⇒ Object
Returns the value of attribute sym.
Instance Method Summary collapse
- #each ⇒ Object
- #each_deduce(context, rules, tabs, id) ⇒ Object
-
#initialize(logic, sym, *args) ⇒ Deduction
constructor
A new instance of Deduction.
Constructor Details
#initialize(logic, sym, *args) ⇒ Deduction
Returns a new instance of Deduction.
6 7 8 9 10 11 |
# File 'lib/rbprolog/deduction.rb', line 6 def initialize(logic, sym, *args) @logic = logic @sym = sym @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
4 5 6 |
# File 'lib/rbprolog/deduction.rb', line 4 def args @args end |
#sym ⇒ Object
Returns the value of attribute sym.
4 5 6 |
# File 'lib/rbprolog/deduction.rb', line 4 def sym @sym end |
Instance Method Details
#each ⇒ Object
13 14 15 16 17 |
# File 'lib/rbprolog/deduction.rb', line 13 def each each_deduce(Context.new, @logic.rules, "", []) do |hash| yield hash end end |
#each_deduce(context, rules, tabs, id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rbprolog/deduction.rb', line 19 def each_deduce(context, rules, tabs, id) print "#{tabs}#{id.join('.')} #{@sym}?(#{@args.map(&:to_s).join(', ')})" rules.select {|rule| rule.sym == @sym}.each_with_index do |rule, i| context.scope(self) do puts " => #{@sym}?(#{@args.map {|arg| context.deduce(arg).to_s}.join(', ')})" if i == 0 #{context.to_s} #{context.binds.inspect}" if i == 0 rule.each_deduce(rules, *@args.map {|arg| context.deduce(arg)}, tabs + "\t", id + [i]) do |hash| context.scope(self) do rule.args.each_with_index do |rule_arg, rule_arg_index| deduced_arg = context.deduce(@args[rule_arg_index]) if Var === deduced_arg context.binds[deduced_arg.sym] = Var === rule_arg ? hash[rule_arg.sym] : rule_arg end end yield context.binds end end end end end |