Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 2 changed files with 16 additions and 3 deletions. Show diff stats Hide diff stats

  1. +11 1 bin/ez-scheme
  2. +5 2 lib/ez-scheme/interpreter.rb
12 bin/ez-scheme
... ... @@ -1,3 +1,13 @@
1 1 require 'ez-scheme/interpreter'
2 2
3   -interactive_interpreter()
  3 +if file = ARGV[0]
  4 + interp = ::SchemeInterpreter.new # by default output_stream is $stdout
  5 + parser = ::Parser.new
  6 + inp = IO.read(file)
  7 + parsed = parser.parse(inp)
  8 + parsed.each do |expr|
  9 + interp.interpret(expr)
  10 + end
  11 +else
  12 + interactive_interpreter()
  13 +end
7 lib/ez-scheme/interpreter.rb
@@ -12,6 +12,9 @@ class Procedure
12 12 #
13 13 # Consists of a list of arguments and body (both nested Pairs), together
14 14 # with a link to the environment in which the procedure was defined.
  15 +
  16 + attr_reader :args, :body, :env
  17 +
15 18 def initialize(args, body, env)
16 19 @args = args
17 20 @body = body
@@ -135,8 +138,8 @@ def _apply(proc, args)
135 138 return proc.apply(expand_nested_pairs(args))
136 139 elsif proc.instance_of?(Procedure)
137 140 if DEBUG
138   - puts("~~~~ Applying procedure with args: %s" % proc.params)
139   - puts(" and body:\n%s" % expr_repr(proc.body))
  141 + puts("~~~~ Applying procedure with args: #{proc.args}")
  142 + puts(" and body:\n#{expr_repr(proc.body)}")
140 143 end
141 144 return _eval_sequence(proc.body,
142 145 _extend_env_for_procedure(proc.env,

0 comments on commit ceeabda

Please sign in to comment.
Something went wrong with that request. Please try again.