Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: quote. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/lisp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/test_lisp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down