skeem 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/lib/skeem/primitive/primitive_builder.rb +73 -0
- data/lib/skeem/version.rb +1 -1
- data/spec/skeem/interpreter_spec.rb +78 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a42694aa5f20550be636b493bcf451db3b5d70f8
|
4
|
+
data.tar.gz: a3f65ef0a724758a257fbaaf5570edf8c341ea08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afa3959e8f8e9873b08cc242954350dbf61ab0cb2296ce46175f68e70070498cc10446031b32011536e39b8f7cb9a2f7bd1977e949c98a7b541b61aae2310674
|
7
|
+
data.tar.gz: 6c07561060a42c776a14534fa117734850c3878d83c915bda6c997eab1e29cf88417d35bdaa9fa0e0071ad7c3ac5aef38759ee7e0855aeaf2e774cd6fa810959
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
+
## [0.0.11] - 2018-09-16
|
2
|
+
Added primitive procedures: `=`, `<`, `>`, `>=`, `<=`
|
3
|
+
|
4
|
+
### Added
|
5
|
+
- Class `PrimitiveBuilder`. Added methods to implement the comparison operators `=`, `<`, `>`, `>=`, `<=`
|
6
|
+
- File `interpreter_spec.rb` added tests for `<`, `>`, `>=`, `<=`
|
7
|
+
|
1
8
|
## [0.0.10] - 2018-09-15
|
2
9
|
Added primitive procedures: 'boolean?', 'string?', 'symbol?', and 'not'
|
3
10
|
|
4
11
|
### Added
|
5
12
|
- Class `PrimitiveBuilder`. Added methods to implement the predicates 'boolean?', 'string?', 'symbol?', and 'not'
|
6
|
-
- File `interpreter_spec.rb`
|
13
|
+
- File `interpreter_spec.rb` added tests for 'boolean?', 'string?', 'symbol?'
|
7
14
|
|
8
15
|
### Changed
|
9
16
|
- Class hierarchy `SExprElement`. Prefix `SExpr` in class names changed into 'Skm'
|
@@ -5,6 +5,7 @@ module Skeem
|
|
5
5
|
module PrimitiveBuilder
|
6
6
|
def add_primitives(aRuntime)
|
7
7
|
add_arithmetic(aRuntime)
|
8
|
+
add_comparison(aRuntime)
|
8
9
|
add_number_predicates(aRuntime)
|
9
10
|
add_boolean_procedures(aRuntime)
|
10
11
|
add_string_procedures(aRuntime)
|
@@ -20,6 +21,14 @@ module Skeem
|
|
20
21
|
def_procedure(aRuntime, create_divide)
|
21
22
|
end
|
22
23
|
|
24
|
+
def add_comparison(aRuntime)
|
25
|
+
def_procedure(aRuntime, create_equal)
|
26
|
+
def_procedure(aRuntime, create_lt)
|
27
|
+
def_procedure(aRuntime, create_gt)
|
28
|
+
def_procedure(aRuntime, create_lte)
|
29
|
+
def_procedure(aRuntime, create_gte)
|
30
|
+
end
|
31
|
+
|
23
32
|
def add_number_predicates(aRuntime)
|
24
33
|
def_procedure(aRuntime, create_number?)
|
25
34
|
def_procedure(aRuntime, create_real?)
|
@@ -91,6 +100,70 @@ module Skeem
|
|
91
100
|
['/', divide_code]
|
92
101
|
end
|
93
102
|
|
103
|
+
def create_equal
|
104
|
+
equal_code = ->(runtime, arglist) do
|
105
|
+
first_one = arglist.head.evaluate(runtime)
|
106
|
+
operands = arglist.tail.to_eval_enum(runtime)
|
107
|
+
first_value = first_one.value
|
108
|
+
all_equal = operands.all? { |elem| first_value == elem.value }
|
109
|
+
to_skm(all_equal)
|
110
|
+
end
|
111
|
+
|
112
|
+
['=', equal_code]
|
113
|
+
end
|
114
|
+
|
115
|
+
def create_lt
|
116
|
+
lt_code = ->(runtime, arglist) do
|
117
|
+
operands = arglist.to_eval_enum(runtime)
|
118
|
+
result = true
|
119
|
+
operands.each_cons(2) do |(elem1, elem2)|
|
120
|
+
result &&= elem1.value < elem2.value
|
121
|
+
end
|
122
|
+
to_skm(result)
|
123
|
+
end
|
124
|
+
|
125
|
+
['<', lt_code]
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_gt
|
129
|
+
gt_code = ->(runtime, arglist) do
|
130
|
+
operands = arglist.to_eval_enum(runtime)
|
131
|
+
result = true
|
132
|
+
operands.each_cons(2) do |(elem1, elem2)|
|
133
|
+
result &&= elem1.value > elem2.value
|
134
|
+
end
|
135
|
+
to_skm(result)
|
136
|
+
end
|
137
|
+
|
138
|
+
['>', gt_code]
|
139
|
+
end
|
140
|
+
|
141
|
+
def create_lte
|
142
|
+
lte_code = ->(runtime, arglist) do
|
143
|
+
operands = arglist.to_eval_enum(runtime)
|
144
|
+
result = true
|
145
|
+
operands.each_cons(2) do |(elem1, elem2)|
|
146
|
+
result &&= elem1.value <= elem2.value
|
147
|
+
end
|
148
|
+
to_skm(result)
|
149
|
+
end
|
150
|
+
|
151
|
+
['<=', lte_code]
|
152
|
+
end
|
153
|
+
|
154
|
+
def create_gte
|
155
|
+
gte_code = ->(runtime, arglist) do
|
156
|
+
operands = arglist.to_eval_enum(runtime)
|
157
|
+
result = true
|
158
|
+
operands.each_cons(2) do |(elem1, elem2)|
|
159
|
+
result &&= elem1.value >= elem2.value
|
160
|
+
end
|
161
|
+
to_skm(result)
|
162
|
+
end
|
163
|
+
|
164
|
+
['>=', gte_code]
|
165
|
+
end
|
166
|
+
|
94
167
|
def create_number?()
|
95
168
|
pred_code = ->(runtime, arg) do
|
96
169
|
arg_evaluated = arg.evaluate(runtime)
|
data/lib/skeem/version.rb
CHANGED
@@ -102,7 +102,7 @@ module Skeem
|
|
102
102
|
expect(result).to be_kind_of(SkmReal)
|
103
103
|
expect(result.value).to eq(4.34)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it 'should implement the negation of integer' do
|
107
107
|
result = subject.run('(- 3)')
|
108
108
|
expect(result).to be_kind_of(SkmInteger)
|
@@ -113,11 +113,11 @@ module Skeem
|
|
113
113
|
result = subject.run('(- 3 4)')
|
114
114
|
expect(result).to be_kind_of(SkmInteger)
|
115
115
|
expect(result.value).to eq(-1)
|
116
|
-
|
116
|
+
|
117
117
|
result = subject.run('(- 3 4 5)')
|
118
118
|
expect(result).to be_kind_of(SkmInteger)
|
119
|
-
expect(result.value).to eq(-6)
|
120
|
-
end
|
119
|
+
expect(result.value).to eq(-6)
|
120
|
+
end
|
121
121
|
|
122
122
|
it 'should implement the product of numbers' do
|
123
123
|
result = subject.run('(* 2 3 4)')
|
@@ -136,7 +136,79 @@ module Skeem
|
|
136
136
|
expect(result).to be_kind_of(SkmInteger)
|
137
137
|
expect(result.value).to eq(210)
|
138
138
|
end
|
139
|
+
|
140
|
+
it 'should implement the equality operator' do
|
141
|
+
checks = [
|
142
|
+
['(= 3 3)', true],
|
143
|
+
['(= 3 (+ 1 2) (- 4 1))', true],
|
144
|
+
['(= "foo" "foo")', true],
|
145
|
+
['(= 3 4)', false],
|
146
|
+
['(= "foo" "bar")', false]
|
147
|
+
]
|
148
|
+
checks.each do |(skeem_expr, expectation)|
|
149
|
+
result = subject.run(skeem_expr)
|
150
|
+
expect(result.value).to eq(expectation)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should implement the less than operator' do
|
155
|
+
checks = [
|
156
|
+
['(< 3 4)', true],
|
157
|
+
['(< 3 (+ 2 2) (+ 4 1))', true],
|
158
|
+
['(< 3 3)', false],
|
159
|
+
['(< 3 2)', false],
|
160
|
+
['(< 3 4 5 4)', false]
|
161
|
+
]
|
162
|
+
checks.each do |(skeem_expr, expectation)|
|
163
|
+
result = subject.run(skeem_expr)
|
164
|
+
expect(result.value).to eq(expectation)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should implement the greater than operator' do
|
169
|
+
checks = [
|
170
|
+
['(> 3 2)', true],
|
171
|
+
['(> 3 (- 4 2) (- 2 1))', true],
|
172
|
+
['(> 3 3)', false],
|
173
|
+
['(> 3 4)', false],
|
174
|
+
['(> 3 2 1 2)', false]
|
175
|
+
]
|
176
|
+
checks.each do |(skeem_expr, expectation)|
|
177
|
+
result = subject.run(skeem_expr)
|
178
|
+
expect(result.value).to eq(expectation)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should implement the less or equal than operator' do
|
183
|
+
checks = [
|
184
|
+
['(<= 3 4)', true],
|
185
|
+
['(<= 3 (+ 2 2) (+ 4 1))', true],
|
186
|
+
['(<= 3 3)', true],
|
187
|
+
['(<= 3 2)', false],
|
188
|
+
['(<= 3 4 5 4)', false],
|
189
|
+
['(<= 3 4 5 5)', true]
|
190
|
+
]
|
191
|
+
checks.each do |(skeem_expr, expectation)|
|
192
|
+
result = subject.run(skeem_expr)
|
193
|
+
expect(result.value).to eq(expectation)
|
194
|
+
end
|
195
|
+
end
|
139
196
|
|
197
|
+
it 'should implement the greater or equal than operator' do
|
198
|
+
checks = [
|
199
|
+
['(>= 3 2)', true],
|
200
|
+
['(>= 3 (- 4 2) (- 2 1))', true],
|
201
|
+
['(>= 3 3)', true],
|
202
|
+
['(>= 3 4)', false],
|
203
|
+
['(>= 3 2 1 2)', false],
|
204
|
+
['(>= 3 2 1 1)', true]
|
205
|
+
]
|
206
|
+
checks.each do |(skeem_expr, expectation)|
|
207
|
+
result = subject.run(skeem_expr)
|
208
|
+
expect(result.value).to eq(expectation)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
140
212
|
it 'should implement the number? predicate' do
|
141
213
|
checks = [
|
142
214
|
['(number? 3.1)', true],
|
@@ -149,7 +221,7 @@ module Skeem
|
|
149
221
|
expect(result.value).to eq(expectation)
|
150
222
|
end
|
151
223
|
end
|
152
|
-
|
224
|
+
|
153
225
|
it 'should implement the real? predicate' do
|
154
226
|
checks = [
|
155
227
|
['(real? 3.1)', true],
|
@@ -221,7 +293,7 @@ module Skeem
|
|
221
293
|
result = subject.run(skeem_expr)
|
222
294
|
expect(result.value).to eq(expectation)
|
223
295
|
end
|
224
|
-
end
|
296
|
+
end
|
225
297
|
end # context
|
226
298
|
end # describe
|
227
299
|
end # module
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skeem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|