Skip to content

Commit

Permalink
Add #inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Mar 10, 2011
1 parent d2e2349 commit 3b9dbcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/schemer/interpreter.rb
Expand Up @@ -28,6 +28,10 @@ def initialize(ast = nil)
nil
end)

env.add_binding(:inspect, lambda do |object|
object.inspect
end)

env.add_binding(:define, lambda do |parameters, body|
if parameters.is_a?(AST::Identifier)
# We are declaring a variable. We must eager-evaluate the value.
Expand Down
6 changes: 6 additions & 0 deletions spec/schemer/interpreter_spec.rb
Expand Up @@ -49,6 +49,12 @@ module Schemer
end
end

describe "#inspect" do
it 'returns the object inspected' do
"(inspect x)".should evaluate_to("#<Identifier::x>")
end
end

describe "#define" do
it 'defines a variable' do
expression = "(define number 3)"
Expand Down

0 comments on commit 3b9dbcc

Please sign in to comment.