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.



47
48
49
# File 'lib/ruby-prolog/ruby-prolog.rb', line 47

def initialize(db, pred, args)
  @db, @pred, @args = db, pred, args
end

Instance Method Details

#<<(rhs) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/ruby-prolog/ruby-prolog.rb', line 65

def <<(rhs)
  case rhs
  when Array
    si(*rhs)
  else
    si(rhs)
  end
end

#calls(&callback) ⇒ Object



74
75
76
# File 'lib/ruby-prolog/ruby-prolog.rb', line 74

def calls(&callback)
  @db.append(self.to_goal, callback)
end

#factObject



61
62
63
# File 'lib/ruby-prolog/ruby-prolog.rb', line 61

def fact
  si
end

#si(*rhs) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/ruby-prolog/ruby-prolog.rb', line 51

def si(*rhs)
  goals = rhs.map do |x|
    case x
    when TempClause then x.to_goal
    else x
    end
  end
  @db.append(self.to_goal, list(*goals))
end

#to_goalObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby-prolog/ruby-prolog.rb', line 78

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