Class: RubyProlog::Goal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pred, args) ⇒ Goal

Returns a new instance of Goal.



38
39
40
# File 'lib/ruby-prolog/ruby-prolog.rb', line 38

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



30
31
32
# File 'lib/ruby-prolog/ruby-prolog.rb', line 30

def args
  @args
end

#predObject (readonly)

Returns the value of attribute pred.



30
31
32
# File 'lib/ruby-prolog/ruby-prolog.rb', line 30

def pred
  @pred
end

Instance Method Details

#<<(rhs) ⇒ Object



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

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

#calls(&callback) ⇒ Object



59
60
61
# File 'lib/ruby-prolog/ruby-prolog.rb', line 59

def calls(&callback)
  @pred.defs << [self, callback]
end

#factObject



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

def fact
  si
end

#inspectObject



63
64
65
# File 'lib/ruby-prolog/ruby-prolog.rb', line 63

def inspect
  return @pred.inspect.to_s + @args.inspect.to_s
end

#list(*x) ⇒ Object



32
33
34
35
36
# File 'lib/ruby-prolog/ruby-prolog.rb', line 32

def list(*x)
  y = nil
  x.reverse_each {|e| y = Cons.new(e, y)}
  return y
end

#si(*rhs) ⇒ Object



42
43
44
# File 'lib/ruby-prolog/ruby-prolog.rb', line 42

def si(*rhs)
  @pred.defs << [self, list(*rhs)]
end