rubylog 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,19 @@
|
|
1
|
+
/* file atom_concat */
|
2
|
+
|
3
|
+
[atom_concat('hello',' world',A), [[A <-- 'hello world']]].
|
4
|
+
[atom_concat(T,' world','small world'), [[T <-- 'small']]].
|
5
|
+
[atom_concat('hello',' world','small world'), failure].
|
6
|
+
[atom_concat(T1,T2,'hello'),
|
7
|
+
[[T1 <-- '',T2 <-- 'hello'],
|
8
|
+
[T1 <-- 'h',T2 <-- 'ello'],
|
9
|
+
[T1 <-- 'he',T2 <-- 'llo'],
|
10
|
+
[T1 <-- 'hel',T2 <-- 'lo'],
|
11
|
+
[T1 <-- 'hell',T2 <-- 'o'],
|
12
|
+
[T1 <-- 'hello',T2 <-- '']]].
|
13
|
+
[atom_concat(A1,'iso',A3), instantiation_error].
|
14
|
+
[atom_concat('iso',A2,A3), instantiation_error].
|
15
|
+
[atom_concat(f(a),'iso',A3), type_error(atom,f(a))].
|
16
|
+
[atom_concat('iso',f(a),A3), type_error(atom,f(a))].
|
17
|
+
[atom_concat(A1,A2,f(a)), type_error(atom,f(a))].
|
18
|
+
|
19
|
+
/* end of file atom_concat */
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* file atom_length */
|
2
|
+
|
3
|
+
[atom_length('enchanted evening', N), [[N <-- 17]]].
|
4
|
+
%[atom_length('enchanted\
|
5
|
+
% evening', N), [[N <-- 17]]].
|
6
|
+
[atom_length('', N), [[N <-- 0]]].
|
7
|
+
[atom_length('scarlet', 5), failure].
|
8
|
+
[atom_length(Atom, 4), instantiation_error]. % Culprit Atom
|
9
|
+
[atom_length(1.23, 4), type_error(atom, 1.23)].
|
10
|
+
[atom_length(atom, '4'), type_error(integer, '4')].
|
11
|
+
|
12
|
+
/* end of file atom_length */
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/* file of bagof */
|
2
|
+
|
3
|
+
[bagof(X,(X=1;X=2),L), [[L <-- [1, 2]]]].
|
4
|
+
|
5
|
+
[bagof(X,(X=1;X=2),X), [[X <-- [1, 2]]]].
|
6
|
+
|
7
|
+
[bagof(X,(X=Y;X=Z),L), [[L <-- [Y, Z]]]].
|
8
|
+
|
9
|
+
[bagof(X,fail,L), failure].
|
10
|
+
|
11
|
+
[bagof(1,(Y=1;Y=2),L), [[L <-- [1], Y <-- 1], [L <-- [1], Y <-- 2]]].
|
12
|
+
|
13
|
+
[bagof(f(X,Y),(X=a;Y=b),L), [[L <-- [f(a, _), f(_, b)]]]].
|
14
|
+
|
15
|
+
[bagof(X,Y^((X=1,Y=1);(X=2,Y=2)),S), [[S <-- [1, 2]]]].
|
16
|
+
|
17
|
+
[bagof(X,Y^((X=1;Y=1);(X=2,Y=2)),S), [[S <-- [1, _, 2]]]].
|
18
|
+
|
19
|
+
[(set_prolog_flag(unknown, warning),
|
20
|
+
bagof(X,(Y^(X=1;Y=1);X=3),S)), [[S <-- [3]]]].
|
21
|
+
|
22
|
+
[bagof(X,(X=Y;X=Z;Y=1),L), [[L <-- [Y, Z]], [L <-- [_], Y <-- 1]]].
|
23
|
+
|
24
|
+
|
25
|
+
[bagof(X,Y^Z,L), instantiation_error].
|
26
|
+
|
27
|
+
[bagof(X,1,L), type_error(callable, 1)].
|
28
|
+
|
29
|
+
[findall(X,call(4),S),type_error(callable, 4)].
|
30
|
+
|
31
|
+
/* end of bagof */
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
/* file call */
|
3
|
+
% To see the side effect of these goals, use the goal :
|
4
|
+
% display_io(on), run_bip('bips-ex/call'), dispaly_io(off).
|
5
|
+
|
6
|
+
[call(!),success].
|
7
|
+
[call(fail), failure].
|
8
|
+
[call((fail, X)), failure].
|
9
|
+
[call((fail, call(1))), failure].
|
10
|
+
[call((write(3), X)), instantiation_error].
|
11
|
+
[call((write(3), call(1))), type_error(callable,1)].
|
12
|
+
[call(X), instantiation_error].
|
13
|
+
[call(1), type_error(callable,1)].
|
14
|
+
[call((fail, 1)), type_error(callable,(fail,1))].
|
15
|
+
[call((write(3), 1)), type_error(callable,(write(3), 1))].
|
16
|
+
[call((1; true)), type_error(callable,(1; true))].
|
17
|
+
|
18
|
+
/* end of call */
|
19
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/* file catch-and-throw */
|
2
|
+
/* give the goal: display_io(on),
|
3
|
+
run_bip('bips-ex/catch-and-throw'),
|
4
|
+
display_io(off).
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
[(catch(true, C, write('something')), throw(blabla)), system_error].
|
9
|
+
% The system catchs 'blabla'
|
10
|
+
|
11
|
+
[catch(number_chars(A,L), error(instantiation_error, _), fail), failure].
|
12
|
+
|
13
|
+
|
14
|
+
/* end of file catch-and-throw */
|
15
|
+
|
16
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/* file char_code */
|
2
|
+
[char_code(a,Code),[[Code <-- 0'a]]].
|
3
|
+
[char_code(Char,99),[[Char <-- c]]].
|
4
|
+
[char_code(Char,0'c),[[Char <-- c]]].
|
5
|
+
[char_code(Char,163),[[Char <-- '\xa3\']]].
|
6
|
+
[char_code(b,98),success].
|
7
|
+
[char_code(b,4),failure].
|
8
|
+
[char_code('ab',Code),type_error(character, 'ab')].
|
9
|
+
[char_code(a,x),type_error(integer, x)].
|
10
|
+
[char_code(Char,Code),instantiation_error].
|
11
|
+
[char_code(Char,-2),representation_error(character_code)].
|
12
|
+
/* end of char_code */
|
13
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/* file clause */
|
2
|
+
|
3
|
+
|
4
|
+
[clause(x,Body), failure].
|
5
|
+
|
6
|
+
[clause(_,B), instantiation_error].
|
7
|
+
|
8
|
+
[clause(4,B), type_error(callable,4)].
|
9
|
+
|
10
|
+
[clause(f(_),5), type_error(callable,5)].
|
11
|
+
|
12
|
+
[clause(atom(_),Body), permission_error(access,private_procedure,atom/1)].
|
13
|
+
|
14
|
+
|
15
|
+
/* end of clause */
|
16
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/* file copy_term */
|
2
|
+
|
3
|
+
[copy_term(X,Y), success].
|
4
|
+
|
5
|
+
[copy_term(X,3), success].
|
6
|
+
|
7
|
+
[copy_term(_,a), success].
|
8
|
+
|
9
|
+
[copy_term(a+X,X+b),[[X <-- a]]].
|
10
|
+
|
11
|
+
[copy_term(_,_), success].
|
12
|
+
|
13
|
+
[copy_term(X+X+Y,A+B+B),[[B <-- A]]].
|
14
|
+
|
15
|
+
[copy_term(a,a), success].
|
16
|
+
|
17
|
+
[copy_term(a,b), failure].
|
18
|
+
|
19
|
+
[copy_term(f(a),f(X)),[[X <-- a]]].
|
20
|
+
|
21
|
+
[(copy_term(a+X,X+b),copy_term(a+X,X+b)), failure].
|
22
|
+
|
23
|
+
|
24
|
+
/* end of copy_term */
|
25
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/* file current_predicate */
|
2
|
+
|
3
|
+
|
4
|
+
[current_predicate(current_predicate/1), failure].
|
5
|
+
|
6
|
+
/* depends on the test harness */
|
7
|
+
[current_predicate(run_tests/1), success].
|
8
|
+
|
9
|
+
[current_predicate(4), type_error(predicate_indicator, 4)].
|
10
|
+
|
11
|
+
[current_predicate(dog), type_error(predicate_indicator, dog)].
|
12
|
+
|
13
|
+
[current_predicate(0/dog), type_error(predicate_indicator, 0/dog)].
|
14
|
+
|
15
|
+
/* end of current_predicate */
|
16
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* file current_prolog_flag */
|
2
|
+
|
3
|
+
[current_prolog_flag(debug, off), success].
|
4
|
+
[(set_prolog_flag(unknown, warning),
|
5
|
+
current_prolog_flag(unknown, warning)), success].
|
6
|
+
[(set_prolog_flag(unknown, warning),
|
7
|
+
current_prolog_flag(unknown, error)), failure].
|
8
|
+
[current_prolog_flag(debug, V), [[V <-- off]]].
|
9
|
+
[current_prolog_flag(5, V), type_error(atom,5)].
|
10
|
+
[current_prolog_flag(warning, V), domain_error(prolog_flag,warning)].
|
11
|
+
|
12
|
+
/* end of current_prolog_flag */
|
data/spec/inriasuite/cut
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
/* file fail */
|
3
|
+
|
4
|
+
[fail, failure].
|
5
|
+
|
6
|
+
[undef_pred, existence_error(procedure, undef_pred/0)]. % the value of flag 'unknown' is 'error'.
|
7
|
+
|
8
|
+
[(set_prolog_flag(unknown, fail), undef_pred), failure].
|
9
|
+
|
10
|
+
[(set_prolog_flag(unknown, warning), undef_pred), failure]. % A warning message
|
11
|
+
% appears in the outputfile (see forest by: run_forest or bip_forest).
|
12
|
+
|
13
|
+
|
14
|
+
/* end of fail */
|
15
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/* file file_manip (group together: seek,at and get_char) */
|
2
|
+
/* For these BIPs and put_char and write, see the search tree */
|
3
|
+
/* by 'run_forest' predicate */
|
4
|
+
[(seek(my_file,3),at(my_file,X)),in(my_file),[[X <-- 3]]].
|
5
|
+
[(seek(my_file,eof),at(my_file,X)),in(my_file),[[X <-- eof]]].
|
6
|
+
[(seek(my_file,3),get_char(X,my_file)),in(my_file),[[X <-- e]]].
|
7
|
+
/* end of file_manip */
|
8
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/* file findall */
|
2
|
+
|
3
|
+
[findall(X,(X=1 ; X=2),S),[[S <-- [1,2]]]].
|
4
|
+
|
5
|
+
[findall(X+Y,(X=1),S),[[S <-- [1+_]]]].
|
6
|
+
|
7
|
+
[findall(X,fail,L),[[L <-- []]]].
|
8
|
+
|
9
|
+
[findall(X,(X=1 ; X=1),S),[[S <-- [1,1]]]].
|
10
|
+
|
11
|
+
[findall(X,(X=2 ; X=1),[1,2]), failure].
|
12
|
+
|
13
|
+
[findall(X,(X=1 ; X=2),[X,Y]), [[X <-- 1, Y <-- 2]]].
|
14
|
+
|
15
|
+
[findall(X,Goal,S),instantiation_error]. % Culprit Goal
|
16
|
+
|
17
|
+
[findall(X,4,S),type_error(callable, 4)].
|
18
|
+
|
19
|
+
[findall(X,call(1),S),type_error(callable, 1)].
|
20
|
+
|
21
|
+
/* end of findall */
|
22
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/* file functor */
|
2
|
+
|
3
|
+
[functor(foo(a,b,c),foo,3), success].
|
4
|
+
|
5
|
+
[functor(foo(a,b,c),X,Y), [[X <-- foo, Y <-- 3]]].
|
6
|
+
|
7
|
+
[functor(X,foo,3), [[X <-- foo(A,B,C)]]]. % A, B and C are 3 new variables
|
8
|
+
|
9
|
+
[functor(X,foo,0), [[X <-- foo]]].
|
10
|
+
|
11
|
+
[functor(mats(A,B),A,B), [[A <-- mats,B <-- 2]]].
|
12
|
+
|
13
|
+
[functor(foo(a),foo,2), failure].
|
14
|
+
|
15
|
+
[functor(foo(a),fo,1), failure].
|
16
|
+
|
17
|
+
[functor(1,X,Y), [[X <-- 1,Y <-- 0]]].
|
18
|
+
|
19
|
+
[functor(X,1.1,0), [[X <-- 1.1]]].
|
20
|
+
|
21
|
+
[functor([_|_],'.',2), success].
|
22
|
+
|
23
|
+
[functor([],[],0), success].
|
24
|
+
|
25
|
+
[functor(X, Y, 3), instantiation_error].
|
26
|
+
|
27
|
+
[functor(X, foo, N), instantiation_error].
|
28
|
+
|
29
|
+
[functor(X, foo, a), type_error(integer,a)].
|
30
|
+
|
31
|
+
[functor(F, 1.5, 1), type_error(atom,1.5)].
|
32
|
+
|
33
|
+
[functor(F,foo(a),1), type_error(atomic,foo(a))].
|
34
|
+
|
35
|
+
[(current_prolog_flag(max_arity,A), X is A + 1, functor(T, foo, X)),
|
36
|
+
representation_error(max_arity)].
|
37
|
+
|
38
|
+
[functor(T, foo, -1), domain_error(not_less_than_zero,-1)].
|
39
|
+
|
40
|
+
/* end of functor */
|
41
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
[functor(foo(a,b,c),foo,3), % The goal
|
2
|
+
success]. % The 'expected' answer
|
3
|
+
|
4
|
+
[functor(foo(a,b,c),X,Y),
|
5
|
+
[[X <-- foo, Y <-- 2]]]. % Must instantiate Y by 3
|
6
|
+
|
7
|
+
[functor(X,foo,3), [[X <-- foo(A,B,C)]]].
|
8
|
+
|
9
|
+
[functor(X,foo,0), [[X <-- foo]]].
|
10
|
+
|
11
|
+
[functor(mats(A,B),A,B), [[A <-- mats,B <-- 2]]].
|
12
|
+
|
13
|
+
[functor(foo(a),foo,2), success]. % Must fail
|
14
|
+
|
15
|
+
[functor(foo(a),fo,1), failure].
|
16
|
+
|
17
|
+
[functor(1,X,Y), [[X <-- 1,Y <-- 0]]].
|
18
|
+
|
19
|
+
[functor(X,1.1,0), [[X <-- 1.1]]].
|
20
|
+
|
21
|
+
[functor([_|_],'.',2), failure]. % Must succeed
|
22
|
+
|
23
|
+
[functor([],[],0), success].
|
24
|
+
|
25
|
+
[functor(X, Y, 3), instantiation_error].
|
26
|
+
|
27
|
+
[functor(X, foo, N), instantiation_error].
|
28
|
+
|
29
|
+
[functor(X, foo, a),
|
30
|
+
failure]. % type_error(integer,a) expected ('a' not an integer)
|
31
|
+
|
32
|
+
[functor(F, 1.5, 1), type_error(atom,1.5)].
|
33
|
+
|
34
|
+
[functor(F,foo(a),1), type_error(atomic,foo(a))].
|
35
|
+
|
36
|
+
[(current_prolog_flag(max_arity,A),
|
37
|
+
X is A + 1, % 3 goals brackted
|
38
|
+
functor(T, foo, X)),
|
39
|
+
representation_error(max_arity)].
|
40
|
+
|
41
|
+
[functor(T, foo, -1), domain_error(not_less_than_zero,-1)].
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/* file if-then (-> operator) */
|
2
|
+
|
3
|
+
['->'(true, true), success].
|
4
|
+
['->'(true, fail), failure].
|
5
|
+
['->'(fail, true), failure].
|
6
|
+
['->'(true, X=1), [[X <-- 1]]].
|
7
|
+
['->'(';'(X=1, X=2), true), [[X <-- 1]]].
|
8
|
+
['->'(true, ';'(X=1, X=2)), [[X <-- 1], [X <-- 2]]].
|
9
|
+
|
10
|
+
/* end of file if-then (-> operator) */
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* file if-then-else (Cond -> Then ; Else) */
|
2
|
+
|
3
|
+
[';'('->'(true, true), fail), success].
|
4
|
+
[';'('->'(fail, true), true), success].
|
5
|
+
[';'('->'(true, fail), fail), failure].
|
6
|
+
[';'('->'(fail, true), fail), failure].
|
7
|
+
[';'('->'(true, X=1), X=2), [[X <-- 1]]].
|
8
|
+
[';'('->'(fail, X=1), X=2), [[X <-- 2]]].
|
9
|
+
[';'('->'(true, ';'(X=1, X=2)), true), [[X <-- 1], [X <-- 2]]].
|
10
|
+
[';'('->'(';'(X=1, X=2), true), true), [[X <-- 1]]].
|
11
|
+
|
12
|
+
/* end of file if (-> operator) */
|
Binary file
|