Class: RubyProlog::TempClause

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-prolog/ruby-prolog.rb

Instance Method Summary collapse

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

#factObject



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_goalObject



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