mini_kraken 0.2.00 → 0.3.00

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +334 -0
  3. data/CHANGELOG.md +50 -0
  4. data/README.md +26 -24
  5. data/lib/mini_kraken.rb +2 -3
  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 +5 -9
  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 +624 -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 +21 -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 +134 -32
  43. data/lib/mini_kraken/glue/run_star_expression.rb +28 -32
  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 +146 -0
  47. data/lib/mini_kraken/rela/conj2.rb +65 -0
  48. data/lib/mini_kraken/rela/def_relation.rb +64 -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 +6 -3
  55. data/spec/.rubocop.yml +13 -0
  56. data/spec/atomic/atomic_term_spec.rb +97 -0
  57. data/spec/{core → atomic}/k_boolean_spec.rb +25 -34
  58. data/spec/{core → atomic}/k_symbol_spec.rb +4 -17
  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 +91 -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 +221 -0
  69. data/spec/core/core_spec.rb +40 -0
  70. data/spec/core/duck_fiber_spec.rb +22 -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 +250 -125
  84. data/spec/glue/dsl_chap2_spec.rb +226 -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 +102 -64
  96. data/lib/mini_kraken/core/association_walker.rb +0 -183
  97. data/lib/mini_kraken/core/atomic_term.rb +0 -66
  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 -81
  105. data/lib/mini_kraken/core/def_relation.rb +0 -49
  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 -159
  110. data/lib/mini_kraken/core/formal_arg.rb +0 -22
  111. data/lib/mini_kraken/core/formal_ref.rb +0 -24
  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 -60
  115. data/lib/mini_kraken/core/k_boolean.rb +0 -31
  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 -77
  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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bbfe3d58d4c7271a5c8a54486a743c51d6fddcb3b068095cad44cacad575c83
4
- data.tar.gz: 012b412a95752592b5be70859e00d94b379e2c4c564d37d932a300a03cbc9716
3
+ metadata.gz: ceccf4c9ffeb71fc8759bbf1ea1db003d83e9e150df95793de7e729716c9538d
4
+ data.tar.gz: bab9d4b22a86eec0fcd95955a799a40bfd51c032d05a56b5c2569e0e833b4d2d
5
5
  SHA512:
6
- metadata.gz: 952d93b01de392c7168e7cfb4a3cc911e4d1b53be11a4a10d67012bb4ab4a8f69aa42f41bf13a756f89a6d09eb775a5594174d73334c57c2230039b7991e89fd
7
- data.tar.gz: a60adbd5da627495badab63de355336f131a5e599c40226931366a7c1b4a349b2542ccb55cf30ef8e60990341c1f5d8547804b1552fbbbc504bd1bed40a36d9e
6
+ metadata.gz: 5b8dac966209d3209419b2721c67ecd9ec1d1985b0a457877def4e9eda3a305b6952d996e1791436db33f863a046553df1567ef142fc7fe6d5d8092b7d0e2ecd
7
+ data.tar.gz: 5c99a985287a32d2e6a2c6dbbcabeaea07203e533372183817660eb2259edda6465b4993997b9dcb8dd0db59e0b69772f31409f17a587a3d55381d7f06151a74
@@ -0,0 +1,334 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'exp/**/*'
4
+
5
+ Layout/ArgumentAlignment:
6
+ Enabled: false
7
+
8
+ Layout/ArrayAlignment:
9
+ Enabled: true
10
+ EnforcedStyle: with_fixed_indentation
11
+
12
+ Layout/CaseIndentation:
13
+ Enabled: false
14
+
15
+ Layout/ClosingHeredocIndentation:
16
+ Enabled: false
17
+
18
+ Layout/CommentIndentation:
19
+ Enabled: false
20
+
21
+ Layout/ElseAlignment:
22
+ Enabled: false
23
+
24
+ Layout/EmptyLines:
25
+ Enabled: false
26
+
27
+ Layout/EndAlignment:
28
+ Enabled: false
29
+
30
+ Layout/EndOfLine:
31
+ Enabled: true
32
+ EnforcedStyle: lf
33
+
34
+ Layout/FirstArgumentIndentation:
35
+ Enabled: false
36
+
37
+ Layout/IndentationWidth:
38
+ Enabled: false
39
+
40
+ Layout/IndentationConsistency:
41
+ Enabled: true
42
+
43
+ Layout/HeredocIndentation:
44
+ Enabled: false
45
+
46
+ Layout/MultilineHashBraceLayout:
47
+ Enabled: true
48
+
49
+ Layout/MultilineMethodCallBraceLayout:
50
+ Enabled: true
51
+ EnforcedStyle: same_line
52
+
53
+ Layout/SpaceAroundOperators:
54
+ Enabled: true
55
+
56
+ Layout/SpaceInsideParens:
57
+ Enabled: true
58
+
59
+ Layout/IndentationStyle:
60
+ Enabled: true
61
+
62
+ Layout/SpaceAroundMethodCallOperator:
63
+ Enabled: true
64
+
65
+ Layout/TrailingEmptyLines:
66
+ Enabled: true
67
+
68
+ Layout/TrailingWhitespace:
69
+ Enabled: true
70
+
71
+ Lint/Loop:
72
+ Enabled: true
73
+
74
+ Lint/RaiseException:
75
+ Enabled: true
76
+
77
+ Lint/RescueException:
78
+ Enabled: true
79
+
80
+ Lint/StructNewOverride:
81
+ Enabled: true
82
+
83
+ Lint/UnusedMethodArgument:
84
+ Enabled: true
85
+
86
+ Lint/UselessAccessModifier:
87
+ Enabled: true
88
+
89
+ Lint/Void:
90
+ Enabled: false
91
+
92
+ Lint/UselessAssignment:
93
+ Enabled: true
94
+
95
+ Metrics/AbcSize:
96
+ Enabled: false
97
+
98
+ Metrics/BlockLength:
99
+ Enabled: true
100
+ Max: 350
101
+
102
+ Metrics/BlockNesting:
103
+ Enabled: true
104
+ Max: 5
105
+
106
+ Metrics/ClassLength:
107
+ Enabled: true
108
+ Max: 350
109
+
110
+ Metrics/CyclomaticComplexity:
111
+ Enabled: false
112
+
113
+ Layout/LineLength:
114
+ Enabled: false
115
+ Max: 90
116
+
117
+ Metrics/MethodLength:
118
+ Enabled: true
119
+ Max: 50
120
+
121
+ Metrics/ModuleLength:
122
+ Enabled: true
123
+ Max: 500
124
+
125
+ Metrics/PerceivedComplexity:
126
+ Enabled: false
127
+
128
+ Naming/ConstantName:
129
+ Enabled: false
130
+
131
+ Naming/ClassAndModuleCamelCase:
132
+ Enabled: false
133
+
134
+ Naming/BlockParameterName:
135
+ Enabled: true
136
+
137
+ Naming/MethodParameterName:
138
+ Enabled: false
139
+
140
+ Naming/VariableName:
141
+ Enabled: false
142
+
143
+ Style/Alias:
144
+ Enabled: true
145
+
146
+ Layout/HashAlignment:
147
+ Enabled: false
148
+
149
+ Style/AsciiComments:
150
+ Enabled: false
151
+
152
+ Style/BarePercentLiterals:
153
+ Enabled: false
154
+
155
+ Style/BlockComments:
156
+ Enabled: false
157
+
158
+ Style/CharacterLiteral:
159
+ Enabled: false
160
+
161
+ Style/ClassCheck:
162
+ Enabled: false
163
+
164
+ Style/ClassVars:
165
+ Enabled: false
166
+
167
+ Style/ColonMethodCall:
168
+ Enabled: false
169
+
170
+ Style/CommentAnnotation:
171
+ Enabled: false
172
+
173
+ Style/CommentedKeyword:
174
+ Enabled: false
175
+
176
+ Style/ConditionalAssignment:
177
+ Enabled: false
178
+
179
+ Style/DefWithParentheses:
180
+ Enabled: true
181
+
182
+ Style/Documentation:
183
+ Enabled: false
184
+
185
+ Style/ExpandPathArguments:
186
+ Enabled: false
187
+
188
+ Style/ExponentialNotation:
189
+ Enabled: true
190
+
191
+ Style/GuardClause:
192
+ Enabled: false
193
+
194
+ Style/HashEachMethods:
195
+ Enabled: true
196
+
197
+ Style/HashTransformKeys:
198
+ Enabled: true
199
+
200
+ Style/HashTransformValues:
201
+ Enabled: true
202
+
203
+ Style/IfUnlessModifier:
204
+ Enabled: false
205
+
206
+ Style/InverseMethods:
207
+ Enabled: true
208
+
209
+ Style/MissingRespondToMissing:
210
+ Enabled: false
211
+
212
+ Style/Next:
213
+ Enabled: false
214
+
215
+ Style/NumericLiterals:
216
+ Enabled: false
217
+
218
+ Style/RaiseArgs:
219
+ Enabled: true
220
+
221
+ Style/RedundantReturn:
222
+ Enabled: false
223
+
224
+ Style/RedundantSelf:
225
+ Enabled: true
226
+
227
+ Style/RegexpLiteral:
228
+ Enabled: false
229
+
230
+ Style/PercentLiteralDelimiters:
231
+ Enabled: false
232
+
233
+ Style/StderrPuts:
234
+ Enabled: false
235
+
236
+ Style/StringLiterals:
237
+ Enabled: true
238
+
239
+ Style/TernaryParentheses:
240
+ Enabled: false
241
+
242
+ Style/UnlessElse:
243
+ Enabled: false
244
+
245
+ # Rubocop complains when it doesn't find an explicit setting for the following cops:
246
+ Layout/EmptyLinesAroundAttributeAccessor:
247
+ Enabled: true
248
+
249
+ Lint/BinaryOperatorWithIdenticalOperands:
250
+ Enabled: true
251
+
252
+ Lint/DeprecatedOpenSSLConstant:
253
+ Enabled: true
254
+
255
+ Lint/DuplicateElsifCondition:
256
+ Enabled: true
257
+
258
+ Lint/DuplicateRescueException:
259
+ Enabled: true
260
+
261
+ Lint/EmptyConditionalBody:
262
+ Enabled: true
263
+
264
+ Lint/FloatComparison:
265
+ Enabled: true
266
+
267
+ Lint/MissingSuper:
268
+ Enabled: true
269
+
270
+ Lint/MixedRegexpCaptureTypes:
271
+ Enabled: true
272
+
273
+ Lint/OutOfRangeRegexpRef:
274
+ Enabled: true
275
+
276
+ Lint/SelfAssignment:
277
+ Enabled: true
278
+
279
+ Lint/TopLevelReturnWithArgument:
280
+ Enabled: true
281
+
282
+ Lint/UnreachableLoop:
283
+ Enabled: true
284
+
285
+ Style/AccessorGrouping:
286
+ Enabled: true
287
+
288
+ Style/ArrayCoercion:
289
+ Enabled: true
290
+
291
+ Style/BisectedAttrAccessor:
292
+ Enabled: true
293
+
294
+ Style/CaseLikeIf:
295
+ Enabled: true
296
+
297
+ Style/ExplicitBlockArgument:
298
+ Enabled: true
299
+
300
+ Style/GlobalStdStream:
301
+ Enabled: true
302
+
303
+ Style/HashAsLastArrayItem:
304
+ Enabled: true
305
+
306
+ Style/HashLikeCase:
307
+ Enabled: true
308
+
309
+ Style/OptionalBooleanParameter:
310
+ Enabled: true
311
+
312
+ Style/RedundantAssignment:
313
+ Enabled: true
314
+
315
+ Style/RedundantFetchBlock:
316
+ Enabled: true
317
+
318
+ Style/RedundantFileExtensionInRequire:
319
+ Enabled: true
320
+
321
+ Style/RedundantRegexpCharacterClass:
322
+ Enabled: true
323
+
324
+ Style/RedundantRegexpEscape:
325
+ Enabled: true
326
+
327
+ Style/SingleArgumentDig:
328
+ Enabled: true
329
+
330
+ Style/SlicingWithRange:
331
+ Enabled: true
332
+
333
+ Style/StringConcatenation:
334
+ Enabled: true
@@ -1,3 +1,53 @@
1
+ ## [0.3.00] - 2020-12-16
2
+ - Version number bump because this is a vast code rewrite
3
+
4
+ ### CHANGED
5
+ - Most classes have been reworked
6
+ - Relation `Equals` has been renamed to `Unify`
7
+
8
+ ## [0.2.04] - 2020-09-02
9
+ - Intermediate version before vast code rework.
10
+
11
+ ### CHANGED
12
+ - Classes `KBoolean`, `KSymbol`, `KInteger` moved to namespace `Atomic`
13
+ - Classes `ConsCell`, `ConsCellVisitor` moved to namespace `Composite`
14
+ - Class `Variable` renamed to `LogVar`
15
+ - Class `VariableRef` renamed to `LogVarRef`
16
+
17
+ ## [0.2.03] - 2020-09-02
18
+ - The DSL (Domain Specific Language) supports the `caro` relation & passes frames up to 2-8 from Chapter 2.
19
+
20
+ ### NEW
21
+ - Class `ConsCellVisitor`. Its method `df_visitor` builds a Fiber that walks over a ConsCell (list/graph).
22
+ - Method `Outcome#failure?`
23
+ - Method `Outcome#prune!` for removing associations of transient variables.
24
+ - Method `VariableRef#to_s` for providing a text representation of a variable reference
25
+ - Method `Vocabulary#prune` for removing associations of transient variables.
26
+ - Class `FreshEnvFactory` as its name implies, is used to build `FreshEnv` instances.
27
+
28
+ ### CHANGED
29
+ - Method `Outcome#successful?` renamed to `Outcome#success?`
30
+
31
+ ### FIXED
32
+ - Method `Equals#solver_for` now prunes associations of transient variables.
33
+ - Method `Equals#unify_composite_terms` now copes with Conscell vs. VariableRef unification.
34
+
35
+ ## [0.2.02] - 2020-08-08
36
+ - The DSL (Domain Specific Language) now supports `conde` and passes all examples from Chapter 1.
37
+
38
+ ### NEW
39
+ - Method`Glue::DSL#conde` to implement conde goals.
40
+ - Method `KBoolean#to_s` returns a text representation of a boolean value.
41
+
42
+ ## [0.2.01] - 2020-08-07
43
+ - The DSL (Domain Specific Language) now supports `defrel` and boolean literals.
44
+
45
+ ### CHANGED
46
+ - Constructor `DefRelation#initialize` now freezes any new class instance.
47
+ - Constructor `GoalTemplate#initialize` now freezes any new class instance.
48
+ - Mixin module `Glue::DSL` new method `defrel` to build custom relations.
49
+ - File `.rubocop.yml` to please Rubocop 0.89
50
+
1
51
  ## [0.2.00] - 2020-07-12
2
52
  - First release of DSL (Domain Specific Language)
3
53
  - Fix defect for fused variables that remain fresh
data/README.md CHANGED
@@ -4,10 +4,9 @@
4
4
  [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/famished-tiger/mini_kraken/blob/master/LICENSE.txt)
5
5
 
6
6
  ### What is __mini_kraken__ ?
7
- A library containing an implementation of the [miniKanren](http://minikanren.org/)
8
- relational programming language in Ruby.
9
- *miniKanren* is a small language for relational (logic) programming.
10
- Based on the reference implementation, in Scheme from the "The Reasoned Schemer" book.
7
+ A library containing an implementation in Ruby of the [miniKanren](http://minikanren.org/)
8
+ language.
9
+ *miniKanren* is a small language for relational (logic) programming as defined in the "The Reasoned Schemer" book.
11
10
  Daniel P. Friedman, William E. Byrd, Oleg Kiselyov, and Jason Hemann: "The Reasoned Schemer", Second Edition,
12
11
  ISBN: 9780262535519, (2018), MIT Press.
13
12
 
@@ -15,6 +14,7 @@ ISBN: 9780262535519, (2018), MIT Press.
15
14
  - Pure Ruby implementation, not a port from another language
16
15
  - Object-Oriented design
17
16
  - No runtime dependencies
17
+ - Test suite patterned on the examples from the reference book.
18
18
 
19
19
  ### miniKanren Features
20
20
  - [X] ==
@@ -23,19 +23,19 @@ ISBN: 9780262535519, (2018), MIT Press.
23
23
  - [X] conde
24
24
  - [X] conj2
25
25
  - [X] disj2
26
- - [X] defrel
26
+ - [X] defrel
27
+ - [X] caro
28
+ - [X] cdro
27
29
 
28
30
  ### TODO
29
31
 
30
32
  - [ ] Occurs check
31
33
 
32
34
  List-centric relations from Chapter 2
33
- - [ ] caro
34
- - [ ] cdro
35
- - [ ] conso
36
- - [ ] nullo
37
- - [ ] pairo
38
- - [ ] singletono
35
+ - [ ] conso
36
+ - [ ] nullo
37
+ - [ ] pairo
38
+ - [ ] singletono
39
39
 
40
40
  ## Installation
41
41
 
@@ -65,7 +65,7 @@ require 'mini_kraken' # Load MiniKraken library
65
65
 
66
66
  extend(MiniKraken::Glue::DSL) # Add DSL method to self (object in context)
67
67
 
68
- result = run_star('q', equals(q, :pea))
68
+ result = run_star('q', unify(q, :pea))
69
69
  puts result # => (:pea)
70
70
  ```
71
71
 
@@ -73,17 +73,17 @@ The two first lines in the above code snippet are pretty standard:
73
73
  - The first line loads the `mini_kraken` library.
74
74
  - The second line add the DSL methods to the current object.
75
75
 
76
- The next line constitutes a trivial `miniKanren` program.
77
- The aim of a `miniKanren` program is to find one or more solutions involving provided variable(s)
78
- and satisfying one or more goals.
76
+ The next line constitutes a trivial `miniKanren` program.
77
+ The aim of a `miniKanren` program is to find one or more solutions involving the given logical variable(s)
78
+ and satisfying one or more goals to the `run_star method.
79
79
  In our example, the `run_star` method instructs `MiniKraken` to find all solutions,
80
80
  knowing that each successful solution:
81
81
  - binds a value to the provided variable `q` and
82
- - meets the goal `equals(q, :pea)`.
82
+ - meets the goal `unify(q, :pea)`.
83
83
 
84
- The goal `equals(q, :pea)` succeeds because the logical variable `q` is _fresh_ (that is,
84
+ The goal `unify(q, :pea)` succeeds because the logical variable `q` is _fresh_ (that is,
85
85
  not yet bound to a value) and will be bound to the symbol `:pea` as a side effect
86
- of the goal `equals`.
86
+ of the goal `unify`.
87
87
 
88
88
  So the above program succeeds and the only found solution is obtained by binding
89
89
  the variable `q` to the value :pea. Hence the result of the `puts` method.
@@ -97,11 +97,12 @@ So the above program succeeds and the only found solution is obtained by binding
97
97
  extend(MiniKraken::Glue::DSL) # Add DSL method to self (object in context)
98
98
 
99
99
  # Following miniKanren program fails
100
- result = run_star('q', [equals(q, :pea), equals(q, :pod)])
100
+ result = run_star('q', [unify(q, :pea), unify(q, :pod)])
101
101
  puts result # => ()
102
102
  ```
103
103
  In this example, we learn that `run_star` can take multiple goals placed in an array.
104
- The program fails to find a solution since it is not possible to satisfy the two `equals` goals simultaneously. In that case, the `run_star` return an empty list represented as `()` in the output.
104
+ The program fails to find a solution since it is not possible to satisfy the two `unify` goals simultaneously.
105
+ In case of failure, the `run_star` returns an empty list represented as `()` in the output.
105
106
 
106
107
 
107
108
  ### Example 3
@@ -110,7 +111,7 @@ The program fails to find a solution since it is not possible to satisfy the two
110
111
  ```ruby
111
112
  # In this example and following, one assumes that DSL is loaded as shown in Example 1
112
113
 
113
- result = run_star(['x', 'y'], [equals(:hello, x), equals(y, :world)])
114
+ result = run_star(['x', 'y'], [unify(:hello, x), unify(y, :world)])
114
115
  puts result # => ((:hello :world))
115
116
  ```
116
117
 
@@ -121,13 +122,14 @@ This time, `run_star` takes two logical variables -`x` and `y`- and successfully
121
122
  ```ruby
122
123
  result = run_star(['x', 'y'],
123
124
  [
124
- disj2(equals(x, :blue), equals(x, :red)),
125
- disj2(equals(y, :sea), equals(:mountain, y))
125
+ disj2(unify(x, :blue), unify(x, :red)),
126
+ disj2(unify(y, :sea), unify(:mountain, y))
126
127
  ])
127
128
  puts result # => ((:blue :sea) (:blue :mountain) (:red :sea) (:red :mountain))
128
129
  ```
129
130
 
130
- Here, `run_star` takes two logical variables and two `disj2` goals. A `disj2` succeeds if any of its arguments succeeds.
131
+ Here, `run_star` takes two logical variables and two `disj2` goals.
132
+ A `disj2` succeeds if any of its arguments succeeds.
131
133
  This program finds four distinct solutions for x, y pairs.
132
134
 
133
135
  ## Development