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
@@ -1,13 +1,910 @@
1
- describe "and" do
2
- specify do
3
- (X.is(1).and X.var).to_a.should == []
4
- (X.var.and X.is(1)).to_a.should == [1]
5
- (:fail.and :call[3]).to_a.should == []
6
- lambda { (:nofoo[X].and X.call).to_a }.
7
- should raise_error ExistenceError
8
- (X.is(:true).and X.call).should == [:true]
1
+ require 'spec_helper'
2
+
3
+ describe "inriasuite", :rubylog=>true do
4
+
5
+ describe "abolish", :pending=>"Not supported in Rubylog" do
6
+ specify %([abolish(abolish/1), permission_error(modify,static_procedure,abolish/1)].)
7
+ specify %([abolish(foo/a), type_error(integer,a)].)
8
+ specify %([abolish(foo/(-1)), domain_error(not_less_than_zero,-1)].)
9
+ specify %([(current_prolog_flag(max_arity,A), X is A + 1, abolish(foo/X)), )
10
+ specify %( representation_error(max_arity)]. )
11
+ specify %( [abolish(5/2), type_error(atom,5)].)
12
+ end
13
+
14
+ describe "and" do
15
+ specify "[','(X=1, var(X)), failure]." do
16
+ X.is(1).and{X.is_a? Rubylog::Variable}.to_a.should == []
17
+ end
18
+ specify "[','(var(X), X=1), [[X <-- 1]]]." do
19
+ proc{X.is_a? Rubylog::Variable}.and(X.is(1)).map{X}.should == [1]
20
+ end
21
+ specify "[','(fail, call(3)), failure]." do
22
+ :fail.and(proc{raise StopIteration}).true?.should be_false
23
+ end
24
+ specify "[','(nofoo(X), call(X)), existence_error(procedure, nofoo/1)]." do
25
+ lambda { X.is{proc{raise StopIteration}}.and(X).true? }.should raise_error StopIteration
26
+ end
27
+ specify "[','(X = true, call(X)), [[X <-- true]]]." do
28
+ X.is(:true).and(X).map{X}.should == [:true]
29
+ end
30
+ end
31
+
32
+ describe "arg", :pending => "Not supported in Rubylog. Use s.structure(predicate, functor, args)" do
33
+ specify "[arg(1,foo(a,b),a), success]."
34
+ specify "[arg(1,foo(a,b),X), [[X <-- a]]]."
35
+ specify "[arg(1,foo(X,b),a), [[X <-- a]]]."
36
+ specify "[arg(2,foo(a, f(X,b), c), f(a, Y)), [[X <-- a, Y <-- b]]]."
37
+ specify "[arg(1,foo(X,b),Y), [[Y <-- X]]]."
38
+ specify "[arg(1,foo(a,b),b), failure]."
39
+ specify "[arg(0,foo(a,b),foo), failure]."
40
+ specify "[arg(3,foo(3,4),N), failure]."
41
+ specify "[arg(X,foo(a,b),a), instantiation_error]."
42
+ specify "[arg(1,X,a), instantiation_error]."
43
+ specify "[arg(0,atom,A), type_error(compound, atom)]."
44
+ specify "[arg(0,3,A), type_error(compound, 3)]. "
45
+ specify "[arg(-3,foo(a,b),A), domain_error(not_less_than_zero,-3)]. "
46
+ specify "[arg(a,foo(a,b),X), type_error(integer, a)]."
47
+ end
48
+
49
+ describe "arith_diff" do
50
+ specify "['=\\\\='(0,1), success]." do
51
+ proc{0 != 1}.true?.should be_true
52
+ end
53
+ specify "['=\\\\='(1.0,1), failure]." do
54
+ proc{1.0 != 1}.true?.should be_false
55
+ end
56
+ specify "['=\\\\='(3 * 2,7 - 1), failure]." do
57
+ proc{3*2 != 7-1}.true?.should be_false
58
+ end
59
+ specify "['=\\\\='(N,5), instantiation_error].", :pending=> "this is not an error in Rubylog"
60
+ specify "['=\\\\='(floot(1),5), type_error(evaluable, floot/1)].", :pending=> "this is not an error in Rubylog"
61
+ end
62
+
63
+ describe "arith_eq" do
64
+ specify %(['=:='(0,1), failure].) do
65
+ proc{0 == 1}.true?.should be_false
66
+ end
67
+ specify %(['=:='(1.0,1), success].) do
68
+ proc{1.0 == 1}.true?.should be_true
69
+ end
70
+ specify %(['=:='(3 * 2,7 - 1), success].) do
71
+ proc{3*2 == 7-1}.true?.should be_true
72
+ end
73
+ specify %(['=:='(N,5), instantiation_error].), :pending=> "this is not an error in Rubylog"
74
+ specify %(['=:='(floot(1),5), type_error(evaluable, floot/1)].), :pending=> "this is not an error in Rubylog"
75
+ specify %([0.333 =:= 1/3, failure].) do
76
+ proc{0.333 == 1/3}.true?.should be_false
77
+ end
78
+ end
79
+
80
+ describe "arith_gt" do
81
+ specify %(['>'(0,1), failure].) do
82
+ proc{0 > 1}.true?.should be_false
83
+ end
84
+ specify %(['>'(1.0,1), failure].) do
85
+ proc{1.0 > 1}.true?.should be_false
86
+ end
87
+ specify %(['>'(3*2,7-1), failure].) do
88
+ proc{3*2 > 7-1}.true?.should be_false
89
+ end
90
+ specify %(['>'(X,5), instantiation_error].) do
91
+ proc { proc{X > 5}.true? }.should raise_error NoMethodError
92
+ end
93
+ specify %(['>'(2 + floot(1),5), type_error(evaluable, floot/1)].) do
94
+ proc { proc{2+4.is(4) > 5}.true? }.should raise_error TypeError
95
+ end
96
+ end
97
+
98
+ describe "arith_gt=" do
99
+ specify %(['>='(0,1), failure].) do
100
+ proc{0 >= 1}.true?.should be_false
101
+ end
102
+ specify %(['>='(1.0,1), success].) do
103
+ proc{1.0 >= 1}.true?.should be_true
104
+ end
105
+ specify %(['>='(3*2,7-1), success].) do
106
+ proc{3*2 >= 7-1}.true?.should be_true
107
+ end
108
+ specify %(['>='(X,5), instantiation_error].) do
109
+ proc { proc{X >= 5}.true? }.should raise_error NoMethodError
110
+ end
111
+ specify %(['>='(2 + floot(1),5), type_error(evaluable, floot/1)].) do
112
+ proc { proc{2+4.is(4) >= 5}.true? }.should raise_error TypeError
113
+ end
114
+ end
115
+
116
+ describe "arith_lt" do
117
+ specify %(['<'(0,1), success].) do
118
+ proc{0 < 1}.true?.should be_true
119
+ end
120
+ specify %(['<'(1.0,1), failure].) do
121
+ proc{1.0 < 1}.true?.should be_false
122
+ end
123
+ specify %(['<'(3*2,7-1), failure].) do
124
+ proc{3*2 < 7-1}.true?.should be_false
125
+ end
126
+ specify %(['<'(X,5), instantiation_error].) do
127
+ proc { proc{X < 5}.true? }.should raise_error NoMethodError
128
+ end
129
+ specify %(['<'(2 + floot(1),5), type_error(evaluable, floot/1)].) do
130
+ proc { proc{2+4.is(4) < 5}.true? }.should raise_error TypeError
131
+ end
132
+ end
133
+
134
+ describe "arith_lt=" do
135
+ specify %(['=<'(0,1), success].) do
136
+ proc{0 <= 1}.true?.should be_true
137
+ end
138
+ specify %(['=<'(1.0,1), success].) do
139
+ proc{1.0 <= 1}.true?.should be_true
140
+ end
141
+ specify %(['=<'(3*2,7-1), success].) do
142
+ proc{3*2 <= 7-1}.true?.should be_true
143
+ end
144
+ specify %(['=<'(X,5), instantiation_error].) do
145
+ proc { proc{X <= 5}.true? }.should raise_error NoMethodError
146
+ end
147
+ specify %(['=<'(2 + floot(1),5), type_error(evaluable, floot/1)].) do
148
+ proc { proc{2+4.is(4) <= 5}.true? }.should raise_error TypeError
149
+ end
150
+ end
151
+
152
+ describe "asserta", :pending => "Not supported in Rubylog." do
153
+ specify %([(asserta((bar(X) :- X)), clause(bar(X), B)), [[B <-- call(X)]]].)
154
+ specify %([asserta(_), instantiation_error].)
155
+ specify %([asserta(4), type_error(callable, 4)]. )
156
+ specify %([asserta((foo :- 4)), type_error(callable, 4)]. )
157
+ specify %([asserta((atom(_) :- true)), permission_error(modify,static_procedure,atom/1)].)
158
+ end
159
+
160
+ describe "assertz", :pending => "Not supported in Rubylog." do
161
+ specify %([assertz((foo(X) :- X -> call(X))), success].)
162
+ specify %([assertz(_), instantiation_error].)
163
+ specify %([assertz(4), type_error(callable, 4)].)
164
+ specify %([assertz((foo :- 4)), type_error(callable, 4)].)
165
+ specify %([assertz((atom(_) :- true)), )
166
+ specify %( permission_error(modify,static_procedure,atom/1)].)
167
+ end
168
+
169
+ describe "atom", :pending=>"Not supported in Rubylog. Use #is_a?(String) or #is_a?(Symbol)" do
170
+ specify %([atom(atom), success].)
171
+ specify %([atom('string'), success].)
172
+ specify %([atom(a(b)), failure].)
173
+ specify %([atom(Var), failure].)
174
+ specify %([atom([]), success].)
175
+ specify %([atom(6), failure].)
176
+ specify %([atom(3.3), failure].)
177
+ end
178
+
179
+ describe "atom_chars", :pending => "Not supported in Rubylog." do
180
+ specify %([atom_chars('',L), [[L <-- []]]].)
181
+ specify %([atom_chars([],L), [[L <-- ['[',']']]]].)
182
+ specify %([atom_chars('''',L), [[L <-- ['''']]]].)
183
+ specify %([atom_chars('iso',L), [[L <-- ['i','s','o']]]].)
184
+ specify %([atom_chars(A,['p','r','o','l','o','g']), [[A <-- 'prolog']]].)
185
+ specify %([atom_chars('North',['N'|X]), [[X <-- ['o','r','t','h']]]].)
186
+ specify %([atom_chars('iso',['i','s']), failure].)
187
+ specify %([atom_chars(A,L), instantiation_error].)
188
+ specify %([atom_chars(A,[a,E,c]), instantiation_error].)
189
+ specify %([atom_chars(A,[a,b|L]), instantiation_error].)
190
+ specify %([atom_chars(f(a),L), type_error(atom,f(a))].)
191
+ specify %([atom_chars(A,iso), type_error(list,iso)].)
192
+ specify %([atom_chars(A,[a,f(b)]), type_error(character,f(b))].)
193
+ specify %([(atom_chars(X,['1','2']), Y is X + 1), type_error(evaluable, '12'/0)].)
194
+ end
195
+
196
+ describe "atom_codes", :pending => "Not supported in Rubylog." do
197
+ specify %([atom_codes('',L), [[L <-- []]]].)
198
+ specify %([atom_codes([],L), [[L <-- [ 0'[, 0'] ]]]].)
199
+ specify %([atom_codes('''',L), [[L <-- [ 39 ]]]].)
200
+ specify %([atom_codes('iso',L), [[L <-- [ 0'i, 0's, 0'o ]]]].)
201
+ specify %([atom_codes(A,[ 0'p, 0'r, 0'o, 0'l, 0'o, 0'g]), [[A <-- 'prolog']]].)
202
+ specify %([atom_codes('North',[0'N | L]), [[L <-- [0'o, 0'r, 0't, 0'h]]]].)
203
+ specify %([atom_codes('iso',[0'i, 0's]), failure].)
204
+ specify %([atom_codes(A,L), instantiation_error].)
205
+ specify %([atom_codes(f(a),L), type_error(atom,f(a))].)
206
+ specify %([atom_codes(A, 0'x), type_error(list,0'x)].)
207
+ specify %([atom_codes(A,[ 0'i, 0's, 1000]), representation_error(character_code)]. % 1000 not a code)
208
+ end
209
+
210
+ describe "atom_concat" do
211
+ specify %([atom_concat('hello',' world',A), [[A <-- 'hello world']]].) do
212
+ A.is("#{"hello"}#{" world"}").map{A}.should eql ['hello world']
213
+ end
214
+ specify %([atom_concat(T,' world','small world'), [[T <-- 'small']]].) do
215
+ "small world".is("#{T} world").map{T}.should eql ['small']
216
+ end
217
+ specify %([atom_concat('hello',' world','small world'), failure].) do
218
+ "small world".is("#{"hello"}#{" world"}").true?.should be_false
219
+ end
220
+ specify %([atom_concat(T1,T2,'hello'),
221
+ [[T1 <-- '',T2 <-- 'hello'],
222
+ [T1 <-- 'h',T2 <-- 'ello'],
223
+ [T1 <-- 'he',T2 <-- 'llo'],
224
+ [T1 <-- 'hel',T2 <-- 'lo'],
225
+ [T1 <-- 'hell',T2 <-- 'o'],
226
+ [T1 <-- 'hello',T2 <-- '']]]. ) do
227
+ "hello".is("#{A}#{B}").map{[A,B]}.should eql [
228
+ ['','hello'],
229
+ ['h','ello'],
230
+ ['he','llo'],
231
+ ['hel','lo'],
232
+ ['hell','o'],
233
+ ['hello','']]
234
+ end
235
+ specify %( [atom_concat(A1,'iso',A3), instantiation_error].), :pending=>"This is not an error in Rubylog"
236
+ specify %( [atom_concat('iso',A2,A3), instantiation_error].), :pending=>"This is not an error in Rubylog"
237
+ specify %( [atom_concat(f(a),'iso',A3), type_error(atom,f(a))].), :pending=>"This is not an error in Rubylog"
238
+ specify %( [atom_concat('iso',f(a),A3), type_error(atom,f(a))].), :pending=>"This is not an error in Rubylog"
239
+ specify %( [atom_concat(A1,A2,f(a)), type_error(atom,f(a))].), :pending=>"This is not an error in Rubylog"
240
+ end
241
+
242
+ describe "atom_length", :pending=>"Not supported in Rubylog" do
243
+ specify %([atom_length('enchanted evening', N), [[N <-- 17]]].)
244
+ #specify %(%[atom_length('enchanted\)
245
+ #evening', N), [[N <-- 17]]].)
246
+ specify %([atom_length('', N), [[N <-- 0]]].)
247
+ specify %([atom_length('scarlet', 5), failure].)
248
+ specify %([atom_length(Atom, 4), instantiation_error]. % Culprit Atom)
249
+ specify %([atom_length(1.23, 4), type_error(atom, 1.23)].)
250
+ specify %([atom_length(atom, '4'), type_error(integer, '4')].)
251
+ end
252
+
253
+ describe "atomic", :pending=>"There is no such feature in Rubylog. Use !is_a?(Rubylog::CompoundTerm)" do
254
+ specify %([atomic(atom), success].)
255
+ specify %([atomic(a(b)), failure].)
256
+ specify %([atomic(Var), failure].)
257
+ specify %([atomic([]), success].)
258
+ specify %([atomic(6), success].)
259
+ specify %([atomic(3.3), success].)
260
+ end
261
+
262
+ describe "bagof" do
263
+ specify %([bagof(X,(X=1;X=2),L), [[L <-- [1, 2]]]].) do
264
+ X.is(1).or(X.is(2)).map{X}.should eql [1,2]
265
+ end
266
+ specify %([bagof(X,(X=1;X=2),X), [[X <-- [1, 2]]]].), :pending=>"This does not work in Rubylog because of dynamic and static contexts"
267
+ specify %([bagof(X,(X=Y;X=Z),L), [[L <-- [Y, Z]]]].), :pending=>"This does not work in Rubylog because of dynamic and static contexts"
268
+ specify %([bagof(X,fail,L), failure].), :pending=>"This does not work in Rubylog because of dynamic and static contexts"
269
+ specify %([bagof(1,(Y=1;Y=2),L), [[L <-- [1], Y <-- 1], [L <-- [1], Y <-- 2]]].), :pending=>"This does not work in Rubylog because of dynamic and static contexts"
270
+ specify %([bagof(f(X,Y),(X=a;Y=b),L), [[L <-- [f(a, _), f(_, b)]]]].) do
271
+ X.is('a').or(Y.is('b')).map{[X,Y]}.should eql [['a',Y],[X,'b']]
272
+ end
273
+ specify %([bagof(X,Y^((X=1,Y=1);(X=2,Y=2)),S), [[S <-- [1, 2]]]].)
274
+ specify %([bagof(X,Y^((X=1;Y=1);(X=2,Y=2)),S), [[S <-- [1, _, 2]]]].)
275
+ specify %([(set_prolog_flag(unknown, warning),
276
+ bagof(X,(Y^(X=1;Y=1);X=3),S)), [[S <-- [3]]]].)
277
+ specify %( [bagof(X,(X=Y;X=Z;Y=1),L), [[L <-- [Y, Z]], [L <-- [_], Y <-- 1]]].)
278
+ specify %( [bagof(X,Y^Z,L), instantiation_error].)
279
+ specify %( [bagof(X,1,L), type_error(callable, 1)].)
280
+ specify %( [findall(X,call(4),S),type_error(callable, 4)].)
281
+ end
282
+
283
+ describe "call" do
284
+ specify %([call(!),success].) do
285
+ A.is(:cut!).and(A).true?.should be_true
286
+ end
287
+ specify %([call(fail), failure].) do
288
+ A.is(:fail).and(A).true?.should be_false
289
+ end
290
+ specify %([call((fail, X)), failure].) do
291
+ A.is(:fail.and(X)).and(A).true?.should be_false
292
+ end
293
+ specify %([call((fail, call(1))), failure].) do
294
+ A.is(:fail.and(X.is(1).and(X))).and(A).true?.should be_false
295
+ end
296
+ specify %([call((write(3), X)), instantiation_error].) do
297
+ lambda { A.is(proc{p 3; true}.and(X)).and(A).true? }.should raise_error Rubylog::InstantiationError
298
+ end
299
+ specify %([call((write(3), call(1))), type_error(callable,1)].) do
300
+ lambda { A.is(proc{p 3; true}.and(X.is(1).and(X))).and(A).true? }.should raise_error NoMethodError
301
+ end
302
+ specify %([call(X), instantiation_error].) do
303
+ lambda { A.true? }.should raise_error Rubylog::InstantiationError
304
+ end
305
+ specify %([call(1), type_error(callable,1)].) do
306
+ lambda { A.is(1).and(A).true? }.should raise_error NoMethodError
307
+ end
308
+ specify %([call((fail, 1)), type_error(callable,(fail,1))].), :pending=>"Not an error in Rubylog"
309
+ specify %([call((write(3), 1)), type_error(callable,(write(3), 1))].) do
310
+ lambda { A.is(proc{p 3; true}.and(1)).and(A).true? }.should raise_error NoMethodError
311
+ end
312
+ specify %([call((1; true)), type_error(callable,(1; true))].) do
313
+ lambda { A.is(Rubylog::Structure.new(A.or(B).predicate, :or, 1, :true)).and(A).true? }.should raise_error NoMethodError
314
+ end
315
+ end
316
+
317
+ describe "catch-and-throw", :pending=>"There is no such thing in Rubylog yet. Maybe someday." do
318
+ specify %([(catch(true, C, write('something')), throw(blabla)), system_error]. ) #% The system catchs 'blabla'
319
+ specify %([catch(number_chars(A,L), error(instantiation_error, _), fail), failure].)
320
+ end
321
+
322
+ describe "char_code", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
323
+ specify %([char_code(Char,99),[[Char <-- c]]].)
324
+ specify %([char_code(Char,0'c),[[Char <-- c]]].)
325
+ specify %([char_code(Char,163),[[Char <-- '\xa3\']]].)
326
+ specify %([char_code(b,98),success].)
327
+ specify %([char_code(b,4),failure].)
328
+ specify %([char_code('ab',Code),type_error(character, 'ab')].)
329
+ specify %([char_code(a,x),type_error(integer, x)].)
330
+ specify %([char_code(Char,Code),instantiation_error].)
331
+ specify %([char_code(Char,-2),representation_error(character_code)].)
332
+ end
333
+
334
+ describe "clause" do
335
+ specify %([clause(x,Body), failure].) do
336
+ predicate ":x"
337
+ :x.follows_from(Body).true?.should be_false
338
+ end
339
+ specify %([clause(_,B), instantiation_error].) do
340
+ proc { ANY.follows_from(B).true? }.should raise_error Rubylog::InstantiationError
341
+ end
342
+ specify %([clause(4,B), type_error(callable,4)].) do
343
+ proc { A.is(4).and(A.follows_from(B)).true? }.should raise_error NoMethodError
344
+ end
345
+ specify %([clause(f(_),5), type_error(callable,5)].), :pending=>"As there is no compiling, this is not an error in Rubylog, it simply fails."
346
+ specify %([clause(atom(_),Body), permission_error(access,private_procedure,atom/1)]. ) do
347
+ proc { ANY.false.follows_from(B).true? }.should raise_error NoMethodError
348
+ end
349
+ end
350
+
351
+ describe "compound", :pending=>"There is no such feature in Rubylog. Use is_a?(Rubylog::CompoundTerm)" do
352
+ specify %([compound(33.3), failure].)
353
+ specify %([compound(-33.3), failure].)
354
+ specify %([compound(-a), success].)
355
+ specify %([compound(_), failure].)
356
+ specify %([compound(a), failure].)
357
+ specify %([compound(a(b)), success].)
358
+ specify %([compound([a]),success].)
359
+ end
360
+
361
+ describe "copy_term", :pending=>"Not supported in Rubylog" do
362
+ specify %([copy_term(X,Y), success].)
363
+ specify %([copy_term(X,3), success].)
364
+ specify %([copy_term(_,a), success].)
365
+ specify %([copy_term(a+X,X+b),[[X <-- a]]].)
366
+ specify %([copy_term(_,_), success].)
367
+ specify %([copy_term(X+X+Y,A+B+B),[[B <-- A]]].)
368
+ specify %([copy_term(a,a), success].)
369
+ specify %([copy_term(a,b), failure].)
370
+ specify %([copy_term(f(a),f(X)),[[X <-- a]]].)
371
+ specify %([(copy_term(a+X,X+b),copy_term(a+X,X+b)), failure].)
372
+ end
373
+
374
+ describe "current_input", :pending=>"Not supported in Rubylog. Use $stdin" do
375
+ specify %([exists(current_input/1), success].)
376
+ end
377
+
378
+ describe "current_output", :pending=>"Not supported in Rubylog. Use $stdout" do
379
+ specify %([exists(current_output/1), success]. )
380
+ end
381
+
382
+ describe "current_predicate", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
383
+ specify %([current_predicate(current_predicate/1), failure]. )
384
+ specify %(/* depends on the test harness */)
385
+ specify %([current_predicate(run_tests/1), success]. )
386
+ specify %([current_predicate(4), type_error(predicate_indicator, 4)].)
387
+ specify %([current_predicate(dog), type_error(predicate_indicator, dog)].)
388
+ specify %([current_predicate(0/dog), type_error(predicate_indicator, 0/dog)].)
389
+ end
390
+
391
+ describe "current_prolog_flag", :pending=>"Not supported in Rubylog" do
392
+ specify %([current_prolog_flag(debug, off), success].)
393
+ specify %([(set_prolog_flag(unknown, warning), )
394
+ specify %( current_prolog_flag(unknown, warning)), success].)
395
+ specify %( [(set_prolog_flag(unknown, warning), )
396
+ specify %( current_prolog_flag(unknown, error)), failure].)
397
+ specify %( [current_prolog_flag(debug, V), [[V <-- off]]].)
398
+ specify %( [current_prolog_flag(5, V), type_error(atom,5)].)
399
+ specify %( [current_prolog_flag(warning, V), domain_error(prolog_flag,warning)].)
400
+ end
401
+
402
+ describe "cut" do
403
+ specify %([(!,fail;true), failure].) do
404
+ :cut!.and(:fail).or(:true).true?.should be_false
405
+ end
406
+ specify %([(call(!),fail;true), success].) do
407
+ X.is(:cut!).and(X.and(:fail).or(:true)).true?.should be_true
408
+ end
409
+ end
410
+
411
+ describe "fail" do
412
+ specify %([fail, failure].) do
413
+ :fail.true?.should be_false
414
+ end
415
+ specify %([undef_pred, existence_error(procedure, undef_pred/0)]. % the value of flag 'unknown' is 'error'.) do
416
+ proc{ :undef_pred.true? }.should raise_error Rubylog::ExistenceError
417
+ end
418
+ specify %([(set_prolog_flag(unknown, fail), undef_pred), failure.), :pending=>"Not supported in Rubylog"
419
+ specify %([(set_prolog_flag(unknown, warning), undef_pred), failure]. % A warning message
420
+ % appears in the outputfile (see forest by: run_forest or bip_forest).), :pending=>"Not supported in Rubylog"
9
421
  end
10
- end
11
422
 
423
+ describe "file_manip", :pending=>"Not supported in Rubylog" do
424
+ specify %(/* by 'run_forest' predicate */)
425
+ specify %([(seek(my_file,3),at(my_file,X)),in(my_file),[[X <-- 3]]].)
426
+ specify %([(seek(my_file,eof),at(my_file,X)),in(my_file),[[X <-- eof]]].)
427
+ specify %([(seek(my_file,3),get_char(X,my_file)),in(my_file),[[X <-- e]]].)
428
+ end
429
+
430
+ describe "findall" do
431
+ predicate_for Symbol, ".likes()"
432
+
433
+ specify %([findall(X,(X=1 ; X=2),S),[[S <-- [1,2]]]].) do
434
+ check S.is{X.is(1).or(X.is(2)).map{X}}.and{S == [1,2]}
435
+ end
436
+ specify %([findall(X+Y,(X=1),S),[[S <-- [1+_]]]].) do
437
+ check S.is{X.is(:john).map{X.likes(Y)}}.and{S == [:john.likes(Y)]}
438
+ end
439
+ specify %([findall(X,fail,L),[[L <-- []]]].) do
440
+ check G.is(:fail.or :fail).and L.is{G.map{X}}.and{L == []}
441
+ end
442
+ specify %([findall(X,(X=1 ; X=1),S),[[S <-- [1,1]]]].) do
443
+ check S.is{X.is(1).or(X.is(1)).map{X}}.and{S == [1,1]}
444
+ end
445
+ specify %([findall(X,(X=2 ; X=1),[1,2]), failure].) do
446
+ check [1,2].is{X.is(2).or(X.is(1)).map{X}}.false
447
+ end
448
+ specify %([findall(X,(X=1 ; X=2),[X,Y]), [[X <-- 1, Y <-- 2]]].) do
449
+ check [X,Y].is{A.is(1).or(A.is(2)).map{A}}.and{X == 1}.and{Y == 2}
450
+ end
451
+ specify %([findall(X,Goal,S),instantiation_error]. % Culprit Goal) do
452
+ expect {(S.is {Goal.map{X}}).solve}.to raise_error NoMethodError
453
+ end
454
+ specify %([findall(X,4,S),type_error(callable, 4)].) do
455
+ expect {(S.is {4.map{X}}).solve}.to raise_error NoMethodError
456
+ end
457
+ end
458
+
459
+ describe "float", :pending=>"Not supported in Rubylog. Use is_a? Float" do
460
+ specify %([float(3.3), success].)
461
+ specify %([float(-3.3), success].)
462
+ specify %([float(3), failure].)
463
+ specify %([float(atom), failure].)
464
+ specify %([float(X), failure].)
465
+ end
466
+
467
+ describe "functor", :pending=>"Not supported in Rubylog. Use s.structure(predicate, functor, args)" do
468
+ specify %([functor(foo(a,b,c),foo,3), success].)
469
+ specify %([functor(foo(a,b,c),X,Y), [[X <-- foo, Y <-- 3]]].)
470
+ specify %([functor(X,foo,3), [[X <-- foo(A,B,C)]]]. % A, B and C are 3 new variables)
471
+ specify %([functor(X,foo,0), [[X <-- foo]]].)
472
+ specify %([functor(mats(A,B),A,B), [[A <-- mats,B <-- 2]]].)
473
+ specify %([functor(foo(a),foo,2), failure].)
474
+ specify %([functor(foo(a),fo,1), failure].)
475
+ specify %([functor(1,X,Y), [[X <-- 1,Y <-- 0]]].)
476
+ specify %([functor(X,1.1,0), [[X <-- 1.1]]].)
477
+ specify %([functor([_|_],'.',2), success].)
478
+ specify %([functor([],[],0), success].)
479
+ specify %([functor(X, Y, 3), instantiation_error].)
480
+ specify %([functor(X, foo, N), instantiation_error].)
481
+ specify %([functor(X, foo, a), type_error(integer,a)].)
482
+ specify %([functor(F, 1.5, 1), type_error(atom,1.5)].)
483
+ specify %([functor(F,foo(a),1), type_error(atomic,foo(a))].)
484
+ specify %([(current_prolog_flag(max_arity,A), X is A + 1, functor(T, foo, X)), )
485
+ specify %( representation_error(max_arity)]. )
486
+ specify %( [functor(T, foo, -1), domain_error(not_less_than_zero,-1)].)
487
+ end
488
+
489
+ describe "halt", :pending=>"Not supported in Rubylog" do
490
+ specify %([halt, impl_defined].)
491
+ specify %([halt(1), impl_defined].)
492
+ specify %([halt(a), type_error(integer, a)].)
493
+ end
494
+
495
+ describe "if-then", :pending=>"Not supported in Rubylog yet. Maybe someday." do
496
+ specify %(['->'(true, true), success].)
497
+ specify %(['->'(true, fail), failure].)
498
+ specify %(['->'(fail, true), failure].)
499
+ specify %(['->'(true, X=1), [[X <-- 1]]].)
500
+ specify %(['->'(';'(X=1, X=2), true), [[X <-- 1]]]. )
501
+ specify %(['->'(true, ';'(X=1, X=2)), [[X <-- 1], [X <-- 2]]].)
502
+ end
503
+
504
+ describe "if-then-else", :pending=>"Not supported in Rubylog yet. Maybe someday." do
505
+ specify %([';'('->'(true, true), fail), success].)
506
+ specify %([';'('->'(fail, true), true), success].)
507
+ specify %([';'('->'(true, fail), fail), failure].)
508
+ specify %([';'('->'(fail, true), fail), failure].)
509
+ specify %([';'('->'(true, X=1), X=2), [[X <-- 1]]].)
510
+ specify %([';'('->'(fail, X=1), X=2), [[X <-- 2]]].)
511
+ specify %([';'('->'(true, ';'(X=1, X=2)), true), [[X <-- 1], [X <-- 2]]].)
512
+ specify %([';'('->'(';'(X=1, X=2), true), true), [[X <-- 1]]].)
513
+ end
514
+
515
+ describe "integer", :pending=>"Not supported in Rubylog. Use #is_a?(Integer)" do
516
+ specify %([integer(3), success].)
517
+ specify %([integer(-3), success].)
518
+ specify %([integer(3.3), failure].)
519
+ specify %([integer(X), failure].)
520
+ specify %([integer(atom), failure].)
521
+ end
522
+
523
+ describe "is" do
524
+ specify %(['is'(Result,3 + 11.0),[[Result <-- 14.0]]].) do
525
+ Result.is{3+11.0}.map{Result}.should eql [14.0]
526
+ end
527
+ specify %([(X = 1 + 2, 'is'(Y, X * 3)),[[X <-- (1 + 2), Y <-- 9]]]. % error? 1+2), :pending=>"Not supported in Rubylog"
528
+ specify %(['is'(foo,77), failure]. % error? foo), :pending=>"Not supported in Rubylog"
529
+ specify %(['is'(77, N), instantiation_error].), :pending=>"Not supported in Rubylog"
530
+ specify %(['is'(77, foo), type_error(evaluable, foo/0)].), :pending=>"Not supported in Rubylog"
531
+ specify %(['is'(X,float(3)),[[X <-- 3.0]]].) do
532
+ X.is{3.to_f}.map{X}.should eql [3.0]
533
+ end
534
+ end
535
+
536
+ describe "nonvar" do
537
+ specify %([nonvar(33.3), success].) do
538
+ X.is(33.3).and{!X.is_a? Rubylog::Variable}.true?.should == true
539
+ end
540
+ specify %([nonvar(foo), success].) do
541
+ X.is(:foo).and{!X.is_a? Rubylog::Variable}.true?.should be_true
542
+ end
543
+ specify %([nonvar(Foo), failure].) do
544
+ X.is(Foo).and{!X.is_a? Rubylog::Variable}.true?.should be_false
545
+ end
546
+ specify %([(foo=Foo,nonvar(Foo)),[[Foo <-- foo]]].) do
547
+ :foo.is(Foo).and(X.is(Foo)).and{!X.is_a? Rubylog::Variable}.true?.should == true
548
+ end
549
+ specify %([nonvar(_), failure].) do
550
+ ANY.is(X).and{!X.is_a? Rubylog::Variable}.true?.should == false
551
+ end
552
+ specify %([nonvar(a(b)), success].) do
553
+ :b.false.is(X).and{!X.is_a? Rubylog::Variable}.true?.should == true
554
+ end
555
+ end
556
+
557
+ describe "not_provable" do
558
+ specify %([\+(true), failure].) do
559
+ :true.false.true?.should == false
560
+ end
561
+ specify %([\+(!), failure].) do
562
+ :cut!.false.true?.should == false
563
+ end
564
+ specify %([\+((!,fail)), success].) do
565
+ :cut!.and(:fail).false.true?.should == true
566
+ end
567
+ specify %([((X=1;X=2), \+((!,fail))), [[X <-- 1],[X <-- 2]]].) do
568
+ X.is(1).or(X.is(2)).and(:cut!.and(:fail).false).map{X}.should eql [1,2]
569
+ end
570
+ specify %([\+(4 = 5), success].) do
571
+ 4.is(5).false.true?.should == true
572
+ end
573
+ specify %([\+(3), type_error(callable, 3)].) do
574
+ expect { 3.false.true? } .to raise_error NoMethodError
575
+ end
576
+ specify %([\+(X), instantiation_error]. % Culprit X) do
577
+ expect { X.false.true? }.to raise_error Rubylog::InstantiationError
578
+ end
579
+ end
580
+
581
+ describe "not_unify" do
582
+ specify %(['\\='(1,1), failure].) do
583
+ 1.is_not(1).true?.should == false
584
+ end
585
+ specify %(['\\='(X,1), failure].) do
586
+ X.is_not(1).true?.should == false
587
+ end
588
+ specify %(['\\='(X,Y), failure].) do
589
+ X.is_not(Y).true?.should == false
590
+ end
591
+ specify %([('\\='(X,Y),'\\='(X,abc)), failure].) do
592
+ X.is_not(Y).and(X.is_not(:abc)).true?.should == false
593
+ end
594
+ specify %(['\\='(f(X,def),f(def,Y)), failure].) do
595
+ X.and(:def).is_not(:def.and(Y)).true?.should == false
596
+ end
597
+ specify %(['\\='(1,2), success].) do
598
+ 1.is_not(2).true?.should == true
599
+ end
600
+ specify %(['\\='(1,1.0), success].) do
601
+ 1.is_not(1.0).true?.should == true
602
+ end
603
+ specify %(['\\='(g(X),f(f(X))), success].) do
604
+ predicate_for Rubylog::Structure, ".g .f"
605
+ X.g.is_not(X.f.f).true?.should == true
606
+ end
607
+ specify %(['\\='(f(X,1),f(a(X))), success].), :pending=>"No overloading of procedures in Rubylog yet."
608
+ specify %(['\\='(f(X,Y,X),f(a(X),a(Y),Y,2)), success].), :pending=>"No overloading of procedures in Rubylog yet."
609
+ end
610
+
611
+ describe "number", :pending=>"Not supported in Rubylog. Use #is_a?(Numeric)" do
612
+ specify %([number(3), success].)
613
+ specify %([number(3.3), success].)
614
+ specify %([number(-3), success].)
615
+ specify %([number(a), failure].)
616
+ specify %([number(X), failure].)
617
+ end
618
+
619
+ describe "number_chars", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
620
+ specify %([number_chars(33,L), [[L <-- ['3','3']]]].)
621
+ specify %([number_chars(33,['3','3']), success].)
622
+ specify %([number_chars(33.0,L), [[L <-- ['3','3','.','0']]]].)
623
+ specify %([number_chars(X,['3','.','3','E','+','0']), [[X <-- 3.3]]].)
624
+ specify %([number_chars(3.3,['3','.','3','E','+','0']), success].)
625
+ specify %([number_chars(A,['-','2','5']), [[A <-- (-25)]]].)
626
+ specify %([number_chars(A,['\n',' ','3']), [[A <-- 3]]]. )
627
+ specify %([number_chars(A,['3',' ']), syntax_error(_)].)
628
+ specify %([number_chars(A,['0',x,f]), [[A <-- 15]]].)
629
+ specify %([number_chars(A,['0','''','A']), [[A <-- 65]]].)
630
+ specify %([number_chars(A,['4','.','2']), [[A <-- 4.2]]].)
631
+ specify %([number_chars(A,['4','2','.','0','e','-','1']), [[A <-- 4.2]]].)
632
+ specify %([number_chars(A,L), instantiation_error].)
633
+ specify %([number_chars(a,L), type_error(number, a)].)
634
+ specify %([number_chars(A,4), type_error(list, 4)].)
635
+ specify %([number_chars(A,['4',2]), type_error(character, 2)].)
636
+ end
637
+
638
+ describe "number_codes", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
639
+ specify %([number_codes(33,L), [[L <-- [0'3,0'3]]]].)
640
+ specify %([number_codes(33,[0'3,0'3]), success].)
641
+ specify %([number_codes(33.0,L), [[L <-- [51,51,46,48]]]].)
642
+ specify %([number_codes(33.0,[0'3,0'.,0'3,0'E,0'+,0'0,0'1]), success].)
643
+ specify %([number_codes(A,[0'-,0'2,0'5]), [[A <-- (-25)]]].)
644
+ specify %([number_codes(A,[0' ,0'3]), [[A <-- 3]]].)
645
+ specify %([number_codes(A,[0'0,0'x,0'f]), [[A <-- 15]]].)
646
+ specify %([number_codes(A,[0'0,39,0'a]), [[A <-- 97]]].)
647
+ specify %([number_codes(A,[0'4,0'.,0'2]), [[A <-- 4.2]]].)
648
+ specify %([number_codes(A,[0'4,0'2,0'.,0'0,0'e,0'-,0'1]), [[A <-- 4.2]]].)
649
+ specify %([number_codes(A,L), instantiation_error].)
650
+ specify %([number_codes(a,L), type_error(number,a)].)
651
+ specify %([number_codes(A,4), type_error(list,4)].)
652
+ specify %([number_codes(A,[ 0'1, 0'2, 1000]), representation_error(character_code)]. % 1000 not a code)
653
+ end
654
+
655
+ describe "once" do
656
+ specify %([once(!), success].) do
657
+ :cut!.any.true?.should == true
658
+ end
659
+ specify %([(once(!), (X=1; X=2)), [[X <-- 1],[X <-- 2]]].) do
660
+ :cut!.any.and(X.is(1).or(X.is(2))).map{X}.should == [1,2]
661
+ end
662
+ specify %([once(repeat), success].) do
663
+ class << primitives
664
+ def repeat
665
+ yield while true
666
+ end
667
+ end
668
+ :repeat.any.true?.should == true
669
+ end
670
+ specify %([once(fail), failure].) do
671
+ :fail.any.true?.should == false
672
+ end
673
+ specify %([once(3), type_error(callable, 3)].) do
674
+ expect { 3.any.true? }.to raise_error(NoMethodError)
675
+ end
676
+ specify %([once(X), instantiation_error]. % Culprit X) do
677
+ expect { X.any.true? }.to raise_error(Rubylog::InstantiationError)
678
+ end
679
+ end
12
680
 
681
+ describe "or" do
682
+ specify %([';'(true, fail), success].) do
683
+ :true.or(:fail).true?.should == true
684
+ end
685
+ specify %([';'((!, fail), true), failure].) do
686
+ :cut!.and(:fail).or(:true).true?.should == false
687
+ end
688
+ specify %([';'(!, call(3)), success].) do
689
+ :cut!.or(proc{fail}).true?.should == true
690
+ end
691
+ specify %([';'((X=1, !), X=2), [[X <-- 1]]].) do
692
+ X.is(1).and(:cut!).or(X.is(2)).map{X}.should == [1]
693
+ end
694
+ specify %([';'(X=1, X=2), [[X <-- 1], [X <-- 2]]].) do
695
+ (X.is(1).or(X.is(2))).map{X}.should == [1,2]
696
+ end
697
+ end
698
+
699
+ describe "repeat" do
700
+ before do
701
+ class << primitives
702
+ def repeat
703
+ yield while true
704
+ end
705
+ end
706
+ end
707
+ specify %([(repeat,!,fail), failure].) do
708
+ :repeat.and(:cut!).and(:fail).true?.should == false
709
+ end
710
+ end
711
+
712
+ describe "retract", :pending=>"Not supported in Rubylog" do
713
+ specify %([retract((4 :- X)), type_error(callable, 4)]. )
714
+ specify %([retract((atom(_) :- X == '[]')), )
715
+ specify %( permission_error(modify,static_procedure,atom/1)].)
716
+ end
717
+
718
+ describe "set_prolog_flag", :pending=>"Not supported in Rubylog" do
719
+ specify %([(set_prolog_flag(unknown, fail),)
720
+ specify %(current_prolog_flag(unknown, V)), [[V <-- fail]]].)
721
+ specify %([set_prolog_flag(X, warning), instantiation_error].)
722
+ specify %([set_prolog_flag(5, decimals), type_error(atom,5)].)
723
+ specify %([set_prolog_flag(date, 'July 1999'), domain_error(prolog_flag,date)].)
724
+ specify %([set_prolog_flag(debug, no), domain_error(flag_value,debug+no)].)
725
+ specify %([set_prolog_flag(max_arity, 40), permission_error(modify, flag, max_arity)].)
726
+ specify %(/* swindles to get tests of double quotes flag to work. */)
727
+ specify %([set_prolog_flag(double_quotes, atom), success].)
728
+ specify %([X = "fred", [[X <-- fred]]].)
729
+ specify %([set_prolog_flag(double_quotes, codes), success].)
730
+ specify %([X = "fred", [[X <-- [102,114,101,100]]]].)
731
+ specify %([set_prolog_flag(double_quotes, chars), success].)
732
+ specify %([X = "fred", [[X <-- [f,r,e,d]]]].)
733
+ end
734
+
735
+ describe "setof", :pending=>"Not supported in Rubylog. Use map{} instead" do
736
+ specify %([setof(X,(X=1;X=2),L), [[L <-- [1, 2]]]].)
737
+ specify %([setof(X,(X=1;X=2),X), [[X <-- [1, 2]]]].)
738
+ specify %([setof(X,(X=2;X=1),L), [[L <-- [1, 2]]]].)
739
+ specify %([setof(X,(X=2;X=2),L), [[L <-- [2]]]].)
740
+ specify %([setof(X,fail,L), failure].)
741
+ specify %([setof(1,(Y=2;Y=1),L), [[L <-- [1], Y <-- 1], [L <-- [1], Y <-- 2]]].)
742
+ specify %([setof(f(X,Y),(X=a;Y=b),L), [[L <-- [f(_, b), f(a, _)]]]].)
743
+ specify %([setof(X,Y^((X=1,Y=1);(X=2,Y=2)),S), [[S <-- [1, 2]]]].)
744
+ specify %([setof(X,Y^((X=1;Y=1);(X=2,Y=2)),S), [[S <-- [_, 1, 2]]]].)
745
+ specify %([(set_prolog_flag(unknown, warning), )
746
+ specify %( setof(X,(Y^(X=1;Y=1);X=3),S)), [[S <-- [3]]]].)
747
+ specify %( [(set_prolog_flag(unknown, warning), )
748
+ specify %( setof(X,Y^(X=1;Y=1;X=3),S)), [[S <-- [_, 1,3]]]].)
749
+ specify %( [setof(X,(X=Y;X=Z;Y=1),L), [[L <-- [Y, Z]], [L <-- [_], Y <-- 1]]].)
750
+ specify %( [setof(X, X^(true; 4),L), type_error(callable,(true;4))].)
751
+ specify %( [setof(X,1,L), type_error(callable,1)].)
752
+ end
753
+
754
+ describe "sub_atom" do
755
+ specify %([sub_atom(abracadabra, 0, 5, _, S2), [[S2 <-- 'abrac']]].) do
756
+ 'abracadabra'.is("#{S2[:length=>5]}#{ANY}").map{S2}.should eql ['abrac']
757
+ end
758
+ specify %([sub_atom(abracadabra, _, 5, 0, S2), [[S2 <-- 'dabra']]].) do
759
+ 'abracadabra'.is("#{ANY}#{S2[:length=>5]}").map{S2}.should eql ['dabra']
760
+ end
761
+ specify %([sub_atom(abracadabra, 3, Length, 3, S2), [[Length <-- 5, S2 <-- 'acada']]].), :pending=>"There is no such feature in Rubylog yet. Maybe someday."
762
+ specify %([sub_atom(abracadabra, Before, 2, After, ab),
763
+ [[Before <-- 0, After <-- 9],
764
+ [Before <-- 7, After <-- 2]]].) do
765
+ 'abracadabra'.is("#{X}ab#{Y}").map{[X.length,Y.length]}.should eql [[0,9],[7,2]]
766
+ end
767
+ specify %( [sub_atom('Banana', 3, 2, _, S2), [[S2 <-- 'an']]].) do
768
+ 'Banana'.is("#{ANY[:length=>3]}#{X[:length=>2]}#{ANY}").map{X}.should eql ["an"]
769
+ end
770
+ specify %( [sub_atom('charity', _, 3, _, S2), [[S2 <-- 'cha'],
771
+ [S2 <-- 'har'],
772
+ [S2 <-- 'ari'],
773
+ [S2 <-- 'rit'],
774
+ [S2 <-- 'ity']]].) do
775
+ "charity".is("#{ANY}#{X[:length=>3]}#{ANY}").map{X}.should ==
776
+ %w(cha har ari rit ity)
777
+ end
778
+ specify %( [sub_atom('ab', Before, Length, After, Sub_atom),
779
+ [[Before <-- 1, Length <-- 0, Sub_atom <-- ''],
780
+ [Before <-- 1, Length <-- 1, Sub_atom <-- 'a'],
781
+ [Before <-- 1, Length <-- 2, Sub_atom <-- 'ab'],
782
+ [Before <-- 2, Length <-- 0, Sub_atom <-- ''],
783
+ [Before <-- 2, Length <-- 1, Sub_atom <-- 'b'],
784
+ [Before <-- 3, Length <-- 0, Sub_atom <-- '']]].), :comment=>"This is a bug in inriasuite, the Before values are 1 less in reality, at least in GNU Prolog." do
785
+ "ab".is("#{B}#{X}#{ANY}").map{[B.length,X.length,X]}.should ==
786
+ [[0,0,''],
787
+ [0,1,'a'],
788
+ [0,2,'ab'],
789
+ [1,0,''],
790
+ [1,1,'b'],
791
+ [2,0,'']]
792
+ end
793
+ specify %( [sub_atom(Banana, 3, 2, _, S2), instantiation_error].), :pending=>"Not supported in Rubylog"
794
+ specify %( [sub_atom(f(a), 2, 2, _, S2), type_error(atom,f(a))].), :pending=>"Not an error in Rubylog"
795
+ specify %( [sub_atom('Banana', 4, 2, _, 2), type_error(atom,2)].), :pending=>"Not supported in Rubylog"
796
+ specify %( [sub_atom('Banana', a, 2, _, S2), type_error(integer,a)].), :pending=>"Not supported in Rubylog"
797
+ specify %( [sub_atom('Banana', 4, n, _, S2), type_error(integer,n)].), :pending=>"Not supported in Rubylog"
798
+ specify %( [sub_atom('Banana', 4, _, m, S2), type_error(integer,m)].), :pending=>"Not supported in Rubylog"
799
+ end
800
+
801
+ describe "term_diff", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
802
+ specify %(['\\=='(1,1), failure].)
803
+ specify %(['\\=='(X,X), failure].)
804
+ specify %(['\\=='(1,2), success].)
805
+ specify %(['\\=='(X,1), success].)
806
+ specify %(['\\=='(X,Y), success].)
807
+ specify %(['\\=='(_,_), success].)
808
+ specify %(['\\=='(X,a(X)), success].)
809
+ specify %(['\\=='(f(a),f(a)), failure].)
810
+ end
811
+
812
+ describe "term_eq", :pending=>"There is no such feature in Rubylog yet. Maybe someday." do
813
+ specify %(['=='(1,1), success].)
814
+ specify %(['=='(X,X), success].)
815
+ specify %(['=='(1,2), failure].)
816
+ specify %(['=='(X,1), failure].)
817
+ specify %(['=='(X,Y), failure].)
818
+ specify %(['=='(_,_), failure].)
819
+ specify %(['=='(X,a(X)), failure].)
820
+ specify %(['=='(f(a),f(a)), success].)
821
+ end
822
+
823
+ describe "term_gt", :pending=>"Not supported in Rubylog" do
824
+ specify %(['@>'(1.0,1), failure].)
825
+ specify %(['@>'(aardvark,zebra), failure].)
826
+ specify %(['@>'(short,short), failure].)
827
+ specify %(['@>'(short,shorter), failure].)
828
+ specify %(['@>'(foo(b),foo(a)), success].)
829
+ specify %(['@>'(X,X), failure].)
830
+ specify %(['@>'(foo(a,X),foo(b,Y)), failure].)
831
+ end
832
+
833
+ describe "term_gt=", :pending=>"Not supported in Rubylog" do
834
+ specify %(['@>='(1.0,1), failure].)
835
+ specify %(['@>='(aardvark,zebra), failure].)
836
+ specify %(['@>='(short,short), success].)
837
+ specify %(['@>='(short,shorter), failure].)
838
+ specify %(['@>='(foo(b),foo(a)), success].)
839
+ specify %(['@>='(X,X), success].)
840
+ specify %(['@>='(foo(a,X),foo(b,Y)), failure].)
841
+ end
842
+
843
+ describe "term_lt", :pending=>"Not supported in Rubylog" do
844
+ specify %(['@<'(1.0,1), success].)
845
+ specify %(['@<'(aardvark,zebra), success].)
846
+ specify %(['@<'(short,short), failure].)
847
+ specify %(['@<'(short,shorter), success].)
848
+ specify %(['@<'(foo(b),foo(a)), failure].)
849
+ specify %(['@<'(X,X), failure].)
850
+ specify %(['@<'(foo(a,X),foo(b,Y)), success].)
851
+ end
852
+
853
+ describe "term_lt=", :pending=>"Not supported in Rubylog" do
854
+ specify %(['@=<'(1.0,1), success].)
855
+ specify %(['@=<'(aardvark,zebra), success].)
856
+ specify %(['@=<'(short,short), success].)
857
+ specify %(['@=<'(short,shorter), success].)
858
+ specify %(['@=<'(foo(b),foo(a)), failure].)
859
+ specify %(['@=<'(X,X), success].)
860
+ specify %(['@=<'(foo(a,X),foo(b,Y)), success].)
861
+ end
862
+
863
+ describe "true" do
864
+ specify %([true, success].) do
865
+ :true.true?.should == true
866
+ end
867
+ end
868
+
869
+ describe "unify" do
870
+ specify %(['='(X,1),[[X <-- 1]]].) do
871
+ X.is(1).map{X}.should eql [1]
872
+ end
873
+ specify %(['='(X,Y),[[Y <-- X]]].) do
874
+ X.is(Y).map{Y}.should eql [X]
875
+ end
876
+ specify %([('='(X,Y),'='(X,abc)),[[X <-- abc, Y <-- abc]]].) do
877
+ X.is(Y).and(X.is(:abc)).map{[X,Y]}.should eql [[:abc,:abc]]
878
+ end
879
+ specify %(['='(f(X,def),f(def,Y)), [[X <-- def, Y <-- def]]].) do
880
+ predicate_for Symbol, ".f()"
881
+ X.f(:def).is(:def.f(Y)).map{[X,Y]}.should eql [[:def,:def]]
882
+ end
883
+ specify %(['='(1,2), failure].) do
884
+ 1.is?(2).should eql false
885
+ end
886
+ specify %(['='(1,1.0), failure].) do
887
+ 1.is?(1.0).should eql false
888
+ end
889
+ specify %(['='(g(X),f(f(X))), failure].) do
890
+ predicate ".g .f"
891
+ X.g.is(X.f.f).true?.should eql false
892
+ end
893
+ specify %(['='(f(X,1),f(a(X))), failure].), :pending=>"No overloading in Rubylog yet"
894
+ specify %(['='(f(X,Y,X),f(a(X),a(Y),Y,2)), failure].), :pending=>"No overloading in Rubylog yet"
895
+ specify %(['='(f(A,B,C),f(g(B,B),g(C,C),g(D,D))),
896
+ [[A <-- g(g(g(D,D),g(D,D)),g(g(D,D),g(D,D))),
897
+ B <-- g(g(D,D),g(D,D)),
898
+ C <-- g(D,D)]]].) do
899
+ predicate ".g() .f(,)"
900
+ A.f(B,C).is(B.g(B).f(C.g(C),D.g(D))).map{[A,B,C]}.should eql [[
901
+ D.g(D).g(D.g(D)).g(D.g(D).g(D.g(D))),
902
+ D.g(D).g(D.g(D)),
903
+ D.g(D)
904
+ ]]
905
+ end
906
+
907
+ end
908
+
909
+ end
13
910