rubylog 0.0.0
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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +96 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/4queens.rb +10 -0
- data/examples/calculation.rb +12 -0
- data/examples/concepts.rb +46 -0
- data/examples/factorial.rb +16 -0
- data/examples/fp.rb +56 -0
- data/examples/hello.rb +9 -0
- data/examples/historia_de_espana.rb +31 -0
- data/examples/idea.rb +143 -0
- data/examples/lists.rb +5 -0
- data/examples/mechanika.rb +409 -0
- data/examples/parse.rb +15 -0
- data/examples/theory.rb +20 -0
- data/lib/array.rb +24 -0
- data/lib/class.rb +11 -0
- data/lib/method.rb +4 -0
- data/lib/object.rb +5 -0
- data/lib/proc.rb +4 -0
- data/lib/rubylog/builtins.rb +193 -0
- data/lib/rubylog/callable.rb +20 -0
- data/lib/rubylog/clause.rb +113 -0
- data/lib/rubylog/composite_term.rb +38 -0
- data/lib/rubylog/dsl/constants.rb +15 -0
- data/lib/rubylog/dsl/first_order_functors.rb +9 -0
- data/lib/rubylog/dsl/global_functors.rb +3 -0
- data/lib/rubylog/dsl/second_order_functors.rb +8 -0
- data/lib/rubylog/dsl.rb +52 -0
- data/lib/rubylog/errors.rb +18 -0
- data/lib/rubylog/internal_helpers.rb +16 -0
- data/lib/rubylog/predicate.rb +34 -0
- data/lib/rubylog/proc_method_additions.rb +69 -0
- data/lib/rubylog/term.rb +20 -0
- data/lib/rubylog/theory.rb +133 -0
- data/lib/rubylog/unifiable.rb +19 -0
- data/lib/rubylog/variable.rb +97 -0
- data/lib/rubylog.rb +39 -0
- data/lib/symbol.rb +35 -0
- data/rubylog.gemspec +187 -0
- data/script/inriasuite2spec +0 -0
- data/script/inriasuite2spec.pl +22 -0
- data/spec/bartak_guide_spec.rb +91 -0
- data/spec/inriasuite/README +122 -0
- data/spec/inriasuite/abolish +18 -0
- data/spec/inriasuite/and +9 -0
- data/spec/inriasuite/arg +32 -0
- data/spec/inriasuite/arith_diff +10 -0
- data/spec/inriasuite/arith_eq +10 -0
- data/spec/inriasuite/arith_gt +10 -0
- data/spec/inriasuite/arith_gt= +10 -0
- data/spec/inriasuite/arith_lt +10 -0
- data/spec/inriasuite/arith_lt= +10 -0
- data/spec/inriasuite/asserta +18 -0
- data/spec/inriasuite/assertz +16 -0
- data/spec/inriasuite/atom +12 -0
- data/spec/inriasuite/atom_chars +19 -0
- data/spec/inriasuite/atom_codes +15 -0
- data/spec/inriasuite/atom_concat +19 -0
- data/spec/inriasuite/atom_length +12 -0
- data/spec/inriasuite/atomic +11 -0
- data/spec/inriasuite/bagof +31 -0
- data/spec/inriasuite/call +19 -0
- data/spec/inriasuite/catch-and-throw +16 -0
- data/spec/inriasuite/char_code +13 -0
- data/spec/inriasuite/clause +16 -0
- data/spec/inriasuite/compound +12 -0
- data/spec/inriasuite/copy_term +25 -0
- data/spec/inriasuite/current_input +5 -0
- data/spec/inriasuite/current_output +5 -0
- data/spec/inriasuite/current_predicate +16 -0
- data/spec/inriasuite/current_prolog_flag +12 -0
- data/spec/inriasuite/cut +9 -0
- data/spec/inriasuite/fail +15 -0
- data/spec/inriasuite/file_manip +8 -0
- data/spec/inriasuite/findall +22 -0
- data/spec/inriasuite/float +10 -0
- data/spec/inriasuite/functor +41 -0
- data/spec/inriasuite/functor-bis +41 -0
- data/spec/inriasuite/halt +7 -0
- data/spec/inriasuite/if-then +10 -0
- data/spec/inriasuite/if-then-else +12 -0
- data/spec/inriasuite/inriasuite.obp +0 -0
- data/spec/inriasuite/inriasuite.pl +836 -0
- data/spec/inriasuite/integer +10 -0
- data/spec/inriasuite/is +11 -0
- data/spec/inriasuite/junk +0 -0
- data/spec/inriasuite/nonvar +11 -0
- data/spec/inriasuite/not_provable +12 -0
- data/spec/inriasuite/not_unify +15 -0
- data/spec/inriasuite/number +10 -0
- data/spec/inriasuite/number_chars +22 -0
- data/spec/inriasuite/number_codes +19 -0
- data/spec/inriasuite/once +11 -0
- data/spec/inriasuite/or +9 -0
- data/spec/inriasuite/repeat +5 -0
- data/spec/inriasuite/retract +10 -0
- data/spec/inriasuite/set_prolog_flag +21 -0
- data/spec/inriasuite/setof +36 -0
- data/spec/inriasuite/sub_atom +30 -0
- data/spec/inriasuite/t +1 -0
- data/spec/inriasuite/t_foo.pl +4 -0
- data/spec/inriasuite/term_diff +13 -0
- data/spec/inriasuite/term_eq +12 -0
- data/spec/inriasuite/term_gt +12 -0
- data/spec/inriasuite/term_gt= +12 -0
- data/spec/inriasuite/term_lt +12 -0
- data/spec/inriasuite/term_lt= +12 -0
- data/spec/inriasuite/true +7 -0
- data/spec/inriasuite/unify +18 -0
- data/spec/inriasuite.rb +20 -0
- data/spec/recursion_spec.rb +18 -0
- data/spec/rubylog/builtins/splits_to.rb +18 -0
- data/spec/rubylog/clause_spec.rb +81 -0
- data/spec/rubylog/variable_spec.rb +25 -0
- data/spec/rubylog_spec.rb +914 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/theory_spec.rb +1 -0
- metadata +339 -0
data/lib/symbol.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class Symbol
|
|
2
|
+
|
|
3
|
+
# a proxy for Clause
|
|
4
|
+
def functor
|
|
5
|
+
self
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def arity
|
|
9
|
+
0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def desc
|
|
13
|
+
[self, 0]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def args
|
|
17
|
+
[]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Unifiable methods
|
|
21
|
+
include Rubylog::Unifiable
|
|
22
|
+
|
|
23
|
+
# Callable methods
|
|
24
|
+
include Rubylog::Callable
|
|
25
|
+
|
|
26
|
+
def prove
|
|
27
|
+
predicate = Rubylog.theory[self][0]
|
|
28
|
+
raise Rubylog::ExistenceError, desc.inspect if not predicate
|
|
29
|
+
predicate.call(*args) { yield }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Second-order functors (:is_false, :and, :or, :then)
|
|
33
|
+
include Rubylog::DSL::SecondOrderFunctors
|
|
34
|
+
|
|
35
|
+
end
|
data/rubylog.gemspec
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{rubylog}
|
|
8
|
+
s.version = "0.0.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Bern\303\241t Kall\303\263"]
|
|
12
|
+
s.date = %q{2012-02-07}
|
|
13
|
+
s.description = %q{Rubylog is an embedded Prolog language and interpreter for Ruby.}
|
|
14
|
+
s.email = %q{kallo.bernat@gmail.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE.txt",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
".document",
|
|
21
|
+
".rspec",
|
|
22
|
+
"Gemfile",
|
|
23
|
+
"Gemfile.lock",
|
|
24
|
+
"LICENSE.txt",
|
|
25
|
+
"README.rdoc",
|
|
26
|
+
"Rakefile",
|
|
27
|
+
"VERSION",
|
|
28
|
+
"examples/4queens.rb",
|
|
29
|
+
"examples/calculation.rb",
|
|
30
|
+
"examples/concepts.rb",
|
|
31
|
+
"examples/factorial.rb",
|
|
32
|
+
"examples/fp.rb",
|
|
33
|
+
"examples/hello.rb",
|
|
34
|
+
"examples/historia_de_espana.rb",
|
|
35
|
+
"examples/idea.rb",
|
|
36
|
+
"examples/lists.rb",
|
|
37
|
+
"examples/mechanika.rb",
|
|
38
|
+
"examples/parse.rb",
|
|
39
|
+
"examples/theory.rb",
|
|
40
|
+
"lib/array.rb",
|
|
41
|
+
"lib/class.rb",
|
|
42
|
+
"lib/method.rb",
|
|
43
|
+
"lib/object.rb",
|
|
44
|
+
"lib/proc.rb",
|
|
45
|
+
"lib/rubylog.rb",
|
|
46
|
+
"lib/rubylog/builtins.rb",
|
|
47
|
+
"lib/rubylog/callable.rb",
|
|
48
|
+
"lib/rubylog/clause.rb",
|
|
49
|
+
"lib/rubylog/composite_term.rb",
|
|
50
|
+
"lib/rubylog/dsl.rb",
|
|
51
|
+
"lib/rubylog/dsl/constants.rb",
|
|
52
|
+
"lib/rubylog/dsl/first_order_functors.rb",
|
|
53
|
+
"lib/rubylog/dsl/global_functors.rb",
|
|
54
|
+
"lib/rubylog/dsl/second_order_functors.rb",
|
|
55
|
+
"lib/rubylog/errors.rb",
|
|
56
|
+
"lib/rubylog/internal_helpers.rb",
|
|
57
|
+
"lib/rubylog/predicate.rb",
|
|
58
|
+
"lib/rubylog/proc_method_additions.rb",
|
|
59
|
+
"lib/rubylog/term.rb",
|
|
60
|
+
"lib/rubylog/theory.rb",
|
|
61
|
+
"lib/rubylog/unifiable.rb",
|
|
62
|
+
"lib/rubylog/variable.rb",
|
|
63
|
+
"lib/symbol.rb",
|
|
64
|
+
"rubylog.gemspec",
|
|
65
|
+
"script/inriasuite2spec",
|
|
66
|
+
"script/inriasuite2spec.pl",
|
|
67
|
+
"spec/bartak_guide_spec.rb",
|
|
68
|
+
"spec/inriasuite.rb",
|
|
69
|
+
"spec/inriasuite/README",
|
|
70
|
+
"spec/inriasuite/abolish",
|
|
71
|
+
"spec/inriasuite/and",
|
|
72
|
+
"spec/inriasuite/arg",
|
|
73
|
+
"spec/inriasuite/arith_diff",
|
|
74
|
+
"spec/inriasuite/arith_eq",
|
|
75
|
+
"spec/inriasuite/arith_gt",
|
|
76
|
+
"spec/inriasuite/arith_gt=",
|
|
77
|
+
"spec/inriasuite/arith_lt",
|
|
78
|
+
"spec/inriasuite/arith_lt=",
|
|
79
|
+
"spec/inriasuite/asserta",
|
|
80
|
+
"spec/inriasuite/assertz",
|
|
81
|
+
"spec/inriasuite/atom",
|
|
82
|
+
"spec/inriasuite/atom_chars",
|
|
83
|
+
"spec/inriasuite/atom_codes",
|
|
84
|
+
"spec/inriasuite/atom_concat",
|
|
85
|
+
"spec/inriasuite/atom_length",
|
|
86
|
+
"spec/inriasuite/atomic",
|
|
87
|
+
"spec/inriasuite/bagof",
|
|
88
|
+
"spec/inriasuite/call",
|
|
89
|
+
"spec/inriasuite/catch-and-throw",
|
|
90
|
+
"spec/inriasuite/char_code",
|
|
91
|
+
"spec/inriasuite/clause",
|
|
92
|
+
"spec/inriasuite/compound",
|
|
93
|
+
"spec/inriasuite/copy_term",
|
|
94
|
+
"spec/inriasuite/current_input",
|
|
95
|
+
"spec/inriasuite/current_output",
|
|
96
|
+
"spec/inriasuite/current_predicate",
|
|
97
|
+
"spec/inriasuite/current_prolog_flag",
|
|
98
|
+
"spec/inriasuite/cut",
|
|
99
|
+
"spec/inriasuite/fail",
|
|
100
|
+
"spec/inriasuite/file_manip",
|
|
101
|
+
"spec/inriasuite/findall",
|
|
102
|
+
"spec/inriasuite/float",
|
|
103
|
+
"spec/inriasuite/functor",
|
|
104
|
+
"spec/inriasuite/functor-bis",
|
|
105
|
+
"spec/inriasuite/halt",
|
|
106
|
+
"spec/inriasuite/if-then",
|
|
107
|
+
"spec/inriasuite/if-then-else",
|
|
108
|
+
"spec/inriasuite/inriasuite.obp",
|
|
109
|
+
"spec/inriasuite/inriasuite.pl",
|
|
110
|
+
"spec/inriasuite/integer",
|
|
111
|
+
"spec/inriasuite/is",
|
|
112
|
+
"spec/inriasuite/junk",
|
|
113
|
+
"spec/inriasuite/nonvar",
|
|
114
|
+
"spec/inriasuite/not_provable",
|
|
115
|
+
"spec/inriasuite/not_unify",
|
|
116
|
+
"spec/inriasuite/number",
|
|
117
|
+
"spec/inriasuite/number_chars",
|
|
118
|
+
"spec/inriasuite/number_codes",
|
|
119
|
+
"spec/inriasuite/once",
|
|
120
|
+
"spec/inriasuite/or",
|
|
121
|
+
"spec/inriasuite/repeat",
|
|
122
|
+
"spec/inriasuite/retract",
|
|
123
|
+
"spec/inriasuite/set_prolog_flag",
|
|
124
|
+
"spec/inriasuite/setof",
|
|
125
|
+
"spec/inriasuite/sub_atom",
|
|
126
|
+
"spec/inriasuite/t",
|
|
127
|
+
"spec/inriasuite/t_foo.pl",
|
|
128
|
+
"spec/inriasuite/term_diff",
|
|
129
|
+
"spec/inriasuite/term_eq",
|
|
130
|
+
"spec/inriasuite/term_gt",
|
|
131
|
+
"spec/inriasuite/term_gt=",
|
|
132
|
+
"spec/inriasuite/term_lt",
|
|
133
|
+
"spec/inriasuite/term_lt=",
|
|
134
|
+
"spec/inriasuite/true",
|
|
135
|
+
"spec/inriasuite/unify",
|
|
136
|
+
"spec/recursion_spec.rb",
|
|
137
|
+
"spec/rubylog/builtins/splits_to.rb",
|
|
138
|
+
"spec/rubylog/clause_spec.rb",
|
|
139
|
+
"spec/rubylog/variable_spec.rb",
|
|
140
|
+
"spec/rubylog_spec.rb",
|
|
141
|
+
"spec/spec_helper.rb",
|
|
142
|
+
"spec/theory_spec.rb"
|
|
143
|
+
]
|
|
144
|
+
s.homepage = %q{https://github.com/cie/rubylog}
|
|
145
|
+
s.licenses = ["MIT"]
|
|
146
|
+
s.require_paths = ["lib"]
|
|
147
|
+
s.rubygems_version = %q{1.3.7}
|
|
148
|
+
s.summary = %q{An embedded Prolog interpreter}
|
|
149
|
+
|
|
150
|
+
if s.respond_to? :specification_version then
|
|
151
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
152
|
+
s.specification_version = 3
|
|
153
|
+
|
|
154
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
155
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
156
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
|
157
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
158
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
|
159
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
160
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
161
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
162
|
+
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
|
163
|
+
s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
|
|
164
|
+
else
|
|
165
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
166
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
167
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
168
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
169
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
170
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
171
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
172
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
|
173
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
|
174
|
+
end
|
|
175
|
+
else
|
|
176
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
177
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
178
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
179
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
|
180
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
|
181
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
182
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
183
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
|
184
|
+
s.add_dependency(%q<roodi>, ["~> 2.1.0"])
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
%:-
|
|
2
|
+
%
|
|
3
|
+
:- op( 20, xfx, <-- ).
|
|
4
|
+
|
|
5
|
+
main :-
|
|
6
|
+
open_file,
|
|
7
|
+
repeat,
|
|
8
|
+
(read([Goal, Result]); halt),
|
|
9
|
+
print_assertion(Goal, Result),
|
|
10
|
+
fail; true.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
open_file :-
|
|
14
|
+
argument_list([Filename]),
|
|
15
|
+
open(Filename, read, S),
|
|
16
|
+
set_input(S).
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
print_assertion(Goal, Result) :-
|
|
20
|
+
write(Goal), write(Result), nl.
|
|
21
|
+
|
|
22
|
+
:- initialization(main).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# These are the rubylog transcripts of prolog codes from Roman Barták's Prolog
|
|
3
|
+
# guide: http://kti.mff.cuni.cz/~bartak/prolog/
|
|
4
|
+
|
|
5
|
+
require 'rubylog'
|
|
6
|
+
|
|
7
|
+
class << Rubylog.theory
|
|
8
|
+
describe Rubylog do
|
|
9
|
+
before do
|
|
10
|
+
Rubylog.theory.clear
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
specify "Genealogy database" do
|
|
14
|
+
Symbol.rubylog_functor :man, :woman
|
|
15
|
+
|
|
16
|
+
:adam.man!
|
|
17
|
+
:peter.man!
|
|
18
|
+
:paul.man!
|
|
19
|
+
|
|
20
|
+
:marry.woman!
|
|
21
|
+
:eve.woman!
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
specify "Lists" do
|
|
27
|
+
Object.rubylog_functor :head_of
|
|
28
|
+
Array.rubylog_functor :tail_of
|
|
29
|
+
|
|
30
|
+
H.head_of(A).if A.splits_to(H,ANY)
|
|
31
|
+
T.tail_of(A).if A.splits_to(ANY,T)
|
|
32
|
+
|
|
33
|
+
2.should be_head_of [2,3,4]
|
|
34
|
+
2.should be_head_of [2]
|
|
35
|
+
2.should_not be_head_of [1]
|
|
36
|
+
2.should_not be_head_of []
|
|
37
|
+
|
|
38
|
+
[3,4].should be_tail_of [2,3,4]
|
|
39
|
+
[]. should be_tail_of [1]
|
|
40
|
+
|
|
41
|
+
Object.rubylog_functor :member_of
|
|
42
|
+
|
|
43
|
+
M.member_of(A).if A.splits_to(M,ANY)
|
|
44
|
+
M.member_of(A).if A.splits_to(ANY,T).and M.member_of(T)
|
|
45
|
+
|
|
46
|
+
0.should_not be_member_of [1,2,3]
|
|
47
|
+
1.should be_member_of [1,2,3]
|
|
48
|
+
2.should be_member_of [1,2,3]
|
|
49
|
+
3.should be_member_of [1,2,3]
|
|
50
|
+
4.should_not be_member_of [1,2,3]
|
|
51
|
+
|
|
52
|
+
Object.rubylog_functor :first_of, :last_of
|
|
53
|
+
|
|
54
|
+
F.first_of(A).if A.splits_to(F,ANY)
|
|
55
|
+
L.last_of(A).if A.splits_to(L,[])
|
|
56
|
+
L.last_of(A).if A.splits_to(H,T).and L.last_of(T)
|
|
57
|
+
|
|
58
|
+
1.should be_first_of [1,2,3]
|
|
59
|
+
3.should_not be_last_of []
|
|
60
|
+
3.should be_last_of [3]
|
|
61
|
+
3.should be_last_of [2,3]
|
|
62
|
+
3.should be_last_of [1,2,3]
|
|
63
|
+
1.should_not be_last_of [1,2,3]
|
|
64
|
+
|
|
65
|
+
Array.rubylog_functor :prefix_of
|
|
66
|
+
|
|
67
|
+
[].prefix_of! ANY_LIST
|
|
68
|
+
A.prefix_of(B).if A.splits_to(H,TA).and B.splits_to(H,TB).and TA.prefix_of(TB)
|
|
69
|
+
|
|
70
|
+
[1,2,3].should be_prefix_of [1,2,3]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
describe "How does it work?" do
|
|
75
|
+
|
|
76
|
+
specify "declarative character" do
|
|
77
|
+
(1.in? [1,2,3]).should be_true
|
|
78
|
+
(X.in [1,2,3]).to_a.should == [1,2,3]
|
|
79
|
+
(1.in [X,Y]).to_a.should == [[1,nil], [nil,1]]
|
|
80
|
+
lists = []
|
|
81
|
+
(1.in L).each do |l|
|
|
82
|
+
lists << l
|
|
83
|
+
break if lists.size == 3
|
|
84
|
+
end
|
|
85
|
+
#lists.should == [[1], [nil,1], [nil,nil,1]]
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
This is the README file for version 0.9 of
|
|
2
|
+
the test suite of conformance to the ISO
|
|
3
|
+
Prolog standard based on the Formal specification
|
|
4
|
+
of Pierre Deransart, Ali Ed-Dbali and Lurent Cervoni.
|
|
5
|
+
|
|
6
|
+
The driver for the tests was written by Jonathan Hodgson.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
The suite cotains the following files.
|
|
10
|
+
|
|
11
|
+
README This file
|
|
12
|
+
inriasuite.pl The driver.
|
|
13
|
+
|
|
14
|
+
and a collection of files containing the tests.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
abolish Tests for abolish/1
|
|
18
|
+
and Tests of ','/2
|
|
19
|
+
arg Tests of arg/3
|
|
20
|
+
arith_diff Tests of '=\='/2
|
|
21
|
+
arith_eq Tests of '=:='/2
|
|
22
|
+
arith_gt Tests of '>'/2
|
|
23
|
+
arith_gt= Tests of '>='/2
|
|
24
|
+
arith_lt Tests of '<'/2
|
|
25
|
+
arith_lt= Tests of '=<'/2
|
|
26
|
+
asserta Tests of asserta/1
|
|
27
|
+
assertz Tests of assertz/1
|
|
28
|
+
atom Tests of atom/1
|
|
29
|
+
atom_chars Tests of atom_chars/2
|
|
30
|
+
atom_codes Tests of atom_codes/2
|
|
31
|
+
atom_concat Tests of atom_concat/3
|
|
32
|
+
atom_length Tests of atom_length/2
|
|
33
|
+
atomic Tests of atomic/1
|
|
34
|
+
bagof Tests of bagof/3
|
|
35
|
+
call Tests of call/1
|
|
36
|
+
catch-and-throw Tests of catch/3 and throw/1
|
|
37
|
+
char_code Tests of char_code/2
|
|
38
|
+
clause Tests of clause/2
|
|
39
|
+
compound Tests of compound/1
|
|
40
|
+
copy_term Tests of copy_term/2
|
|
41
|
+
current_input Tests of current_input/1
|
|
42
|
+
current_output Tests of current_output/2
|
|
43
|
+
current_predicate Tests of current_predicate/1
|
|
44
|
+
current_prolog_flag Tests of current_prolog_flag/2
|
|
45
|
+
cut Tests of '!'/0
|
|
46
|
+
fail Tests of fail/0
|
|
47
|
+
file_manip File handling tests (not yet implmented.)
|
|
48
|
+
findall Tests of findall/3
|
|
49
|
+
float Tests of float/1
|
|
50
|
+
functor Tests of functor/3
|
|
51
|
+
halt Tests of halt, provided for documentation only.
|
|
52
|
+
attempts to run these terminate the suite!
|
|
53
|
+
if-then Tests of '->'/2
|
|
54
|
+
if-then-else Tests of '-> ; '/3
|
|
55
|
+
integer Tests of integer/1
|
|
56
|
+
is Tests of is/2
|
|
57
|
+
nonvar Tests of nonvar/1
|
|
58
|
+
not_provable Tests of '\+'/1
|
|
59
|
+
not_unify Tests of '\='/2
|
|
60
|
+
number Tests of number/1
|
|
61
|
+
number_chars Tests of number_chars/2
|
|
62
|
+
number_codes Tests of number_codes/2
|
|
63
|
+
once Tests of once/1
|
|
64
|
+
or Tests of ';'/2
|
|
65
|
+
repeat Tests of repeat/0
|
|
66
|
+
retract Tests of retract/1
|
|
67
|
+
set_prolog_flag Tests of set_prolog_flag/2
|
|
68
|
+
setof Tests of setof/3
|
|
69
|
+
sub_atom Tests of sub_atom/5
|
|
70
|
+
term_diff Tests of '\=='/2
|
|
71
|
+
term_eq Tests of '=='/2
|
|
72
|
+
term_gt Tests of '@>'/2
|
|
73
|
+
term_gt= Tests of '@>='/2
|
|
74
|
+
term_lt Tests of '@<'/2
|
|
75
|
+
term_lt= Tests of '@=<'/2
|
|
76
|
+
true Tests of true/0
|
|
77
|
+
unify Tests of '='/2
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
The driver can be invoked after loading the file "inriasuite.pl"
|
|
81
|
+
by setting the goal run_all_tests. Alternatively one can use one of
|
|
82
|
+
the commented out initialization directives provided at the end
|
|
83
|
+
of the file to run the suite on load.
|
|
84
|
+
|
|
85
|
+
LIMITATIONS.
|
|
86
|
+
|
|
87
|
+
At present this suite does not test IO. Nor does it allow for
|
|
88
|
+
tests in which a user defined program is specified. Future versions
|
|
89
|
+
of the suite will remedy this.
|
|
90
|
+
|
|
91
|
+
REQUIREMENTS.
|
|
92
|
+
|
|
93
|
+
The driver is written in vanilla ISO prolog. It uses the following (standard)
|
|
94
|
+
builtins.
|
|
95
|
+
|
|
96
|
+
!/0
|
|
97
|
+
(=)/2
|
|
98
|
+
(=..)/2
|
|
99
|
+
(==)/2
|
|
100
|
+
(=\=)/2
|
|
101
|
+
(>=)/2
|
|
102
|
+
(\+)/1
|
|
103
|
+
(\==)/2
|
|
104
|
+
asserta/1
|
|
105
|
+
atomic/1
|
|
106
|
+
call/1
|
|
107
|
+
catch/3
|
|
108
|
+
close/1
|
|
109
|
+
copy_term/2
|
|
110
|
+
findall/3
|
|
111
|
+
(is)/2
|
|
112
|
+
nl/0
|
|
113
|
+
open/3
|
|
114
|
+
read/1
|
|
115
|
+
retract/1
|
|
116
|
+
set_prolog_flag/2
|
|
117
|
+
true/0
|
|
118
|
+
var/1
|
|
119
|
+
write/1
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
DATE 3 March 1999
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* file abolish */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[abolish(abolish/1), permission_error(modify,static_procedure,abolish/1)].
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
[abolish(foo/a), type_error(integer,a)].
|
|
8
|
+
|
|
9
|
+
[abolish(foo/(-1)), domain_error(not_less_than_zero,-1)].
|
|
10
|
+
|
|
11
|
+
[(current_prolog_flag(max_arity,A), X is A + 1, abolish(foo/X)),
|
|
12
|
+
representation_error(max_arity)].
|
|
13
|
+
|
|
14
|
+
[abolish(5/2), type_error(atom,5)].
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/* end of abolish */
|
|
18
|
+
|
data/spec/inriasuite/and
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* file ',' (conjunction) */
|
|
2
|
+
|
|
3
|
+
[','(X=1, var(X)), failure].
|
|
4
|
+
[','(var(X), X=1), [[X <-- 1]]].
|
|
5
|
+
[','(fail, call(3)), failure].
|
|
6
|
+
[','(nofoo(X), call(X)), existence_error(procedure, nofoo/1)].
|
|
7
|
+
[','(X = true, call(X)), [[X <-- true]]].
|
|
8
|
+
|
|
9
|
+
/* end of file ',' (conjunction) */
|
data/spec/inriasuite/arg
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* file arg */
|
|
2
|
+
|
|
3
|
+
[arg(1,foo(a,b),a), success].
|
|
4
|
+
|
|
5
|
+
[arg(1,foo(a,b),X), [[X <-- a]]].
|
|
6
|
+
|
|
7
|
+
[arg(1,foo(X,b),a), [[X <-- a]]].
|
|
8
|
+
|
|
9
|
+
[arg(2,foo(a, f(X,b), c), f(a, Y)), [[X <-- a, Y <-- b]]].
|
|
10
|
+
|
|
11
|
+
[arg(1,foo(X,b),Y), [[Y <-- X]]].
|
|
12
|
+
|
|
13
|
+
[arg(1,foo(a,b),b), failure].
|
|
14
|
+
|
|
15
|
+
[arg(0,foo(a,b),foo), failure].
|
|
16
|
+
|
|
17
|
+
[arg(3,foo(3,4),N), failure].
|
|
18
|
+
|
|
19
|
+
[arg(X,foo(a,b),a), instantiation_error].
|
|
20
|
+
|
|
21
|
+
[arg(1,X,a), instantiation_error].
|
|
22
|
+
|
|
23
|
+
[arg(0,atom,A), type_error(compound, atom)].
|
|
24
|
+
|
|
25
|
+
[arg(0,3,A), type_error(compound, 3)].
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
[arg(-3,foo(a,b),A), domain_error(not_less_than_zero,-3)].
|
|
29
|
+
|
|
30
|
+
[arg(a,foo(a,b),X), type_error(integer, a)].
|
|
31
|
+
|
|
32
|
+
/* end of arg */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* file asserta */
|
|
2
|
+
/* use run_forest('bips-ex/progs/asserta_program') to see the program changes */
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
[(asserta((bar(X) :- X)), clause(bar(X), B)), [[B <-- call(X)]]].
|
|
8
|
+
|
|
9
|
+
[asserta(_), instantiation_error].
|
|
10
|
+
|
|
11
|
+
[asserta(4), type_error(callable, 4)].
|
|
12
|
+
|
|
13
|
+
[asserta((foo :- 4)), type_error(callable, 4)].
|
|
14
|
+
|
|
15
|
+
[asserta((atom(_) :- true)), permission_error(modify,static_procedure,atom/1)].
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/* end of asserta */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* file assertz (see the search tree by 'run_forest' predicate) */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[assertz((foo(X) :- X -> call(X))), success].
|
|
5
|
+
|
|
6
|
+
[assertz(_), instantiation_error].
|
|
7
|
+
|
|
8
|
+
[assertz(4), type_error(callable, 4)].
|
|
9
|
+
|
|
10
|
+
[assertz((foo :- 4)), type_error(callable, 4)].
|
|
11
|
+
|
|
12
|
+
[assertz((atom(_) :- true)),
|
|
13
|
+
permission_error(modify,static_procedure,atom/1)].
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/* end of assertz */
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* file atom_chars */
|
|
2
|
+
|
|
3
|
+
[atom_chars('',L), [[L <-- []]]].
|
|
4
|
+
[atom_chars([],L), [[L <-- ['[',']']]]].
|
|
5
|
+
[atom_chars('''',L), [[L <-- ['''']]]].
|
|
6
|
+
[atom_chars('iso',L), [[L <-- ['i','s','o']]]].
|
|
7
|
+
[atom_chars(A,['p','r','o','l','o','g']), [[A <-- 'prolog']]].
|
|
8
|
+
[atom_chars('North',['N'|X]), [[X <-- ['o','r','t','h']]]].
|
|
9
|
+
[atom_chars('iso',['i','s']), failure].
|
|
10
|
+
[atom_chars(A,L), instantiation_error].
|
|
11
|
+
|
|
12
|
+
[atom_chars(A,[a,E,c]), instantiation_error].
|
|
13
|
+
[atom_chars(A,[a,b|L]), instantiation_error].
|
|
14
|
+
[atom_chars(f(a),L), type_error(atom,f(a))].
|
|
15
|
+
[atom_chars(A,iso), type_error(list,iso)].
|
|
16
|
+
[atom_chars(A,[a,f(b)]), type_error(character,f(b))].
|
|
17
|
+
[(atom_chars(X,['1','2']), Y is X + 1), type_error(evaluable, '12'/0)].
|
|
18
|
+
|
|
19
|
+
/* end of file atom_chars */
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* file atom_codes */
|
|
2
|
+
|
|
3
|
+
[atom_codes('',L), [[L <-- []]]].
|
|
4
|
+
[atom_codes([],L), [[L <-- [ 0'[, 0'] ]]]].
|
|
5
|
+
[atom_codes('''',L), [[L <-- [ 39 ]]]].
|
|
6
|
+
[atom_codes('iso',L), [[L <-- [ 0'i, 0's, 0'o ]]]].
|
|
7
|
+
[atom_codes(A,[ 0'p, 0'r, 0'o, 0'l, 0'o, 0'g]), [[A <-- 'prolog']]].
|
|
8
|
+
[atom_codes('North',[0'N | L]), [[L <-- [0'o, 0'r, 0't, 0'h]]]].
|
|
9
|
+
[atom_codes('iso',[0'i, 0's]), failure].
|
|
10
|
+
[atom_codes(A,L), instantiation_error].
|
|
11
|
+
[atom_codes(f(a),L), type_error(atom,f(a))].
|
|
12
|
+
[atom_codes(A, 0'x), type_error(list,0'x)].
|
|
13
|
+
[atom_codes(A,[ 0'i, 0's, 1000]), representation_error(character_code)]. % 1000 not a code
|
|
14
|
+
|
|
15
|
+
/* end of file atom_codes */
|