skeem 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/skeem/interpreter.rb +1 -0
- data/lib/skeem/s_expr_nodes.rb +14 -10
- data/lib/skeem/version.rb +1 -1
- data/spec/skeem/interpreter_spec.rb +10 -4
- data/spec/skeem/s_expr_nodes_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c8a2b41577b541764b4ff1e2702ba30502020a4
|
4
|
+
data.tar.gz: f2844f165479416e313c25452ed7e6d05a8cf722
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a070f9dd299720eb3b5c2b71a3133270183d923a766b9d3a6d10ed62e539875bd59f9fc30aec016756ba82ff359978dec03a8f76a12771710c1f58cdeac64c1d
|
7
|
+
data.tar.gz: 364f3f3d0da779b2cd0e6e083902b9db9fd97368b6254ac80cc700069c53187524fdaf9f1e9724fd3d4dd176cccaa0a0cf786265006fff8b1dd69190641107ba
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.0.17] - 2018-10-06
|
2
|
+
- Fix: now support calls of anonymous lambda procedures.
|
3
|
+
|
4
|
+
### Fixed
|
5
|
+
- Method `SkmProcedureCall#evaluate` Fix: no procedure name lookup for anonymous ones!
|
6
|
+
|
1
7
|
## [0.0.16] - 2018-10-06
|
2
8
|
- Added built-in procedures `odd?`, `even?`, `square`, and `floor-remainder` (`modulo`).
|
3
9
|
- Supports procedures without argument.
|
data/lib/skeem/interpreter.rb
CHANGED
data/lib/skeem/s_expr_nodes.rb
CHANGED
@@ -340,16 +340,20 @@ module Skeem
|
|
340
340
|
end
|
341
341
|
|
342
342
|
def evaluate(aRuntime)
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
343
|
+
if operator.kind_of?(SkmLambda)
|
344
|
+
procedure = operator
|
345
|
+
else
|
346
|
+
var_key = operator.evaluate(aRuntime)
|
347
|
+
unless aRuntime.include?(var_key.value)
|
348
|
+
err = StandardError
|
349
|
+
key = var_key.kind_of?(SkmIdentifier) ? var_key.value : var_key
|
350
|
+
err_msg = "Unknown procedure '#{key}'"
|
351
|
+
raise err, err_msg
|
352
|
+
end
|
353
|
+
procedure = aRuntime.environment.fetch(var_key.value)
|
354
|
+
# $stderr.puts "## CALL(#{var_key.value}) ###################"
|
355
|
+
# $stderr.puts operands.inspect
|
349
356
|
end
|
350
|
-
procedure = aRuntime.environment.fetch(var_key.value)
|
351
|
-
# $stderr.puts "## CALL(#{var_key.value}) ###################"
|
352
|
-
# $stderr.puts operands.inspect
|
353
357
|
result = procedure.call(aRuntime, self)
|
354
358
|
# $stderr.puts "## RETURN #{result.inspect}"
|
355
359
|
result
|
@@ -357,7 +361,7 @@ module Skeem
|
|
357
361
|
|
358
362
|
def inspect
|
359
363
|
result = inspect_prefix + operator.inspect + ', '
|
360
|
-
result << operands.inspect + inspect_suffix
|
364
|
+
result << '@operands ' + operands.inspect + inspect_suffix
|
361
365
|
result
|
362
366
|
end
|
363
367
|
|
data/lib/skeem/version.rb
CHANGED
@@ -171,16 +171,22 @@ SKEEM
|
|
171
171
|
expect(result.value).to eq(3628800)
|
172
172
|
end
|
173
173
|
|
174
|
-
|
175
|
-
|
174
|
+
it 'should implement the compact define + lambda syntax' do
|
175
|
+
source = <<-SKEEM
|
176
176
|
; Alternative syntax to: (define f (lambda x (+ x 42)))
|
177
177
|
(define (f x)
|
178
178
|
(+ x 42))
|
179
179
|
(f 23)
|
180
180
|
SKEEM
|
181
|
+
result = subject.run(source)
|
182
|
+
expect(result.value).to eq(65)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should call anonymous procedure' do
|
186
|
+
source = '((lambda (x) (+ x x)) 4)'
|
181
187
|
result = subject.run(source)
|
182
|
-
expect(result.value).to eq(
|
183
|
-
|
188
|
+
expect(result.value).to eq(8)
|
189
|
+
end
|
184
190
|
end # context
|
185
191
|
|
186
192
|
context 'Built-in primitive procedures' do
|
@@ -330,7 +330,7 @@ describe SkmIdentifier do
|
|
330
330
|
context 'Provided services:' do
|
331
331
|
it 'should return its text representation' do
|
332
332
|
txt1 = '<Skeem::ProcedureCall: <Skeem::SkmIdentifier: +>, '
|
333
|
-
txt2 = '<Skeem::SkmList: 1, 2, 3>>'
|
333
|
+
txt2 = '@operands <Skeem::SkmList: 1, 2, 3>>'
|
334
334
|
expect(subject.inspect).to eq(txt1 + txt2)
|
335
335
|
end
|
336
336
|
end # context
|