def eval(x, env):
	"Evaluate an expression in an environment."
	if isa(x, Symbol):		  # variable reference
		return env[x]
	elif isa(x, list):		  # (proc exp*)
		proc = eval(x[0], env)
		if hasattr(proc, '__call__'):
			return proc(env,*x[1:])
		raise ValueError("%s = %s is not a procedure" % (to_string(x[0]),to_string(proc)))
	return x
Beispiel #2
0
def eval(x, env):
	"Evaluate an expression in an environment."
	if isa(x, Symbol):		  # variable reference
		return env[x]
	elif isa(x, list):		  # (proc exp*)
		proc = eval(x[0], env)
		if hasattr(proc, '__call__'):
			return proc(env,*x[1:])
		raise ValueError("%s = %s is not a procedure" % (to_string(x[0]),to_string(proc)))
	return x
def repl(prompt='vau> '):
	try:
		while True:
			full_line = raw_input(prompt)
			rps = full_line.count("(")-full_line.count(")")
			while rps != 0 or full_line == "":
				line = raw_input(">\t")
				full_line += line
				rps += line.count("(")-line.count(")")
			try:
				tokens = tokenize(full_line)
				while len(tokens) > 0:
					val = eval(parse(tokens),global_env)
					if val is not None: print to_string(val)
			except ValueError as e:
				print e.message
	except (KeyboardInterrupt, SystemExit):
		pass
	except:
		print "\nFatal Error\n"
		traceback.print_exc()
def repl(prompt='vau> '):
    try:
        while True:
            full_line = raw_input(prompt)
            rps = full_line.count("(") - full_line.count(")")
            while rps != 0 or full_line == "":
                line = raw_input(">\t")
                full_line += line
                rps += line.count("(") - line.count(")")
            try:
                tokens = tokenize(full_line)
                while len(tokens) > 0:
                    tree = parse(tokens)
                    if tree is not None:
                        val = eval(tree, global_env)
                        if val is not None: print to_string(val)
            except ValueError as e:
                print e.message
    except (KeyboardInterrupt, SystemExit):
        pass
    except:
        print "\nFatal Error\n"
        traceback.print_exc()
def vprint(v, e):
    val = eval(e, v)
    print to_string(val)
    return val
Beispiel #6
0
def vprint(v, e):
    val = eval(e, v)
    print to_string(val)
    return val