Class: RubyProlog::TempClause
- Inherits:
-
Object
- Object
- RubyProlog::TempClause
- Defined in:
- lib/ruby-prolog/ruby-prolog.rb
Instance Method Summary collapse
- #<<(rhs) ⇒ Object
- #calls(&callback) ⇒ Object
- #fact ⇒ Object
-
#initialize(db, pred, args) ⇒ TempClause
constructor
A new instance of TempClause.
- #si(*rhs) ⇒ Object
- #to_goal ⇒ Object
Constructor Details
#initialize(db, pred, args) ⇒ TempClause
Returns a new instance of TempClause.
54 55 56 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 54 def initialize(db, pred, args) @db, @pred, @args = db, pred, args end |
Instance Method Details
#<<(rhs) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 73 def <<(rhs) case rhs when Array si(*rhs) else si(rhs) end end |
#calls(&callback) ⇒ Object
82 83 84 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 82 def calls(&callback) @db.append(self.to_goal, callback) end |
#fact ⇒ Object
69 70 71 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 69 def fact si end |
#si(*rhs) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 58 def si(*rhs) goals = rhs.map do |x| case x when TempClause then x.to_goal when false then Goal.new(0, 'false', []) else x end end @db.append(self.to_goal, list(*goals)) end |
#to_goal ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ruby-prolog/ruby-prolog.rb', line 86 def to_goal Goal.new(@pred.id, @pred.name, @args.map do |arg| case arg when TempClause arg.to_goal else arg end end) end |