mini_kraken 0.2.01 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/mini_kraken.rb +3 -3
- data/lib/mini_kraken/core/formal_ref.rb +1 -1
- data/lib/mini_kraken/core/k_boolean.rb +4 -0
- data/lib/mini_kraken/glue/dsl.rb +17 -0
- data/lib/mini_kraken/version.rb +1 -1
- data/spec/core/conde_spec.rb +1 -1
- data/spec/core/k_boolean_spec.rb +6 -0
- data/spec/glue/dsl_chap1_spec.rb +80 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24222422e142dde60f6f5a3c92ca1b4967eb358f26d29a0d834f719d25fcab11
|
4
|
+
data.tar.gz: 855880806c2210763e6c77d442f8d0463c39b9bde81072ff91f65ca21a275998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7840d5f469d0924b5018a87ca9e349f7c17f81fb23c1b8001890f9b5ca752125fae2de08eb10af1e8fc430347dba3c1a635e25fe7c188196f93415ccaecbe95
|
7
|
+
data.tar.gz: 3a16f04afa89e31dbe572af6c26eeafb169143dc5d55419f4db1ee0c90b0268c60e0a1bee643a3bcdce769e3fd524dd6be37b8ad60211d814321f5b90e7f3350
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
## [0.2.02] - 2020-08-08
|
2
|
+
- The DSL (Domain Specific Language) now supports `conde` and passes all examples from Chapter 1.
|
3
|
+
|
4
|
+
### NEW
|
5
|
+
- Method`Glue::DSL#conde` to implement conde goals.
|
6
|
+
- Method `KBoolean#to_s` returns a text representation of a boolean value.
|
7
|
+
|
1
8
|
## [0.2.01] - 2020-08-07
|
2
9
|
- The DSL (Domain Specific Language) now supports `defrel` and boolean literals.
|
3
10
|
|
4
11
|
### CHANGED
|
5
12
|
- Constructor `DefRelation#initialize` now freezes any new class instance.
|
6
13
|
- Constructor `GoalTemplate#initialize` now freezes any new class instance.
|
7
|
-
- Mixin module `
|
14
|
+
- Mixin module `Glue::DSL` new method `defrel` to build custom relations.
|
8
15
|
- File `.rubocop.yml` to please Rubocop 0.89
|
9
16
|
|
10
17
|
## [0.2.00] - 2020-07-12
|
data/lib/mini_kraken.rb
CHANGED
@@ -7,7 +7,7 @@ module MiniKraken
|
|
7
7
|
# A formal reference represents the occurrence of a formal argument name in a
|
8
8
|
# goal template argument list.
|
9
9
|
class FormalRef < BaseArg
|
10
|
-
# @return [String]
|
10
|
+
# @return [String] The name of a formal argument.
|
11
11
|
attr_reader :name
|
12
12
|
|
13
13
|
def initialize(aName)
|
data/lib/mini_kraken/glue/dsl.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'set'
|
4
4
|
require_relative '../core/any_value'
|
5
|
+
require_relative '../core/conde'
|
5
6
|
require_relative '../core/conj2'
|
6
7
|
require_relative '../core/cons_cell'
|
7
8
|
require_relative '../core/def_relation'
|
@@ -10,6 +11,7 @@ require_relative '../core/equals'
|
|
10
11
|
require_relative '../core/fail'
|
11
12
|
require_relative '../core/formal_arg'
|
12
13
|
require_relative '../core/formal_ref'
|
14
|
+
require_relative '../glue/fresh_env'
|
13
15
|
require_relative '../core/goal_template'
|
14
16
|
require_relative '../core/k_boolean'
|
15
17
|
require_relative '../core/k_symbol'
|
@@ -33,6 +35,19 @@ module MiniKraken
|
|
33
35
|
program.run
|
34
36
|
end
|
35
37
|
|
38
|
+
def conde(*goals)
|
39
|
+
# require 'debug'
|
40
|
+
args = goals.map do |goal_maybe|
|
41
|
+
if goal_maybe.kind_of?(Array)
|
42
|
+
goal_maybe.map { |g| convert(g)}
|
43
|
+
else
|
44
|
+
convert(goal_maybe)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Core::Goal.new(Core::Conde.instance, args)
|
49
|
+
end
|
50
|
+
|
36
51
|
# conj2 stands for conjunction of two arguments.
|
37
52
|
# Returns a goal linked to the Core::Conj2 relation.
|
38
53
|
# The rule of that relation succeeds when both arguments succeed.
|
@@ -142,6 +157,8 @@ module MiniKraken
|
|
142
157
|
converted = anArgument
|
143
158
|
when Core::FormalRef
|
144
159
|
converted = anArgument
|
160
|
+
when FreshEnv
|
161
|
+
converted = anArgument
|
145
162
|
when Core::Goal
|
146
163
|
converted = anArgument
|
147
164
|
when Core::GoalTemplate
|
data/lib/mini_kraken/version.rb
CHANGED
data/spec/core/conde_spec.rb
CHANGED
@@ -58,7 +58,7 @@ module MiniKraken
|
|
58
58
|
expect { subject.solver_for([pea, succeeds], env) }.to raise_error(err)
|
59
59
|
end
|
60
60
|
|
61
|
-
it 'should
|
61
|
+
it 'should fail when all goals fail' do
|
62
62
|
solver = subject.solver_for([fails, fails, fails], env)
|
63
63
|
expect(solver.resume).not_to be_successful
|
64
64
|
expect(solver.resume).to be_nil
|
data/spec/core/k_boolean_spec.rb
CHANGED
@@ -101,6 +101,12 @@ module MiniKraken
|
|
101
101
|
# Default Ruby representation, different value
|
102
102
|
expect(subject == false).to be_falsy
|
103
103
|
end
|
104
|
+
|
105
|
+
it 'provides a text representation of itself' do
|
106
|
+
expect(subject.to_s).to eq('true')
|
107
|
+
other = KBoolean.new('#f')
|
108
|
+
expect(other.to_s).to eq('false')
|
109
|
+
end
|
104
110
|
end # context
|
105
111
|
end # describe
|
106
112
|
end # module
|
data/spec/glue/dsl_chap1_spec.rb
CHANGED
@@ -565,9 +565,7 @@ module MiniKraken
|
|
565
565
|
|
566
566
|
defrel_teacupo
|
567
567
|
result = run_star(%w[x y], [teacupo(x), teacupo(x)])
|
568
|
-
|
569
|
-
expect(result.car).to eq(cons(:tea, cons(:_0)))
|
570
|
-
expect(result.cdr.car).to eq(cons(:cup, cons(:_0)))
|
568
|
+
expect(result.to_s).to eq('((:tea _0) (:cup _0))')
|
571
569
|
end
|
572
570
|
|
573
571
|
it 'passes frame 1:87' do
|
@@ -583,11 +581,90 @@ module MiniKraken
|
|
583
581
|
conj2(equals('#f', x), teacupo(y))))
|
584
582
|
|
585
583
|
# Order of solutions differs from RS book
|
584
|
+
expected = '((:tea _0) (:cup _0) (false :tea) (false :cup))'
|
585
|
+
expect(result.to_s).to eq(expected)
|
586
586
|
expect(result.car).to eq(cons(:tea, cons(:_0)))
|
587
587
|
expect(result.cdr.car).to eq(cons(:cup, cons(:_0)))
|
588
588
|
expect(result.cdr.cdr.car).to eq(cons(false, cons(:tea)))
|
589
589
|
expect(result.cdr.cdr.cdr.car).to eq(cons(false, cons(:cup)))
|
590
590
|
end
|
591
|
+
|
592
|
+
it 'supports conde and passes frame 1:88 (i)' do
|
593
|
+
# Reasoned S2, frame 1:88
|
594
|
+
# (run* (x y)
|
595
|
+
# (conde
|
596
|
+
# ((teacupo x) (teacupo x))
|
597
|
+
# ((== #f x) (teacupo y)))) ;; => ((#f tea)(#f cup)(tea _0)(cup _0))
|
598
|
+
|
599
|
+
defrel_teacupo
|
600
|
+
result = run_star(%w[x y], conde(
|
601
|
+
[teacupo(x), teacupo(x)],
|
602
|
+
[equals('#f', x), teacupo(y)]))
|
603
|
+
|
604
|
+
# Order of solutions differs from RS book
|
605
|
+
expected = '((:tea _0) (:cup _0) (false :tea) (false :cup))'
|
606
|
+
expect(result.to_s).to eq(expected)
|
607
|
+
end
|
608
|
+
|
609
|
+
it 'supports conde and passes frame 1:88 (ii)' do
|
610
|
+
# Reasoned S2, frame 1:88 (second part, a rewrite of 1:76)
|
611
|
+
# (run* (x y)
|
612
|
+
# (conde
|
613
|
+
# ((== 'split x) (== 'pea y))
|
614
|
+
# ((== 'red x) (== 'bean y)))) ;; => ((split pea)(red bean))
|
615
|
+
result = run_star(%w[x y], conde(
|
616
|
+
[equals(:split, x), equals(:pea, y)],
|
617
|
+
[equals(:red, x), equals(:bean, y)]))
|
618
|
+
|
619
|
+
expected = '((:split :pea) (:red :bean))'
|
620
|
+
expect(result.to_s).to eq(expected)
|
621
|
+
end
|
622
|
+
|
623
|
+
it 'passes frame 1:89' do
|
624
|
+
# Reasoned S2, frame 1:89 (rewrite of 1:62)
|
625
|
+
# (run* x
|
626
|
+
# (conde
|
627
|
+
# ((== 'olive x) fail)
|
628
|
+
# ('oil x))) ;; => (oil)
|
629
|
+
|
630
|
+
result = run_star('x', conde(
|
631
|
+
[equals(:olive, x), _fail],
|
632
|
+
equals(:oil, x)))
|
633
|
+
|
634
|
+
expect(result.to_s).to eq('(:oil)')
|
635
|
+
end
|
636
|
+
|
637
|
+
it 'passes frame 1:90' do
|
638
|
+
# Reasoned S2, frame 1:90
|
639
|
+
# (run* (x y)
|
640
|
+
# (conde
|
641
|
+
# ((fresh (z)
|
642
|
+
# (== 'lentil z)))
|
643
|
+
# ((== x y)))) ;; => ((_0 _1)(_0 _0))
|
644
|
+
|
645
|
+
result = run_star(%w[x y], conde(
|
646
|
+
[fresh(%w[z], equals(:lentil, z))],
|
647
|
+
[equals(x, y)]))
|
648
|
+
|
649
|
+
expect(result.to_s).to eq('((_0 _1) (_0 _0))')
|
650
|
+
end
|
651
|
+
|
652
|
+
it 'passes frame 1:91' do
|
653
|
+
# Reasoned S2, frame 1:91
|
654
|
+
# (run* (x y)
|
655
|
+
# (conde
|
656
|
+
# ((== 'split x) (== 'pea y))
|
657
|
+
# ((== 'red x) (== 'bean y))
|
658
|
+
# ((== 'green x) (== 'lentil y))))
|
659
|
+
# ;; => ((split pea)(red bean)(green lentil))
|
660
|
+
result = run_star(%w[x y], conde(
|
661
|
+
[equals(:split, x), equals(:pea, y)],
|
662
|
+
[equals(:red, x), equals(:bean, y)],
|
663
|
+
[equals(:green, x), equals(:lentil, y)]))
|
664
|
+
|
665
|
+
expected = '((:split :pea) (:red :bean) (:green :lentil))'
|
666
|
+
expect(result.to_s).to eq(expected)
|
667
|
+
end
|
591
668
|
end # context
|
592
669
|
end # describe
|
593
670
|
end # module
|
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.02
|
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-08-
|
11
|
+
date: 2020-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|