skeem 0.0.26 → 0.0.27

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: dac0bc87694eef9365c7c7ba6dab9b1827eab533
4
- data.tar.gz: 5097264ce99da2c1e9a8e662e2276144a31b1660
3
+ metadata.gz: a462458401748edba53f3c95f80b56478d7cfeb0
4
+ data.tar.gz: bca52ec89e55cfe23c95e644da601fd2557877c8
5
5
  SHA512:
6
- metadata.gz: 25d09cd405ff9463eba60c098933df4804ff28051a663af4b1bed8217aee280ebfba0a4ff86391d7500b606ccbede4f3cb2021e9713c0535600ce0c30291f72d
7
- data.tar.gz: 5e36e23fe874f945b394adb866b4ffb85b62a014a7afacd5653c279d4d7d9902f2b012ddf19b680259e8cc73e69385a0a9bd556b47f2c4ae46b7a35297d2974b
6
+ metadata.gz: fbcbaf830c1ba588cd34700f7ebc4f7815b0972efa8ddd496fbda977538e2d5921cdb88830e880ee2cc4c6a7ecb6f214d903ea945a970b46653d366de22b4fc0
7
+ data.tar.gz: 959251339c07128dc76a7557761d915cacea326432bf4ab0e3728d894f63bf2fe609d743ea07b1b0753ca65d728528e2d4fe8b3b246bf381ddd0b74533aca1ca
@@ -1,3 +1,9 @@
1
+ ## [0.0.27] - 2018-11-25
2
+ ### Fixed
3
+ - The interpreter failed with second-order lambdas (lambda expression that contains another lambda)
4
+ - Added a specific test in `interpreter_spec.rb`
5
+
6
+
1
7
  ## [0.0.26] - 2018-11-25
2
8
 
3
9
  ### Added
@@ -17,6 +17,7 @@ module Skeem
17
17
  # Arguments are positional in a primitive procedure.
18
18
  def call(aRuntime, aProcedureCall)
19
19
  check_actual_count(aProcedureCall)
20
+ aProcedureCall.operands_consumed = true
20
21
  do_call(aRuntime, aProcedureCall.operands.to_a)
21
22
  end
22
23
 
@@ -93,8 +93,8 @@ module Skeem
93
93
  call_stack.pop
94
94
  end
95
95
 
96
- def caller
97
- call_stack.last
96
+ def caller(index = -1)
97
+ call_stack[index]
98
98
  end
99
99
 
100
100
  private
@@ -121,6 +121,7 @@ module Skeem
121
121
  attr_reader :operator
122
122
  attr_reader :operands
123
123
  attr_accessor :call_site
124
+ attr_accessor :operands_consumed
124
125
 
125
126
  def initialize(aPosition, anOperator, theOperands)
126
127
  super(aPosition)
@@ -131,13 +132,28 @@ module Skeem
131
132
  @operator = anOperator
132
133
  end
133
134
  @operands = SkmList.new(theOperands)
135
+ @operands_consumed = false
134
136
  end
135
137
 
136
138
  def evaluate(aRuntime)
139
+ aRuntime.push_call(self)
137
140
  if operator.kind_of?(SkmLambda)
138
141
  procedure = operator
139
142
  else
140
143
  var_key = operator.evaluate(aRuntime)
144
+ if operator.kind_of?(ProcedureCall) && operands_consumed
145
+ return var_key
146
+ end
147
+ begin
148
+ aRuntime.include?(var_key.value)
149
+ rescue NoMethodError
150
+ $stderr.puts "VVVVVVVVVVVVVVV"
151
+ $stderr.puts 'var_key: ' + var_key.inspect
152
+ $stderr.puts 'operator: ' + operator.inspect
153
+ $stderr.puts 'operands: ' + operands.inspect
154
+ $stderr.puts 'operands_consumed: ' + operands_consumed.inspect
155
+ $stderr.puts "^^^^^^^^^^^^^^^"
156
+ end
141
157
  unless aRuntime.include?(var_key.value)
142
158
  err = StandardError
143
159
  key = var_key.kind_of?(SkmIdentifier) ? var_key.value : var_key
@@ -145,13 +161,16 @@ module Skeem
145
161
  raise err, err_msg
146
162
  end
147
163
  procedure = aRuntime.environment.fetch(var_key.value)
148
- # $stderr.puts "## CALL(#{var_key.value}) ###################"
149
- # $stderr.puts operands.inspect
150
164
  end
151
- aRuntime.push_call(self)
165
+ # $stderr.puts "## In ProcCall #{var_key.value} #############"
166
+ # $stderr.puts 'operator: ' + operator.inspect
167
+ # $stderr.puts 'operands: ' + operands.inspect
168
+ # $stderr.puts "## CALL(#{var_key.value}) ###################"
169
+ # $stderr.puts 'callee: ' + procedure.inspect
152
170
  result = procedure.call(aRuntime, self)
171
+ operands_consumed = true
153
172
  aRuntime.pop_call
154
- # $stderr.puts "## RETURN #{result.inspect}"
173
+ # $stderr.puts "## RETURN #{result.inspect} from #{var_key.value}"
155
174
  result
156
175
  end
157
176
 
@@ -317,7 +336,6 @@ module Skeem
317
336
  def call(aRuntime, aProcedureCall)
318
337
  aRuntime.nest
319
338
  bind_locals(aRuntime, aProcedureCall)
320
- # TODO remove next line
321
339
  # $stderr.puts aRuntime.environment.inspect
322
340
  result = evaluate_defs(aRuntime)
323
341
  result = evaluate_sequence(aRuntime)
@@ -382,7 +400,14 @@ module Skeem
382
400
  def evaluate_sequence(aRuntime)
383
401
  result = nil
384
402
  if sequence
385
- sequence.each { |cmd| result = cmd.evaluate(aRuntime) }
403
+ sequence.each do |cmd|
404
+ if cmd.kind_of?(SkmLambda)
405
+ aRuntime.caller(-2).operands_consumed = true
406
+ result = cmd.call(aRuntime, aRuntime.caller(-2))
407
+ else
408
+ result = cmd.evaluate(aRuntime)
409
+ end
410
+ end
386
411
  end
387
412
 
388
413
  result
@@ -411,10 +436,10 @@ module Skeem
411
436
  end
412
437
  end
413
438
 
414
- def msg_arity_mismatch(aProcedureCall)
439
+ def msg_arity_mismatch(aProcCall)
415
440
  # *** ERROR: wrong number of arguments for #<closure morph> (required 2, got 1)
416
- msg1 = "Wrong number of arguments for procedure #{operator} "
417
- count_actuals = aProcedureCall.operands.members.size
441
+ msg1 = "Wrong number of arguments for procedure #{aProcCall.operator} "
442
+ count_actuals = aProcCall.operands.members.size
418
443
  msg2 = "(required #{required_arity}, got #{count_actuals})"
419
444
  msg1 + msg2
420
445
  end
@@ -1,3 +1,3 @@
1
1
  module Skeem
2
- VERSION = '0.0.26'.freeze
2
+ VERSION = '0.0.27'.freeze
3
3
  end
@@ -202,7 +202,7 @@ SKEEM
202
202
  result = subject.run(source)
203
203
  expect(result).to be_kind_of(SkmList)
204
204
  expect(result).to be_null
205
- end
205
+ end
206
206
 
207
207
  it 'should implement the lambda function with one arg' do
208
208
  source = <<-SKEEM
@@ -332,7 +332,7 @@ SKEEM
332
332
  expect(result.members[index]).to eq(value)
333
333
  end
334
334
  end
335
-
335
+
336
336
  it 'should implement the unquote of vectors' do
337
337
  source = '`#( ,(+ 1 2) 4)'
338
338
  result = subject.run(source)
@@ -350,7 +350,7 @@ SKEEM
350
350
  result = subject.run(source)
351
351
  expect(result).to be_kind_of(SkmVector)
352
352
  expect(result).to be_empty
353
-
353
+
354
354
  # Nested vectors
355
355
  source = '`#(a b #(,(+ 2 3) c) d)'
356
356
  result = subject.run(source)
@@ -365,9 +365,9 @@ SKEEM
365
365
  predictions.each_with_index do |(type, value), index|
366
366
  expect(result.members[index]).to be_kind_of(type)
367
367
  expect(result.members[index]).to eq(value)
368
- end
369
- end
370
-
368
+ end
369
+ end
370
+
371
371
  it 'should implement the quasiquotation of lists' do
372
372
  source = '(quasiquote (+ 1 2))'
373
373
  result = subject.run(source)
@@ -387,7 +387,7 @@ SKEEM
387
387
  expect(result).to be_kind_of(SkmList)
388
388
  expect(result).to be_null
389
389
  end
390
-
390
+
391
391
  it 'should implement the unquote of lists' do
392
392
  source = '`(list ,(+ 1 2) 4)'
393
393
  result = subject.run(source)
@@ -406,7 +406,7 @@ SKEEM
406
406
  result = subject.run(source)
407
407
  expect(result).to be_kind_of(SkmList)
408
408
  expect(result).to be_null
409
-
409
+
410
410
  # nested lists
411
411
  source = '`(a b (,(+ 2 3) c) d)'
412
412
  result = subject.run(source)
@@ -421,22 +421,22 @@ SKEEM
421
421
  predictions.each_with_index do |(type, value), index|
422
422
  expect(result.members[index]).to be_kind_of(type)
423
423
  expect(result.members[index]).to eq(value)
424
- end
424
+ end
425
425
  end
426
426
  =begin
427
427
  `(+ 2 ,(* 3 4)) (+ 2 12)
428
428
  `(a b ,(reverse '(c d e)) f g) (a b (e d c) f g)
429
429
  (let ([a 1] [b 2])
430
- `(,a . ,b)) (1 . 2)
430
+ `(,a . ,b)) (1 . 2)
431
431
 
432
432
  `(+ ,@(cdr '(* 2 3))) (+ 2 3)
433
433
  `(a b ,@(reverse '(c d e)) f g) (a b e d c f g)
434
434
  (let ([a 1] [b 2])
435
435
  `(,a ,@b)) (1 . 2)
436
- `#(,@(list 1 2 3)) #(1 2 3)
436
+ `#(,@(list 1 2 3)) #(1 2 3)
437
437
 
438
438
  '`,(cons 'a 'b) `,(cons 'a 'b)
439
- `',(cons 'a 'b) '(a . b)
439
+ `',(cons 'a 'b) '(a . b)
440
440
  =end
441
441
  end # context
442
442
 
@@ -567,7 +567,7 @@ SKEEM
567
567
  expect(result).to eq(expectation)
568
568
  end
569
569
  end
570
-
570
+
571
571
  it 'should implement the not procedure' do
572
572
  checks = [
573
573
  ['(not #t)', false],
@@ -582,8 +582,8 @@ SKEEM
582
582
  result = subject.run(skeem_expr)
583
583
  expect(result).to eq(expectation)
584
584
  end
585
- end
586
-
585
+ end
586
+
587
587
  it 'should implement the list procedure' do
588
588
  checks = [
589
589
  ['(list)', []],
@@ -595,7 +595,7 @@ SKEEM
595
595
  expect(result.members).to eq(expectation)
596
596
  end
597
597
  end
598
-
598
+
599
599
  it 'should implement the symbol=? procedure' do
600
600
  checks = [
601
601
  ["(symbol=? 'a 'a)", true],
@@ -606,7 +606,21 @@ SKEEM
606
606
  result = subject.run(skeem_expr)
607
607
  expect(result).to eq(expectation)
608
608
  end
609
- end
609
+ end
610
+ end # context
611
+
612
+ context 'More advanced tests' do
613
+ it 'should implement second-order functions' do
614
+ source = <<-SKEEM
615
+ (define compose
616
+ (lambda (f g)
617
+ (lambda (x)
618
+ (f (g x)))))
619
+ ((compose list square) 5)
620
+ SKEEM
621
+ result = subject.run(source)
622
+ expect(result.last.members).to eq([25])
623
+ end
610
624
  end # context
611
625
  end # describe
612
626
  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.26
4
+ version: 0.0.27
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-11-25 00:00:00.000000000 Z
11
+ date: 2018-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley