class Rubylog::Structure

Attributes

args[R]

data structure

functor[R]

data structure

rubylog_variables[R]

Public Class Methods

new(predicate, functor, *args) click to toggle source
# File lib/rubylog/structure.rb, line 7
def initialize predicate, functor, *args
  #raise Rubylog::TypeError, "functor cannot be #{functor}" unless functor.is_a? Symbol
  @predicate = predicate
  @functor = functor
  @args = args.freeze
  @arity = args.count
end

Public Instance Methods

==(other) click to toggle source
# File lib/rubylog/structure.rb, line 23
def == other
  other.instance_of? Structure and
  @functor == other.functor and @args == other.args
end
Also aliased as: eql?
[](i) click to toggle source
# File lib/rubylog/structure.rb, line 19
def [] i
  @args[i]
end
arity() click to toggle source
# File lib/rubylog/structure.rb, line 43
def arity
  @arity
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/rubylog/structure.rb, line 29
def hash
  @functor.hash ^ @args.hash
end
indicator() click to toggle source
# File lib/rubylog/structure.rb, line 47
def indicator
  [@functor, @arity]
end
inspect() click to toggle source
# File lib/rubylog/structure.rb, line 33
def inspect
  "#{@args[0].inspect}.#{@functor}#{
    "(#{@args[1..-1].inspect[1..-2]})" if @args.count>1
  }"
end
predicate() click to toggle source
# File lib/rubylog/structure.rb, line 15
def predicate
  @predicate 
end
prove() { || ... } click to toggle source
# File lib/rubylog/structure.rb, line 57
def prove
  count = 0
  predicate.call(*@args) { yield; count+=1 }
  count
end
rubylog_clone(&block) click to toggle source
# File lib/rubylog/structure.rb, line 83
def rubylog_clone &block
  block.call Structure.new @predicate, @functor.rubylog_clone(&block),
    *@args.map{|a| a.rubylog_clone &block}
end
rubylog_deep_dereference() click to toggle source
# File lib/rubylog/structure.rb, line 88
def rubylog_deep_dereference
  Structure.new @predicate, @functor.rubylog_deep_dereference,
    *@args.rubylog_deep_dereference
end
rubylog_unify(other) { || ... } click to toggle source
Calls superclass method Rubylog::Term#rubylog_unify
# File lib/rubylog/structure.rb, line 71
def rubylog_unify other
  return super{yield} unless other.instance_of? self.class
  return unless other.functor == @functor
  return unless @arity == other.arity
  @args.rubylog_unify(other.args) { yield }
end
to_s() click to toggle source
# File lib/rubylog/structure.rb, line 39
def to_s
  inspect
end