mini_kraken 0.2.02 → 0.2.03
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +3 -3
- data/lib/mini_kraken.rb +0 -1
- data/lib/mini_kraken/core/conde.rb +1 -1
- data/lib/mini_kraken/core/conj2.rb +3 -3
- data/lib/mini_kraken/core/cons_cell_visitor.rb +102 -0
- data/lib/mini_kraken/core/def_relation.rb +3 -0
- data/lib/mini_kraken/core/disj2.rb +2 -2
- data/lib/mini_kraken/core/environment.rb +1 -1
- data/lib/mini_kraken/core/equals.rb +59 -22
- data/lib/mini_kraken/core/goal_template.rb +42 -2
- data/lib/mini_kraken/core/k_boolean.rb +1 -1
- data/lib/mini_kraken/core/outcome.rb +11 -1
- data/lib/mini_kraken/core/variable_ref.rb +6 -0
- data/lib/mini_kraken/core/vocabulary.rb +6 -2
- data/lib/mini_kraken/glue/dsl.rb +17 -8
- data/lib/mini_kraken/glue/fresh_env.rb +31 -3
- data/lib/mini_kraken/glue/fresh_env_factory.rb +83 -0
- data/lib/mini_kraken/glue/run_star_expression.rb +2 -2
- data/lib/mini_kraken/version.rb +1 -1
- data/spec/core/conde_spec.rb +9 -9
- data/spec/core/conj2_spec.rb +7 -7
- data/spec/core/cons_cell_visitor_spec.rb +144 -0
- data/spec/core/def_relation_spec.rb +6 -5
- data/spec/core/disj2_spec.rb +5 -5
- data/spec/core/duck_fiber_spec.rb +1 -1
- data/spec/core/equals_spec.rb +34 -21
- data/spec/core/goal_spec.rb +2 -2
- data/spec/core/outcome_spec.rb +8 -0
- data/spec/core/variable_ref_spec.rb +3 -0
- data/spec/glue/dsl_chap1_spec.rb +10 -2
- data/spec/glue/dsl_chap2_spec.rb +100 -0
- data/spec/glue/fresh_env_factory_spec.rb +97 -0
- data/spec/glue/run_star_expression_spec.rb +3 -2
- metadata +10 -2
@@ -0,0 +1,97 @@
|
|
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_methods'
|
9
|
+
|
10
|
+
# Load the class under test
|
11
|
+
require_relative '../../lib/mini_kraken/glue/fresh_env_factory'
|
12
|
+
|
13
|
+
|
14
|
+
module MiniKraken
|
15
|
+
module Glue
|
16
|
+
describe FreshEnvFactory do
|
17
|
+
include FactoryMethods
|
18
|
+
|
19
|
+
# (fresh (d) (== d r))
|
20
|
+
let(:r_formal_ref) { Core::FormalRef.new('r') }
|
21
|
+
let(:d_ref) { var_ref('d') }
|
22
|
+
let(:sample_goal_t) do
|
23
|
+
Core::GoalTemplate.new(Core::Equals.instance, [d_ref, r_formal_ref])
|
24
|
+
end
|
25
|
+
subject { FreshEnvFactory.new(['d'], sample_goal_t) }
|
26
|
+
|
27
|
+
context 'Initialization:' do
|
28
|
+
it 'should be initialized with names and a goal template' do
|
29
|
+
expect { FreshEnvFactory.new(['d'], sample_goal_t) }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should know the variable names' do
|
33
|
+
expect(subject.names).to eq(['d'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should know the goal template' do
|
37
|
+
expect(subject.goal_template).to eq(sample_goal_t)
|
38
|
+
end
|
39
|
+
end # context
|
40
|
+
|
41
|
+
context 'Factory for FreshEnv instances' do
|
42
|
+
# (defrel (caro r a)
|
43
|
+
# (fresh (d)
|
44
|
+
# (== (cons a d) r)))
|
45
|
+
# ;; r, a are formal args, they part of caro signature
|
46
|
+
# ;; d is a formal ref argument
|
47
|
+
let(:pea) { k_symbol(:pea) }
|
48
|
+
let(:q_ref) { var_ref('q') }
|
49
|
+
let(:r_formal) { Core::FormalRef.new('r') }
|
50
|
+
let(:a_formal) { Core::FormalRef.new('a') }
|
51
|
+
let(:t_param1) { Core::ConsCell.new(a_formal, d_ref) }
|
52
|
+
let(:other_goal_t) do
|
53
|
+
Core::GoalTemplate.new(Core::Equals.instance, [t_param1, r_formal])
|
54
|
+
end
|
55
|
+
|
56
|
+
# (fresh (d) (== d r))
|
57
|
+
it 'should build FreshEnv instance with simple goal' do
|
58
|
+
created = subject.instantiate([r_formal], [pea])
|
59
|
+
|
60
|
+
# Are variables correctly built?
|
61
|
+
expect(created).to be_kind_of(FreshEnv)
|
62
|
+
expect(created.vars['d']).to be_kind_of(Core::Variable)
|
63
|
+
|
64
|
+
# Is the goal correectly built?
|
65
|
+
goal = created.goal
|
66
|
+
expect(goal.relation).to eq(Core::Equals.instance)
|
67
|
+
expect(goal.actuals[0]).to be_kind_of(Core::VariableRef)
|
68
|
+
expect(goal.actuals[0].name).to eq('d')
|
69
|
+
expect(goal.actuals[1]).to be_kind_of(Core::KSymbol)
|
70
|
+
expect(goal.actuals[1]).to eq(:pea)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should build FreshEnv instance with goal' do
|
74
|
+
instance = FreshEnvFactory.new(['d'], other_goal_t)
|
75
|
+
acorn = cons(k_symbol(:a), cons(k_symbol(:c), cons(k_symbol(:o),
|
76
|
+
cons(k_symbol(:r), cons(k_symbol(:n))))))
|
77
|
+
created = instance.instantiate([r_formal, a_formal], [acorn, q_ref])
|
78
|
+
|
79
|
+
# Are variables correctly built?
|
80
|
+
expect(created).to be_kind_of(FreshEnv)
|
81
|
+
expect(created.vars['d']).to be_kind_of(Core::Variable)
|
82
|
+
|
83
|
+
# Is the goal correctly built?
|
84
|
+
goal = created.goal
|
85
|
+
expect(goal.relation).to eq(Core::Equals.instance)
|
86
|
+
expect(goal.actuals[0]).to be_kind_of(Core::ConsCell)
|
87
|
+
expect(goal.actuals[0].car).to be_kind_of(Core::VariableRef)
|
88
|
+
expect(goal.actuals[0].car.name).to eq('q')
|
89
|
+
expect(goal.actuals[0].cdr).to be_kind_of(Core::VariableRef)
|
90
|
+
expect(goal.actuals[0].cdr.name).to eq('d')
|
91
|
+
expect(goal.actuals[1]).to be_kind_of(Core::ConsCell)
|
92
|
+
expect(goal.actuals[1].to_s).to eq('(:a :c :o :r :n)')
|
93
|
+
end
|
94
|
+
end # context
|
95
|
+
end # describe
|
96
|
+
end # module
|
97
|
+
end # module
|
@@ -23,6 +23,7 @@ module MiniKraken
|
|
23
23
|
module Glue
|
24
24
|
describe RunStarExpression do
|
25
25
|
include FactoryMethods
|
26
|
+
|
26
27
|
let(:pea) { k_symbol(:pea) }
|
27
28
|
let(:pod) { k_symbol(:pod) }
|
28
29
|
let(:sample_goal) { equals_goal(pea, pod) }
|
@@ -265,8 +266,8 @@ module MiniKraken
|
|
265
266
|
it 'should unify complex equality expressions (IV)' do
|
266
267
|
# Reasoned S2, frame 1:36
|
267
268
|
# (run* q (fresh (x) (== '(((,q)) (,x)) `(((,x)) pod)))) ;; => ('pod)
|
268
|
-
expr1 = cons(cons(cons(ref_q)), ref_x)
|
269
|
-
expr2 = cons(cons(cons(ref_x)), pod)
|
269
|
+
expr1 = cons(cons(cons(ref_q)), cons(ref_x))
|
270
|
+
expr2 = cons(cons(cons(ref_x)), cons(pod))
|
270
271
|
goal = equals_goal(expr1, expr2)
|
271
272
|
fresh_env = FreshEnv.new(['x'], goal)
|
272
273
|
instance = RunStarExpression.new('q', fresh_env)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_kraken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.03
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/mini_kraken/core/conde.rb
|
81
81
|
- lib/mini_kraken/core/conj2.rb
|
82
82
|
- lib/mini_kraken/core/cons_cell.rb
|
83
|
+
- lib/mini_kraken/core/cons_cell_visitor.rb
|
83
84
|
- lib/mini_kraken/core/def_relation.rb
|
84
85
|
- lib/mini_kraken/core/designation.rb
|
85
86
|
- lib/mini_kraken/core/disj2.rb
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- lib/mini_kraken/core/vocabulary.rb
|
108
109
|
- lib/mini_kraken/glue/dsl.rb
|
109
110
|
- lib/mini_kraken/glue/fresh_env.rb
|
111
|
+
- lib/mini_kraken/glue/fresh_env_factory.rb
|
110
112
|
- lib/mini_kraken/glue/run_star_expression.rb
|
111
113
|
- lib/mini_kraken/version.rb
|
112
114
|
- mini_kraken.gemspec
|
@@ -116,6 +118,7 @@ files:
|
|
116
118
|
- spec/core/conde_spec.rb
|
117
119
|
- spec/core/conj2_spec.rb
|
118
120
|
- spec/core/cons_cell_spec.rb
|
121
|
+
- spec/core/cons_cell_visitor_spec.rb
|
119
122
|
- spec/core/def_relation_spec.rb
|
120
123
|
- spec/core/disj2_spec.rb
|
121
124
|
- spec/core/duck_fiber_spec.rb
|
@@ -132,6 +135,8 @@ files:
|
|
132
135
|
- spec/core/variable_spec.rb
|
133
136
|
- spec/core/vocabulary_spec.rb
|
134
137
|
- spec/glue/dsl_chap1_spec.rb
|
138
|
+
- spec/glue/dsl_chap2_spec.rb
|
139
|
+
- spec/glue/fresh_env_factory_spec.rb
|
135
140
|
- spec/glue/fresh_env_spec.rb
|
136
141
|
- spec/glue/run_star_expression_spec.rb
|
137
142
|
- spec/mini_kraken_spec.rb
|
@@ -167,6 +172,7 @@ test_files:
|
|
167
172
|
- spec/core/conde_spec.rb
|
168
173
|
- spec/core/conj2_spec.rb
|
169
174
|
- spec/core/cons_cell_spec.rb
|
175
|
+
- spec/core/cons_cell_visitor_spec.rb
|
170
176
|
- spec/core/def_relation_spec.rb
|
171
177
|
- spec/core/disj2_spec.rb
|
172
178
|
- spec/core/duck_fiber_spec.rb
|
@@ -183,6 +189,8 @@ test_files:
|
|
183
189
|
- spec/core/variable_spec.rb
|
184
190
|
- spec/core/vocabulary_spec.rb
|
185
191
|
- spec/glue/dsl_chap1_spec.rb
|
192
|
+
- spec/glue/dsl_chap2_spec.rb
|
193
|
+
- spec/glue/fresh_env_factory_spec.rb
|
186
194
|
- spec/glue/fresh_env_spec.rb
|
187
195
|
- spec/glue/run_star_expression_spec.rb
|
188
196
|
- spec/mini_kraken_spec.rb
|