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.
Files changed (124) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +18 -0
  4. data/Gemfile.lock +64 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +96 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/examples/4queens.rb +10 -0
  10. data/examples/calculation.rb +12 -0
  11. data/examples/concepts.rb +46 -0
  12. data/examples/factorial.rb +16 -0
  13. data/examples/fp.rb +56 -0
  14. data/examples/hello.rb +9 -0
  15. data/examples/historia_de_espana.rb +31 -0
  16. data/examples/idea.rb +143 -0
  17. data/examples/lists.rb +5 -0
  18. data/examples/mechanika.rb +409 -0
  19. data/examples/parse.rb +15 -0
  20. data/examples/theory.rb +20 -0
  21. data/lib/array.rb +24 -0
  22. data/lib/class.rb +11 -0
  23. data/lib/method.rb +4 -0
  24. data/lib/object.rb +5 -0
  25. data/lib/proc.rb +4 -0
  26. data/lib/rubylog/builtins.rb +193 -0
  27. data/lib/rubylog/callable.rb +20 -0
  28. data/lib/rubylog/clause.rb +113 -0
  29. data/lib/rubylog/composite_term.rb +38 -0
  30. data/lib/rubylog/dsl/constants.rb +15 -0
  31. data/lib/rubylog/dsl/first_order_functors.rb +9 -0
  32. data/lib/rubylog/dsl/global_functors.rb +3 -0
  33. data/lib/rubylog/dsl/second_order_functors.rb +8 -0
  34. data/lib/rubylog/dsl.rb +52 -0
  35. data/lib/rubylog/errors.rb +18 -0
  36. data/lib/rubylog/internal_helpers.rb +16 -0
  37. data/lib/rubylog/predicate.rb +34 -0
  38. data/lib/rubylog/proc_method_additions.rb +69 -0
  39. data/lib/rubylog/term.rb +20 -0
  40. data/lib/rubylog/theory.rb +133 -0
  41. data/lib/rubylog/unifiable.rb +19 -0
  42. data/lib/rubylog/variable.rb +97 -0
  43. data/lib/rubylog.rb +39 -0
  44. data/lib/symbol.rb +35 -0
  45. data/rubylog.gemspec +187 -0
  46. data/script/inriasuite2spec +0 -0
  47. data/script/inriasuite2spec.pl +22 -0
  48. data/spec/bartak_guide_spec.rb +91 -0
  49. data/spec/inriasuite/README +122 -0
  50. data/spec/inriasuite/abolish +18 -0
  51. data/spec/inriasuite/and +9 -0
  52. data/spec/inriasuite/arg +32 -0
  53. data/spec/inriasuite/arith_diff +10 -0
  54. data/spec/inriasuite/arith_eq +10 -0
  55. data/spec/inriasuite/arith_gt +10 -0
  56. data/spec/inriasuite/arith_gt= +10 -0
  57. data/spec/inriasuite/arith_lt +10 -0
  58. data/spec/inriasuite/arith_lt= +10 -0
  59. data/spec/inriasuite/asserta +18 -0
  60. data/spec/inriasuite/assertz +16 -0
  61. data/spec/inriasuite/atom +12 -0
  62. data/spec/inriasuite/atom_chars +19 -0
  63. data/spec/inriasuite/atom_codes +15 -0
  64. data/spec/inriasuite/atom_concat +19 -0
  65. data/spec/inriasuite/atom_length +12 -0
  66. data/spec/inriasuite/atomic +11 -0
  67. data/spec/inriasuite/bagof +31 -0
  68. data/spec/inriasuite/call +19 -0
  69. data/spec/inriasuite/catch-and-throw +16 -0
  70. data/spec/inriasuite/char_code +13 -0
  71. data/spec/inriasuite/clause +16 -0
  72. data/spec/inriasuite/compound +12 -0
  73. data/spec/inriasuite/copy_term +25 -0
  74. data/spec/inriasuite/current_input +5 -0
  75. data/spec/inriasuite/current_output +5 -0
  76. data/spec/inriasuite/current_predicate +16 -0
  77. data/spec/inriasuite/current_prolog_flag +12 -0
  78. data/spec/inriasuite/cut +9 -0
  79. data/spec/inriasuite/fail +15 -0
  80. data/spec/inriasuite/file_manip +8 -0
  81. data/spec/inriasuite/findall +22 -0
  82. data/spec/inriasuite/float +10 -0
  83. data/spec/inriasuite/functor +41 -0
  84. data/spec/inriasuite/functor-bis +41 -0
  85. data/spec/inriasuite/halt +7 -0
  86. data/spec/inriasuite/if-then +10 -0
  87. data/spec/inriasuite/if-then-else +12 -0
  88. data/spec/inriasuite/inriasuite.obp +0 -0
  89. data/spec/inriasuite/inriasuite.pl +836 -0
  90. data/spec/inriasuite/integer +10 -0
  91. data/spec/inriasuite/is +11 -0
  92. data/spec/inriasuite/junk +0 -0
  93. data/spec/inriasuite/nonvar +11 -0
  94. data/spec/inriasuite/not_provable +12 -0
  95. data/spec/inriasuite/not_unify +15 -0
  96. data/spec/inriasuite/number +10 -0
  97. data/spec/inriasuite/number_chars +22 -0
  98. data/spec/inriasuite/number_codes +19 -0
  99. data/spec/inriasuite/once +11 -0
  100. data/spec/inriasuite/or +9 -0
  101. data/spec/inriasuite/repeat +5 -0
  102. data/spec/inriasuite/retract +10 -0
  103. data/spec/inriasuite/set_prolog_flag +21 -0
  104. data/spec/inriasuite/setof +36 -0
  105. data/spec/inriasuite/sub_atom +30 -0
  106. data/spec/inriasuite/t +1 -0
  107. data/spec/inriasuite/t_foo.pl +4 -0
  108. data/spec/inriasuite/term_diff +13 -0
  109. data/spec/inriasuite/term_eq +12 -0
  110. data/spec/inriasuite/term_gt +12 -0
  111. data/spec/inriasuite/term_gt= +12 -0
  112. data/spec/inriasuite/term_lt +12 -0
  113. data/spec/inriasuite/term_lt= +12 -0
  114. data/spec/inriasuite/true +7 -0
  115. data/spec/inriasuite/unify +18 -0
  116. data/spec/inriasuite.rb +20 -0
  117. data/spec/recursion_spec.rb +18 -0
  118. data/spec/rubylog/builtins/splits_to.rb +18 -0
  119. data/spec/rubylog/clause_spec.rb +81 -0
  120. data/spec/rubylog/variable_spec.rb +25 -0
  121. data/spec/rubylog_spec.rb +914 -0
  122. data/spec/spec_helper.rb +12 -0
  123. data/spec/theory_spec.rb +1 -0
  124. metadata +339 -0
@@ -0,0 +1,10 @@
1
+ /* file integer */
2
+
3
+ [integer(3), success].
4
+ [integer(-3), success].
5
+ [integer(3.3), failure].
6
+ [integer(X), failure].
7
+ [integer(atom), failure].
8
+
9
+ /* end of integer */
10
+
@@ -0,0 +1,11 @@
1
+ /* file is */
2
+
3
+ ['is'(Result,3 + 11.0),[[Result <-- 14.0]]].
4
+ [(X = 1 + 2, 'is'(Y, X * 3)),[[X <-- (1 + 2), Y <-- 9]]]. % error? 1+2
5
+ ['is'(foo,77), failure]. % error? foo
6
+ ['is'(77, N), instantiation_error].
7
+ ['is'(77, foo), type_error(evaluable, foo/0)].
8
+
9
+ ['is'(X,float(3)),[[X <-- 3.0]]].
10
+
11
+ /* end of is */
File without changes
@@ -0,0 +1,11 @@
1
+ /* file nonvar */
2
+
3
+ [nonvar(33.3), success].
4
+ [nonvar(foo), success].
5
+ [nonvar(Foo), failure].
6
+ [(foo=Foo,nonvar(Foo)),[[Foo <-- foo]]].
7
+ [nonvar(_), failure].
8
+ [nonvar(a(b)), success].
9
+
10
+ /* end of nonvar */
11
+
@@ -0,0 +1,12 @@
1
+ /* file \+ */
2
+
3
+ [\+(true), failure].
4
+ [\+(!), failure].
5
+ [\+((!,fail)), success].
6
+ [((X=1;X=2), \+((!,fail))), [[X <-- 1],[X <-- 2]]].
7
+ [\+(4 = 5), success].
8
+ [\+(3), type_error(callable, 3)].
9
+ [\+(X), instantiation_error]. % Culprit X
10
+
11
+ /* end of \+ */
12
+
@@ -0,0 +1,15 @@
1
+ /* file \= */
2
+
3
+ ['\\='(1,1), failure].
4
+ ['\\='(X,1), failure].
5
+ ['\\='(X,Y), failure].
6
+ [('\\='(X,Y),'\\='(X,abc)), failure].
7
+ ['\\='(f(X,def),f(def,Y)), failure].
8
+ ['\\='(1,2), success].
9
+ ['\\='(1,1.0), success].
10
+ ['\\='(g(X),f(f(X))), success].
11
+ ['\\='(f(X,1),f(a(X))), success].
12
+ ['\\='(f(X,Y,X),f(a(X),a(Y),Y,2)), success].
13
+
14
+ /* end of \= */
15
+
@@ -0,0 +1,10 @@
1
+ /* file number */
2
+
3
+ [number(3), success].
4
+ [number(3.3), success].
5
+ [number(-3), success].
6
+ [number(a), failure].
7
+ [number(X), failure].
8
+
9
+ /* end of number */
10
+
@@ -0,0 +1,22 @@
1
+ /* file number_chars */
2
+ /* Some goals fails because the parser is not yet implemented */
3
+
4
+ [number_chars(33,L), [[L <-- ['3','3']]]].
5
+ [number_chars(33,['3','3']), success].
6
+ [number_chars(33.0,L), [[L <-- ['3','3','.','0']]]].
7
+ [number_chars(X,['3','.','3','E','+','0']), [[X <-- 3.3]]].
8
+ [number_chars(3.3,['3','.','3','E','+','0']), success].
9
+ [number_chars(A,['-','2','5']), [[A <-- (-25)]]].
10
+ [number_chars(A,['\n',' ','3']), [[A <-- 3]]].
11
+ [number_chars(A,['3',' ']), syntax_error(_)].
12
+ [number_chars(A,['0',x,f]), [[A <-- 15]]].
13
+ [number_chars(A,['0','''','A']), [[A <-- 65]]].
14
+ [number_chars(A,['4','.','2']), [[A <-- 4.2]]].
15
+ [number_chars(A,['4','2','.','0','e','-','1']), [[A <-- 4.2]]].
16
+
17
+ [number_chars(A,L), instantiation_error].
18
+ [number_chars(a,L), type_error(number, a)].
19
+ [number_chars(A,4), type_error(list, 4)].
20
+ [number_chars(A,['4',2]), type_error(character, 2)].
21
+
22
+ /* end of file number_chars */
@@ -0,0 +1,19 @@
1
+ /* file number_codes */
2
+ /* Some goals fails because the parser is not yet implemented */
3
+
4
+ [number_codes(33,L), [[L <-- [0'3,0'3]]]].
5
+ [number_codes(33,[0'3,0'3]), success].
6
+ [number_codes(33.0,L), [[L <-- [51,51,46,48]]]].
7
+ [number_codes(33.0,[0'3,0'.,0'3,0'E,0'+,0'0,0'1]), success].
8
+ [number_codes(A,[0'-,0'2,0'5]), [[A <-- (-25)]]].
9
+ [number_codes(A,[0' ,0'3]), [[A <-- 3]]].
10
+ [number_codes(A,[0'0,0'x,0'f]), [[A <-- 15]]].
11
+ [number_codes(A,[0'0,39,0'a]), [[A <-- 97]]].
12
+ [number_codes(A,[0'4,0'.,0'2]), [[A <-- 4.2]]].
13
+ [number_codes(A,[0'4,0'2,0'.,0'0,0'e,0'-,0'1]), [[A <-- 4.2]]].
14
+
15
+ [number_codes(A,L), instantiation_error].
16
+ [number_codes(a,L), type_error(number,a)].
17
+ [number_codes(A,4), type_error(list,4)].
18
+ [number_codes(A,[ 0'1, 0'2, 1000]), representation_error(character_code)]. % 1000 not a code
19
+ /* end of file number_codes */
@@ -0,0 +1,11 @@
1
+ /* file once */
2
+
3
+ [once(!), success].
4
+ [(once(!), (X=1; X=2)), [[X <-- 1],[X <-- 2]]].
5
+ [once(repeat), success].
6
+ [once(fail), failure].
7
+ [once(3), type_error(callable, 3)].
8
+ [once(X), instantiation_error]. % Culprit X
9
+
10
+ /* end of once */
11
+
@@ -0,0 +1,9 @@
1
+ /* file ';' (or = disjunction) */
2
+
3
+ [';'(true, fail), success].
4
+ [';'((!, fail), true), failure].
5
+ [';'(!, call(3)), success].
6
+ [';'((X=1, !), X=2), [[X <-- 1]]].
7
+ [';'(X=1, X=2), [[X <-- 1], [X <-- 2]]].
8
+
9
+ /* end of file ';' (or = disjunction) */
@@ -0,0 +1,5 @@
1
+ /* file repeat */
2
+
3
+ [(repeat,!,fail), failure].
4
+
5
+ /* end of repeat */
@@ -0,0 +1,10 @@
1
+ /* file retract */
2
+
3
+
4
+ [retract((4 :- X)), type_error(callable, 4)].
5
+
6
+ [retract((atom(_) :- X == '[]')),
7
+ permission_error(modify,static_procedure,atom/1)].
8
+
9
+ /* end of retract */
10
+
@@ -0,0 +1,21 @@
1
+ /* file current_prolog_flag */
2
+
3
+ [(set_prolog_flag(unknown, fail),
4
+ current_prolog_flag(unknown, V)), [[V <-- fail]]].
5
+ [set_prolog_flag(X, warning), instantiation_error].
6
+ [set_prolog_flag(5, decimals), type_error(atom,5)].
7
+ [set_prolog_flag(date, 'July 1999'), domain_error(prolog_flag,date)].
8
+ [set_prolog_flag(debug, no), domain_error(flag_value,debug+no)].
9
+ [set_prolog_flag(max_arity, 40), permission_error(modify, flag, max_arity)].
10
+ /* swindles to get tests of double quotes flag to work. */
11
+
12
+ [set_prolog_flag(double_quotes, atom), success].
13
+ [X = "fred", [[X <-- fred]]].
14
+
15
+ [set_prolog_flag(double_quotes, codes), success].
16
+ [X = "fred", [[X <-- [102,114,101,100]]]].
17
+
18
+ [set_prolog_flag(double_quotes, chars), success].
19
+ [X = "fred", [[X <-- [f,r,e,d]]]].
20
+
21
+ /* end of current_prolog_flag */
@@ -0,0 +1,36 @@
1
+ /* file of setof */
2
+
3
+ [setof(X,(X=1;X=2),L), [[L <-- [1, 2]]]].
4
+
5
+ [setof(X,(X=1;X=2),X), [[X <-- [1, 2]]]].
6
+
7
+ [setof(X,(X=2;X=1),L), [[L <-- [1, 2]]]].
8
+
9
+ [setof(X,(X=2;X=2),L), [[L <-- [2]]]].
10
+
11
+
12
+ [setof(X,fail,L), failure].
13
+
14
+ [setof(1,(Y=2;Y=1),L), [[L <-- [1], Y <-- 1], [L <-- [1], Y <-- 2]]].
15
+
16
+ [setof(f(X,Y),(X=a;Y=b),L), [[L <-- [f(_, b), f(a, _)]]]].
17
+
18
+ [setof(X,Y^((X=1,Y=1);(X=2,Y=2)),S), [[S <-- [1, 2]]]].
19
+
20
+ [setof(X,Y^((X=1;Y=1);(X=2,Y=2)),S), [[S <-- [_, 1, 2]]]].
21
+
22
+ [(set_prolog_flag(unknown, warning),
23
+ setof(X,(Y^(X=1;Y=1);X=3),S)), [[S <-- [3]]]].
24
+ [(set_prolog_flag(unknown, warning),
25
+ setof(X,Y^(X=1;Y=1;X=3),S)), [[S <-- [_, 1,3]]]].
26
+
27
+ [setof(X,(X=Y;X=Z;Y=1),L), [[L <-- [Y, Z]], [L <-- [_], Y <-- 1]]].
28
+
29
+
30
+
31
+
32
+ [setof(X, X^(true; 4),L), type_error(callable,(true;4))].
33
+
34
+ [setof(X,1,L), type_error(callable,1)].
35
+
36
+ /* end of setof */
@@ -0,0 +1,30 @@
1
+ /* file sub_atom */
2
+
3
+ [sub_atom(abracadabra, 0, 5, _, S2), [[S2 <-- 'abrac']]].
4
+ [sub_atom(abracadabra, _, 5, 0, S2), [[S2 <-- 'dabra']]].
5
+ [sub_atom(abracadabra, 3, Length, 3, S2), [[Length <-- 5, S2 <-- 'acada']]].
6
+ [sub_atom(abracadabra, Before, 2, After, ab),
7
+ [[Before <-- 0, After <-- 9],
8
+ [Before <-- 7, After <-- 2]]].
9
+ [sub_atom('Banana', 3, 2, _, S2), [[S2 <-- 'an']]].
10
+ [sub_atom('charity', _, 3, _, S2), [[S2 <-- 'cha'],
11
+ [S2 <-- 'har'],
12
+ [S2 <-- 'ari'],
13
+ [S2 <-- 'rit'],
14
+ [S2 <-- 'ity']]].
15
+ [sub_atom('ab', Before, Length, After, Sub_atom),
16
+ [[Before <-- 1, Length <-- 0, Sub_atom <-- ''],
17
+ [Before <-- 1, Length <-- 1, Sub_atom <-- 'a'],
18
+ [Before <-- 1, Length <-- 2, Sub_atom <-- 'ab'],
19
+ [Before <-- 2, Length <-- 0, Sub_atom <-- ''],
20
+ [Before <-- 2, Length <-- 1, Sub_atom <-- 'b'],
21
+ [Before <-- 3, Length <-- 0, Sub_atom <-- '']]].
22
+
23
+ [sub_atom(Banana, 3, 2, _, S2), instantiation_error].
24
+ [sub_atom(f(a), 2, 2, _, S2), type_error(atom,f(a))].
25
+ [sub_atom('Banana', 4, 2, _, 2), type_error(atom,2)].
26
+ [sub_atom('Banana', a, 2, _, S2), type_error(integer,a)].
27
+ [sub_atom('Banana', 4, n, _, S2), type_error(integer,n)].
28
+ [sub_atom('Banana', 4, _, m, S2), type_error(integer,m)].
29
+
30
+ /* end of sub_atom */
data/spec/inriasuite/t ADDED
@@ -0,0 +1 @@
1
+ [bagof([X,Y], t_foo(X,Y), S) , t_foo, success].
@@ -0,0 +1,4 @@
1
+ t_foo(1,2).
2
+ t_foo(2,3).
3
+ t_foo(3,4).
4
+ t_foo(_,_).
@@ -0,0 +1,13 @@
1
+ /* file \== */
2
+
3
+ ['\\=='(1,1), failure].
4
+ ['\\=='(X,X), failure].
5
+ ['\\=='(1,2), success].
6
+ ['\\=='(X,1), success].
7
+ ['\\=='(X,Y), success].
8
+ ['\\=='(_,_), success].
9
+ ['\\=='(X,a(X)), success].
10
+ ['\\=='(f(a),f(a)), failure].
11
+
12
+ /* end of \== */
13
+
@@ -0,0 +1,12 @@
1
+ /* file == */
2
+
3
+ ['=='(1,1), success].
4
+ ['=='(X,X), success].
5
+ ['=='(1,2), failure].
6
+ ['=='(X,1), failure].
7
+ ['=='(X,Y), failure].
8
+ ['=='(_,_), failure].
9
+ ['=='(X,a(X)), failure].
10
+ ['=='(f(a),f(a)), success].
11
+
12
+ /* end of == */
@@ -0,0 +1,12 @@
1
+ /* file @> */
2
+
3
+ ['@>'(1.0,1), failure].
4
+ ['@>'(aardvark,zebra), failure].
5
+ ['@>'(short,short), failure].
6
+ ['@>'(short,shorter), failure].
7
+ ['@>'(foo(b),foo(a)), success].
8
+ ['@>'(X,X), failure].
9
+ ['@>'(foo(a,X),foo(b,Y)), failure].
10
+
11
+ /* end of @> */
12
+
@@ -0,0 +1,12 @@
1
+ /* file @>= */
2
+
3
+ ['@>='(1.0,1), failure].
4
+ ['@>='(aardvark,zebra), failure].
5
+ ['@>='(short,short), success].
6
+ ['@>='(short,shorter), failure].
7
+ ['@>='(foo(b),foo(a)), success].
8
+ ['@>='(X,X), success].
9
+ ['@>='(foo(a,X),foo(b,Y)), failure].
10
+
11
+ /* end of @>= */
12
+
@@ -0,0 +1,12 @@
1
+ /* file @< */
2
+
3
+ ['@<'(1.0,1), success].
4
+ ['@<'(aardvark,zebra), success].
5
+ ['@<'(short,short), failure].
6
+ ['@<'(short,shorter), success].
7
+ ['@<'(foo(b),foo(a)), failure].
8
+ ['@<'(X,X), failure].
9
+ ['@<'(foo(a,X),foo(b,Y)), success].
10
+
11
+ /* end of @< */
12
+
@@ -0,0 +1,12 @@
1
+ /* file @=< */
2
+
3
+ ['@=<'(1.0,1), success].
4
+ ['@=<'(aardvark,zebra), success].
5
+ ['@=<'(short,short), success].
6
+ ['@=<'(short,shorter), success].
7
+ ['@=<'(foo(b),foo(a)), failure].
8
+ ['@=<'(X,X), success].
9
+ ['@=<'(foo(a,X),foo(b,Y)), success].
10
+
11
+ /* end of @=< */
12
+
@@ -0,0 +1,7 @@
1
+
2
+ /* file true */
3
+
4
+ [true, success].
5
+
6
+ /* end of true */
7
+
@@ -0,0 +1,18 @@
1
+ /* file = */
2
+ ['='(1,1), success].
3
+ ['='(X,1),[[X <-- 1]]].
4
+ ['='(X,Y),[[Y <-- X]]].
5
+ [('='(X,Y),'='(X,abc)),[[X <-- abc, Y <-- abc]]].
6
+ ['='(f(X,def),f(def,Y)), [[X <-- def, Y <-- def]]].
7
+ ['='(1,2), failure].
8
+ ['='(1,1.0), failure].
9
+ ['='(g(X),f(f(X))), failure].
10
+ ['='(f(X,1),f(a(X))), failure].
11
+ ['='(f(X,Y,X),f(a(X),a(Y),Y,2)), failure].
12
+ ['='(f(A,B,C),f(g(B,B),g(C,C),g(D,D))),
13
+ [[A <-- g(g(g(D,D),g(D,D)),g(g(D,D),g(D,D))),
14
+ B <-- g(g(D,D),g(D,D)),
15
+ C <-- g(D,D)]]].
16
+
17
+ /* end of = */
18
+
@@ -0,0 +1,20 @@
1
+ describe "abolish" do
2
+
3
+ end
4
+
5
+ describe "and" do
6
+ it {
7
+ (X.is(1).and X.var).to_a.should == []
8
+ (X.var.and X.is(1)).to_a.should == [1]
9
+ (:fail.and :call[3]).to_a.should == []
10
+ lambda { (:nofoo[X].and X.call).to_a }.
11
+ should raise_error ExistenceError
12
+ (X.is(:true).and X.call).should == [:true]
13
+ }
14
+ end
15
+
16
+
17
+ describe "arg" do
18
+
19
+ end
20
+
@@ -0,0 +1,18 @@
1
+
2
+ require 'rubylog'
3
+
4
+ class << Rubylog.theory
5
+ describe "recursion" do
6
+ specify "factorial" do
7
+ Integer.rubylog_functor :factorial
8
+ 0.factorial! 1
9
+ N.factorial(K).if lambda{|n|n>0}.and N1.is{|n|n-1}.and N1.factorial(K1).and K.is{|n,_,_,k1|k1*n}
10
+
11
+ (0.factorial K).to_a.should == [1]
12
+ (1.factorial K).to_a.should == [1]
13
+ (2.factorial K).to_a.should == [2]
14
+ (3.factorial K).to_a.should == [6]
15
+ (4.factorial K).to_a.should == [24]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubylog'
2
+
3
+ class << Rubylog.theory
4
+ describe "splits_to" do
5
+ specify do
6
+ def split_to a,b
7
+ be_splits_to a,b
8
+ end
9
+
10
+ [].should_not split_to(ANY,ANY)
11
+ [1].should split_to(1,[])
12
+ [1,2].should split_to(1,[2])
13
+ [1,2,3].should split_to(1,[2,3])
14
+
15
+ ([1,2,3].splits_to(B,C)).to_a.should == [[1,[2,3]]]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ require 'rubylog'
2
+
3
+ class << Rubylog.theory
4
+ describe "clauses" do
5
+ it "can be created" do
6
+ (:john.is_happy).should be_kind_of Rubylog::Term
7
+ (:john.likes :beer).should be_kind_of Rubylog::Term
8
+ (A.likes :beer).should be_kind_of Rubylog::Term
9
+ (:john.likes Drink).should be_kind_of Rubylog::Term
10
+ (:john.likes :drinking.in :bar).should be_kind_of Rubylog::Term
11
+ end
12
+ it "forbids non-declared names" do
13
+ lambda { :john.something_else }.should raise_error(NoMethodError)
14
+ end
15
+ it "also work with operators" do
16
+ (:is_happy%1).should be_kind_of Rubylog::Term
17
+ (A%B).should be_kind_of Rubylog::Term
18
+ end
19
+ it "can be asked for their functor" do
20
+ (:john.is_happy).functor.should == :is_happy
21
+ (:is_happy%1).functor.should == :%
22
+ (A%1).functor.should == :%
23
+ (:john.likes :drinking.in :bar).functor.should == :likes
24
+ end
25
+ it "can be indexed" do
26
+ (:john.is_happy)[0].should == :john
27
+ (:john.likes :beer)[0].should == :john
28
+ (:john.likes :beer)[1].should == :beer
29
+ (:john.likes(:cold, :beer))[2].should == :beer
30
+ (:john.likes(:cold, :beer))[1..2].should == [:cold,:beer]
31
+ (:john.likes :drinking.in :bar)[1].should == (:drinking.in :bar)
32
+ end
33
+ it "can be asked for their args" do
34
+ (:john.is_happy).args.should == [:john]
35
+ (:john.likes :beer).args.should == [:john, :beer]
36
+ (:john.likes(:cold, :beer)).args.should == [:john, :cold, :beer]
37
+ (:john.likes :drinking.in :bar).args.should == [:john, :drinking.in(:bar)]
38
+ end
39
+ it "support ==" do
40
+ (:john.is_happy).should == (:john.is_happy)
41
+ (:john.is_happy).should_not be_equal(:john.is_happy)
42
+ (:john.is_happy).should_not == nil
43
+ (:john.is_happy).should_not == 9
44
+ (:john.is_happy).should_not == :john
45
+ (:john.is_happy).should_not == Rubylog
46
+ (:john.likes :drinking.in :bar).should == (:john.likes :drinking.in :bar)
47
+ end
48
+ it "support eql?" do
49
+ (:john.is_happy).should be_eql(:john.is_happy)
50
+ (:john.is_happy).should_not be_eql nil
51
+ (:john.is_happy).should_not be_eql 9
52
+ (:john.is_happy).should_not be_eql :john
53
+ (:john.is_happy).should_not be_eql Rubylog
54
+ (:john.likes :drinking.in :bar).should be_eql(:john.likes :drinking.in :bar)
55
+ end
56
+ it "support hash" do
57
+ (:john.is_happy).hash.should == (:john.is_happy).hash
58
+ (:john.likes :drinking.in :bar).hash.should ==
59
+ (:john.likes :drinking.in :bar).hash
60
+ end
61
+ it "support inspect" do
62
+ (:john.is_happy).inspect.should == ":john.is_happy"
63
+ (:john.likes :beer).inspect.should == ":john.likes(:beer)"
64
+ (:john.likes :drinking,:beer).inspect.should == ":john.likes(:drinking, :beer)"
65
+ (:john.likes :drinking.in :bar).inspect.should == ":john.likes(:drinking.in(:bar))"
66
+ end
67
+ it "can tell their arity" do
68
+ (:john.is_happy).arity.should == 1
69
+ (:john.likes :beer).arity.should == 2
70
+ (:john.likes :drinking,:beer).arity.should == 3
71
+ (:john.likes :drinking.in :bar).arity.should == 2
72
+ end
73
+ it "can tell their descriptor" do
74
+ (:john.is_happy).desc.should == [:is_happy,1]
75
+ (:john.likes :beer).desc.should == [:likes,2]
76
+ (:john.likes :drinking,:beer).desc.should == [:likes,3]
77
+ (:john.likes :drinking.in :bar).desc.should == [:likes,2]
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,25 @@
1
+ require 'rubylog'
2
+
3
+ class << Rubylog.theory
4
+ describe "variables" do
5
+ it "are undefined constants" do
6
+ [A, SomethingLong].each{|x|x.should be_kind_of Rubylog::Variable}
7
+ end
8
+
9
+ it "support ==" do
10
+ A.should == A
11
+ end
12
+
13
+ it "support eql?" do
14
+ A.should be_eql A
15
+ end
16
+
17
+ it "returns different instances" do
18
+ A.should_not be_equal A
19
+ end
20
+
21
+ specify "that start with ANY... are dont care" do
22
+ [ANY, ANYTHING, ANYTIME].each{|x|x.should be_kind_of Rubylog::Variable; x.should be_dont_care}
23
+ end
24
+ end
25
+ end