Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixup a few bugs, allow ez-scheme foo.scm to work

if no file given fall back to repl
  • Loading branch information...
commit ceeabdadb40db58c14619b9dcf59de5f387cf84c 1 parent 4611de2
Ezra Zygmuntowicz authored
Showing with 16 additions and 3 deletions.
  1. +11 −1 bin/ez-scheme
  2. +5 −2 lib/ez-scheme/interpreter.rb
View
12 bin/ez-scheme
@@ -1,3 +1,13 @@
require 'ez-scheme/interpreter'
-interactive_interpreter()
+if file = ARGV[0]
+ interp = ::SchemeInterpreter.new # by default output_stream is $stdout
+ parser = ::Parser.new
+ inp = IO.read(file)
+ parsed = parser.parse(inp)
+ parsed.each do |expr|
+ interp.interpret(expr)
+ end
+else
+ interactive_interpreter()
+end
View
7 lib/ez-scheme/interpreter.rb
@@ -12,6 +12,9 @@ class Procedure
#
# Consists of a list of arguments and body (both nested Pairs), together
# with a link to the environment in which the procedure was defined.
+
+ attr_reader :args, :body, :env
+
def initialize(args, body, env)
@args = args
@body = body
@@ -135,8 +138,8 @@ def _apply(proc, args)
return proc.apply(expand_nested_pairs(args))
elsif proc.instance_of?(Procedure)
if DEBUG
- puts("~~~~ Applying procedure with args: %s" % proc.params)
- puts(" and body:\n%s" % expr_repr(proc.body))
+ puts("~~~~ Applying procedure with args: #{proc.args}")
+ puts(" and body:\n#{expr_repr(proc.body)}")
end
return _eval_sequence(proc.body,
_extend_env_for_procedure(proc.env,
Please sign in to comment.
Something went wrong with that request. Please try again.