rubylog 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/Gemfile +1 -1
  2. data/README.hu.rb +58 -0
  3. data/README.rdoc +248 -89
  4. data/Rakefile +6 -1
  5. data/VERSION +1 -1
  6. data/bin/rubylog +18 -0
  7. data/examples/dcg.rb +35 -0
  8. data/examples/dcg2.rb +42 -0
  9. data/examples/enumerators.rb +30 -0
  10. data/examples/factorial.rb +9 -8
  11. data/examples/hanoi.rb +24 -0
  12. data/examples/hello.rb +11 -5
  13. data/examples/parsing.rb +27 -0
  14. data/examples/primitives.rb +24 -0
  15. data/examples/theory.rb +22 -10
  16. data/lib/rubylog/builtins/default.rb +10 -0
  17. data/lib/rubylog/builtins/file_system.rb +15 -0
  18. data/lib/rubylog/builtins/logic.rb +109 -0
  19. data/lib/rubylog/builtins/reflection.rb +94 -0
  20. data/lib/rubylog/builtins/term.rb +47 -0
  21. data/lib/rubylog/dsl/array_splat.rb +25 -0
  22. data/lib/rubylog/dsl/primitives.rb +17 -0
  23. data/lib/rubylog/dsl/thats.rb +22 -0
  24. data/lib/rubylog/dsl/variables.rb +30 -0
  25. data/lib/rubylog/dsl.rb +35 -17
  26. data/lib/rubylog/errors.rb +19 -1
  27. data/lib/rubylog/interfaces/assertable.rb +16 -0
  28. data/lib/rubylog/interfaces/callable.rb +18 -0
  29. data/lib/rubylog/interfaces/composite_term.rb +47 -0
  30. data/lib/rubylog/interfaces/predicate.rb +8 -0
  31. data/lib/rubylog/interfaces/procedure.rb +60 -0
  32. data/lib/rubylog/interfaces/term.rb +41 -0
  33. data/lib/rubylog/mixins/array.rb +118 -0
  34. data/lib/{class.rb → rubylog/mixins/class.rb} +2 -2
  35. data/lib/rubylog/mixins/hash.rb +8 -0
  36. data/lib/rubylog/mixins/kernel.rb +5 -0
  37. data/lib/rubylog/mixins/method.rb +3 -0
  38. data/lib/rubylog/mixins/object.rb +8 -0
  39. data/lib/rubylog/mixins/proc.rb +37 -0
  40. data/lib/rubylog/mixins/string.rb +104 -0
  41. data/lib/rubylog/mixins/symbol.rb +44 -0
  42. data/lib/rubylog/simple_procedure.rb +8 -0
  43. data/lib/rubylog/{clause.rb → structure.rb} +32 -31
  44. data/lib/rubylog/theory.rb +368 -79
  45. data/lib/rubylog/variable.rb +102 -23
  46. data/lib/rubylog.rb +33 -25
  47. data/logic/builtins/file_system_logic.rb +23 -0
  48. data/logic/builtins/reflection_logic.rb +40 -0
  49. data/logic/dereference_logic.rb +23 -0
  50. data/logic/directory_structure_logic.rb +19 -0
  51. data/logic/dsl_logic.rb +29 -0
  52. data/logic/errors_logic.rb +9 -0
  53. data/logic/guard_logic.rb +115 -0
  54. data/logic/list_logic.rb +55 -0
  55. data/logic/map_logic.rb +15 -0
  56. data/logic/multitheory.rb +23 -0
  57. data/logic/recursion_logic.rb +12 -0
  58. data/logic/string_logic.rb +41 -0
  59. data/logic/thats_logic.rb +51 -0
  60. data/logic/variable_logic.rb +24 -0
  61. data/rubylog.gemspec +85 -46
  62. data/spec/bartak_guide_spec.rb +57 -62
  63. data/spec/builtins/all_spec.rb +99 -0
  64. data/spec/builtins/and_spec.rb +22 -0
  65. data/spec/builtins/array_spec.rb +16 -0
  66. data/spec/builtins/branch_or_spec.rb +27 -0
  67. data/spec/builtins/cut_spec.rb +44 -0
  68. data/spec/builtins/fail_spec.rb +5 -0
  69. data/spec/builtins/false_spec.rb +5 -0
  70. data/spec/builtins/in_spec.rb +38 -0
  71. data/spec/builtins/is_false_spec.rb +12 -0
  72. data/spec/builtins/is_spec.rb +26 -0
  73. data/spec/builtins/matches_spec.rb +23 -0
  74. data/spec/builtins/or_spec.rb +22 -0
  75. data/spec/{rubylog/builtins → builtins}/splits_to.rb +0 -0
  76. data/spec/builtins/then_spec.rb +27 -0
  77. data/spec/builtins/true_spec.rb +5 -0
  78. data/spec/clause_spec.rb +82 -0
  79. data/spec/compilation_spec.rb +61 -0
  80. data/spec/custom_classes_spec.rb +43 -0
  81. data/spec/dereference.rb +10 -0
  82. data/spec/{inriasuite.rb → inriasuite_spec.rb} +2 -9
  83. data/spec/queries_spec.rb +150 -0
  84. data/spec/recursion_spec.rb +4 -4
  85. data/spec/ruby_code_spec.rb +52 -0
  86. data/spec/rules_spec.rb +97 -0
  87. data/spec/spec_helper.rb +6 -2
  88. data/spec/theory_spec.rb +28 -0
  89. data/spec/unification_spec.rb +84 -0
  90. data/spec/variable_spec.rb +26 -0
  91. metadata +153 -180
  92. data/examples/4queens.rb +0 -10
  93. data/examples/calculation.rb +0 -12
  94. data/examples/concepts.rb +0 -46
  95. data/examples/fp.rb +0 -56
  96. data/examples/historia_de_espana.rb +0 -31
  97. data/examples/idea.rb +0 -143
  98. data/examples/lists.rb +0 -5
  99. data/examples/mechanika.rb +0 -409
  100. data/examples/parse.rb +0 -15
  101. data/lib/array.rb +0 -24
  102. data/lib/method.rb +0 -4
  103. data/lib/object.rb +0 -5
  104. data/lib/proc.rb +0 -4
  105. data/lib/rubylog/builtins.rb +0 -193
  106. data/lib/rubylog/callable.rb +0 -20
  107. data/lib/rubylog/composite_term.rb +0 -38
  108. data/lib/rubylog/dsl/constants.rb +0 -15
  109. data/lib/rubylog/dsl/first_order_functors.rb +0 -9
  110. data/lib/rubylog/dsl/global_functors.rb +0 -3
  111. data/lib/rubylog/dsl/second_order_functors.rb +0 -8
  112. data/lib/rubylog/internal_helpers.rb +0 -16
  113. data/lib/rubylog/predicate.rb +0 -34
  114. data/lib/rubylog/proc_method_additions.rb +0 -69
  115. data/lib/rubylog/term.rb +0 -20
  116. data/lib/rubylog/unifiable.rb +0 -19
  117. data/lib/symbol.rb +0 -35
  118. data/script/inriasuite2spec +0 -0
  119. data/script/inriasuite2spec.pl +0 -22
  120. data/spec/rubylog/clause_spec.rb +0 -81
  121. data/spec/rubylog/variable_spec.rb +0 -25
  122. data/spec/rubylog_spec.rb +0 -914
data/rubylog.gemspec CHANGED
@@ -4,16 +4,18 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{rubylog}
8
- s.version = "0.0.1"
7
+ s.name = "rubylog"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bern\303\241t Kall\303\263"]
12
- s.date = %q{2012-02-07}
13
- s.description = %q{Rubylog is an embedded Prolog language and interpreter for Ruby.}
14
- s.email = %q{kallo.bernat@gmail.com}
11
+ s.authors = ["Bern\u{e1}t Kall\u{f3}"]
12
+ s.date = "2013-02-27"
13
+ s.description = "Rubylog is an embedded Prolog language and interpreter for Ruby."
14
+ s.email = "kallo.bernat@gmail.com"
15
+ s.executables = ["rubylog"]
15
16
  s.extra_rdoc_files = [
16
17
  "LICENSE.txt",
18
+ "README.hu.rb",
17
19
  "README.rdoc"
18
20
  ]
19
21
  s.files = [
@@ -22,50 +24,86 @@ Gem::Specification.new do |s|
22
24
  "Gemfile",
23
25
  "Gemfile.lock",
24
26
  "LICENSE.txt",
27
+ "README.hu.rb",
25
28
  "README.rdoc",
26
29
  "Rakefile",
27
30
  "VERSION",
28
- "examples/4queens.rb",
29
- "examples/calculation.rb",
30
- "examples/concepts.rb",
31
+ "bin/rubylog",
32
+ "examples/dcg.rb",
33
+ "examples/dcg2.rb",
34
+ "examples/enumerators.rb",
31
35
  "examples/factorial.rb",
32
- "examples/fp.rb",
36
+ "examples/hanoi.rb",
33
37
  "examples/hello.rb",
34
- "examples/historia_de_espana.rb",
35
- "examples/idea.rb",
36
- "examples/lists.rb",
37
- "examples/mechanika.rb",
38
- "examples/parse.rb",
38
+ "examples/parsing.rb",
39
+ "examples/primitives.rb",
39
40
  "examples/theory.rb",
40
- "lib/array.rb",
41
- "lib/class.rb",
42
- "lib/method.rb",
43
- "lib/object.rb",
44
- "lib/proc.rb",
45
41
  "lib/rubylog.rb",
46
- "lib/rubylog/builtins.rb",
47
- "lib/rubylog/callable.rb",
48
- "lib/rubylog/clause.rb",
49
- "lib/rubylog/composite_term.rb",
42
+ "lib/rubylog/builtins/default.rb",
43
+ "lib/rubylog/builtins/file_system.rb",
44
+ "lib/rubylog/builtins/logic.rb",
45
+ "lib/rubylog/builtins/reflection.rb",
46
+ "lib/rubylog/builtins/term.rb",
50
47
  "lib/rubylog/dsl.rb",
51
- "lib/rubylog/dsl/constants.rb",
52
- "lib/rubylog/dsl/first_order_functors.rb",
53
- "lib/rubylog/dsl/global_functors.rb",
54
- "lib/rubylog/dsl/second_order_functors.rb",
48
+ "lib/rubylog/dsl/array_splat.rb",
49
+ "lib/rubylog/dsl/primitives.rb",
50
+ "lib/rubylog/dsl/thats.rb",
51
+ "lib/rubylog/dsl/variables.rb",
55
52
  "lib/rubylog/errors.rb",
56
- "lib/rubylog/internal_helpers.rb",
57
- "lib/rubylog/predicate.rb",
58
- "lib/rubylog/proc_method_additions.rb",
59
- "lib/rubylog/term.rb",
53
+ "lib/rubylog/interfaces/assertable.rb",
54
+ "lib/rubylog/interfaces/callable.rb",
55
+ "lib/rubylog/interfaces/composite_term.rb",
56
+ "lib/rubylog/interfaces/predicate.rb",
57
+ "lib/rubylog/interfaces/procedure.rb",
58
+ "lib/rubylog/interfaces/term.rb",
59
+ "lib/rubylog/mixins/array.rb",
60
+ "lib/rubylog/mixins/class.rb",
61
+ "lib/rubylog/mixins/hash.rb",
62
+ "lib/rubylog/mixins/kernel.rb",
63
+ "lib/rubylog/mixins/method.rb",
64
+ "lib/rubylog/mixins/object.rb",
65
+ "lib/rubylog/mixins/proc.rb",
66
+ "lib/rubylog/mixins/string.rb",
67
+ "lib/rubylog/mixins/symbol.rb",
68
+ "lib/rubylog/simple_procedure.rb",
69
+ "lib/rubylog/structure.rb",
60
70
  "lib/rubylog/theory.rb",
61
- "lib/rubylog/unifiable.rb",
62
71
  "lib/rubylog/variable.rb",
63
- "lib/symbol.rb",
72
+ "logic/builtins/file_system_logic.rb",
73
+ "logic/builtins/reflection_logic.rb",
74
+ "logic/dereference_logic.rb",
75
+ "logic/directory_structure_logic.rb",
76
+ "logic/dsl_logic.rb",
77
+ "logic/errors_logic.rb",
78
+ "logic/guard_logic.rb",
79
+ "logic/list_logic.rb",
80
+ "logic/map_logic.rb",
81
+ "logic/multitheory.rb",
82
+ "logic/recursion_logic.rb",
83
+ "logic/string_logic.rb",
84
+ "logic/thats_logic.rb",
85
+ "logic/variable_logic.rb",
64
86
  "rubylog.gemspec",
65
- "script/inriasuite2spec",
66
- "script/inriasuite2spec.pl",
67
87
  "spec/bartak_guide_spec.rb",
68
- "spec/inriasuite.rb",
88
+ "spec/builtins/all_spec.rb",
89
+ "spec/builtins/and_spec.rb",
90
+ "spec/builtins/array_spec.rb",
91
+ "spec/builtins/branch_or_spec.rb",
92
+ "spec/builtins/cut_spec.rb",
93
+ "spec/builtins/fail_spec.rb",
94
+ "spec/builtins/false_spec.rb",
95
+ "spec/builtins/in_spec.rb",
96
+ "spec/builtins/is_false_spec.rb",
97
+ "spec/builtins/is_spec.rb",
98
+ "spec/builtins/matches_spec.rb",
99
+ "spec/builtins/or_spec.rb",
100
+ "spec/builtins/splits_to.rb",
101
+ "spec/builtins/then_spec.rb",
102
+ "spec/builtins/true_spec.rb",
103
+ "spec/clause_spec.rb",
104
+ "spec/compilation_spec.rb",
105
+ "spec/custom_classes_spec.rb",
106
+ "spec/dereference.rb",
69
107
  "spec/inriasuite/README",
70
108
  "spec/inriasuite/abolish",
71
109
  "spec/inriasuite/and",
@@ -133,22 +171,23 @@ Gem::Specification.new do |s|
133
171
  "spec/inriasuite/term_lt=",
134
172
  "spec/inriasuite/true",
135
173
  "spec/inriasuite/unify",
174
+ "spec/inriasuite_spec.rb",
175
+ "spec/queries_spec.rb",
136
176
  "spec/recursion_spec.rb",
137
- "spec/rubylog/builtins/splits_to.rb",
138
- "spec/rubylog/clause_spec.rb",
139
- "spec/rubylog/variable_spec.rb",
140
- "spec/rubylog_spec.rb",
177
+ "spec/ruby_code_spec.rb",
178
+ "spec/rules_spec.rb",
141
179
  "spec/spec_helper.rb",
142
- "spec/theory_spec.rb"
180
+ "spec/theory_spec.rb",
181
+ "spec/unification_spec.rb",
182
+ "spec/variable_spec.rb"
143
183
  ]
144
- s.homepage = %q{https://github.com/cie/rubylog}
184
+ s.homepage = "https://github.com/cie/rubylog"
145
185
  s.licenses = ["MIT"]
146
186
  s.require_paths = ["lib"]
147
- s.rubygems_version = %q{1.3.7}
148
- s.summary = %q{An embedded Prolog interpreter}
187
+ s.rubygems_version = "1.8.15"
188
+ s.summary = "An embedded Prolog interpreter"
149
189
 
150
190
  if s.respond_to? :specification_version then
151
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
152
191
  s.specification_version = 3
153
192
 
154
193
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -4,88 +4,83 @@
4
4
 
5
5
  require 'rubylog'
6
6
 
7
- class << Rubylog.theory
8
- describe Rubylog do
9
- before do
10
- Rubylog.theory.clear
11
- end
12
-
13
- specify "Genealogy database" do
14
- Symbol.rubylog_functor :man, :woman
15
-
16
- :adam.man!
17
- :peter.man!
18
- :paul.man!
19
7
 
20
- :marry.woman!
21
- :eve.woman!
8
+ theory "Genealogy" do
9
+ subject Symbol
10
+ functor :man, :woman
22
11
 
23
- end
12
+ :adam.man!
13
+ :peter.man!
14
+ :paul.man!
24
15
 
16
+ :marry.woman!
17
+ :eve.woman!
18
+ end
25
19
 
26
- specify "Lists" do
27
- Object.rubylog_functor :head_of
28
- Array.rubylog_functor :tail_of
20
+ __END__
21
+ theory "Lists" do
22
+ functor_for Object, :head_of
23
+ functor_for Array, :tail_of
29
24
 
30
- H.head_of(A).if A.splits_to(H,ANY)
31
- T.tail_of(A).if A.splits_to(ANY,T)
25
+ H.head_of(A).if A.splits_to(H,ANY)
26
+ T.tail_of(A).if A.splits_to(ANY,T)
32
27
 
33
- 2.should be_head_of [2,3,4]
34
- 2.should be_head_of [2]
35
- 2.should_not be_head_of [1]
36
- 2.should_not be_head_of []
28
+ 2.should be_head_of [2,3,4]
29
+ 2.should be_head_of [2]
30
+ 2.should_not be_head_of [1]
31
+ 2.should_not be_head_of []
37
32
 
38
- [3,4].should be_tail_of [2,3,4]
39
- []. should be_tail_of [1]
33
+ [3,4].should be_tail_of [2,3,4]
34
+ []. should be_tail_of [1]
40
35
 
41
- Object.rubylog_functor :member_of
36
+ Object.rubylog_functor :member_of
42
37
 
43
- M.member_of(A).if A.splits_to(M,ANY)
44
- M.member_of(A).if A.splits_to(ANY,T).and M.member_of(T)
38
+ M.member_of(A).if A.splits_to(M,ANY)
39
+ M.member_of(A).if A.splits_to(ANY,T).and M.member_of(T)
45
40
 
46
- 0.should_not be_member_of [1,2,3]
47
- 1.should be_member_of [1,2,3]
48
- 2.should be_member_of [1,2,3]
49
- 3.should be_member_of [1,2,3]
50
- 4.should_not be_member_of [1,2,3]
41
+ 0.should_not be_member_of [1,2,3]
42
+ 1.should be_member_of [1,2,3]
43
+ 2.should be_member_of [1,2,3]
44
+ 3.should be_member_of [1,2,3]
45
+ 4.should_not be_member_of [1,2,3]
51
46
 
52
- Object.rubylog_functor :first_of, :last_of
47
+ Object.rubylog_functor :first_of, :last_of
53
48
 
54
- F.first_of(A).if A.splits_to(F,ANY)
55
- L.last_of(A).if A.splits_to(L,[])
56
- L.last_of(A).if A.splits_to(H,T).and L.last_of(T)
49
+ F.first_of(A).if A.splits_to(F,ANY)
50
+ L.last_of(A).if A.splits_to(L,[])
51
+ L.last_of(A).if A.splits_to(H,T).and L.last_of(T)
57
52
 
58
- 1.should be_first_of [1,2,3]
59
- 3.should_not be_last_of []
60
- 3.should be_last_of [3]
61
- 3.should be_last_of [2,3]
62
- 3.should be_last_of [1,2,3]
63
- 1.should_not be_last_of [1,2,3]
53
+ 1.should be_first_of [1,2,3]
54
+ 3.should_not be_last_of []
55
+ 3.should be_last_of [3]
56
+ 3.should be_last_of [2,3]
57
+ 3.should be_last_of [1,2,3]
58
+ 1.should_not be_last_of [1,2,3]
64
59
 
65
- Array.rubylog_functor :prefix_of
60
+ Array.rubylog_functor :prefix_of
66
61
 
67
- [].prefix_of! ANY_LIST
68
- A.prefix_of(B).if A.splits_to(H,TA).and B.splits_to(H,TB).and TA.prefix_of(TB)
62
+ [].prefix_of! ANY_LIST
63
+ A.prefix_of(B).if A.splits_to(H,TA).and B.splits_to(H,TB).and TA.prefix_of(TB)
69
64
 
70
- [1,2,3].should be_prefix_of [1,2,3]
71
- end
65
+ [1,2,3].should be_prefix_of [1,2,3]
66
+ end
72
67
 
73
68
 
74
- describe "How does it work?" do
69
+ describe "How does it work?" do
75
70
 
76
- specify "declarative character" do
77
- (1.in? [1,2,3]).should be_true
78
- (X.in [1,2,3]).to_a.should == [1,2,3]
79
- (1.in [X,Y]).to_a.should == [[1,nil], [nil,1]]
80
- lists = []
81
- (1.in L).each do |l|
82
- lists << l
83
- break if lists.size == 3
84
- end
85
- #lists.should == [[1], [nil,1], [nil,nil,1]]
86
- end
71
+ specify "declarative character" do
72
+ (1.in? [1,2,3]).should be_true
73
+ (X.in [1,2,3]).to_a.should == [1,2,3]
74
+ (1.in [X,Y]).to_a.should == [[1,nil], [nil,1]]
75
+ lists = []
76
+ (1.in L).each do |l|
77
+ lists << l
78
+ break if lists.size == 3
87
79
  end
88
-
80
+ #lists.should == [[1], [nil,1], [nil,nil,1]]
89
81
  end
90
82
  end
91
83
 
84
+ end
85
+ end
86
+
@@ -0,0 +1,99 @@
1
+
2
+ describe "all,any,one,none" do
3
+ before do
4
+ :john.likes! :water
5
+ :john.likes! :beer
6
+
7
+ :jane.likes! :water
8
+ :jane.likes! :milk
9
+ :jane.likes! :beer
10
+
11
+ :jeff.likes! :water
12
+ :jeff.likes! :absinth
13
+
14
+ :todd.likes! :milk
15
+
16
+ @predicates = [:all, :any, :one, :none]
17
+ @names = :john, :jane, :jeff, :todd
18
+ @good =
19
+ [
20
+ [[1,1,0,0], [0,1,0,0], [0,0,1,0], [0,1,0,1]], # all
21
+ [[1,1,1,0], [1,1,1,1], [1,1,1,0], [0,1,0,1]], # any
22
+ [[0,0,1,0], [0,0,1,1], [1,1,0,0], [0,1,0,1]], # one
23
+ [[0,0,0,1], [0,0,0,0], [0,0,0,1], [1,0,1,0]] # none
24
+ ]
25
+ end
26
+
27
+ it "work" do
28
+ @predicates.map{|p| @names.map{|n| @names.map{|m|
29
+ (n.likes(K).send p, m.likes(K)).true? ? 1 : 0
30
+ }}}.should == @good
31
+ end
32
+
33
+ it "mimic well enumerators' predicates" do
34
+ @predicates.map{|p| @names.map{|n| @names.map{|m|
35
+ n.likes(K).to_a.send(:"#{p}?"){|x| m.likes?(x) } ? 1 : 0
36
+ }}}.should == @good
37
+ end
38
+
39
+
40
+
41
+ it "all works" do
42
+ (:john.likes(X).all(:john.likes(X))).should stand
43
+ (:john.likes(X).all(:jane.likes(X))).should stand
44
+ (:john.likes(X).all(:jeff.likes(X))).should_not stand
45
+ (:john.likes(X).all(:todd.likes(X))).should_not stand
46
+
47
+ (:jane.likes(X).all(:john.likes(X))).should_not stand
48
+ (:jane.likes(X).all(:jane.likes(X))).should stand
49
+ (:jane.likes(X).all(:jeff.likes(X))).should_not stand
50
+ (:jane.likes(X).all(:todd.likes(X))).should_not stand
51
+
52
+ (:jeff.likes(X).all(:john.likes(X))).should_not stand
53
+ (:jeff.likes(X).all(:jane.likes(X))).should_not stand
54
+ (:jeff.likes(X).all(:jeff.likes(X))).should stand
55
+ (:jeff.likes(X).all(:todd.likes(X))).should_not stand
56
+
57
+ (:todd.likes(X).all(:john.likes(X))).should_not stand
58
+ (:todd.likes(X).all(:jane.likes(X))).should stand
59
+ (:todd.likes(X).all(:jeff.likes(X))).should_not stand
60
+ (:todd.likes(X).all(:todd.likes(X))).should stand
61
+ end
62
+
63
+ it "can be called with global functor syntax" do
64
+ extend Rubylog::DSL::GlobalFunctors
65
+ all(:john.likes(X), :jane.likes(X)).should stand
66
+ all(:jane.likes(X), :john.likes(X)).should_not stand
67
+ any(:jane.likes(X), :todd.likes(X)).should stand
68
+ any(:john.likes(X), :todd.likes(X)).should_not stand
69
+ end
70
+
71
+ it "can be called unarily" do
72
+ extend Rubylog::DSL::GlobalFunctors
73
+ one(:john.likes(X)).should_not stand
74
+ one(:jane.likes(X)).should_not stand
75
+ one(:jeff.likes(X)).should_not stand
76
+ one(:todd.likes(X)).should stand
77
+ one(:jim.likes(X)).should_not stand
78
+
79
+ any(:john.likes(X)).should stand
80
+ any(:jane.likes(X)).should stand
81
+ any(:jeff.likes(X)).should stand
82
+ any(:todd.likes(X)).should stand
83
+ any(:jim.likes(X)).should_not stand
84
+
85
+ all(:john.likes(X)).should stand
86
+ all(:jane.likes(X)).should stand
87
+ all(:jeff.likes(X)).should stand
88
+ all(:todd.likes(X)).should stand
89
+ all(:jim.likes(X)).should stand
90
+
91
+ none(:john.likes(X)).should_not stand
92
+ none(:jane.likes(X)).should_not stand
93
+ none(:jeff.likes(X)).should_not stand
94
+ none(:todd.likes(X)).should_not stand
95
+ none(:jim.likes(X)).should stand
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,22 @@
1
+
2
+ describe "and" do
3
+ it "works 1" do
4
+ :john.happy.if :fail.and :true
5
+ :john.should_not be_happy
6
+ end
7
+
8
+ it "works 2" do
9
+ :john.happy.if :true.and :fail
10
+ :john.should_not be_happy
11
+ end
12
+
13
+ it "works 3" do
14
+ :john.happy.if :fail.and :fail
15
+ :john.should_not be_happy
16
+ end
17
+
18
+ it "works 4" do
19
+ :john.happy.if :true.and :true
20
+ :john.should be_happy
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+
2
+ describe "Array" do
3
+ it "can be unified" do
4
+ result = false
5
+ [A,B].rubylog_unify(12) { result = true }
6
+ result.should == false
7
+
8
+ result = false
9
+ [A,B].rubylog_unify([12,13]) { result = true }
10
+ result.should == true
11
+
12
+ result = false
13
+ [14,B].rubylog_unify([12,13]) { result = true }
14
+ result.should == false
15
+ end
16
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,5 @@
1
+
2
+ it "fail" do
3
+ :john.happy.if :fail
4
+ :john.should_not be_happy
5
+ end
@@ -0,0 +1,5 @@
1
+
2
+ it "false" do
3
+ :john.happy.if :false
4
+ :john.should_not be_happy
5
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,12 @@
1
+
2
+ describe "is_false" do
3
+ it "works 5" do
4
+ :john.happy.if :true.is_false
5
+ :john.should_not be_happy
6
+ end
7
+
8
+ it "works 5" do
9
+ :john.happy.if :fail.is_false
10
+ :john.should be_happy
11
+ end
12
+ end
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,22 @@
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
File without changes