rubylog 1.0.0 → 2.0pre1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/rules_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
|
2
|
-
describe "rules" do
|
3
|
-
describe "with prolog body" do
|
4
|
-
it "cannot be asserted in a builtin's desc" do
|
5
|
-
lambda {
|
6
|
-
:john.likes(:beer).and! :jane.likes(:milk)
|
7
|
-
}.should raise_error(Rubylog::BuiltinPredicateError)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "can be asserted with if" do
|
11
|
-
Rubylog.theory.predicate [:we_have, 2]
|
12
|
-
:john.is_happy.if :-@.we_have(:beer)
|
13
|
-
:john.is_happy?.should be_false
|
14
|
-
:-@.we_have!(:beer)
|
15
|
-
:john.is_happy?.should be_true
|
16
|
-
end
|
17
|
-
|
18
|
-
it "can be asserted with unless" do
|
19
|
-
Rubylog.theory.predicate [:we_have, 2]
|
20
|
-
:john.is_happy.unless :-@.we_have(:problem)
|
21
|
-
:john.is_happy?.should be_true
|
22
|
-
:-@.we_have!(:problem)
|
23
|
-
:john.is_happy?.should be_false
|
24
|
-
end
|
25
|
-
|
26
|
-
it "can do simple general implications" do
|
27
|
-
Rubylog.theory.predicate [:is_happy,1], [:has,2]
|
28
|
-
Rubylog.theory.discontinuous [:likes,2]
|
29
|
-
X.is_happy.if X.likes(Y).and X.has(Y)
|
30
|
-
:john.likes! :milk
|
31
|
-
:john.is_happy?.should be_false
|
32
|
-
:john.has! :beer
|
33
|
-
:john.is_happy?.should be_false
|
34
|
-
:john.likes! :beer
|
35
|
-
:john.is_happy?.should be_true
|
36
|
-
end
|
37
|
-
|
38
|
-
it "can yield implied solutions" do
|
39
|
-
X.brother(Y).if X.father(Z).and Y.father(Z).and X.neq(Y)
|
40
|
-
X.uncle(Y).if X.father(Z).and Z.brother(Y)
|
41
|
-
X.neq(Y).if proc {|x,y|x != y}
|
42
|
-
|
43
|
-
:john.father! :dad
|
44
|
-
:jack.father! :dad
|
45
|
-
:dad.father! :grandpa
|
46
|
-
:jim.father! :grandpa
|
47
|
-
|
48
|
-
(:john.brother X).to_a.should == [:jack]
|
49
|
-
(:john.father X).to_a.should == [:dad]
|
50
|
-
(X.father :dad).to_a.should == [:john, :jack]
|
51
|
-
(ANY.father X).to_a.should == [:dad, :dad, :grandpa, :grandpa]
|
52
|
-
(:john.uncle X).to_a.should == [:jim]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "with ruby body" do
|
57
|
-
it "can be asserted (true)" do
|
58
|
-
:john.is_happy.if proc{ true }
|
59
|
-
:john.is_happy?.should be_true
|
60
|
-
end
|
61
|
-
it "can be asserted (false)" do
|
62
|
-
:john.is_happy.if proc{ false }
|
63
|
-
:john.is_happy?.should be_false
|
64
|
-
end
|
65
|
-
|
66
|
-
it "can be asserted implicitly (true)" do
|
67
|
-
:john.is_happy.if { true }
|
68
|
-
:john.is_happy?.should be_true
|
69
|
-
end
|
70
|
-
|
71
|
-
it "can be asserted implicitly (false)" do
|
72
|
-
:john.is_happy.if { false }
|
73
|
-
:john.is_happy?.should be_false
|
74
|
-
end
|
75
|
-
|
76
|
-
it "run the body during every query" do
|
77
|
-
count = 0
|
78
|
-
:john.is_happy.if proc{ count += 1 }
|
79
|
-
count.should == 0
|
80
|
-
:john.is_happy?
|
81
|
-
count.should == 1
|
82
|
-
:john.is_happy?
|
83
|
-
count.should == 2
|
84
|
-
end
|
85
|
-
|
86
|
-
it "can take arguments" do
|
87
|
-
(A.divides B).if proc{|a,b| b % a == 0}
|
88
|
-
(4.divides? 16).should be_true
|
89
|
-
(4.divides? 17).should be_false
|
90
|
-
(4.divides? 18).should be_false
|
91
|
-
(3.divides? 3).should be_true
|
92
|
-
(3.divides? 4).should be_false
|
93
|
-
(3.divides? 5).should be_false
|
94
|
-
(3.divides? 6).should be_true
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
data/spec/theory_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
theory "Th" do
|
2
|
-
subject Symbol
|
3
|
-
functor \
|
4
|
-
:likes, :is_happy, :in, :has, :we_have,
|
5
|
-
:brother, :father, :uncle, :neq, :happy, :%
|
6
|
-
end
|
7
|
-
|
8
|
-
|
9
|
-
describe "facts" do
|
10
|
-
it "can be asserted with assert" do
|
11
|
-
Th.assert(:john.is_happy)
|
12
|
-
Th[[:is_happy,1]].should include(Rubylog::Clause.new :-, :john.is_happy, :true)
|
13
|
-
Th.assert(:john.likes :beer)
|
14
|
-
Th[[:likes,2]].should include(Rubylog::Clause.new :-, :john.likes(:beer), :true)
|
15
|
-
Th.assert(:john.likes :drinking.in :bar)
|
16
|
-
Th[[:likes,2]].should include(:john.likes(:drinking.in :bar) - :true)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can be asserted with a bang, and it returns the zeroth arg" do
|
20
|
-
:john.is_happy!.should == :john
|
21
|
-
Th[[:is_happy,1]].should include(:john.is_happy.-:true)
|
22
|
-
:john.likes!(:beer).should == :john
|
23
|
-
Th[[:likes,2]].should include(:john.likes(:beer).-:true)
|
24
|
-
:john.likes!(:drinking.in :bar).should == :john
|
25
|
-
Th[[:likes,2]].should include(:john.likes(:drinking.in :bar).-:true)
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
end
|
data/spec/variable_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubylog'
|
2
|
-
|
3
|
-
theory "Vars" do
|
4
|
-
end
|
5
|
-
describe "variables" do
|
6
|
-
it "are undefined constants" do
|
7
|
-
[A, SomethingLong].each{|x|x.should be_kind_of Rubylog::Variable}
|
8
|
-
end
|
9
|
-
|
10
|
-
it "support ==" do
|
11
|
-
A.should == A
|
12
|
-
end
|
13
|
-
|
14
|
-
it "support eql?" do
|
15
|
-
A.should be_eql A
|
16
|
-
end
|
17
|
-
|
18
|
-
it "returns different instances" do
|
19
|
-
A.should_not be_equal A
|
20
|
-
end
|
21
|
-
|
22
|
-
specify "that start with ANY... are dont care" do
|
23
|
-
[ANY, ANYTHING, ANYTIME].each{|x|x.should be_kind_of Rubylog::Variable; x.should be_dont_care}
|
24
|
-
[NOBODY, EVERYBODY, SOMEBODY].each{|x|x.should be_kind_of Rubylog::Variable; x.should_not be_dont_care}
|
25
|
-
end
|
26
|
-
end
|