diff --git a/lib/lisp.rb b/lib/lisp.rb index 31e4c05..ca3a472 100644 --- a/lib/lisp.rb +++ b/lib/lisp.rb @@ -53,6 +53,9 @@ def self.execute expression, scope = global _, test, consequent, alternative = expression expression = if execute test, scope then consequent else alternative end execute expression, scope + when :quote + _, expression = expression + expression when :set! _, var, expression = expression if scope.has_key?(var) then scope[var] = execute expression, scope else raise "#{var} is undefined" end diff --git a/test/test_lisp.rb b/test/test_lisp.rb index dd7fba1..a6e45ff 100755 --- a/test/test_lisp.rb +++ b/test/test_lisp.rb @@ -52,6 +52,11 @@ def test_set! assert_raises(RuntimeError) { Lisp.eval("(set! foo 0)") } end + def test_quote + assert_equal [1,2,3], Lisp.eval("(quote (1 2 3))") + assert_equal [0,1,2,3], Lisp.eval("(+ (quote (0)) (quote (1 2 3)))") + end + def test_begin assert_equal 4, Lisp.eval("(begin (define x 1) (set! x (+ x 1)) (* x 2))") end