skeem 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/skeem/primitive/primitive_builder.rb +39 -0
- data/lib/skeem/s_expr_nodes.rb +22 -3
- data/lib/skeem/version.rb +1 -1
- data/spec/skeem/interpreter_spec.rb +1 -1
- data/spec/skeem/primitive/primitive_builder_spec.rb +45 -0
- 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: 9cb4724d17594667921a2ccd39d5c39891edf55b
|
4
|
+
data.tar.gz: e5ac55b88a2c71fb84e5752881e11c36546e5c98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70733db86074f7828e19bfb069f957372bfc10e95d2fa0d85484de418b147d6392ff357f533977d6d10db4fa08a29372f916274dd2d192fa6bdd8887561f608
|
7
|
+
data.tar.gz: 5ed2a9db63d57adb2d93cb1c99d4b5d40a452f5174531d3c06522c80c6f1914c34fd4e97ca02059e3c733a227d3dfb22c9eeba363b01dadb7d75786ad90f3c48
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## [0.0.19] - 2018-10-15
|
2
|
+
Added primitive procedures `list?`, `null?`, `length`
|
3
|
+
|
4
|
+
### Added
|
5
|
+
- File `primitive_builder.rb` implementation of: `list?`, `null?`, `length` procedures.
|
6
|
+
- File `primitive_builder_spec.rb` spec examples for: `list?`, `null?`, `length` procedures.
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- Method `SkmLambda#bind_locals` Fix: a variadic procedure with no argument provided, should have empty list as actual argument.
|
10
|
+
- File `interpreter_spec.rb` Added test case for calling `list` procedure without argument.
|
11
|
+
|
1
12
|
## [0.0.18] - 2018-10-14
|
2
13
|
Reworked procedure argument-passing.
|
3
14
|
|
@@ -12,6 +12,7 @@ module Skeem
|
|
12
12
|
add_boolean_procedures(aRuntime)
|
13
13
|
add_string_procedures(aRuntime)
|
14
14
|
add_symbol_procedures(aRuntime)
|
15
|
+
add_list_procedures(aRuntime)
|
15
16
|
add_io_procedures(aRuntime)
|
16
17
|
add_special_procedures(aRuntime)
|
17
18
|
end
|
@@ -72,6 +73,12 @@ module Skeem
|
|
72
73
|
def add_symbol_procedures(aRuntime)
|
73
74
|
create_symbol?(aRuntime)
|
74
75
|
end
|
76
|
+
|
77
|
+
def add_list_procedures(aRuntime)
|
78
|
+
create_list?(aRuntime)
|
79
|
+
create_null?(aRuntime)
|
80
|
+
create_length(aRuntime)
|
81
|
+
end
|
75
82
|
|
76
83
|
def add_io_procedures(aRuntime)(aRuntime)
|
77
84
|
create_newline(aRuntime)
|
@@ -317,6 +324,38 @@ module Skeem
|
|
317
324
|
|
318
325
|
define_primitive_proc(aRuntime, 'symbol?', unary, primitive)
|
319
326
|
end
|
327
|
+
|
328
|
+
def create_list?(aRuntime)
|
329
|
+
primitive = ->(runtime, arg) do
|
330
|
+
arg_evaluated = arg.evaluate(runtime)
|
331
|
+
to_skm(arg_evaluated.list?)
|
332
|
+
end
|
333
|
+
|
334
|
+
define_primitive_proc(aRuntime, 'list?', unary, primitive)
|
335
|
+
end
|
336
|
+
|
337
|
+
def create_null?(aRuntime)
|
338
|
+
primitive = ->(runtime, arg) do
|
339
|
+
arg_evaluated = arg.evaluate(runtime)
|
340
|
+
to_skm(arg_evaluated.null?)
|
341
|
+
end
|
342
|
+
|
343
|
+
define_primitive_proc(aRuntime, 'null?', unary, primitive)
|
344
|
+
end
|
345
|
+
|
346
|
+
def create_length(aRuntime)
|
347
|
+
primitive = ->(runtime, arg) do
|
348
|
+
arg_evaluated = arg.evaluate(runtime)
|
349
|
+
unless arg_evaluated.kind_of?(SkmList)
|
350
|
+
msg1 = "Procedure 'length': list argument required,"
|
351
|
+
msg2 = "but got #{arg_evaluated.value}"
|
352
|
+
raise StandardError, msg1 + ' ' + msg2
|
353
|
+
end
|
354
|
+
to_skm(arg_evaluated.length)
|
355
|
+
end
|
356
|
+
|
357
|
+
define_primitive_proc(aRuntime, 'length', unary, primitive)
|
358
|
+
end
|
320
359
|
|
321
360
|
def create_newline(aRuntime)
|
322
361
|
primitive = ->(runtime) do
|
data/lib/skeem/s_expr_nodes.rb
CHANGED
@@ -48,6 +48,14 @@ module Skeem
|
|
48
48
|
def symbol?
|
49
49
|
false
|
50
50
|
end
|
51
|
+
|
52
|
+
def list?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def null?
|
57
|
+
false
|
58
|
+
end
|
51
59
|
|
52
60
|
# Abstract method.
|
53
61
|
# Part of the 'visitee' role in Visitor design pattern.
|
@@ -185,6 +193,14 @@ module Skeem
|
|
185
193
|
def tail()
|
186
194
|
SkmList.new(members.slice(1..-1))
|
187
195
|
end
|
196
|
+
|
197
|
+
def list?
|
198
|
+
true
|
199
|
+
end
|
200
|
+
|
201
|
+
def null?
|
202
|
+
empty?
|
203
|
+
end
|
188
204
|
|
189
205
|
def evaluate(aRuntime)
|
190
206
|
list_evaluated = members.map { |elem| elem.evaluate(aRuntime) }
|
@@ -519,9 +535,8 @@ module Skeem
|
|
519
535
|
((count_actuals > required_arity) && !formals.variadic?)
|
520
536
|
raise StandardError, msg_arity_mismatch(aProcedureCall)
|
521
537
|
end
|
522
|
-
return if count_actuals.zero?
|
538
|
+
return if count_actuals.zero? && !formals.variadic?
|
523
539
|
bind_required_locals(aRuntime, aProcedureCall)
|
524
|
-
|
525
540
|
if formals.variadic?
|
526
541
|
variadic_part_raw = actuals.drop(required_arity)
|
527
542
|
variadic_part = variadic_part_raw.map do |actual|
|
@@ -558,7 +573,11 @@ module Skeem
|
|
558
573
|
formals.formals.each_with_index do |arg_name, index|
|
559
574
|
arg = actuals[index]
|
560
575
|
if arg.nil?
|
561
|
-
|
576
|
+
if actuals.empty? && formals.variadic?
|
577
|
+
arg = SkmList.new([])
|
578
|
+
else
|
579
|
+
raise StandardError, "Unbound variable: '#{arg_name.value}'"
|
580
|
+
end
|
562
581
|
end
|
563
582
|
|
564
583
|
# IMPORTANT: execute procedure call in argument list now
|
data/lib/skeem/version.rb
CHANGED
@@ -242,6 +242,51 @@ module Skeem
|
|
242
242
|
end
|
243
243
|
end # context
|
244
244
|
|
245
|
+
context 'List procedures:' do
|
246
|
+
it 'should implement the list? procedure' do
|
247
|
+
checks = [
|
248
|
+
['(list? #f)', false],
|
249
|
+
['(list? 1)', false],
|
250
|
+
['(list? "bar")', false],
|
251
|
+
['(list? (list 1 2 3))', true],
|
252
|
+
['(list? (list))', true]
|
253
|
+
]
|
254
|
+
checks.each do |(skeem_expr, expectation)|
|
255
|
+
result = subject.run(skeem_expr)
|
256
|
+
expect(result.value).to eq(expectation)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should implement the null? procedure' do
|
261
|
+
checks = [
|
262
|
+
['(null? #f)', false],
|
263
|
+
['(null? 1)', false],
|
264
|
+
['(null? 0)', false],
|
265
|
+
['(null? "bar")', false],
|
266
|
+
['(null? "")', false],
|
267
|
+
['(null? (list 1 2 3))', false],
|
268
|
+
['(list? (list))', true]
|
269
|
+
]
|
270
|
+
checks.each do |(skeem_expr, expectation)|
|
271
|
+
result = subject.run(skeem_expr)
|
272
|
+
expect(result.value).to eq(expectation)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'should implement the length procedure' do
|
277
|
+
checks = [
|
278
|
+
['(length (list))', 0],
|
279
|
+
['(length (list 1))', 1],
|
280
|
+
['(length (list 1 2))', 2],
|
281
|
+
['(length (list 1 2 3))', 3]
|
282
|
+
]
|
283
|
+
checks.each do |(skeem_expr, expectation)|
|
284
|
+
result = subject.run(skeem_expr)
|
285
|
+
expect(result.value).to eq(expectation)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end # context
|
289
|
+
|
245
290
|
context 'IO procedures:' do
|
246
291
|
it 'should implement the newline procedure' do
|
247
292
|
default_stdout = $stdout
|
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.19
|
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-10-
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|