mini_kraken 0.2.02 → 0.3.02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +378 -333
  3. data/CHANGELOG.md +52 -0
  4. data/README.md +19 -19
  5. data/lib/mini_kraken.rb +0 -1
  6. data/lib/mini_kraken/atomic/all_atomic.rb +5 -0
  7. data/lib/mini_kraken/atomic/atomic_term.rb +96 -0
  8. data/lib/mini_kraken/atomic/k_boolean.rb +42 -0
  9. data/lib/mini_kraken/{core → atomic}/k_integer.rb +2 -5
  10. data/lib/mini_kraken/atomic/k_string.rb +17 -0
  11. data/lib/mini_kraken/{core → atomic}/k_symbol.rb +4 -8
  12. data/lib/mini_kraken/composite/all_composite.rb +4 -0
  13. data/lib/mini_kraken/composite/composite_term.rb +27 -0
  14. data/lib/mini_kraken/composite/cons_cell.rb +299 -0
  15. data/lib/mini_kraken/composite/cons_cell_visitor.rb +50 -0
  16. data/lib/mini_kraken/composite/list.rb +32 -0
  17. data/lib/mini_kraken/core/all_core.rb +8 -0
  18. data/lib/mini_kraken/core/any_value.rb +31 -7
  19. data/lib/mini_kraken/core/arity.rb +69 -0
  20. data/lib/mini_kraken/core/association.rb +29 -4
  21. data/lib/mini_kraken/core/association_copy.rb +50 -0
  22. data/lib/mini_kraken/core/base_term.rb +13 -0
  23. data/lib/mini_kraken/core/blackboard.rb +315 -0
  24. data/lib/mini_kraken/core/bookmark.rb +46 -0
  25. data/lib/mini_kraken/core/context.rb +492 -0
  26. data/lib/mini_kraken/core/duck_fiber.rb +21 -19
  27. data/lib/mini_kraken/core/entry.rb +40 -0
  28. data/lib/mini_kraken/core/fail.rb +20 -18
  29. data/lib/mini_kraken/core/fusion.rb +29 -0
  30. data/lib/mini_kraken/core/goal.rb +20 -29
  31. data/lib/mini_kraken/core/log_var.rb +22 -0
  32. data/lib/mini_kraken/core/log_var_ref.rb +108 -0
  33. data/lib/mini_kraken/core/nullary_relation.rb +2 -9
  34. data/lib/mini_kraken/core/parametrized_term.rb +61 -0
  35. data/lib/mini_kraken/core/relation.rb +14 -28
  36. data/lib/mini_kraken/core/scope.rb +67 -0
  37. data/lib/mini_kraken/core/solver_adapter.rb +58 -0
  38. data/lib/mini_kraken/core/specification.rb +48 -0
  39. data/lib/mini_kraken/core/succeed.rb +21 -17
  40. data/lib/mini_kraken/core/symbol_table.rb +137 -0
  41. data/lib/mini_kraken/core/term.rb +15 -4
  42. data/lib/mini_kraken/glue/dsl.rb +45 -81
  43. data/lib/mini_kraken/glue/run_star_expression.rb +28 -30
  44. data/lib/mini_kraken/rela/all_rela.rb +8 -0
  45. data/lib/mini_kraken/rela/binary_relation.rb +30 -0
  46. data/lib/mini_kraken/rela/conde.rb +143 -0
  47. data/lib/mini_kraken/rela/conj2.rb +65 -0
  48. data/lib/mini_kraken/rela/def_relation.rb +93 -0
  49. data/lib/mini_kraken/rela/disj2.rb +70 -0
  50. data/lib/mini_kraken/rela/fresh.rb +98 -0
  51. data/lib/mini_kraken/{core → rela}/goal_relation.rb +7 -9
  52. data/lib/mini_kraken/rela/unify.rb +258 -0
  53. data/lib/mini_kraken/version.rb +1 -1
  54. data/mini_kraken.gemspec +2 -2
  55. data/spec/.rubocop.yml +1 -1
  56. data/spec/atomic/atomic_term_spec.rb +98 -0
  57. data/spec/{core → atomic}/k_boolean_spec.rb +19 -34
  58. data/spec/{core → atomic}/k_symbol_spec.rb +3 -16
  59. data/spec/composite/cons_cell_spec.rb +225 -0
  60. data/spec/composite/cons_cell_visitor_spec.rb +158 -0
  61. data/spec/composite/list_spec.rb +50 -0
  62. data/spec/core/any_value_spec.rb +52 -0
  63. data/spec/core/arity_spec.rb +92 -0
  64. data/spec/core/association_copy_spec.rb +69 -0
  65. data/spec/core/association_spec.rb +31 -4
  66. data/spec/core/blackboard_spec.rb +287 -0
  67. data/spec/core/bookmark_spec.rb +40 -0
  68. data/spec/core/context_spec.rb +245 -0
  69. data/spec/core/core_spec.rb +40 -0
  70. data/spec/core/duck_fiber_spec.rb +16 -46
  71. data/spec/core/fail_spec.rb +5 -6
  72. data/spec/core/goal_spec.rb +24 -14
  73. data/spec/core/log_var_ref_spec.rb +105 -0
  74. data/spec/core/log_var_spec.rb +64 -0
  75. data/spec/core/nullary_relation_spec.rb +33 -0
  76. data/spec/core/parametrized_tem_spec.rb +39 -0
  77. data/spec/core/relation_spec.rb +33 -0
  78. data/spec/core/scope_spec.rb +73 -0
  79. data/spec/core/solver_adapter_spec.rb +70 -0
  80. data/spec/core/specification_spec.rb +43 -0
  81. data/spec/core/succeed_spec.rb +5 -5
  82. data/spec/core/symbol_table_spec.rb +142 -0
  83. data/spec/glue/dsl_chap1_spec.rb +96 -144
  84. data/spec/glue/dsl_chap2_spec.rb +350 -0
  85. data/spec/glue/run_star_expression_spec.rb +82 -906
  86. data/spec/rela/conde_spec.rb +153 -0
  87. data/spec/rela/conj2_spec.rb +123 -0
  88. data/spec/rela/def_relation_spec.rb +119 -0
  89. data/spec/rela/disj2_spec.rb +117 -0
  90. data/spec/rela/fresh_spec.rb +147 -0
  91. data/spec/rela/unify_spec.rb +369 -0
  92. data/spec/support/factory_atomic.rb +29 -0
  93. data/spec/support/factory_composite.rb +21 -0
  94. data/spec/support/factory_methods.rb +11 -26
  95. metadata +100 -64
  96. data/lib/mini_kraken/core/association_walker.rb +0 -183
  97. data/lib/mini_kraken/core/atomic_term.rb +0 -67
  98. data/lib/mini_kraken/core/base_arg.rb +0 -10
  99. data/lib/mini_kraken/core/binary_relation.rb +0 -63
  100. data/lib/mini_kraken/core/composite_goal.rb +0 -46
  101. data/lib/mini_kraken/core/composite_term.rb +0 -41
  102. data/lib/mini_kraken/core/conde.rb +0 -143
  103. data/lib/mini_kraken/core/conj2.rb +0 -79
  104. data/lib/mini_kraken/core/cons_cell.rb +0 -82
  105. data/lib/mini_kraken/core/def_relation.rb +0 -50
  106. data/lib/mini_kraken/core/designation.rb +0 -55
  107. data/lib/mini_kraken/core/disj2.rb +0 -72
  108. data/lib/mini_kraken/core/environment.rb +0 -73
  109. data/lib/mini_kraken/core/equals.rb +0 -156
  110. data/lib/mini_kraken/core/formal_arg.rb +0 -22
  111. data/lib/mini_kraken/core/formal_ref.rb +0 -25
  112. data/lib/mini_kraken/core/freshness.rb +0 -45
  113. data/lib/mini_kraken/core/goal_arg.rb +0 -12
  114. data/lib/mini_kraken/core/goal_template.rb +0 -62
  115. data/lib/mini_kraken/core/k_boolean.rb +0 -35
  116. data/lib/mini_kraken/core/outcome.rb +0 -53
  117. data/lib/mini_kraken/core/variable.rb +0 -41
  118. data/lib/mini_kraken/core/variable_ref.rb +0 -78
  119. data/lib/mini_kraken/core/vocabulary.rb +0 -442
  120. data/lib/mini_kraken/glue/fresh_env.rb +0 -75
  121. data/spec/core/association_walker_spec.rb +0 -192
  122. data/spec/core/conde_spec.rb +0 -147
  123. data/spec/core/conj2_spec.rb +0 -114
  124. data/spec/core/cons_cell_spec.rb +0 -107
  125. data/spec/core/def_relation_spec.rb +0 -96
  126. data/spec/core/disj2_spec.rb +0 -99
  127. data/spec/core/environment_spec.rb +0 -142
  128. data/spec/core/equals_spec.rb +0 -304
  129. data/spec/core/goal_template_spec.rb +0 -74
  130. data/spec/core/outcome_spec.rb +0 -48
  131. data/spec/core/variable_ref_spec.rb +0 -27
  132. data/spec/core/variable_spec.rb +0 -35
  133. data/spec/core/vocabulary_spec.rb +0 -219
  134. data/spec/glue/fresh_env_spec.rb +0 -62
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'composite_term'
4
-
5
- unless MiniKraken::Core.constants(false).include? :ConsCell
6
- module MiniKraken
7
- module Core
8
- class ConsCell < CompositeTerm
9
- attr_reader :car
10
- attr_reader :cdr
11
-
12
- def initialize(obj1, obj2 = nil)
13
- super()
14
- @car = obj1
15
- if obj2.kind_of?(ConsCell) && obj2.null?
16
- @cdr = nil
17
- else
18
- @cdr = obj2
19
- end
20
- end
21
-
22
- def children
23
- [car, cdr]
24
- end
25
-
26
- # Return true if it is an empty list, otherwise false.
27
- # A list is empty, when both car and cdr fields are nil.
28
- def null?
29
- car.nil? && cdr.nil?
30
- end
31
-
32
- def ==(other)
33
- return false unless other.respond_to?(:car)
34
-
35
- (car == other.car) && (cdr == other.cdr)
36
- end
37
-
38
- def eql?(other)
39
- (self.class == other.class) && car.eql?(other.car) && cdr.eql?(other.cdr)
40
- end
41
-
42
- def quote(anEnv)
43
- return self if null?
44
-
45
- new_car = car.nil? ? nil : car.quote(anEnv)
46
- new_cdr = cdr.nil? ? nil : cdr.quote(anEnv)
47
- ConsCell.new(new_car, new_cdr)
48
- end
49
-
50
- # Use the list notation from Lisp as a text representation.
51
- def to_s
52
- return '()' if null?
53
-
54
- "(#{pair_to_s})"
55
- end
56
-
57
- def append(another)
58
- @cdr = another
59
- end
60
-
61
- protected
62
-
63
- def pair_to_s
64
- result = +car.to_s
65
- if cdr
66
- result << ' '
67
- if cdr.kind_of?(ConsCell)
68
- result << cdr.pair_to_s
69
- else
70
- result << ". #{cdr}"
71
- end
72
- end
73
-
74
- result
75
- end
76
- end # class
77
-
78
- # Constant representing the null (empty) list.
79
- NullList = ConsCell.new(nil, nil).freeze
80
- end # module
81
- end # module
82
- end # defined
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'relation'
4
-
5
- module MiniKraken
6
- module Core
7
- # A relation that is parametrized with generic formal arguments
8
- # and a goal template expression.
9
- class DefRelation < Relation
10
- # @return [Array<FormalArg>] formal arguments of this DefRelation
11
- attr_reader :formals
12
-
13
- # @return [GoalTemplate] goal template
14
- attr_reader :goal_template
15
-
16
- # @param aName [String] name of def relation
17
- # @param aGoalTemplate [GoalTemplate]
18
- def initialize(aName, aGoalTemplate, theFormals, alternateName = nil)
19
- super(aName, alternateName)
20
- @formals = validated_formals(theFormals)
21
- @goal_template = validated_goal_template(aGoalTemplate)
22
- freeze
23
- end
24
-
25
- # Number of arguments for the relation.
26
- # @return [Integer]
27
- def arity
28
- formals.size
29
- end
30
-
31
- # @param actuals [Array<Term>] A two-elements array
32
- # @param anEnv [Vocabulary] A vocabulary object
33
- # @return [Fiber<Outcome>] A Fiber(-like) instance that yields Outcomes
34
- def solver_for(actuals, anEnv)
35
- goal = goal_template.instantiate(formals, actuals)
36
- goal.attain(anEnv)
37
- end
38
-
39
- private
40
-
41
- def validated_formals(theFormals)
42
- theFormals
43
- end
44
-
45
- def validated_goal_template(aGoalTemplate)
46
- aGoalTemplate
47
- end
48
- end # class
49
- end # module
50
- end # module
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MiniKraken
4
- module Core
5
- # Wordnet definition: Identifying word or words by which someone or
6
- # something is called and classified or distinguished from others.
7
- # Mix-in module that contains factored code for managing named entries
8
- # in a vocabulary such as variables and variable references.
9
- module Designation
10
- # @return [String] User-defined name of the variable
11
- attr_reader :name
12
-
13
- def init_designation(aName)
14
- @name = valid_name(aName)
15
- end
16
-
17
- # @param voc [Vocabulary]
18
- # @return [Freshness]
19
- def freshness(voc)
20
- voc.freshness_ref(self)
21
- end
22
-
23
- # @param voc [Vocabulary]
24
- # @return [Boolean]
25
- def fresh?(voc)
26
- frsh = freshness(voc)
27
- frsh.degree == :fresh || frsh.degree == :bound
28
- end
29
-
30
- # @param voc [Vocabulary]
31
- # @return [Boolean]
32
- def bound?(voc)
33
- frsh = freshness(voc)
34
- frsh.degree == :bound
35
- end
36
-
37
- # @param voc [Vocabulary]
38
- # @return [Boolean]
39
- def ground?(voc)
40
- frsh = freshness(voc)
41
- frsh.degree == :bound
42
- end
43
-
44
- private
45
-
46
- def valid_name(aName)
47
- if aName.empty?
48
- raise StandardError, 'Variable name may not be empty.'
49
- end
50
-
51
- aName
52
- end
53
- end # class
54
- end # module
55
- end # module
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'singleton'
4
- require_relative 'duck_fiber'
5
- require_relative 'fail'
6
- require_relative 'goal'
7
- require_relative 'goal_relation'
8
- require_relative 'outcome'
9
-
10
- unless MiniKraken::Core.constants(false).include? :Disj2
11
- module MiniKraken
12
- module Core
13
- # The disjunction is a relation that accepts only goal(s) as its two
14
- # arguments. It succeeds if at least one of its goal arguments succeeds.
15
- class Disj2 < GoalRelation
16
- include Singleton
17
-
18
- def initialize
19
- super('disj2', nil)
20
- end
21
-
22
- # @param actuals [Array<Term>] A two-elements array
23
- # @param anEnv [Vocabulary] A vocabulary object
24
- # @return [Fiber<Outcome>] A Fiber that yields Outcomes objects
25
- def solver_for(actuals, anEnv)
26
- g1, g2 = *validated_args(actuals)
27
- Fiber.new { disjunction(g1, g2, anEnv) }
28
- end
29
-
30
- # Yields [Outcome, NilClass] result of the disjunction
31
- # @param g1 [Goal] First goal argument
32
- # @param g2 [Goal] Second goal argument
33
- # @param voc [Vocabulary] A vocabulary object
34
- def disjunction(g1, g2, voc)
35
- # require 'debug'
36
- outcome1 = nil
37
- outcome2 = nil
38
- if g1.relation.kind_of?(Fail) && g2.relation.kind_of?(Fail)
39
- Fiber.yield Outcome.new(:"#u", voc)
40
- else
41
- f1 = g1.attain(voc)
42
- loop do
43
- outcome1 = f1.resume
44
- break unless outcome1
45
-
46
- outcome1.parent = voc unless outcome1.parent
47
- if outcome1.successful?
48
- Fiber.yield outcome1
49
- outcome1.clear
50
- end
51
- end
52
- f2 = g2.attain(voc)
53
- loop do
54
- outcome2 = f2.resume
55
- break unless outcome2
56
-
57
- outcome2.parent = voc unless outcome2.parent
58
- if outcome2.successful?
59
- Fiber.yield outcome2
60
- outcome2.clear
61
- end
62
- end
63
- end
64
-
65
- Fiber.yield nil
66
- end
67
- end # class
68
-
69
- Disj2.instance.freeze
70
- end # module
71
- end # module
72
- end # unless
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
- require_relative 'vocabulary'
5
-
6
- module MiniKraken
7
- module Core
8
- class Environment
9
- include Vocabulary # Use mix-in module
10
-
11
- # Mapping from user-defined name to Variable instance
12
- # @return [Hash] Pairs of the kind {String => Variable}
13
- attr_reader :vars
14
-
15
- # Mapping from internal name to user-defined name(s)
16
- # @return [Hash] Pairs of the kind {String => Set<String>}
17
- attr_reader :ivars
18
-
19
- # @param aParent [Environment, NilClass] Parent environment to this one.
20
- def initialize(aParent = nil)
21
- init_vocabulary(aParent)
22
- @vars = {}
23
- @ivars = {}
24
- end
25
-
26
- # @param aVariable [Variable]
27
- def add_var(aVariable)
28
- name = aVariable.name
29
- if vars.include?(name)
30
- err_msg = "Variable with name '#{name}' already exists."
31
- raise StandardError, err_msg
32
- end
33
- vars[name] = aVariable
34
- i_name = aVariable.i_name
35
- if ivars.include?(i_name)
36
- set = ivars[i_name]
37
- set.add(name)
38
- else
39
- ivars[i_name] = Set.new([i_name])
40
- end
41
- end
42
-
43
- # Handler for the event: an outcome has been produced.
44
- # Can be overridden in other to propagate associations from child
45
- # @param descendent [Outcome]
46
- def propagate(descendent)
47
- # Rollout associations from hierarchy
48
- walker = descendent.ancestor_walker
49
- begin
50
- env = walker.next
51
- break if env.nil?
52
-
53
- env.do_propagate(descendent) if env.kind_of?(Environment)
54
- end until env.equal?(self)
55
- end
56
-
57
- # Roll up associations from descendent outcome object
58
- # @param descendent [Outcome]
59
- def do_propagate(descendent)
60
- return unless descendent.successful?
61
-
62
- vars.each_key do |var_name|
63
- # assocs = descendent[var_name]
64
- move_assocs(var_name, descendent)
65
- end
66
- end
67
-
68
- def merge_vars(descendent)
69
- descendent.vars.each_value { |vr| add_var(vr) }
70
- end
71
- end # class
72
- end # module
73
- end # module
@@ -1,156 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'singleton'
4
- require_relative 'binary_relation'
5
- # require_relative 'any_value'
6
- require_relative 'duck_fiber'
7
- require_relative 'variable'
8
- require_relative 'variable_ref'
9
-
10
- unless MiniKraken::Core.constants(false).include? :Equals
11
- module MiniKraken
12
- module Core
13
- # equals tries to unify two terms
14
- class Equals < BinaryRelation
15
- include Singleton
16
-
17
- def initialize
18
- super('equals', '==')
19
- end
20
-
21
- # @param actuals [Array<Term>] A two-elements array
22
- # @param anEnv [Vocabulary] A vocabulary object
23
- # @return [Fiber<Outcome>] A Fiber(-like) instance that yields Outcomes
24
- def solver_for(actuals, anEnv)
25
- arg1, arg2 = *actuals
26
- DuckFiber.new(:custom) { unification(arg1, arg2, anEnv) }
27
- end
28
-
29
- def unification(arg1, arg2, anEnv)
30
- arg1_nil = arg1.nil?
31
- arg2_nil = arg2.nil?
32
- if arg1_nil || arg2_nil
33
- if arg1_nil && arg2_nil
34
- result = Outcome.success(anEnv)
35
- else
36
- result = Outcome.failure(anEnv)
37
- end
38
- return result
39
- end
40
- new_arg1, new_arg2 = commute_cond(arg1, arg2, anEnv)
41
- do_unification(new_arg1, new_arg2, anEnv)
42
- end
43
-
44
- private
45
-
46
-
47
- # table: Unification
48
- # | arg1 | arg2 | Criterion || Unification |
49
- # | isa? Atomic | isa? Atomic | arg1.eq? arg2 is true || { "s", [] } |
50
- # | isa? Atomic | isa? Atomic | arg1.eq? arg2 is false || { "u", [] } |
51
- # | isa? CompositeTerm | isa? Atomic | dont_care || { "u", [] } |
52
- # | isa? CompositeTerm | isa? CompositeTerm | unification(arg1.car, arg2.car) => "s" || { "s", [bindings*] } |
53
- # | isa? CompositeTerm | isa? CompositeTerm | unification(arg1.cdr, arg2.cdr) => "u" || { "u", [] ) | |
54
- # | isa? VariableRef | isa? Atomic | arg1.fresh? is true || { "s", [arg2] } |
55
- # | isa? VariableRef | isa? Atomic | arg1.fresh? is false || |
56
- # | | unification(arg1.value, arg2) => "s" || { "s", [bindings*] } |
57
- # | | unification(arg1.value, arg2) => "u" || { "u", [] } |
58
- # | isa? VariableRef | isa? CompositeTerm | arg1.fresh? is true || { "s", [arg2] } | # What if arg1 occurs in arg2?
59
- # | isa? VariableRef | isa? CompositeTerm | arg1.fresh? is false || |
60
- # | | unification(arg1.value, arg2) => "s" || { "s", [bindings*] } |
61
- # | | unification(arg1.value, arg2) => "u" || { "u", [] } |
62
- # | isa? VariableRef | isa? VariableRef | arg1.fresh?, arg2.fresh? => [true, true] || { "s", [arg1 <=> arg2] } |
63
- # | isa? VariableRef | isa? VariableRef | arg1.fresh?, arg2.fresh? => [true, false] || |
64
- # | | unification(arg1, arg2.value) => "s" || { "s", [bindings*] } |
65
- # | | unification(arg1, arg2.value) => "u" || { "u", [] } |
66
- # | isa? VariableRef | isa? VariableRef | arg1.fresh?, arg2.fresh? => [false, false]|| |
67
- # | | unification(arg1, arg2.value) => "s" || { "s", [bindings*] } |
68
- # | | unification(arg1, arg2.value) => "u" || { "u", [] }
69
- def do_unification(arg1, arg2, anEnv)
70
- # require 'debug'
71
- return Outcome.success(anEnv) if arg1.equal?(arg2)
72
-
73
- result = Outcome.failure(anEnv) # default case
74
-
75
- if arg1.kind_of?(AtomicTerm)
76
- result = Outcome.success(anEnv) if arg1.eql?(arg2)
77
- elsif arg1.kind_of?(CompositeTerm)
78
- if arg2.kind_of?(CompositeTerm) # AtomicTerm is default case => fail
79
- result = unify_composite_terms(arg1, arg2, anEnv)
80
- end
81
- elsif arg1.kind_of?(VariableRef)
82
- arg1_freshness = arg1.freshness(anEnv)
83
- if arg2.kind_of?(AtomicTerm)
84
- if arg1_freshness.degree == :fresh
85
- result = Outcome.success(anEnv)
86
- arg1.associate(arg2, result)
87
- else
88
- result = Outcome.success(anEnv) if arg1.value(anEnv).eql?(arg2)
89
- end
90
- elsif arg2.kind_of?(CompositeTerm)
91
- if arg1_freshness.degree == :fresh
92
- result = Outcome.success(anEnv)
93
- arg1.associate(arg2, result)
94
- else
95
- # Ground case...
96
- result = unify_composite_terms(arg1_freshness.associated, arg2, anEnv)
97
- end
98
- elsif arg2.kind_of?(VariableRef)
99
- freshness = [arg1.fresh?(anEnv), arg2.fresh?(anEnv)]
100
- case freshness
101
- when [false, false] # TODO: confirm this...
102
- result = unification(arg1.value(anEnv), arg2.value(anEnv), anEnv)
103
- when [true, true]
104
- result = Outcome.success(anEnv)
105
- if arg1.var_name != arg2.var_name
106
- arg1.associate(arg2, result)
107
- arg2.associate(arg1, result)
108
- end
109
- when [true, false]
110
- result = Outcome.success(anEnv)
111
- arg1.associate(arg2, result)
112
- else
113
- raise StandardError, "Unsupported freshness combination #{freshness}"
114
- end
115
- else
116
- arg_kinds = [arg1.class, arg2.class]
117
- raise StandardError, "Unsupported combination #{arg_kinds}"
118
- end
119
- end
120
-
121
- result
122
- end
123
-
124
- # @return [Freshness]
125
- def unify_composite_terms(arg1, arg2, anEnv)
126
- # require 'debug'
127
- result = Outcome.failure(anEnv)
128
- children1 = arg1.children
129
- children2 = arg2.children
130
-
131
- if children1.size == children2.size
132
- i = 0
133
- subresults = children1.map do |child1|
134
- child2 = children2[i]
135
- i += 1
136
- unification(child1, child2, anEnv)
137
- end
138
- total_success = subresults.all?(&:successful?)
139
- if total_success
140
- memo = Outcome.success(anEnv)
141
- subresults.reduce(memo) do |sub_total, outcome|
142
- sub_total.merge(outcome)
143
- sub_total
144
- end
145
- result = memo
146
- end
147
- end
148
-
149
- result
150
- end
151
- end # class
152
-
153
- Equals.instance.freeze
154
- end # module
155
- end # module
156
- end # unless