mini_kraken 0.2.04 → 0.3.00

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +16 -16
  4. data/lib/mini_kraken/atomic/all_atomic.rb +1 -0
  5. data/lib/mini_kraken/atomic/atomic_term.rb +32 -17
  6. data/lib/mini_kraken/atomic/k_integer.rb +0 -4
  7. data/lib/mini_kraken/atomic/k_string.rb +17 -0
  8. data/lib/mini_kraken/atomic/k_symbol.rb +0 -6
  9. data/lib/mini_kraken/composite/all_composite.rb +4 -0
  10. data/lib/mini_kraken/composite/composite_term.rb +2 -18
  11. data/lib/mini_kraken/composite/cons_cell.rb +178 -11
  12. data/lib/mini_kraken/composite/cons_cell_visitor.rb +12 -64
  13. data/lib/mini_kraken/composite/list.rb +32 -0
  14. data/lib/mini_kraken/core/all_core.rb +8 -0
  15. data/lib/mini_kraken/core/any_value.rb +31 -7
  16. data/lib/mini_kraken/core/arity.rb +69 -0
  17. data/lib/mini_kraken/core/association.rb +29 -4
  18. data/lib/mini_kraken/core/association_copy.rb +50 -0
  19. data/lib/mini_kraken/core/base_term.rb +13 -0
  20. data/lib/mini_kraken/core/blackboard.rb +315 -0
  21. data/lib/mini_kraken/core/bookmark.rb +46 -0
  22. data/lib/mini_kraken/core/context.rb +624 -0
  23. data/lib/mini_kraken/core/duck_fiber.rb +21 -19
  24. data/lib/mini_kraken/core/entry.rb +40 -0
  25. data/lib/mini_kraken/core/fail.rb +20 -18
  26. data/lib/mini_kraken/core/fusion.rb +29 -0
  27. data/lib/mini_kraken/core/goal.rb +20 -29
  28. data/lib/mini_kraken/core/log_var.rb +4 -30
  29. data/lib/mini_kraken/core/log_var_ref.rb +72 -48
  30. data/lib/mini_kraken/core/nullary_relation.rb +2 -9
  31. data/lib/mini_kraken/core/parametrized_term.rb +61 -0
  32. data/lib/mini_kraken/core/relation.rb +14 -28
  33. data/lib/mini_kraken/core/scope.rb +67 -0
  34. data/lib/mini_kraken/core/solver_adapter.rb +58 -0
  35. data/lib/mini_kraken/core/specification.rb +48 -0
  36. data/lib/mini_kraken/core/succeed.rb +21 -17
  37. data/lib/mini_kraken/core/symbol_table.rb +137 -0
  38. data/lib/mini_kraken/core/term.rb +15 -4
  39. data/lib/mini_kraken/glue/dsl.rb +35 -69
  40. data/lib/mini_kraken/glue/run_star_expression.rb +28 -30
  41. data/lib/mini_kraken/rela/all_rela.rb +8 -0
  42. data/lib/mini_kraken/rela/binary_relation.rb +30 -0
  43. data/lib/mini_kraken/rela/conde.rb +146 -0
  44. data/lib/mini_kraken/rela/conj2.rb +65 -0
  45. data/lib/mini_kraken/rela/def_relation.rb +64 -0
  46. data/lib/mini_kraken/rela/disj2.rb +70 -0
  47. data/lib/mini_kraken/rela/fresh.rb +98 -0
  48. data/lib/mini_kraken/{core → rela}/goal_relation.rb +6 -8
  49. data/lib/mini_kraken/rela/unify.rb +258 -0
  50. data/lib/mini_kraken/version.rb +1 -1
  51. data/spec/atomic/atomic_term_spec.rb +23 -20
  52. data/spec/atomic/k_symbol_spec.rb +0 -5
  53. data/spec/composite/cons_cell_spec.rb +116 -0
  54. data/spec/composite/cons_cell_visitor_spec.rb +16 -3
  55. data/spec/composite/list_spec.rb +50 -0
  56. data/spec/core/any_value_spec.rb +52 -0
  57. data/spec/core/arity_spec.rb +91 -0
  58. data/spec/core/association_copy_spec.rb +69 -0
  59. data/spec/core/association_spec.rb +25 -0
  60. data/spec/core/blackboard_spec.rb +287 -0
  61. data/spec/core/bookmark_spec.rb +40 -0
  62. data/spec/core/context_spec.rb +221 -0
  63. data/spec/core/core_spec.rb +40 -0
  64. data/spec/core/duck_fiber_spec.rb +22 -46
  65. data/spec/core/fail_spec.rb +5 -6
  66. data/spec/core/goal_spec.rb +20 -11
  67. data/spec/core/log_var_ref_spec.rb +80 -5
  68. data/spec/core/log_var_spec.rb +35 -6
  69. data/spec/core/nullary_relation_spec.rb +33 -0
  70. data/spec/core/parametrized_tem_spec.rb +39 -0
  71. data/spec/core/relation_spec.rb +33 -0
  72. data/spec/core/scope_spec.rb +73 -0
  73. data/spec/core/solver_adapter_spec.rb +70 -0
  74. data/spec/core/specification_spec.rb +43 -0
  75. data/spec/core/succeed_spec.rb +5 -5
  76. data/spec/core/symbol_table_spec.rb +142 -0
  77. data/spec/glue/dsl_chap1_spec.rb +88 -99
  78. data/spec/glue/dsl_chap2_spec.rb +59 -41
  79. data/spec/glue/run_star_expression_spec.rb +69 -896
  80. data/spec/{core → rela}/conde_spec.rb +50 -46
  81. data/spec/rela/conj2_spec.rb +123 -0
  82. data/spec/rela/def_relation_spec.rb +119 -0
  83. data/spec/rela/disj2_spec.rb +117 -0
  84. data/spec/rela/fresh_spec.rb +147 -0
  85. data/spec/rela/unify_spec.rb +369 -0
  86. data/spec/support/factory_atomic.rb +7 -0
  87. data/spec/support/factory_composite.rb +21 -0
  88. metadata +71 -48
  89. data/lib/mini_kraken/core/association_walker.rb +0 -183
  90. data/lib/mini_kraken/core/base_arg.rb +0 -10
  91. data/lib/mini_kraken/core/binary_relation.rb +0 -63
  92. data/lib/mini_kraken/core/composite_goal.rb +0 -46
  93. data/lib/mini_kraken/core/conde.rb +0 -143
  94. data/lib/mini_kraken/core/conj2.rb +0 -79
  95. data/lib/mini_kraken/core/def_relation.rb +0 -53
  96. data/lib/mini_kraken/core/designation.rb +0 -55
  97. data/lib/mini_kraken/core/disj2.rb +0 -72
  98. data/lib/mini_kraken/core/environment.rb +0 -73
  99. data/lib/mini_kraken/core/equals.rb +0 -191
  100. data/lib/mini_kraken/core/formal_arg.rb +0 -22
  101. data/lib/mini_kraken/core/formal_ref.rb +0 -25
  102. data/lib/mini_kraken/core/freshness.rb +0 -45
  103. data/lib/mini_kraken/core/goal_arg.rb +0 -12
  104. data/lib/mini_kraken/core/goal_template.rb +0 -102
  105. data/lib/mini_kraken/core/outcome.rb +0 -63
  106. data/lib/mini_kraken/core/tap.rb +0 -46
  107. data/lib/mini_kraken/core/vocabulary.rb +0 -446
  108. data/lib/mini_kraken/glue/fresh_env.rb +0 -108
  109. data/lib/mini_kraken/glue/fresh_env_factory.rb +0 -83
  110. data/spec/core/association_walker_spec.rb +0 -194
  111. data/spec/core/conj2_spec.rb +0 -116
  112. data/spec/core/def_relation_spec.rb +0 -99
  113. data/spec/core/disj2_spec.rb +0 -100
  114. data/spec/core/environment_spec.rb +0 -144
  115. data/spec/core/equals_spec.rb +0 -319
  116. data/spec/core/goal_template_spec.rb +0 -74
  117. data/spec/core/outcome_spec.rb +0 -56
  118. data/spec/core/vocabulary_spec.rb +0 -220
  119. data/spec/glue/fresh_env_factory_spec.rb +0 -99
  120. data/spec/glue/fresh_env_spec.rb +0 -62
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/atomic/k_symbol'
5
- require_relative '../../lib/mini_kraken/core/disj2'
6
- require_relative '../../lib/mini_kraken/core/equals'
7
- require_relative '../../lib/mini_kraken/core/formal_arg'
8
- require_relative '../../lib/mini_kraken/core/formal_ref'
9
- require_relative '../../lib/mini_kraken/core/goal'
10
- require_relative '../../lib/mini_kraken/core/log_var_ref'
11
- # require_relative '../../lib/mini_kraken/core/environment'
12
-
13
- # Load the class under test
14
- require_relative '../../lib/mini_kraken/core/goal_template'
15
-
16
-
17
- module MiniKraken
18
- module Core
19
- describe GoalTemplate do
20
- let(:tea) { Atomic::KSymbol.new(:tea) }
21
- let(:t_ref) { FormalRef.new('t') }
22
- subject { GoalTemplate.new(Equals.instance, [tea, t_ref]) }
23
-
24
- context 'Initialization:' do
25
- it 'should be initialized with a relation and args' do
26
- expect { GoalTemplate.new(Equals.instance, [tea, t_ref]) }.not_to raise_error
27
- end
28
-
29
- it 'should know its relation' do
30
- expect(subject.relation).to eq(Equals.instance)
31
- end
32
-
33
- it 'should know its arguments' do
34
- expect(subject.args[0]).to eq(tea)
35
- expect(subject.args[1]).to eq(t_ref)
36
- end
37
- end # context
38
-
39
- context 'Provided services:' do
40
- let(:formal_t) { FormalArg.new('t') }
41
- let(:cup) { Atomic::KSymbol.new(:cup) }
42
- let(:ref_x) { LogVarRef.new('x') }
43
- # let(:env) { Environment.new }
44
-
45
- it 'should instantiate a single-node goal' do
46
- expect(subject.instantiate([formal_t], [cup])).to be_kind_of(Goal)
47
- goal = subject.instantiate([formal_t], [cup])
48
- expect(goal.relation).to eq(Equals.instance)
49
- expect(goal.actuals[0]).to eq(tea)
50
- expect(goal.actuals[1]).to eq(cup)
51
- end
52
-
53
- it 'should instantiate a multiple-nodes goal' do
54
- sub_tmp1 = GoalTemplate.new(Equals.instance, [tea, t_ref])
55
- sub_tmp2 = GoalTemplate.new(Equals.instance, [cup, t_ref])
56
- template = GoalTemplate.new(Disj2.instance, [sub_tmp1, sub_tmp2])
57
-
58
- goal = template.instantiate([formal_t], [ref_x])
59
- expect(goal.relation).to eq(Disj2.instance)
60
- subgoal1 = goal.actuals[0]
61
- expect(subgoal1).to be_kind_of(Goal)
62
- expect(subgoal1.relation).to eq(Equals.instance)
63
- expect(subgoal1.actuals[0]).to eq(tea)
64
- expect(subgoal1.actuals[1]).to eq(ref_x)
65
- subgoal2 = goal.actuals[1]
66
- expect(subgoal2).to be_kind_of(Goal)
67
- expect(subgoal2.relation).to eq(Equals.instance)
68
- expect(subgoal2.actuals[0]).to eq(cup)
69
- expect(subgoal2.actuals[1]).to eq(ref_x)
70
- end
71
- end # context
72
- end # describe
73
- end # module
74
- end # module
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../../lib/mini_kraken/core/vocabulary'
5
-
6
- # Load the class under test
7
- require_relative '../../lib/mini_kraken/core/outcome'
8
-
9
- module MiniKraken
10
- module Core
11
- describe Outcome do
12
- let(:voc) do
13
- obj = Object.new
14
- obj.extend(Vocabulary)
15
- obj
16
- end
17
- subject { Outcome.new(:"#s", voc) }
18
-
19
- context 'Initialization:' do
20
- it 'should be created with a symbol and a vocabulary' do
21
- expect { Outcome.new(:"#s", voc) }.not_to raise_error
22
- end
23
-
24
- it 'should know its resultant' do
25
- expect(subject.resultant).to eq(:"#s")
26
- end
27
-
28
- it 'should know whether it represents a failure' do
29
- expect(Outcome.new(:"#u")).to be_failure
30
- end
31
-
32
- it 'should know whether it represents a success' do
33
- expect(subject).to be_success
34
- end
35
-
36
- it 'should know its parent' do
37
- expect(subject.parent).to eq(voc)
38
- end
39
- end # context
40
-
41
- context 'Provided services:' do
42
- it 'should have a factory for failing outcome' do
43
- instance = Outcome.failure(voc)
44
- expect(instance.resultant).to eq(:"#u")
45
- expect(instance.parent).to eq(voc)
46
- end
47
-
48
- it 'should have a factory for succeeding outcome' do
49
- instance = Outcome.success(voc)
50
- expect(instance.resultant).to eq(:"#s")
51
- expect(instance.parent).to eq(voc)
52
- end
53
- end # context
54
- end # describe
55
- end # module
56
- end # module
@@ -1,220 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
- require_relative '../support/factory_atomic'
5
- require_relative '../../lib/mini_kraken/core/log_var'
6
- require_relative '../../lib/mini_kraken/core/log_var_ref'
7
- require_relative '../support/factory_methods'
8
-
9
- # Load the class under test
10
- # frozen_string_literal: true
11
-
12
- require_relative '../../lib/mini_kraken/core/vocabulary'
13
-
14
- module MiniKraken
15
- module Core
16
- class TestVocabulary
17
- include Vocabulary
18
-
19
- def initialize(aParent = nil)
20
- init_vocabulary(aParent)
21
- end
22
- end # class
23
-
24
- # Helper module that simulates an environment-like object.
25
- module LogVarBearer
26
- attr_reader :vars
27
- attr_accessor :ivars
28
-
29
- def init_var_bearer
30
- @vars = {}
31
- @ivars = {}
32
- self
33
- end
34
-
35
- def add_var(aVarName)
36
- vars[aVarName] = LogVar.new(aVarName)
37
- ivars[aVarName] = Set.new([aVarName])
38
- end
39
- end # module
40
-
41
- describe Vocabulary do
42
- include MiniKraken::FactoryAtomic # Use mix-in module
43
- include FactoryMethods
44
-
45
- let(:parent) { TestVocabulary.new }
46
- subject { TestVocabulary.new }
47
-
48
- context 'Initialization:' do
49
- it 'could be initialized without a parent' do
50
- expect { TestVocabulary.new }.not_to raise_error
51
- end
52
-
53
- it 'could be initialized with a parent' do
54
- expect { TestVocabulary.new(parent) }.not_to raise_error
55
- end
56
-
57
- it 'should know its parent (if any)' do
58
- expect(subject.parent).to be_nil
59
- instance = TestVocabulary.new(parent)
60
- expect(instance.parent).to eq(parent)
61
- end
62
-
63
- it 'should have no associations at initialization' do
64
- expect(subject.associations).to be_empty
65
- end
66
- end # context
67
-
68
- context 'Provided services:' do
69
- let(:pea) { k_symbol(:pea) }
70
- let(:pod) { k_symbol(:pod) }
71
- let(:ref_q) { LogVarRef.new('q') }
72
- let(:ref_x) { LogVarRef.new('x') }
73
- let(:grandma) do
74
- voc = TestVocabulary.new
75
- voc.extend(LogVarBearer)
76
- voc.init_var_bearer
77
- end
78
- let(:mother) { TestVocabulary.new(grandma) }
79
- subject { TestVocabulary.new(mother) }
80
-
81
- it 'should provide a walker over ancestors' do
82
- walker = subject.ancestor_walker
83
- expect(walker).to be_kind_of(Enumerator)
84
- expect(walker.next).to eq(subject)
85
- expect(walker.next).to eq(mother)
86
- expect(walker.next).to eq(grandma)
87
- expect(walker.next).to be_nil
88
- end
89
-
90
- it 'should know if a variable is defined' do
91
- expect(subject.include?('q')).to be_falsey
92
- grandma.add_var('x')
93
- expect(subject.include?('q')).to be_falsey
94
- expect(grandma.include?('x')).to be_truthy
95
- expect(mother.include?('x')).to be_truthy
96
- expect(subject.include?('x')).to be_truthy
97
- subject.extend(LogVarBearer)
98
- subject.init_var_bearer
99
- subject.add_var('y')
100
- expect(subject.include?('y')).to be_truthy
101
- expect(mother.include?('y')).to be_falsey
102
- end
103
-
104
- it 'should allow the addition of associations' do
105
- grandma.add_var('q')
106
- expect(subject['q']).to be_empty
107
- res_add = mother.add_assoc('q', pea)
108
- expect(res_add).to be_kind_of(Association)
109
- expect(subject['q'].size).to eq(1)
110
- expect(subject['q'].first.value).to eq(pea)
111
-
112
- subject.add_assoc('q', ref_x)
113
- expect(subject['q'].size).to eq(2)
114
- expect(subject['q'].first.value).to eq(ref_x)
115
- expect(subject['q'].last.value).to eq(pea)
116
- end
117
-
118
- it 'should allow the deletion of associations' do
119
- grandma.add_var('q')
120
- mother.add_assoc('q', pea)
121
- subject.add_assoc('q', ref_x)
122
- expect(mother.associations.size).to eq(1)
123
- expect(subject.associations.size).to eq(1)
124
-
125
- subject.clear
126
- expect(subject.associations).to be_empty
127
-
128
- mother.clear
129
- expect(mother.associations).to be_empty
130
- end
131
-
132
- it 'should say fresh when a variable has no association at all' do
133
- grandma.add_var('q')
134
- grandma.add_var('x')
135
- expect(subject.fresh?(ref_q)).to be_truthy
136
- subject.add_assoc('q', ref_x) # Dependency: q --> x
137
- expect(subject.fresh?(ref_x)).to be_truthy
138
- end
139
-
140
- it 'should say not fresh when variable --> atomic value' do
141
- grandma.add_var('q')
142
- grandma.add_var('x')
143
- subject.add_assoc('q', ref_x) # Dependency: q --> x
144
- expect(subject.fresh?(ref_q)).to be_truthy
145
-
146
- # Associate with an atomic term
147
- subject.add_assoc('q', pea)
148
- expect(subject.fresh?(ref_q)).to be_falsey
149
- end
150
-
151
- it 'should say not fresh when variable --> composite of atomics' do
152
- grandma.add_var('q')
153
-
154
- # Composite having only atomic terms as leaf elements
155
- expr = cons(pea, cons(pod))
156
- subject.add_assoc('q', expr)
157
- expect(subject.fresh?(ref_q)).to be_falsey
158
- end
159
-
160
- it 'say not fresh when variable --> composite of atomics & bound var' do
161
- grandma.add_var('q')
162
- grandma.add_var('x')
163
- subject.add_assoc('x', pea) # Dependency: x --> pea
164
- expr = cons(pea, cons(pod, cons(ref_x)))
165
- subject.add_assoc('q', expr)
166
- expect(subject.fresh?(ref_q)).to be_falsey
167
- end
168
-
169
- it 'say not fresh when variable --> composite of atomics & fresh var' do
170
- grandma.add_var('q')
171
- grandma.add_var('x')
172
- expr = cons(pea, cons(pod, cons(ref_x)))
173
- subject.add_assoc('q', expr)
174
- expect(subject.fresh?(ref_q)).to be_truthy
175
- end
176
-
177
- it 'say not fresh when variables are fused & one is ground' do
178
- grandma.add_var('q')
179
- grandma.add_var('x')
180
-
181
- # Beware of cyclic structure
182
- subject.add_assoc('q', ref_x) # Dependency: q --> x
183
- subject.add_assoc('x', ref_q) # Dependency: x --> q
184
- expect(subject.fresh?(ref_x)).to be_truthy
185
- expect(subject.fresh?(ref_q)).to be_truthy
186
- expect(subject.associations).to be_empty
187
-
188
- # Associate with an atomic term
189
- subject.add_assoc('x', pea)
190
- expect(subject.fresh?(ref_q)).to be_falsey
191
- end
192
-
193
- it 'should rank names sequentially' do
194
- 2.times do
195
- expect(subject.get_rank('a')).to eq(0)
196
- expect(subject.get_rank('z')).to eq(1)
197
- expect(subject.get_rank('c')).to eq(2)
198
- end
199
- end
200
-
201
- it 'should clear the rankings' do
202
- expect(subject.get_rank('a')).to eq(0)
203
- expect(subject.get_rank('z')).to eq(1)
204
-
205
- subject.clear_rankings
206
- expect(grandma.rankings).to be_empty
207
-
208
- expect(subject.get_rank('z')).to eq(0)
209
- expect(subject.get_rank('a')).to eq(1)
210
- end
211
-
212
- it 'should provide a String representation of itself' do
213
- expectation = +"#<#{subject.class}:#{subject.object_id.to_s(16)} @parent="
214
- expectation << "#<#{subject.parent.class}:#{subject.parent.object_id.to_s(16)}>>"
215
- expect(subject.inspect).to eq(expectation)
216
- end
217
- end # context
218
- end # describe
219
- end # module
220
- end # module
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../lib/mini_kraken/core/equals'
4
- require_relative '../../lib/mini_kraken/core/formal_arg'
5
- require_relative '../../lib/mini_kraken/core/formal_ref'
6
- require_relative '../../lib/mini_kraken/core/goal_template'
7
-
8
- require_relative '../support/factory_atomic'
9
- require_relative '../support/factory_methods'
10
-
11
- # Load the class under test
12
- require_relative '../../lib/mini_kraken/glue/fresh_env_factory'
13
-
14
-
15
- module MiniKraken
16
- module Glue
17
- describe FreshEnvFactory do
18
- include MiniKraken::FactoryAtomic # Use mix-in module
19
- include FactoryMethods
20
-
21
- # (fresh (d) (== d r))
22
- let(:r_formal_ref) { Core::FormalRef.new('r') }
23
- let(:d_ref) { var_ref('d') }
24
- let(:sample_goal_t) do
25
- Core::GoalTemplate.new(Core::Equals.instance, [d_ref, r_formal_ref])
26
- end
27
- subject { FreshEnvFactory.new(['d'], sample_goal_t) }
28
-
29
- context 'Initialization:' do
30
- it 'should be initialized with names and a goal template' do
31
- expect { FreshEnvFactory.new(['d'], sample_goal_t) }.not_to raise_error
32
- end
33
-
34
- it 'should know the variable names' do
35
- expect(subject.names).to eq(['d'])
36
- end
37
-
38
- it 'should know the goal template' do
39
- expect(subject.goal_template).to eq(sample_goal_t)
40
- end
41
- end # context
42
-
43
- context 'Factory for FreshEnv instances' do
44
- # (defrel (caro r a)
45
- # (fresh (d)
46
- # (== (cons a d) r)))
47
- # ;; r, a are formal args, they part of caro signature
48
- # ;; d is a formal ref argument
49
- let(:pea) { k_symbol(:pea) }
50
- let(:q_ref) { var_ref('q') }
51
- let(:r_formal) { Core::FormalRef.new('r') }
52
- let(:a_formal) { Core::FormalRef.new('a') }
53
- let(:t_param1) { Composite::ConsCell.new(a_formal, d_ref) }
54
- let(:other_goal_t) do
55
- Core::GoalTemplate.new(Core::Equals.instance, [t_param1, r_formal])
56
- end
57
-
58
- # (fresh (d) (== d r))
59
- it 'should build FreshEnv instance with simple goal' do
60
- created = subject.instantiate([r_formal], [pea])
61
-
62
- # Are variables correctly built?
63
- expect(created).to be_kind_of(FreshEnv)
64
- expect(created.vars['d']).to be_kind_of(Core::LogVar)
65
-
66
- # Is the goal correectly built?
67
- goal = created.goal
68
- expect(goal.relation).to eq(Core::Equals.instance)
69
- expect(goal.actuals[0]).to be_kind_of(Core::LogVarRef)
70
- expect(goal.actuals[0].name).to eq('d')
71
- expect(goal.actuals[1]).to be_kind_of(Atomic::KSymbol)
72
- expect(goal.actuals[1]).to eq(:pea)
73
- end
74
-
75
- it 'should build FreshEnv instance with goal' do
76
- instance = FreshEnvFactory.new(['d'], other_goal_t)
77
- acorn = cons(k_symbol(:a), cons(k_symbol(:c), cons(k_symbol(:o),
78
- cons(k_symbol(:r), cons(k_symbol(:n))))))
79
- created = instance.instantiate([r_formal, a_formal], [acorn, q_ref])
80
-
81
- # Are variables correctly built?
82
- expect(created).to be_kind_of(FreshEnv)
83
- expect(created.vars['d']).to be_kind_of(Core::LogVar)
84
-
85
- # Is the goal correctly built?
86
- goal = created.goal
87
- expect(goal.relation).to eq(Core::Equals.instance)
88
- expect(goal.actuals[0]).to be_kind_of(Composite::ConsCell)
89
- expect(goal.actuals[0].car).to be_kind_of(Core::LogVarRef)
90
- expect(goal.actuals[0].car.name).to eq('q')
91
- expect(goal.actuals[0].cdr).to be_kind_of(Core::LogVarRef)
92
- expect(goal.actuals[0].cdr.name).to eq('d')
93
- expect(goal.actuals[1]).to be_kind_of(Composite::ConsCell)
94
- expect(goal.actuals[1].to_s).to eq('(:a :c :o :r :n)')
95
- end
96
- end # context
97
- end # describe
98
- end # module
99
- end # module