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