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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b34c77d5c2d4f0893f69e79e8973b4c6eca3481
4
- data.tar.gz: f10a360e77925612bd6c95bb5e160417ba538983
3
+ metadata.gz: 0c8a2b41577b541764b4ff1e2702ba30502020a4
4
+ data.tar.gz: f2844f165479416e313c25452ed7e6d05a8cf722
5
5
  SHA512:
6
- metadata.gz: da4f16148a354cb6ee8553d46e204ed97e27a88a117727a1c6a18f8441b5ed08a93fe56db11ade0fc903e934b60002315a98a70ef9b1a83d5015f7246f27ab4a
7
- data.tar.gz: c75610b85fa5fa4a56c66832e19e193b401118dce728c5dacd755f5d570d3898939a11c2aa46ba83b9d1a6cde23d1a9e865657957dccc565e90c02c8806499aa
6
+ metadata.gz: a070f9dd299720eb3b5c2b71a3133270183d923a766b9d3a6d10ed62e539875bd59f9fc30aec016756ba82ff359978dec03a8f76a12771710c1f58cdeac64c1d
7
+ data.tar.gz: 364f3f3d0da779b2cd0e6e083902b9db9fd97368b6254ac80cc700069c53187524fdaf9f1e9724fd3d4dd176cccaa0a0cf786265006fff8b1dd69190641107ba
@@ -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.
@@ -18,6 +18,7 @@ module Skeem
18
18
  def run(source)
19
19
  @parser ||= Parser.new
20
20
  @ptree = parser.parse(source)
21
+ # $stderr.puts @ptree.root.inspect
21
22
  return @ptree.root.evaluate(runtime)
22
23
  end
23
24
 
@@ -340,16 +340,20 @@ module Skeem
340
340
  end
341
341
 
342
342
  def evaluate(aRuntime)
343
- var_key = operator.evaluate(aRuntime)
344
- unless aRuntime.include?(var_key.value)
345
- err = StandardError
346
- key = var_key.kind_of?(SkmIdentifier) ? var_key.value : var_key
347
- err_msg = "Unknown procedure '#{key}'"
348
- raise err, err_msg
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
 
@@ -1,3 +1,3 @@
1
1
  module Skeem
2
- VERSION = '0.0.16'.freeze
2
+ VERSION = '0.0.17'.freeze
3
3
  end
@@ -171,16 +171,22 @@ SKEEM
171
171
  expect(result.value).to eq(3628800)
172
172
  end
173
173
 
174
- it 'should implement the compact define + lambda syntax' do
175
- source = <<-SKEEM
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(65)
183
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skeem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef