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/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
|
-
|
data/examples/object_oriented.rb
DELETED
data/examples/prefix.rb
DELETED
data/examples/primitives.rb
DELETED
@@ -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
|
-
|