skeem 0.2.03 → 0.2.04

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
  SHA256:
3
- metadata.gz: 6d5dc31ad0db5984772c42897c9ce30f51b5d97b44e7c1b9e65a277f4294c767
4
- data.tar.gz: cdb6ad6e66f703a65327fee0523be67a898215d2efa0e91371ec5b75b5262daa
3
+ metadata.gz: 8efda1e2bcaf2e4d07ca4bc52f3708c0e217b27c191d6ed0a42d3b7125e26de5
4
+ data.tar.gz: '0359bae57e376f724f17b0e10bcc819f6fe8ee1f2478d2b330111c16546ab8ec'
5
5
  SHA512:
6
- metadata.gz: ca03f6c15d90bbebae93cea809aaadd0dae35099bdcf6f7562182963e4c86c703d82a1955b3dde8ccd31369f85072a5e7a38cecaf8b8f4494775f3cf28c71611
7
- data.tar.gz: 8167282d129ecf2e18563b5d6cceb1de387dab5ed4f8e63fc56655f33fc593fc79eeb8a650c72e88520d790b69d967e369e03552b261ce28052c709072867bbe
6
+ metadata.gz: 48f64eea51bbbe3e701214101ad7bf114cf45ef4281db722de2b2786d0e932793cf6945bd2cfbb6afc8ea320264ca7eb920fc79d0f7a81ac49efd1cd9af863c1
7
+ data.tar.gz: d4ae84b2ebf2d3a20efcbb950d11ea1fc2b31b06a62d33c5fd375df6ff726a0a0b51f2a693f8cb3d0a47864de59ed79f2fbafe2cad9e99092ce25f0784271944
@@ -1,7 +1,18 @@
1
+ ## [0.2.04] - 2019-04-29
2
+ - Support for local definitions [initial]
3
+
4
+ ### Changed
5
+ - File `grammar.rb` Added one production rule for third `begin` form syntax.
6
+ - Method `SkmBuilder#reduce_begin_cmd` added to implement semantic action for new `begin...` production rule.
7
+ - File `README.md` Added a couple of links for additional Scheme resources.
8
+
9
+
10
+ ### Removed
11
+ - Method `SkmLambda#evaluate_defs` replaced by homonymous method in `SkmProcedureExec` class.
12
+
1
13
  ## [0.2.03] - 2019-04-26
2
14
  ### Changed
3
15
  - File `README.md` added new example with procedures holding each their local states.
4
-
5
16
  ### Fixed
6
17
  - The nesting of a lambda expression nested in a let construct caused an aliasing of the bindings.
7
18
 
data/README.md CHANGED
@@ -39,6 +39,8 @@ Here are a few pointers for the Scheme programming language:
39
39
  #### Online tutorials and books:
40
40
  - [The Scheme Programming Language, 4th Edition](https://www.scheme.com/tspl4/) by Kent Dybvig. A complete, introductory textbook on Scheme based on the older R5RS standard.
41
41
  - [Teach Yourself Scheme in Fixnum Days](http://ds26gte.github.io/tyscheme/index.html) by Dorai Sitaram
42
+ - [Yet Another Scheme Tutorial](http://www.shido.info/lisp/idx_scm_e.html) by Shido Takafumi
43
+ - [An Introduction to Scheme and its Implementation](http://www.cs.utexas.edu/ftp/garbage/cs345/schintro-v14/schintro_toc.html) by Paul R. Wilson
42
44
 
43
45
  ## Usage
44
46
 
@@ -253,6 +255,7 @@ Here are a few other ones:
253
255
 
254
256
  - [rubic gem](https://rubygems.org/gems/rubic). The last commit for the [project](https://github.com/notozeki/rubic) is June 2015.
255
257
 
258
+ - [RLisp](https://github.com/davydovanton/rlisp) ...Simple scheme interpreter written on ruby
256
259
  ## Contributing
257
260
 
258
261
  Bug reports and pull requests are welcome on GitHub at https://github.com/famished-tiger/Skeem.
@@ -29,7 +29,7 @@ module Skeem
29
29
  rule('cmd_or_def_plus' => 'cmd_or_def').as 'last_cmd_def'
30
30
  rule 'cmd_or_def' => 'command'
31
31
  rule 'cmd_or_def' => 'definition'
32
- # TODO: add BEGIN here p. 64 R7RS
32
+ rule('cmd_or_def' => 'LPAREN BEGIN cmd_or_def_plus RPAREN').as 'begin_cmd'
33
33
  rule 'command' => 'expression'
34
34
  rule('definition' => 'LPAREN DEFINE IDENTIFIER expression RPAREN').as 'definition'
35
35
  rule('definition' => 'LPAREN DEFINE LPAREN IDENTIFIER def_formals RPAREN body RPAREN').as 'alt_definition'
@@ -616,8 +616,9 @@ module Skeem
616
616
  assert_call = aRuntime.caller
617
617
  pos = assert_call.call_site
618
618
  # Error: assertion failed: (> 1 2)
619
- msg = "assertion failed on line #{pos.line}, column #{pos.column}"
620
- raise StandardError, 'Error: ' + msg
619
+ msg1 = "assertion failed on line #{pos.line}, column #{pos.column}"
620
+ msg2 = ", with #{arg.inspect}"
621
+ raise StandardError, 'Error: ' + msg1 + msg2
621
622
  else
622
623
  boolean(true)
623
624
  end
@@ -58,6 +58,11 @@ module Skeem
58
58
  def reduce_last_cmd_def(_production, _range, _tokens, theChildren)
59
59
  SkmPair.create_from_a([theChildren.last])
60
60
  end
61
+
62
+ # rule('cmd_or_def' => 'LPAREN BEGIN cmd_or_def_plus RPAREN').as 'begin_cmd'
63
+ def reduce_begin_cmd(_production, _range, _tokens, theChildren)
64
+ SkmSequencingBlock.new(theChildren[2])
65
+ end
61
66
 
62
67
  # rule('definition' => 'LPAREN DEFINE IDENTIFIER expression RPAREN')
63
68
  # .as 'definition'
@@ -342,24 +342,6 @@ require_relative 'skm_procedure_exec'
342
342
  set_cond_environment(aRuntime.environment) # Last chance for anonymous lambda
343
343
  application = SkmProcedureExec.new(self)
344
344
  application.run!(aRuntime, theActuals)
345
- =begin
346
- # $stderr.puts "Start of lambda #{object_id.to_s(16)}"
347
- aRuntime.nest
348
- # $stderr.puts ' Before bind_locals'
349
- bind_locals(aRuntime, aProcedureCall)
350
- # $stderr.puts ' After bind_locals'
351
- # $stderr.puts 'LOCALS vvvvvvvvvvv'
352
- # $stderr.puts aRuntime.environment.inspect
353
- # $stderr.puts 'LOCALS ^^^^^^^^^^^'
354
- result = evaluate_defs(aRuntime)
355
- # $stderr.puts ' Before evaluate_sequence'
356
- result = evaluate_sequence(aRuntime)
357
- # $stderr.puts ' After evaluate_sequence'
358
- aRuntime.unnest
359
- # $stderr.puts " Result: #{result.inspect}"
360
- # $stderr.puts "End of lambda #{object_id.to_s(16)}"
361
- result
362
- =end
363
345
  end
364
346
 
365
347
  def arity
@@ -414,7 +396,6 @@ require_relative 'skm_procedure_exec'
414
396
  end
415
397
  variadic_arg_name = formals.formals.last
416
398
  args_coll = SkmPair.create_from_a(variadic_part)
417
- # a_def = SkmDefinition.new(position, variadic_arg_name, args_coll)
418
399
  a_def = SkmBinding.new(variadic_arg_name, args_coll)
419
400
  a_def.evaluate(aRuntime)
420
401
  aRuntime.add_binding(a_def.variable, a_def.value)
@@ -427,10 +408,6 @@ require_relative 'skm_procedure_exec'
427
408
  #aProcedureCall.operands_consumed = true
428
409
  end
429
410
 
430
- def evaluate_defs(aRuntime)
431
- definitions.each { |a_def| a_def.evaluate(runtime) }
432
- end
433
-
434
411
  def evaluate_sequence(aRuntime)
435
412
  result = nil
436
413
  if sequence
@@ -18,14 +18,25 @@ module Skeem
18
18
  runtime = aRuntime
19
19
  runtime.push(frame)
20
20
  definition.bind_locals(runtime, theActuals)
21
+ evaluate_defs(aRuntime)
22
+ # definition.evaluate_defs(runtime)
21
23
  # $stderr.puts "Locals"
22
- # $stderr.puts frame.bindings.keys.join(', ')
23
- definition.evaluate_defs(runtime)
24
+ # $stderr.puts frame.bindings.keys.join(', ')
24
25
  result = definition.evaluate_sequence(runtime)
25
26
  runtime.pop
26
27
  # $stderr.puts "Lambda result: #{result.object_id.to_s(16)}" if result.kind_of?(SkmLambda)
27
28
 
28
29
  result
29
30
  end
31
+
32
+ private
33
+
34
+ def evaluate_defs(aRuntime)
35
+ definition.definitions.each do |bndng|
36
+ var = bndng.variable.evaluate(aRuntime)
37
+ val = bndng.value.evaluate(aRuntime)
38
+ frame.add_binding(var, val)
39
+ end
40
+ end
30
41
  end # class
31
42
  end # module
@@ -1,3 +1,3 @@
1
1
  module Skeem
2
- VERSION = '0.2.03'.freeze
2
+ VERSION = '0.2.04'.freeze
3
3
  end
@@ -304,6 +304,20 @@ SKEEM
304
304
  result = subject.run(source)
305
305
  expect(result.last.last.value).to eq(4)
306
306
  end
307
+
308
+
309
+ it 'should support the nested define construct' do
310
+ source = <<-SKEEM
311
+ (define (quadruple x)
312
+ (define (double x) ; define a local procedure double
313
+ (+ x x))
314
+ (double (double x))) ; nested calls to the local procedure
315
+
316
+ (quadruple 5) ; => 20
317
+ SKEEM
318
+ result = subject.run(source)
319
+ expect(result.last.value).to eq(20)
320
+ end
307
321
  end # context
308
322
 
309
323
  context 'Binding constructs:' do
@@ -696,8 +696,9 @@ SKEEM
696
696
  (test-assert (> x y))
697
697
  SKEEM
698
698
  err = StandardError
699
- msg = 'Error: assertion failed on line 3, column 4'
700
- expect { subject.run(source) }.to raise_error(err, msg)
699
+ msg1 = 'Error: assertion failed on line 3, column 4'
700
+ msg2 = 'with <Skeem::SkmBoolean: false>'
701
+ expect { subject.run(source) }.to raise_error(err, msg1 + ', '+ msg2)
701
702
  end
702
703
  end # context
703
704
  end # describe
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.2.03
4
+ version: 0.2.04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rley