mini_kraken 0.1.01 → 0.1.02

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +0 -3
  4. data/lib/mini_kraken/core/any_value.rb +29 -0
  5. data/lib/mini_kraken/core/association.rb +21 -0
  6. data/lib/mini_kraken/core/association_walker.rb +179 -0
  7. data/lib/mini_kraken/core/atomic_term.rb +64 -0
  8. data/lib/mini_kraken/core/binary_relation.rb +61 -0
  9. data/lib/mini_kraken/core/composite_term.rb +54 -0
  10. data/lib/mini_kraken/core/cons_cell.rb +44 -0
  11. data/lib/mini_kraken/core/duck_fiber.rb +44 -0
  12. data/lib/mini_kraken/core/environment.rb +59 -0
  13. data/lib/mini_kraken/core/equals.rb +216 -0
  14. data/lib/mini_kraken/core/fail.rb +8 -5
  15. data/lib/mini_kraken/core/freshness.rb +42 -0
  16. data/lib/mini_kraken/core/goal.rb +31 -6
  17. data/lib/mini_kraken/core/k_integer.rb +15 -0
  18. data/lib/mini_kraken/core/k_symbol.rb +15 -0
  19. data/lib/mini_kraken/core/nullary_relation.rb +11 -3
  20. data/lib/mini_kraken/core/outcome.rb +35 -0
  21. data/lib/mini_kraken/core/relation.rb +31 -4
  22. data/lib/mini_kraken/core/succeed.rb +13 -1
  23. data/lib/mini_kraken/core/term.rb +7 -0
  24. data/lib/mini_kraken/core/variable.rb +45 -3
  25. data/lib/mini_kraken/core/variable_ref.rb +76 -0
  26. data/lib/mini_kraken/core/vocabulary.rb +161 -0
  27. data/lib/mini_kraken/glue/fresh_env.rb +31 -0
  28. data/lib/mini_kraken/glue/run_star_expression.rb +43 -0
  29. data/lib/mini_kraken/version.rb +1 -1
  30. data/spec/core/association_spec.rb +38 -0
  31. data/spec/core/association_walker_spec.rb +191 -0
  32. data/spec/core/cons_cell_spec.rb +63 -0
  33. data/spec/core/duck_fiber_spec.rb +62 -0
  34. data/spec/core/environment_spec.rb +154 -0
  35. data/spec/core/equals_spec.rb +289 -0
  36. data/spec/core/fail_spec.rb +16 -0
  37. data/spec/core/goal_spec.rb +36 -10
  38. data/spec/core/k_symbol_spec.rb +72 -0
  39. data/spec/core/succeed_spec.rb +43 -0
  40. data/spec/core/variable_ref_spec.rb +31 -0
  41. data/spec/core/variable_spec.rb +11 -3
  42. data/spec/core/vocabulary_spec.rb +188 -0
  43. data/spec/glue/fresh_env_spec.rb +36 -0
  44. data/spec/glue/run_star_expression_spec.rb +247 -0
  45. data/spec/support/factory_methods.rb +54 -0
  46. metadata +46 -13
  47. data/lib/mini_kraken/core/facade.rb +0 -45
  48. data/lib/mini_kraken/core/formal_arg.rb +0 -6
  49. data/lib/mini_kraken/core/publisher.rb +0 -27
  50. data/lib/mini_kraken/core/run_star_expression.rb +0 -34
  51. data/lib/mini_kraken/dsl/kraken_dsl.rb +0 -12
  52. data/spec/core/facade_spec.rb +0 -38
  53. data/spec/core/run_star_expression_spec.rb +0 -43
  54. data/spec/dsl/kraken_dsl_spec.rb +0 -31
@@ -0,0 +1,54 @@
1
+ require_relative '../../lib/mini_kraken/core/any_value'
2
+ require_relative '../../lib/mini_kraken/core/cons_cell'
3
+ require_relative '../../lib/mini_kraken/core/k_symbol'
4
+ require_relative '../../lib/mini_kraken/core/variable'
5
+ require_relative '../../lib/mini_kraken/core/variable_ref'
6
+
7
+ module MiniKraken
8
+ # Mix-in module that provides convenience factory methods.
9
+ module FactoryMethods
10
+ # Factory method for constructing an AnyValue instance
11
+ # @param rank [Integer]
12
+ # @return [Core::AnyValue]
13
+ def any_value(rank)
14
+ Core::AnyValue.new(rank)
15
+ end
16
+
17
+ # Factory method for constructing a ConsCell
18
+ # @param obj1 [Term]
19
+ # @param obj2 [Term]
20
+ # @return [Core::ConsCell]
21
+ def cons(obj1, obj2 = nil)
22
+ Core::ConsCell.new(obj1, obj2)
23
+ end
24
+
25
+ # Factory method for constructing a goal using the Equals relation.
26
+ # @param arg1 [Term]
27
+ # @param arg2 [Term]
28
+ # @return [Core::Goal]
29
+ def equals_goal(arg1, arg2)
30
+ Core::Goal.new(Core::Equals.instance, [arg1, arg2])
31
+ end
32
+
33
+ # Factory method for constructing a KSymbol instance
34
+ # @param aSymbol [Symbol]
35
+ # @return [Core::KSymbol]
36
+ def k_symbol(aSymbol)
37
+ Core::KSymbol.new(aSymbol)
38
+ end
39
+
40
+ # Factory method for constructing a Variable
41
+ # @param var_name [String]
42
+ # @return [Core::Variable]
43
+ def var_ref(var_name)
44
+ Core::Variable.new(var_name)
45
+ end
46
+
47
+ # Factory method for constructing a VariableRef
48
+ # @param var_name [String]
49
+ # @return [Core::VariableRef]
50
+ def var_ref(var_name)
51
+ Core::VariableRef.new(var_name)
52
+ end
53
+ end # end
54
+ end # module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_kraken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.01
4
+ version: 0.1.02
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,27 +68,51 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/mini_kraken.rb
71
- - lib/mini_kraken/core/facade.rb
71
+ - lib/mini_kraken/core/any_value.rb
72
+ - lib/mini_kraken/core/association.rb
73
+ - lib/mini_kraken/core/association_walker.rb
74
+ - lib/mini_kraken/core/atomic_term.rb
75
+ - lib/mini_kraken/core/binary_relation.rb
76
+ - lib/mini_kraken/core/composite_term.rb
77
+ - lib/mini_kraken/core/cons_cell.rb
78
+ - lib/mini_kraken/core/duck_fiber.rb
79
+ - lib/mini_kraken/core/environment.rb
80
+ - lib/mini_kraken/core/equals.rb
72
81
  - lib/mini_kraken/core/fail.rb
73
- - lib/mini_kraken/core/formal_arg.rb
82
+ - lib/mini_kraken/core/freshness.rb
74
83
  - lib/mini_kraken/core/goal.rb
84
+ - lib/mini_kraken/core/k_integer.rb
85
+ - lib/mini_kraken/core/k_symbol.rb
75
86
  - lib/mini_kraken/core/nullary_relation.rb
76
- - lib/mini_kraken/core/publisher.rb
87
+ - lib/mini_kraken/core/outcome.rb
77
88
  - lib/mini_kraken/core/relation.rb
78
- - lib/mini_kraken/core/run_star_expression.rb
79
89
  - lib/mini_kraken/core/succeed.rb
90
+ - lib/mini_kraken/core/term.rb
80
91
  - lib/mini_kraken/core/variable.rb
81
- - lib/mini_kraken/dsl/kraken_dsl.rb
92
+ - lib/mini_kraken/core/variable_ref.rb
93
+ - lib/mini_kraken/core/vocabulary.rb
94
+ - lib/mini_kraken/glue/fresh_env.rb
95
+ - lib/mini_kraken/glue/run_star_expression.rb
82
96
  - lib/mini_kraken/version.rb
83
97
  - mini_kraken.gemspec
84
- - spec/core/facade_spec.rb
98
+ - spec/core/association_spec.rb
99
+ - spec/core/association_walker_spec.rb
100
+ - spec/core/cons_cell_spec.rb
101
+ - spec/core/duck_fiber_spec.rb
102
+ - spec/core/environment_spec.rb
103
+ - spec/core/equals_spec.rb
85
104
  - spec/core/fail_spec.rb
86
105
  - spec/core/goal_spec.rb
87
- - spec/core/run_star_expression_spec.rb
106
+ - spec/core/k_symbol_spec.rb
107
+ - spec/core/succeed_spec.rb
108
+ - spec/core/variable_ref_spec.rb
88
109
  - spec/core/variable_spec.rb
89
- - spec/dsl/kraken_dsl_spec.rb
110
+ - spec/core/vocabulary_spec.rb
111
+ - spec/glue/fresh_env_spec.rb
112
+ - spec/glue/run_star_expression_spec.rb
90
113
  - spec/mini_kraken_spec.rb
91
114
  - spec/spec_helper.rb
115
+ - spec/support/factory_methods.rb
92
116
  homepage: https://github.com/famished-tiger/mini_kraken
93
117
  licenses:
94
118
  - MIT
@@ -114,10 +138,19 @@ signing_key:
114
138
  specification_version: 4
115
139
  summary: Implementation of Minikanren language in Ruby. WIP
116
140
  test_files:
117
- - spec/core/facade_spec.rb
141
+ - spec/core/association_spec.rb
142
+ - spec/core/association_walker_spec.rb
143
+ - spec/core/cons_cell_spec.rb
144
+ - spec/core/duck_fiber_spec.rb
145
+ - spec/core/environment_spec.rb
146
+ - spec/core/equals_spec.rb
118
147
  - spec/core/fail_spec.rb
119
148
  - spec/core/goal_spec.rb
120
- - spec/core/run_star_expression_spec.rb
149
+ - spec/core/k_symbol_spec.rb
150
+ - spec/core/succeed_spec.rb
151
+ - spec/core/variable_ref_spec.rb
121
152
  - spec/core/variable_spec.rb
122
- - spec/dsl/kraken_dsl_spec.rb
153
+ - spec/core/vocabulary_spec.rb
154
+ - spec/glue/fresh_env_spec.rb
155
+ - spec/glue/run_star_expression_spec.rb
123
156
  - spec/mini_kraken_spec.rb
@@ -1,45 +0,0 @@
1
- require_relative 'variable'
2
- require_relative 'run_star_expression'
3
-
4
- module MiniKraken
5
- module Core
6
- class Facade
7
- attr_reader :publisher
8
- def initialize(aPublisher)
9
- @publisher = aPublisher
10
- end
11
-
12
- def run_star(theVariables, aGoal)
13
- tuple = build_tuple(theVariables)
14
-
15
- expr = RunStarExpression.new(tuple, aGoal)
16
- expr.run(publisher)
17
- end
18
-
19
- private
20
-
21
- def build_tuple(theVariables)
22
- tuple = nil
23
- if theVariables.kind_of?(Array)
24
- tuple = theVariables.map { |v| build_single_var(v) }
25
- else
26
- tuple = [build_single_var(theVariables)]
27
- end
28
-
29
- tuple
30
- end
31
-
32
- def build_single_var(aVar)
33
- var = nil
34
- case aVar
35
- when Symbol
36
- var = Variable.new(aVar.to_s)
37
- when String
38
- var = Variable.new(aVar)
39
- end
40
-
41
- var
42
- end
43
- end # class
44
- end # module
45
- end # module
@@ -1,6 +0,0 @@
1
- module MiniKraken
2
- module Core
3
- class FormalArg
4
- end # class
5
- end # module
6
- end # module
@@ -1,27 +0,0 @@
1
- module MiniKraken
2
- module Core
3
- class Publisher
4
- attr_reader :subscribers
5
-
6
- def initialize
7
- @subscribers = []
8
- end
9
-
10
- def subscribe(aListener)
11
- @subscribers << aListener
12
- end
13
-
14
- def broadcast_entry(aGoal, variables)
15
- subscribers.each do |subscr|
16
- subscr.on_entry(aGoal, variables)
17
- end
18
- end
19
-
20
- def broadcast_exit(aGoal, variables, outcome)
21
- subscribers.each do |subscr|
22
- subscr.on_exit(aGoal, variables, outcome)
23
- end
24
- end
25
- end # class
26
- end # module
27
- end # module
@@ -1,34 +0,0 @@
1
- module MiniKraken
2
- module Core
3
- class RunStarExpression
4
- attr_reader :vars
5
- attr_reader :goal
6
-
7
- def initialize(theVariables, aGoal)
8
- @vars = validated_vars(theVariables)
9
- @goal = aGoal
10
- end
11
-
12
- def run(aPublisher)
13
- goal.attain(aPublisher, vars)
14
- end
15
-
16
- private
17
-
18
- def validated_vars(theVariables)
19
- variables = {}
20
- case theVariables
21
- when Variable
22
- variables[theVariables.name] = theVariables
23
-
24
- when Array
25
- theVariables.each { |v| variables[v.name] = v }
26
- else
27
- raise StandardError, "Invalid argument #{p theVariables}"
28
- end
29
-
30
- variables
31
- end
32
- end # class
33
- end # module
34
- end # module
@@ -1,12 +0,0 @@
1
- require_relative '../core/fail'
2
- require_relative '../core/goal'
3
-
4
- module MiniKraken
5
- module DSL
6
- module KrakenDSL
7
- def fail
8
- Core::Goal.new(Core::Fail.instance, [])
9
- end
10
- end # module
11
- end # module
12
- end # module
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
-
5
- require_relative '../../lib/mini_kraken/core/fail'
6
- require_relative '../../lib/mini_kraken/core/goal'
7
- require_relative '../../lib/mini_kraken/core/publisher'
8
- require_relative '../../lib/mini_kraken/dsl/kraken_dsl'
9
- # Load the class under test
10
- require_relative '../../lib/mini_kraken/core/facade'
11
-
12
- module MiniKraken
13
- module Core
14
- describe Facade do
15
- include DSL::KrakenDSL
16
-
17
- let(:a_pub) { Publisher.new }
18
- let(:a_relation) { Fail.instance }
19
- subject { Facade.new(a_pub) }
20
-
21
- context 'Initialization:' do
22
- it 'could have one publisher argument' do
23
- expect { Facade.new(a_pub) }.not_to raise_error
24
- end
25
-
26
- it 'should know its publisher' do
27
- expect(subject.publisher).to eq(a_pub)
28
- end
29
- end # context
30
-
31
- context 'Provided services:' do
32
- it 'should support run* expression' do
33
- expect(subject.run_star('q', fail)).to be_empty
34
- end
35
- end # context
36
- end # describe
37
- end # module
38
- end # module
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
-
5
- require_relative '../../lib/mini_kraken/core/variable'
6
- require_relative '../../lib/mini_kraken/core/fail'
7
- require_relative '../../lib/mini_kraken/core/goal'
8
- # Load the class under test
9
- require_relative '../../lib/mini_kraken/core/run_star_expression'
10
-
11
- module MiniKraken
12
- module Core
13
- describe RunStarExpression do
14
- let(:a_var) { Variable.new('q') }
15
- let(:a_relation) { Fail.instance }
16
- let(:a_goal) { Goal.new(a_relation, []) }
17
- subject { RunStarExpression.new(a_var, a_goal) }
18
-
19
- context 'Initialization:' do
20
- it 'could have one variable and a goal' do
21
- expect { RunStarExpression.new(a_var, a_goal) }.not_to raise_error
22
- end
23
-
24
- it 'should know its variables' do
25
- expect(subject.vars['q']).to eq(a_var)
26
- end
27
-
28
- it 'should know its goal' do
29
- expect(subject.goal).to eq(a_goal)
30
- end
31
- end # context
32
-
33
- context 'Provided services:' do
34
- it 'should unify the variable(s) with the given goal' do
35
- pub = double('fake-publisher')
36
- expect(pub).to receive(:broadcast_entry).with(a_goal, subject.vars)
37
- expect(pub).to receive(:broadcast_exit).with(a_goal, subject.vars, [])
38
- expect(subject.run(pub)).to be_empty
39
- end
40
- end # context
41
- end # describe
42
- end # module
43
- end # module
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../spec_helper' # Use the RSpec framework
4
-
5
- # Load the class under test
6
- require_relative '../../lib/mini_kraken/dsl/kraken_dsl'
7
-
8
- module MiniKraken
9
- module DSL
10
- describe KrakenDSL do
11
- subject do
12
- obj = Object.new
13
- obj.extend(KrakenDSL)
14
- end
15
-
16
- context 'Attaching mix-in:' do
17
- it 'should extend object' do
18
- obj = Object.new
19
- expect { obj.extend(KrakenDSL) }.not_to raise_error
20
- end
21
- end # context
22
-
23
- context 'Provided services:' do
24
- it "should provide the 'fail' goal constructor" do
25
- expect(subject.fail).to be_kind_of(Core::Goal)
26
- expect(subject.fail.relation.name).to eq('fail')
27
- end
28
- end # context
29
- end # describe
30
- end # module
31
- end # module