Class: Rubylog::Structure
Instance Attribute Summary collapse
Instance Method Summary
collapse
#rubylog_match_variables
Methods included from Term
#rubylog_dereference, #rubylog_match_variables, #rubylog_resolve_function
Methods included from Goal
#solve, #true?
Methods included from Assertable
#if, #if!, #unless
Constructor Details
#initialize(predicate, functor, *args) ⇒ Structure
Returns a new instance of Structure.
7
8
9
10
11
12
13
|
# File 'lib/rubylog/structure.rb', line 7
def initialize predicate, functor, *args
@predicate = predicate
@functor = functor
@args = args.freeze
@arity = args.count
end
|
Instance Attribute Details
5
6
7
|
# File 'lib/rubylog/structure.rb', line 5
def args
@args
end
|
5
6
7
|
# File 'lib/rubylog/structure.rb', line 5
def functor
@functor
end
|
#rubylog_variables ⇒ Object
Returns the value of attribute rubylog_variables.
78
79
80
|
# File 'lib/rubylog/structure.rb', line 78
def rubylog_variables
@rubylog_variables
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
23
24
25
26
|
# File 'lib/rubylog/structure.rb', line 23
def == other
other.instance_of? Structure and
@functor == other.functor and @args == other.args
end
|
19
20
21
|
# File 'lib/rubylog/structure.rb', line 19
def [] i
@args[i]
end
|
43
44
45
|
# File 'lib/rubylog/structure.rb', line 43
def arity
@arity
end
|
29
30
31
|
# File 'lib/rubylog/structure.rb', line 29
def hash
@functor.hash ^ @args.hash
end
|
#indicator ⇒ Object
47
48
49
|
# File 'lib/rubylog/structure.rb', line 47
def indicator
[@functor, @arity]
end
|
33
34
35
36
37
|
# 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 ⇒ Object
15
16
17
|
# File 'lib/rubylog/structure.rb', line 15
def predicate
@predicate
end
|
57
58
59
60
61
|
# File 'lib/rubylog/structure.rb', line 57
def prove
count = 0
predicate.call(*@args) { yield; count+=1 }
count
end
|
#rubylog_clone(&block) ⇒ Object
83
84
85
86
|
# 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 ⇒ Object
88
89
90
91
|
# 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) ⇒ Object
71
72
73
74
75
76
|
# 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
|
39
40
41
|
# File 'lib/rubylog/structure.rb', line 39
def to_s
inspect
end
|