lisp 1.0.6 → 1.1.0

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: b3f57fa1db992fb2625e762541d96ba5e99f8090
4
- data.tar.gz: ce30c466b692400a1da5ea079b5b0397cc260d28
3
+ metadata.gz: cd79b300ba14a7d6c45496292f33a72767c9f839
4
+ data.tar.gz: a7500b1c04cdc5262d899dee558b6a68648cb141
5
5
  SHA512:
6
- metadata.gz: 5d8b15d758dbc2f8ec0988997d92a9896462d0dfa7cef8a935fbb8fcaa57976961ed5dd3e7fce7f31f142cd3ad6383fda42560accff6e43f8610cd1f890adfb9
7
- data.tar.gz: 2af028559c5a13e1921928fedc01be94e30e6fbe19745e133e97cf42c3a1539e0e298895641957eb0f57f4f11bd289383729a4f9fb604f8366afd656b0a5454a
6
+ metadata.gz: 43b51dfb0eb3ace2920704f9bf54cf4690889a79bf38edca8e06cc703e453fddc3dd6055e45f8965e6a4d1410c8883ae9c2472624ed1e79d37e5157c9441f067
7
+ data.tar.gz: e67b94f6412a29046f759f1666d8fcefef4c5a4f07439f4ff2cfba076cfe04b63d4d14e5ee5ecb581fcd184e79a0684c2dc1a7c0cb963daff398a8d05ca9e3ea
data/README.md CHANGED
@@ -47,6 +47,6 @@ Features
47
47
 
48
48
  - [ ] __quotation__ - (quote exp) Return the exp literally; do not evaluate it. _Example: (quote (a b c)) ⇒ (a b c)_
49
49
 
50
- - [ ] __assignment__ - (set! var exp) Evaluate exp and assign that value to var, which must have been previously defined (with a define or as a parameter to an enclosing procedure). _Example: (set! x2 (* x x))_
50
+ - [x] __assignment__ - (set! var exp) Evaluate exp and assign that value to var, which must have been previously defined (with a define or as a parameter to an enclosing procedure). _Example: (set! x2 (* x x))_
51
51
 
52
- - [ ] __sequencing__ - (begin exp...) Evaluate each of the expressions in left-to-right order, and return the final value. _Example: (begin (set! x 1) (set! x (+ x 1)) (* x 2)) ⇒ 4_
52
+ - [x] __sequencing__ - (begin exp...) Evaluate each of the expressions in left-to-right order, and return the final value. _Example: (begin (set! x 1) (set! x (+ x 1)) (* x 2)) ⇒ 4_
@@ -52,6 +52,12 @@ module Lisp
52
52
  _, test, conseq, alt = exp
53
53
  exp = execute(test, scope) ? conseq : alt
54
54
  execute(exp, scope)
55
+ when :set!
56
+ _, var, exp = exp
57
+ if scope.has_key?(var) then scope[var] = execute(exp, scope) else raise "#{var} is undefined" end
58
+ when :begin
59
+ _, *exp = exp
60
+ exp.map { |exp| execute(exp) }.last
55
61
  else
56
62
  func, *args = exp.map { |exp| execute(exp, scope) }
57
63
  func.call(*args)
@@ -8,17 +8,13 @@ module Lisp
8
8
  catch(:exit) do
9
9
  loop do
10
10
  puts begin
11
- eval input.readline
11
+ eval Coolline.new.readline
12
12
  rescue Exception => e
13
13
  e.message
14
14
  end
15
15
  end
16
16
  end
17
17
  end
18
-
19
- def self.input
20
- Coolline.new
21
- end
22
18
  end
23
19
 
24
20
  if __FILE__ == $0
@@ -1,3 +1,3 @@
1
1
  module Lisp
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -48,6 +48,14 @@ class TestLisp < MiniTest::Unit::TestCase
48
48
  assert_equal 1, Lisp.eval("(if(!= 1 2) 1 2)")
49
49
  end
50
50
 
51
+ def test_set!
52
+ assert_raises(RuntimeError) { Lisp.eval("(set! foo 0)") }
53
+ end
54
+
55
+ def test_begin
56
+ assert_equal 4, Lisp.eval("(begin (define x 1) (set! x (+ x 1)) (* x 2))")
57
+ end
58
+
51
59
  def test_lambda
52
60
  Lisp.eval("(define area (lambda (r) (* 3.141592653 (* r r))))")
53
61
  assert_equal 28.274333877, Lisp.eval("(area 3)")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lisp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Moriarty