rubylog 1.0.0 → 2.0pre1
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.
- data/Gemfile +3 -12
- data/Gemfile.lock +22 -48
- data/README.rdoc +38 -38
- data/README.rdoc.orig +284 -0
- data/RELEASE_NOTES.rdoc +51 -0
- data/Rakefile +14 -18
- data/TODO.txt +0 -0
- data/VERSION +1 -1
- data/examples/a_plus_b.rb +6 -0
- data/examples/checkmate.rb +88 -0
- data/examples/combination.rb +17 -0
- data/examples/dcg.rb +3 -2
- data/examples/dcg2.rb +2 -2
- data/{logic → examples}/directory_structure_logic.rb +3 -5
- data/examples/dirlist.rb +4 -0
- data/examples/divisors.rb +6 -0
- data/examples/enumerators.rb +3 -3
- data/examples/factorial.rb +2 -3
- data/examples/file_search.rb +14 -0
- data/examples/hanoi.rb +4 -5
- data/examples/hello.rb +6 -4
- data/examples/mice.rb +92 -0
- data/examples/mice2.rb +19 -0
- data/examples/n_queens.rb +32 -0
- data/examples/object_oriented.rb +14 -0
- data/examples/palindrome_detection.rb +18 -0
- data/examples/parsing.rb +6 -4
- data/examples/permutation.rb +12 -0
- data/examples/prefix.rb +13 -0
- data/examples/primality_by_division.rb +22 -0
- data/examples/primitives.rb +10 -8
- data/examples/sieve_of_eratosthenes.rb +14 -0
- data/examples/string_interpolation.rb +4 -0
- data/examples/sudoku.rb +52 -0
- data/examples/tracing.rb +19 -0
- data/lib/rspec/rubylog.rb +29 -0
- data/lib/rubylog/assertable.rb +24 -0
- data/lib/rubylog/builtins/arithmetics.rb +63 -0
- data/lib/rubylog/builtins/assumption.rb +71 -0
- data/lib/rubylog/builtins/ensure.rb +13 -0
- data/lib/rubylog/builtins/file_system.rb +30 -8
- data/lib/rubylog/builtins/logic.rb +69 -38
- data/lib/rubylog/builtins/reflection.rb +35 -50
- data/lib/rubylog/builtins/term.rb +15 -17
- data/lib/rubylog/builtins.rb +11 -0
- data/lib/rubylog/clause.rb +19 -0
- data/lib/rubylog/{interfaces/composite_term.rb → compound_term.rb} +3 -3
- data/lib/rubylog/context.rb +24 -0
- data/lib/rubylog/context_creation.rb +71 -0
- data/lib/rubylog/context_modules/checks.rb +35 -0
- data/lib/rubylog/context_modules/demonstration.rb +16 -0
- data/lib/rubylog/context_modules/predicates.rb +86 -0
- data/lib/rubylog/context_modules/primitives.rb +18 -0
- data/lib/rubylog/context_modules/thats.rb +13 -0
- data/lib/rubylog/default_context.rb +9 -0
- data/lib/rubylog/dsl/array_splat.rb +11 -3
- data/lib/rubylog/dsl/primitives.rb +24 -12
- data/lib/rubylog/dsl/thats.rb +6 -0
- data/lib/rubylog/dsl/variables.rb +56 -21
- data/lib/rubylog/errors.rb +26 -15
- data/lib/rubylog/mixins/array.rb +95 -62
- data/lib/rubylog/mixins/kernel.rb +3 -2
- data/lib/rubylog/mixins/method.rb +0 -1
- data/lib/rubylog/mixins/object.rb +2 -1
- data/lib/rubylog/mixins/proc.rb +9 -12
- data/lib/rubylog/mixins/string.rb +15 -23
- data/lib/rubylog/mixins/symbol.rb +7 -24
- data/lib/rubylog/nullary_predicates.rb +3 -0
- data/lib/rubylog/predicate.rb +53 -0
- data/lib/rubylog/primitive.rb +15 -0
- data/lib/rubylog/procedure.rb +42 -0
- data/lib/rubylog/rule.rb +24 -0
- data/lib/rubylog/structure.rb +19 -38
- data/lib/rubylog/{interfaces/term.rb → term.rb} +2 -7
- data/lib/rubylog/tracing.rb +75 -0
- data/lib/rubylog/variable.rb +31 -12
- data/lib/rubylog.rb +36 -32
- data/rubylog.gemspec +92 -84
- data/spec/inriasuite_spec.rb +906 -9
- data/spec/integration/custom_classes_spec.rb +61 -0
- data/spec/integration/dsl_spec.rb +38 -0
- data/spec/integration/recursion_spec.rb +14 -0
- data/spec/integration/theory_as_module_spec.rb +20 -0
- data/spec/integration/theory_as_module_with_include_spec.rb +14 -0
- data/spec/rspec/rubylog_spec.rb +75 -0
- data/spec/rubylog/assertable_spec.rb +111 -0
- data/spec/rubylog/builtins/arithmetics_spec.rb +94 -0
- data/spec/rubylog/builtins/assumption_spec.rb +70 -0
- data/spec/rubylog/builtins/ensure_spec.rb +8 -0
- data/spec/rubylog/builtins/file_system_spec.rb +40 -0
- data/spec/rubylog/builtins/logic_spec.rb +340 -0
- data/spec/rubylog/builtins/reflection_spec.rb +43 -0
- data/spec/rubylog/builtins/term_spec.rb +85 -0
- data/spec/rubylog/context_modules/demonstration_spec.rb +132 -0
- data/spec/rubylog/context_modules/predicates_spec.rb +57 -0
- data/spec/rubylog/context_modules/thats_spec.rb +94 -0
- data/spec/rubylog/dsl/array_splat_spec.rb +15 -0
- data/spec/rubylog/dsl/primitives_spec.rb +43 -0
- data/spec/rubylog/errors_spec.rb +18 -0
- data/spec/{unification_spec.rb → rubylog/interfaces/term_spec.rb} +8 -9
- data/spec/rubylog/mixins/array_spec.rb +80 -0
- data/spec/rubylog/mixins/composite_term_spec.rb +66 -0
- data/spec/rubylog/mixins/proc_spec.rb +59 -0
- data/spec/rubylog/mixins/string_spec.rb +48 -0
- data/spec/rubylog/mixins/symbol_spec.rb +9 -0
- data/spec/{clause_spec.rb → rubylog/structure_spec.rb} +16 -15
- data/spec/rubylog/term_spec.rb +7 -0
- data/spec/rubylog/tracing_spec.input +27 -0
- data/spec/rubylog/tracing_spec.rb +44 -0
- data/spec/rubylog/variable_spec.rb +279 -0
- data/spec/spec_helper.rb +1 -0
- data/vimrc +11 -0
- metadata +103 -123
- data/README.hu.rb +0 -58
- data/bin/rubylog +0 -18
- data/examples/theory.rb +0 -32
- data/lib/rubylog/builtins/default.rb +0 -10
- data/lib/rubylog/dsl.rb +0 -70
- data/lib/rubylog/interfaces/assertable.rb +0 -16
- data/lib/rubylog/interfaces/callable.rb +0 -18
- data/lib/rubylog/interfaces/predicate.rb +0 -8
- data/lib/rubylog/interfaces/procedure.rb +0 -60
- data/lib/rubylog/mixins/class.rb +0 -11
- data/lib/rubylog/simple_procedure.rb +0 -8
- data/lib/rubylog/theory.rb +0 -422
- data/logic/builtins/file_system_logic.rb +0 -23
- data/logic/builtins/reflection_logic.rb +0 -40
- data/logic/dereference_logic.rb +0 -23
- data/logic/dsl_logic.rb +0 -29
- data/logic/errors_logic.rb +0 -9
- data/logic/guard_logic.rb +0 -115
- data/logic/list_logic.rb +0 -55
- data/logic/map_logic.rb +0 -15
- data/logic/multitheory.rb +0 -23
- data/logic/recursion_logic.rb +0 -12
- data/logic/string_logic.rb +0 -41
- data/logic/thats_logic.rb +0 -51
- data/logic/variable_logic.rb +0 -24
- data/spec/bartak_guide_spec.rb +0 -86
- data/spec/builtins/all_spec.rb +0 -99
- data/spec/builtins/and_spec.rb +0 -22
- data/spec/builtins/array_spec.rb +0 -16
- data/spec/builtins/branch_or_spec.rb +0 -27
- data/spec/builtins/cut_spec.rb +0 -44
- data/spec/builtins/fail_spec.rb +0 -5
- data/spec/builtins/false_spec.rb +0 -5
- data/spec/builtins/in_spec.rb +0 -38
- data/spec/builtins/is_false_spec.rb +0 -12
- data/spec/builtins/is_spec.rb +0 -26
- data/spec/builtins/matches_spec.rb +0 -23
- data/spec/builtins/or_spec.rb +0 -22
- data/spec/builtins/splits_to.rb +0 -18
- data/spec/builtins/then_spec.rb +0 -27
- data/spec/builtins/true_spec.rb +0 -5
- data/spec/compilation_spec.rb +0 -61
- data/spec/custom_classes_spec.rb +0 -43
- data/spec/dereference.rb +0 -10
- data/spec/queries_spec.rb +0 -150
- data/spec/recursion_spec.rb +0 -18
- data/spec/ruby_code_spec.rb +0 -52
- data/spec/rules_spec.rb +0 -97
- data/spec/theory_spec.rb +0 -29
- data/spec/variable_spec.rb +0 -26
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe "branch or" do
|
4
|
-
it "works 1" do
|
5
|
-
:john.happy.if :fail
|
6
|
-
:john.happy.if :true
|
7
|
-
:john.should be_happy
|
8
|
-
end
|
9
|
-
|
10
|
-
it "works 2" do
|
11
|
-
:john.happy.if :true
|
12
|
-
:john.happy.if :fail
|
13
|
-
:john.should be_happy
|
14
|
-
end
|
15
|
-
|
16
|
-
it "works 3" do
|
17
|
-
:john.happy.if :fail
|
18
|
-
:john.happy.if :fail
|
19
|
-
:john.should_not be_happy
|
20
|
-
end
|
21
|
-
|
22
|
-
it "works 4" do
|
23
|
-
:john.happy.if :true
|
24
|
-
:john.happy.if :true
|
25
|
-
:john.should be_happy
|
26
|
-
end
|
27
|
-
end
|
data/spec/builtins/cut_spec.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "cut" do
|
3
|
-
it "works with branch or" do
|
4
|
-
:john.happy.if :true.and :cut.and :fail
|
5
|
-
:john.happy.if :true
|
6
|
-
:john.should_not be_happy
|
7
|
-
end
|
8
|
-
it "works with branch or (control)" do
|
9
|
-
:john.happy.if :true.and :fail
|
10
|
-
:john.happy.if :true
|
11
|
-
:john.should be_happy
|
12
|
-
end
|
13
|
-
|
14
|
-
it "works with or" do
|
15
|
-
:john.happy.if((:true.and :cut.and :fail).or :true)
|
16
|
-
:john.should_not be_happy
|
17
|
-
end
|
18
|
-
|
19
|
-
it "works with or (control)" do
|
20
|
-
:john.happy.if((:true.and :fail).or :true)
|
21
|
-
:john.should be_happy
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns true with branch or" do
|
25
|
-
:john.happy.if :true.and :cut.and :true
|
26
|
-
:john.happy.if :true
|
27
|
-
:john.should be_happy
|
28
|
-
end
|
29
|
-
it "returns true with branch or (control)" do
|
30
|
-
:john.happy.if :true.and :true
|
31
|
-
:john.happy.if :true
|
32
|
-
:john.should be_happy
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns true with or" do
|
36
|
-
:john.happy.if((:true.and :cut.and :true).or :true)
|
37
|
-
:john.should be_happy
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns true with or (control)" do
|
41
|
-
:john.happy.if((:true.and :true).or :true)
|
42
|
-
:john.should be_happy
|
43
|
-
end
|
44
|
-
end
|
data/spec/builtins/fail_spec.rb
DELETED
data/spec/builtins/false_spec.rb
DELETED
data/spec/builtins/in_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "in" do
|
3
|
-
before do
|
4
|
-
:john.likes! :beer
|
5
|
-
:jane.likes! :milk
|
6
|
-
end
|
7
|
-
|
8
|
-
it "works for variables" do
|
9
|
-
(A.likes(B).and(B.in [])).to_a.should == []
|
10
|
-
(A.likes(B).and(B.in [:milk])).to_a.should == [[:jane, :milk]]
|
11
|
-
(A.likes(B).and(B.in [:beer])).to_a.should == [[:john, :beer]]
|
12
|
-
(A.likes(B).and(B.in [:milk, :beer])).to_a.should == [[:john, :beer], [:jane, :milk]]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "works with blocks" do
|
16
|
-
(A.likes(B).and(B.in {[]})).to_a.should == []
|
17
|
-
(A.likes(B).and(B.in {|a|[a,:milk]})).to_a.should == [[:jane, :milk]]
|
18
|
-
(A.likes(B).and(B.in {|a,b|[:beer]})).to_a.should == [[:john, :beer]]
|
19
|
-
(A.likes(B).and(B.in {|a,b|[b]})).to_a.should == [[:john, :beer], [:jane, :milk]]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "works as iterator" do
|
23
|
-
(A.in{[1,3,4]}).to_a.should == [1,3,4]
|
24
|
-
(A.in [1,3,4]).to_a.should == [1,3,4]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "works as search" do
|
28
|
-
(1.in{[1,3,4]}).to_a.should == [nil]
|
29
|
-
(2.in{[1,3,4]}).to_a.should == []
|
30
|
-
(1.in [1,3,4]).to_a.should == [nil]
|
31
|
-
(2.in [1,3,4]).to_a.should == []
|
32
|
-
end
|
33
|
-
|
34
|
-
it "works with clauses" do
|
35
|
-
(A.likes(B).and B.in{:john.likes(X)}).to_a.should == [[:john, :beer]]
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/spec/builtins/is_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "is" do
|
3
|
-
before do
|
4
|
-
:john.likes! :beer
|
5
|
-
:jane.likes! :milk
|
6
|
-
end
|
7
|
-
|
8
|
-
it "works for variables" do
|
9
|
-
(A.likes(B).and(B.is :milk)).to_a.should == [[:jane, :milk]]
|
10
|
-
(A.likes(B).and(:milk.is B)).to_a.should == [[:jane, :milk]]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "works as calculation" do
|
14
|
-
(A.is {|| 4+4}).to_a.should == [8]
|
15
|
-
(A.is {4+4}).to_a.should == [8]
|
16
|
-
(A.is(4).and A.is{2*2}).to_a.should == [4]
|
17
|
-
(A.is(4).and A.is{2*3}).to_a.should == []
|
18
|
-
end
|
19
|
-
|
20
|
-
it "works as calculation with vars" do
|
21
|
-
(A.is(4).and B.is{|a|a*4}).to_a.should == [[4,16]]
|
22
|
-
(A.is(4).and A.is{|a|a*1}).to_a.should == [4]
|
23
|
-
(A.is(4).and A.is{|a|a*2}).to_a.should == []
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "matches" do
|
3
|
-
before do
|
4
|
-
:john.likes! "Beer"
|
5
|
-
:jane.likes! "Water"
|
6
|
-
end
|
7
|
-
|
8
|
-
it "works for variables" do
|
9
|
-
(A.likes(B).and(B.matches /e/)).to_a.should == [[:john, "Beer"], [:jane, "Water"]]
|
10
|
-
(A.likes(B).and(B.matches /ee/)).to_a.should == [[:john, "Beer"]]
|
11
|
-
(A.likes(B).and(B.matches /w/i)).to_a.should == [[:jane, "Water"]]
|
12
|
-
end
|
13
|
-
|
14
|
-
it "works as calculation" do
|
15
|
-
(A.likes(B).and(B.matches {|a,b|/e/})).to_a.should == [[:john, "Beer"], [:jane, "Water"]]
|
16
|
-
(A.likes(B).and(B.matches {|a,b|/ee/})).to_a.should == [[:john, "Beer"]]
|
17
|
-
(A.likes(B).and(B.matches {|a,b|/w/i})).to_a.should == [[:jane, "Water"]]
|
18
|
-
(A.likes(B).and(B.matches {|a,b|b})).to_a.should == [[:john, "Beer"], [:jane, "Water"]]
|
19
|
-
(A.likes(B).and(B.matches {|a,b|a})).to_a.should == []
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
end
|
data/spec/builtins/or_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "or" do
|
3
|
-
it "works 1" do
|
4
|
-
:john.happy.if :fail.or :true
|
5
|
-
:john.should be_happy
|
6
|
-
end
|
7
|
-
|
8
|
-
it "works 2" do
|
9
|
-
:john.happy.if :true.or :fail
|
10
|
-
:john.should be_happy
|
11
|
-
end
|
12
|
-
|
13
|
-
it "works 3" do
|
14
|
-
:john.happy.if :fail.or :fail
|
15
|
-
:john.should_not be_happy
|
16
|
-
end
|
17
|
-
|
18
|
-
it "works 4" do
|
19
|
-
:john.happy.if :true.or :true
|
20
|
-
:john.should be_happy
|
21
|
-
end
|
22
|
-
end
|
data/spec/builtins/splits_to.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubylog'
|
2
|
-
|
3
|
-
class << Rubylog.theory
|
4
|
-
describe "splits_to" do
|
5
|
-
specify do
|
6
|
-
def split_to a,b
|
7
|
-
be_splits_to a,b
|
8
|
-
end
|
9
|
-
|
10
|
-
[].should_not split_to(ANY,ANY)
|
11
|
-
[1].should split_to(1,[])
|
12
|
-
[1,2].should split_to(1,[2])
|
13
|
-
[1,2,3].should split_to(1,[2,3])
|
14
|
-
|
15
|
-
([1,2,3].splits_to(B,C)).to_a.should == [[1,[2,3]]]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/builtins/then_spec.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "then" do
|
3
|
-
it "works 1" do
|
4
|
-
:john.happy.if :fail.then :true
|
5
|
-
:john.should_not be_happy
|
6
|
-
end
|
7
|
-
|
8
|
-
it "works 2" do
|
9
|
-
:john.happy.if :true.then :fail
|
10
|
-
:john.should_not be_happy
|
11
|
-
end
|
12
|
-
|
13
|
-
it "works 3" do
|
14
|
-
:john.happy.if :fail.then :fail
|
15
|
-
:john.should_not be_happy
|
16
|
-
end
|
17
|
-
|
18
|
-
it "works 4" do
|
19
|
-
:john.happy.if :true.then :true
|
20
|
-
:john.should be_happy
|
21
|
-
end
|
22
|
-
|
23
|
-
it "works 5" do
|
24
|
-
:john.happy.if :true.then :true
|
25
|
-
:john.should be_happy
|
26
|
-
end
|
27
|
-
end
|
data/spec/builtins/true_spec.rb
DELETED
data/spec/compilation_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "compilation" do
|
3
|
-
|
4
|
-
it "makes eql variables be equal" do
|
5
|
-
a = A; b = A
|
6
|
-
c = (a.likes b)
|
7
|
-
c[0].should be_equal a; c[1].should be_equal b
|
8
|
-
c[0].should_not be_equal c[1]
|
9
|
-
c = c.rubylog_compile_variables
|
10
|
-
c[0].should be_equal c[1]
|
11
|
-
end
|
12
|
-
|
13
|
-
it "makes non-eql variables be non-equal" do
|
14
|
-
a = A; b = B
|
15
|
-
c = (a.likes b)
|
16
|
-
c[0].should be_equal a; c[1].should be_equal b
|
17
|
-
c[0].should_not be_equal c[1]
|
18
|
-
c = c.rubylog_compile_variables
|
19
|
-
c[0].should_not be_equal c[1]
|
20
|
-
end
|
21
|
-
|
22
|
-
it "makes dont-care variables be non-equal" do
|
23
|
-
a = ANY; b = ANY
|
24
|
-
c = (a.likes b)
|
25
|
-
c[0].should be_equal a; c[1].should be_equal b
|
26
|
-
c[0].should_not be_equal c[1]
|
27
|
-
c = c.rubylog_compile_variables
|
28
|
-
c[0].should_not be_equal c[1]
|
29
|
-
end
|
30
|
-
|
31
|
-
it "creates new variables" do
|
32
|
-
a = A; b = B
|
33
|
-
c = (a.likes b)
|
34
|
-
c[0].should be_equal a; c[1].should be_equal b
|
35
|
-
c = c.rubylog_compile_variables
|
36
|
-
c[0].should_not be_equal a
|
37
|
-
c[1].should_not be_equal a
|
38
|
-
c[0].should_not be_equal b
|
39
|
-
c[1].should_not be_equal b
|
40
|
-
end
|
41
|
-
|
42
|
-
it "makes variables available" do
|
43
|
-
a = A; a1 = A; a2 = A; b = B; b1 = B; c = C;
|
44
|
-
(a.likes b).rubylog_compile_variables.rubylog_variables.should == [a, b]
|
45
|
-
(a.likes a1).rubylog_compile_variables.rubylog_variables.should == [a]
|
46
|
-
(a.likes a1.in b).rubylog_compile_variables.rubylog_variables.should == [a, b]
|
47
|
-
(a.likes a1,b,b1,a2,c).rubylog_compile_variables.rubylog_variables.should == [a, b, c]
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not make dont-care variables available" do
|
51
|
-
a = ANY; a1 = ANYTHING; a2 = ANYTHING; b = B; b1 = B; c = C;
|
52
|
-
(a.likes b).rubylog_compile_variables.rubylog_variables.should == [b]
|
53
|
-
(a.likes a1).rubylog_compile_variables.rubylog_variables.should == []
|
54
|
-
(a.likes a1.in b).rubylog_compile_variables.
|
55
|
-
rubylog_variables.should == [b]
|
56
|
-
(a.likes a1,b,b1,a2,c).rubylog_compile_variables.
|
57
|
-
rubylog_variables.should == [b, c]
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
end
|
data/spec/custom_classes_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "custom classes" do
|
3
|
-
before do
|
4
|
-
class User
|
5
|
-
rubylog_functor :girl, :boy
|
6
|
-
include Rubylog::DSL::Constants
|
7
|
-
|
8
|
-
attr_reader :name
|
9
|
-
def initialize name
|
10
|
-
@name = name
|
11
|
-
end
|
12
|
-
|
13
|
-
U.girl.if {|u| u.name =~ /[aeiouh]$/ }
|
14
|
-
U.boy.unless U.girl
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can have ruby predicates" do
|
19
|
-
john = User.new "John"
|
20
|
-
john.girl?.should be_false
|
21
|
-
john.boy?.should be_true
|
22
|
-
jane = User.new "Jane"
|
23
|
-
jane.girl?.should be_true
|
24
|
-
jane.boy?.should be_false
|
25
|
-
end
|
26
|
-
|
27
|
-
it "can be used in assertions" do
|
28
|
-
pete = User.new "Pete"
|
29
|
-
pete.boy?.should be_false
|
30
|
-
pete.boy!
|
31
|
-
pete.boy?.should be_true
|
32
|
-
|
33
|
-
Rubylog.theory[:girl][1].discontinuous!
|
34
|
-
janet = User.new "Janet"
|
35
|
-
janet.girl?.should be_false
|
36
|
-
janet.girl!
|
37
|
-
janet.girl?.should be_true
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
data/spec/dereference.rb
DELETED
data/spec/queries_spec.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "queries" do
|
3
|
-
it "can be run with true?" do
|
4
|
-
lambda {Rubylog.theory.true?(:john.likes :beer)}.should raise_error(Rubylog::ExistenceError)
|
5
|
-
:john.likes! :beer
|
6
|
-
Rubylog.theory.true?(:john.likes :beer).should be_true
|
7
|
-
Rubylog.theory.true?(:john.likes :milk).should be_false
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can be run with question mark" do
|
11
|
-
lambda {Rubylog.theory.true?(:john.likes :beer)}.should raise_error(Rubylog::ExistenceError)
|
12
|
-
:john.likes! :beer
|
13
|
-
:john.likes?(:beer).should be_true
|
14
|
-
end
|
15
|
-
|
16
|
-
it "can be run with true?" do
|
17
|
-
lambda {Rubylog.theory.true?(:john.likes :beer)}.should raise_error(Rubylog::ExistenceError)
|
18
|
-
:john.likes! :beer
|
19
|
-
(:john.likes(:beer)).true?.should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
it "work with variables" do
|
23
|
-
lambda {Rubylog.theory.true?(:john.likes X)}.should raise_error(Rubylog::ExistenceError)
|
24
|
-
:john.likes! :water
|
25
|
-
:john.likes?(X).should be_true
|
26
|
-
end
|
27
|
-
|
28
|
-
it "yield all solutions" do
|
29
|
-
:john.likes! :beer
|
30
|
-
:john.likes! :milk
|
31
|
-
|
32
|
-
k=[]
|
33
|
-
(:john.likes X).each{|x|k << x}
|
34
|
-
k.should == [:beer, :milk]
|
35
|
-
end
|
36
|
-
|
37
|
-
it "yield all solutions with solve" do
|
38
|
-
:john.likes! :beer
|
39
|
-
:john.likes! :milk
|
40
|
-
|
41
|
-
k=[]
|
42
|
-
(:john.likes X).solve{|x|k << x}
|
43
|
-
k.should == [:beer, :milk]
|
44
|
-
end
|
45
|
-
|
46
|
-
it "yield all solutions with solve and multiple vars and multiple block parameters" do
|
47
|
-
:john.likes! :beer
|
48
|
-
:jane.likes! :milk
|
49
|
-
:jane.likes! :water
|
50
|
-
|
51
|
-
k=[]
|
52
|
-
(X.likes Y).solve{|a,b|k << [a,b]}
|
53
|
-
k.should == [[:john, :beer], [:jane, :milk], [:jane, :water]]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "ignore don't-care variables" do
|
57
|
-
:john.likes! :beer
|
58
|
-
|
59
|
-
k=[]
|
60
|
-
ANYONE.likes(X).each{|x|k << x}
|
61
|
-
k.should == [:beer]
|
62
|
-
|
63
|
-
k=[]
|
64
|
-
X.likes(ANYTHING).each{|x|k << x}
|
65
|
-
k.should == [:john]
|
66
|
-
end
|
67
|
-
|
68
|
-
it "makes sure all variables are instantiated" do
|
69
|
-
res = []
|
70
|
-
A.likes(B).if {|a,b| res << a << b }
|
71
|
-
A.likes? :beer
|
72
|
-
res.should == [nil,:beer]
|
73
|
-
end
|
74
|
-
|
75
|
-
it "substitutes deeper variables" do
|
76
|
-
res = []
|
77
|
-
A.likes(B).if {|a,b| res << a << b }
|
78
|
-
(A.is(:john).and B.is(:swimming.in C).and
|
79
|
-
C.is(:sea).and A.likes B).to_a.should == [[:john,:swimming.in(:sea),:sea]]
|
80
|
-
res.should == [:john, :swimming.in(:sea)]
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
describe "support Enumerable" do
|
85
|
-
before do
|
86
|
-
:john.likes! :beer
|
87
|
-
:john.likes! :milk
|
88
|
-
end
|
89
|
-
|
90
|
-
it "#all?, #any? and #none?" do
|
91
|
-
(:john.likes A).all?{|a| Symbol===a}.should be_true
|
92
|
-
(:john.likes A).all?{|a| a == :beer}.should be_false
|
93
|
-
(:john.likes A).all?{|a| a == :beer or a == :milk}.should be_true
|
94
|
-
(:john.likes A).any?{|a| a == :beer}.should be_true
|
95
|
-
(:john.likes A).any?{|a| a == :milk}.should be_true
|
96
|
-
(:john.likes A).any?{|a| a == :water}.should be_false
|
97
|
-
(:john.likes A).none?{|a| a == :water}.should be_true
|
98
|
-
(:john.likes A).none?{|a| a == :beer}.should be_false
|
99
|
-
end
|
100
|
-
|
101
|
-
it "#to_a" do
|
102
|
-
(:john.likes A).to_a.should == [:beer, :milk]
|
103
|
-
(X.likes A).to_a.should == [[:john, :beer], [:john, :milk]]
|
104
|
-
(ANYONE.likes A).to_a.should == [:beer, :milk]
|
105
|
-
end
|
106
|
-
|
107
|
-
it "#first" do
|
108
|
-
(:john.likes A).first.should == :beer
|
109
|
-
end
|
110
|
-
|
111
|
-
it "#map" do
|
112
|
-
(:john.likes A).map{|a|a.to_s}.should == ['beer', 'milk']
|
113
|
-
end
|
114
|
-
|
115
|
-
it "#include? and #member?" do
|
116
|
-
(:john.likes B).member?(:beer).should be_true
|
117
|
-
(:john.likes B).include?(:beer).should be_true
|
118
|
-
(:john.likes B).member?(:milk).should be_true
|
119
|
-
(:john.likes B).include?(:milk).should be_true
|
120
|
-
(:john.likes B).member?(:water).should be_false
|
121
|
-
(:john.likes B).include?(:water).should be_false
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
it "can yield solutions with vars substituted" do
|
127
|
-
:john.likes! :beer
|
128
|
-
:john.likes! :milk
|
129
|
-
:jane.likes! :milk
|
130
|
-
|
131
|
-
(A.likes B).solutions.should == [
|
132
|
-
:john.likes(:beer),
|
133
|
-
:john.likes(:milk),
|
134
|
-
:jane.likes(:milk)
|
135
|
-
]
|
136
|
-
(A.likes(B).and A.is :john).solutions.should == [
|
137
|
-
:john.likes(:beer).and(:john.is :john),
|
138
|
-
:john.likes(:milk).and(:john.is :john)
|
139
|
-
]
|
140
|
-
(:john.likes(B)).solutions.should == [
|
141
|
-
:john.likes(:beer),
|
142
|
-
:john.likes(:milk)
|
143
|
-
]
|
144
|
-
(A.likes(:milk)).solutions.should == [
|
145
|
-
:john.likes(:milk),
|
146
|
-
:jane.likes(:milk)
|
147
|
-
]
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
data/spec/recursion_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubylog'
|
3
|
-
|
4
|
-
describe "recursion" do
|
5
|
-
specify "factorial" do
|
6
|
-
theory "Recursion" do
|
7
|
-
functor_for Integer, :factorial
|
8
|
-
0.factorial! 1
|
9
|
-
N.factorial(K).if lambda{|n|n>0}.and N1.is{|n|n-1}.and N1.factorial(K1).and K.is{|n,_,_,k1|k1*n}
|
10
|
-
|
11
|
-
(0.factorial K).to_a.should == [1]
|
12
|
-
(1.factorial K).to_a.should == [1]
|
13
|
-
(2.factorial K).to_a.should == [2]
|
14
|
-
(3.factorial K).to_a.should == [6]
|
15
|
-
(4.factorial K).to_a.should == [24]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/ruby_code_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "using ruby code in clauses" do
|
3
|
-
it "works" do
|
4
|
-
(:true.and? {false}).should be_false
|
5
|
-
(:true.and? {true}).should be_true
|
6
|
-
(:false.and? {false}).should be_false
|
7
|
-
(:false.and? {true}).should be_false
|
8
|
-
(:true.or? {false}).should be_true
|
9
|
-
(:true.or? {true}).should be_true
|
10
|
-
(:false.or? {false}).should be_false
|
11
|
-
(:false.or? {true}).should be_true
|
12
|
-
|
13
|
-
(:fail.or? {false}).should be_false
|
14
|
-
(:fail.or? {true}).should be_true
|
15
|
-
end
|
16
|
-
it "runs the query once at every evaluation" do
|
17
|
-
count = 0
|
18
|
-
:john.is_happy.if :true.and { count += 1 }
|
19
|
-
count.should == 0
|
20
|
-
:john.is_happy?
|
21
|
-
count.should == 1
|
22
|
-
:john.is_happy?
|
23
|
-
count.should == 2
|
24
|
-
(:false.or? {count+=1}).should be_true
|
25
|
-
count.should == 3
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "bindings" do
|
29
|
-
it "works for rule bodies" do
|
30
|
-
result = nil;
|
31
|
-
(A.likes(B).if {|*args| result = args})
|
32
|
-
(:john.likes(:beer)).solve{}
|
33
|
-
result.should == [:john,:beer]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "works for rules" do
|
37
|
-
result = nil
|
38
|
-
(A.likes(B).if B.is(4).and A.is(2).and C.is(5).and {|*args| result = args})
|
39
|
-
(A.likes(B)).solve{}
|
40
|
-
result.should == [2,4,5]
|
41
|
-
end
|
42
|
-
|
43
|
-
it "works for inline terms" do
|
44
|
-
result = nil
|
45
|
-
(A.is(1).and B.is(2).and {|*args| result = args}).solve{}
|
46
|
-
result.should == [1,2]
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|