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.
Files changed (163) hide show
  1. data/Gemfile +3 -12
  2. data/Gemfile.lock +22 -48
  3. data/README.rdoc +38 -38
  4. data/README.rdoc.orig +284 -0
  5. data/RELEASE_NOTES.rdoc +51 -0
  6. data/Rakefile +14 -18
  7. data/TODO.txt +0 -0
  8. data/VERSION +1 -1
  9. data/examples/a_plus_b.rb +6 -0
  10. data/examples/checkmate.rb +88 -0
  11. data/examples/combination.rb +17 -0
  12. data/examples/dcg.rb +3 -2
  13. data/examples/dcg2.rb +2 -2
  14. data/{logic → examples}/directory_structure_logic.rb +3 -5
  15. data/examples/dirlist.rb +4 -0
  16. data/examples/divisors.rb +6 -0
  17. data/examples/enumerators.rb +3 -3
  18. data/examples/factorial.rb +2 -3
  19. data/examples/file_search.rb +14 -0
  20. data/examples/hanoi.rb +4 -5
  21. data/examples/hello.rb +6 -4
  22. data/examples/mice.rb +92 -0
  23. data/examples/mice2.rb +19 -0
  24. data/examples/n_queens.rb +32 -0
  25. data/examples/object_oriented.rb +14 -0
  26. data/examples/palindrome_detection.rb +18 -0
  27. data/examples/parsing.rb +6 -4
  28. data/examples/permutation.rb +12 -0
  29. data/examples/prefix.rb +13 -0
  30. data/examples/primality_by_division.rb +22 -0
  31. data/examples/primitives.rb +10 -8
  32. data/examples/sieve_of_eratosthenes.rb +14 -0
  33. data/examples/string_interpolation.rb +4 -0
  34. data/examples/sudoku.rb +52 -0
  35. data/examples/tracing.rb +19 -0
  36. data/lib/rspec/rubylog.rb +29 -0
  37. data/lib/rubylog/assertable.rb +24 -0
  38. data/lib/rubylog/builtins/arithmetics.rb +63 -0
  39. data/lib/rubylog/builtins/assumption.rb +71 -0
  40. data/lib/rubylog/builtins/ensure.rb +13 -0
  41. data/lib/rubylog/builtins/file_system.rb +30 -8
  42. data/lib/rubylog/builtins/logic.rb +69 -38
  43. data/lib/rubylog/builtins/reflection.rb +35 -50
  44. data/lib/rubylog/builtins/term.rb +15 -17
  45. data/lib/rubylog/builtins.rb +11 -0
  46. data/lib/rubylog/clause.rb +19 -0
  47. data/lib/rubylog/{interfaces/composite_term.rb → compound_term.rb} +3 -3
  48. data/lib/rubylog/context.rb +24 -0
  49. data/lib/rubylog/context_creation.rb +71 -0
  50. data/lib/rubylog/context_modules/checks.rb +35 -0
  51. data/lib/rubylog/context_modules/demonstration.rb +16 -0
  52. data/lib/rubylog/context_modules/predicates.rb +86 -0
  53. data/lib/rubylog/context_modules/primitives.rb +18 -0
  54. data/lib/rubylog/context_modules/thats.rb +13 -0
  55. data/lib/rubylog/default_context.rb +9 -0
  56. data/lib/rubylog/dsl/array_splat.rb +11 -3
  57. data/lib/rubylog/dsl/primitives.rb +24 -12
  58. data/lib/rubylog/dsl/thats.rb +6 -0
  59. data/lib/rubylog/dsl/variables.rb +56 -21
  60. data/lib/rubylog/errors.rb +26 -15
  61. data/lib/rubylog/mixins/array.rb +95 -62
  62. data/lib/rubylog/mixins/kernel.rb +3 -2
  63. data/lib/rubylog/mixins/method.rb +0 -1
  64. data/lib/rubylog/mixins/object.rb +2 -1
  65. data/lib/rubylog/mixins/proc.rb +9 -12
  66. data/lib/rubylog/mixins/string.rb +15 -23
  67. data/lib/rubylog/mixins/symbol.rb +7 -24
  68. data/lib/rubylog/nullary_predicates.rb +3 -0
  69. data/lib/rubylog/predicate.rb +53 -0
  70. data/lib/rubylog/primitive.rb +15 -0
  71. data/lib/rubylog/procedure.rb +42 -0
  72. data/lib/rubylog/rule.rb +24 -0
  73. data/lib/rubylog/structure.rb +19 -38
  74. data/lib/rubylog/{interfaces/term.rb → term.rb} +2 -7
  75. data/lib/rubylog/tracing.rb +75 -0
  76. data/lib/rubylog/variable.rb +31 -12
  77. data/lib/rubylog.rb +36 -32
  78. data/rubylog.gemspec +92 -84
  79. data/spec/inriasuite_spec.rb +906 -9
  80. data/spec/integration/custom_classes_spec.rb +61 -0
  81. data/spec/integration/dsl_spec.rb +38 -0
  82. data/spec/integration/recursion_spec.rb +14 -0
  83. data/spec/integration/theory_as_module_spec.rb +20 -0
  84. data/spec/integration/theory_as_module_with_include_spec.rb +14 -0
  85. data/spec/rspec/rubylog_spec.rb +75 -0
  86. data/spec/rubylog/assertable_spec.rb +111 -0
  87. data/spec/rubylog/builtins/arithmetics_spec.rb +94 -0
  88. data/spec/rubylog/builtins/assumption_spec.rb +70 -0
  89. data/spec/rubylog/builtins/ensure_spec.rb +8 -0
  90. data/spec/rubylog/builtins/file_system_spec.rb +40 -0
  91. data/spec/rubylog/builtins/logic_spec.rb +340 -0
  92. data/spec/rubylog/builtins/reflection_spec.rb +43 -0
  93. data/spec/rubylog/builtins/term_spec.rb +85 -0
  94. data/spec/rubylog/context_modules/demonstration_spec.rb +132 -0
  95. data/spec/rubylog/context_modules/predicates_spec.rb +57 -0
  96. data/spec/rubylog/context_modules/thats_spec.rb +94 -0
  97. data/spec/rubylog/dsl/array_splat_spec.rb +15 -0
  98. data/spec/rubylog/dsl/primitives_spec.rb +43 -0
  99. data/spec/rubylog/errors_spec.rb +18 -0
  100. data/spec/{unification_spec.rb → rubylog/interfaces/term_spec.rb} +8 -9
  101. data/spec/rubylog/mixins/array_spec.rb +80 -0
  102. data/spec/rubylog/mixins/composite_term_spec.rb +66 -0
  103. data/spec/rubylog/mixins/proc_spec.rb +59 -0
  104. data/spec/rubylog/mixins/string_spec.rb +48 -0
  105. data/spec/rubylog/mixins/symbol_spec.rb +9 -0
  106. data/spec/{clause_spec.rb → rubylog/structure_spec.rb} +16 -15
  107. data/spec/rubylog/term_spec.rb +7 -0
  108. data/spec/rubylog/tracing_spec.input +27 -0
  109. data/spec/rubylog/tracing_spec.rb +44 -0
  110. data/spec/rubylog/variable_spec.rb +279 -0
  111. data/spec/spec_helper.rb +1 -0
  112. data/vimrc +11 -0
  113. metadata +103 -123
  114. data/README.hu.rb +0 -58
  115. data/bin/rubylog +0 -18
  116. data/examples/theory.rb +0 -32
  117. data/lib/rubylog/builtins/default.rb +0 -10
  118. data/lib/rubylog/dsl.rb +0 -70
  119. data/lib/rubylog/interfaces/assertable.rb +0 -16
  120. data/lib/rubylog/interfaces/callable.rb +0 -18
  121. data/lib/rubylog/interfaces/predicate.rb +0 -8
  122. data/lib/rubylog/interfaces/procedure.rb +0 -60
  123. data/lib/rubylog/mixins/class.rb +0 -11
  124. data/lib/rubylog/simple_procedure.rb +0 -8
  125. data/lib/rubylog/theory.rb +0 -422
  126. data/logic/builtins/file_system_logic.rb +0 -23
  127. data/logic/builtins/reflection_logic.rb +0 -40
  128. data/logic/dereference_logic.rb +0 -23
  129. data/logic/dsl_logic.rb +0 -29
  130. data/logic/errors_logic.rb +0 -9
  131. data/logic/guard_logic.rb +0 -115
  132. data/logic/list_logic.rb +0 -55
  133. data/logic/map_logic.rb +0 -15
  134. data/logic/multitheory.rb +0 -23
  135. data/logic/recursion_logic.rb +0 -12
  136. data/logic/string_logic.rb +0 -41
  137. data/logic/thats_logic.rb +0 -51
  138. data/logic/variable_logic.rb +0 -24
  139. data/spec/bartak_guide_spec.rb +0 -86
  140. data/spec/builtins/all_spec.rb +0 -99
  141. data/spec/builtins/and_spec.rb +0 -22
  142. data/spec/builtins/array_spec.rb +0 -16
  143. data/spec/builtins/branch_or_spec.rb +0 -27
  144. data/spec/builtins/cut_spec.rb +0 -44
  145. data/spec/builtins/fail_spec.rb +0 -5
  146. data/spec/builtins/false_spec.rb +0 -5
  147. data/spec/builtins/in_spec.rb +0 -38
  148. data/spec/builtins/is_false_spec.rb +0 -12
  149. data/spec/builtins/is_spec.rb +0 -26
  150. data/spec/builtins/matches_spec.rb +0 -23
  151. data/spec/builtins/or_spec.rb +0 -22
  152. data/spec/builtins/splits_to.rb +0 -18
  153. data/spec/builtins/then_spec.rb +0 -27
  154. data/spec/builtins/true_spec.rb +0 -5
  155. data/spec/compilation_spec.rb +0 -61
  156. data/spec/custom_classes_spec.rb +0 -43
  157. data/spec/dereference.rb +0 -10
  158. data/spec/queries_spec.rb +0 -150
  159. data/spec/recursion_spec.rb +0 -18
  160. data/spec/ruby_code_spec.rb +0 -52
  161. data/spec/rules_spec.rb +0 -97
  162. data/spec/theory_spec.rb +0 -29
  163. 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
@@ -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