rubylog 2.0.1 → 2.1.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 (81) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +10 -0
  3. data/README.rdoc +1 -1
  4. data/RELEASE_NOTES.rdoc +7 -4
  5. data/VERSION +1 -1
  6. data/{examples → benchmark}/benchmark.rb +1 -0
  7. data/{examples → benchmark}/benchmark/compiled_not_indexed.rb +0 -0
  8. data/{examples → benchmark}/benchmark/compiled_sequence_indexed.rb +0 -0
  9. data/{examples → benchmark}/benchmark/indexed_procedure.rb +0 -0
  10. data/{examples → benchmark}/benchmark/prolog.rb +0 -0
  11. data/benchmark/benchmark/pure.rb +28 -0
  12. data/bin/rubylog +14 -0
  13. data/examples/a_plus_b.rb +2 -2
  14. data/examples/dcg.rb +22 -26
  15. data/examples/dcg2.rb +25 -30
  16. data/examples/divisors.rb +1 -3
  17. data/examples/factorial.rb +8 -15
  18. data/examples/file_search.rb +14 -13
  19. data/examples/hanoi.rb +1 -3
  20. data/examples/hu/csaladfa.rb +0 -4
  21. data/examples/n_queens.rb +17 -22
  22. data/examples/palindrome_detection.rb +1 -2
  23. data/examples/parsing.rb +19 -23
  24. data/examples/permutation.rb +1 -3
  25. data/examples/primality_by_division.rb +2 -2
  26. data/examples/sieve_of_eratosthenes.rb +2 -2
  27. data/examples/string_interpolation.rb +0 -3
  28. data/examples/tracing.rb +0 -4
  29. data/lib/rubylog/builtins/assumption.rb +2 -1
  30. data/lib/rubylog/builtins/file_system.rb +1 -1
  31. data/lib/rubylog/default_context.rb +3 -5
  32. data/lib/rubylog/mixins/kernel.rb +9 -1
  33. data/lib/rubylog/rubylog_files.rb +7 -0
  34. data/rubylog.gemspec +17 -22
  35. data/spec/inriasuite_spec.rb +851 -847
  36. data/spec/integration/dsl_spec.rb +32 -29
  37. data/spec/rspec/rubylog_spec.rb +46 -52
  38. data/spec/rubylog/assertable_spec.rb +92 -90
  39. data/spec/rubylog/builtins/arithmetics_spec.rb +92 -90
  40. data/spec/rubylog/builtins/assumption_spec.rb +59 -57
  41. data/spec/rubylog/builtins/ensure_spec.rb +6 -4
  42. data/spec/rubylog/builtins/file_system_spec.rb +41 -39
  43. data/spec/rubylog/builtins/logic_spec.rb +308 -306
  44. data/spec/rubylog/builtins/reflection_spec.rb +31 -29
  45. data/spec/rubylog/builtins/term_spec.rb +62 -60
  46. data/spec/rubylog/context_modules/demonstration_spec.rb +108 -106
  47. data/spec/rubylog/context_modules/predicates_spec.rb +29 -27
  48. data/spec/rubylog/context_modules/thats_spec.rb +77 -75
  49. data/spec/rubylog/dsl/array_splat_spec.rb +11 -9
  50. data/spec/rubylog/dsl/indicators_spec.rb +23 -21
  51. data/spec/rubylog/dsl/primitives_spec.rb +30 -28
  52. data/spec/rubylog/errors_spec.rb +13 -11
  53. data/spec/rubylog/interfaces/term_spec.rb +78 -76
  54. data/spec/rubylog/mixins/array_spec.rb +60 -58
  55. data/spec/rubylog/mixins/composite_term_spec.rb +55 -53
  56. data/spec/rubylog/mixins/proc_spec.rb +48 -46
  57. data/spec/rubylog/mixins/string_spec.rb +45 -43
  58. data/spec/rubylog/mixins/symbol_spec.rb +7 -5
  59. data/spec/rubylog/procedure_spec.rb +8 -6
  60. data/spec/rubylog/rule_spec.rb +10 -8
  61. data/spec/rubylog/structure_spec.rb +73 -71
  62. data/spec/rubylog/term_spec.rb +5 -3
  63. data/spec/rubylog/tracing_spec.rb +35 -33
  64. data/spec/rubylog/variable_spec.rb +249 -247
  65. data/spec/spec_helper.rb +4 -0
  66. metadata +54 -43
  67. data/examples/benchmark/pure.rb +0 -26
  68. data/examples/checkmate.rb +0 -88
  69. data/examples/combination.rb +0 -17
  70. data/examples/directory_structure_logic.rb +0 -17
  71. data/examples/dirlist.rb +0 -4
  72. data/examples/enumerators.rb +0 -30
  73. data/examples/hello.rb +0 -17
  74. data/examples/mice.rb +0 -92
  75. data/examples/mice2.rb +0 -37
  76. data/examples/object_oriented.rb +0 -14
  77. data/examples/prefix.rb +0 -13
  78. data/examples/primitives.rb +0 -26
  79. data/examples/sudoku.rb +0 -17
  80. data/spec/integration/theory_as_module_spec.rb +0 -20
  81. data/spec/integration/theory_as_module_with_include_spec.rb +0 -14
data/examples/mice2.rb DELETED
@@ -1,37 +0,0 @@
1
- require "rubylog"
2
- extend Rubylog::Context
3
-
4
- predicate_for Rubylog::Variable, ".bound"
5
- A.bound.if { A.is_a? Rubylog::Variable }
6
-
7
- class Array
8
- extend Rubylog::Context
9
-
10
- predicate ".can_have_neighbours"
11
- [*ANY,:yes,:yes,*ANY].can_have_neighbours!
12
-
13
- predicate ".has_neighbours"
14
- [*ANY,A,B,*ANY].has_neighbours.if { A == :yes && B == :yes}
15
-
16
- predicate ".cannot_have_neighbours"
17
- A.cannot_have_neighbours.if A.can_have_neighbours.false
18
-
19
- predicate ".decidable"
20
- A.decidable.if A.has_neighbours.or A.cannot_have_neighbours
21
-
22
-
23
- predicate ".guessed"
24
- A.guessed.if every X.in(A), X.is(:yes).or(X.is(:no)).or(:true)
25
-
26
- predicate ".easy"
27
- A.easy.if A.guessed.and A.decidable.and any X.in(A), X.bound.false
28
-
29
- Rubylog.trace
30
- N.in(0..6).each do
31
- puts "#{N}: #{([ANY]*N).easy?}"
32
- end
33
-
34
- end
35
-
36
-
37
-
@@ -1,14 +0,0 @@
1
- $:.unshift File.dirname(__FILE__)+"/../lib"
2
- require "rubylog"
3
-
4
- class User
5
- extend Rubylog::Context
6
- predicate_for self, ".user", ".admin"
7
-
8
- def initialize admin=false
9
- self.user!
10
- self.admin! if admin
11
- end
12
- end
13
-
14
-
data/examples/prefix.rb DELETED
@@ -1,13 +0,0 @@
1
- require "rubylog"
2
- extend Rubylog::Context
3
-
4
- predicate_for Kernel, ".hello()"
5
-
6
- hello!(2)
7
- hello(5).if { puts "Hello" }
8
-
9
- hello?(5)
10
-
11
- check hello(2)
12
- check hello(4).false
13
-
@@ -1,26 +0,0 @@
1
- $:.unshift File.dirname(__FILE__)+"/../lib"
2
- require 'rubylog'
3
-
4
- Try = Rubylog.create_context
5
- Try.instance_eval do
6
- predicate ":hello_world"
7
-
8
- def primitives.hello
9
- puts "Hello"
10
- yield
11
- end
12
-
13
- class << primitives_for(String)
14
- def hello x
15
- puts "Hello #{x.rubylog_deep_dereference}!"
16
- yield
17
- end
18
- end
19
-
20
- :hello_world.if "World".hello
21
-
22
- end
23
-
24
-
25
- p Try.true? :hello
26
- p Try.true? :hello_world
data/examples/sudoku.rb DELETED
@@ -1,17 +0,0 @@
1
- $:.unshift File.dirname(__FILE__)+"/../lib"
2
- require "rubylog"
3
-
4
- def blocks_of s
5
- (0..2).map {|a| (0..2).map {|b| (0..2).map {|c| (0..2).map {|d|
6
- s[a*3+c][b*3+d]
7
- }}.flatten(1) }}.flatten(1)
8
- end
9
-
10
- predicate_for Array, ".sudoku .row_unique .col_unique .block_unique .unique"
11
-
12
- S.sudoku.if S.is([[ANY]*9]*9).and S.row_unique.and S.col_unique.and S.block_unique.and every(ROW.in(S).and(X.in(ROW)), X.in(1..9))
13
-
14
- S.row_unique.if every ROW.in(S), ROW.unique
15
- S.col_unique.if every COL.in{S.transpose}, COL.unique
16
- S.col_unique.if every BLOCK.in{blocks_of(S)}, BLOCK.unique
17
-
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- extend Rubylog::Context
4
-
5
- predicate_for Integer, %w(.divides())
6
-
7
- (A[thats > 0].divides B[thats > 0]).if { B%A == 0 }
8
-
9
- (N.is 210).solve do
10
-
11
- (I.in [1, 2, 3, 5, 6, 7, 10, 14, 15, 21, 30, 35, 42, 70, 105, 210]).each do
12
- check(I.divides N)
13
- end
14
-
15
- (I.in [4, 8, 9, 11, 12, 20, 31]).each do
16
- check( (I.divides N).false )
17
- end
18
-
19
- end
20
-
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
-
3
- class MyClass
4
- include Rubylog::Context
5
- end
6
-
7
- a=MyClass.new
8
-
9
- a.instance_eval do
10
- predicate_for Integer, %w(.divides())
11
- (N.divides M).if { M%N == 0 }
12
-
13
- check 23.divides(230)
14
- end