from plisp import builtins
from plisp import environment
from plisp import parser


class DefaultEnvironment(environment.Environment): 
    def __init__(self):
        self.table = {
                '+': builtins.AddFunction(self),
                '-': builtins.SubtractFunction(self),
                '*': builtins.MultiplyFunction(self),
                '/': builtins.DivisionFunction(self),
            }


class PLispInterpreter:
    def __init__(self):
        self.program = None
        self.environment = DefaultEnvironment()

    def load_file(self, f):
        self.program = self.f.read()

    def load_string(self, string):
        self.program = string

    def execute(self):
        plist_parser = parser.PLispParser(self.program) 
        ast = plist_parser.parse()
        results = [ex.evaluate(self.environment) for ex in ast]
        return results[-1]

@@ -75,16 +75,40 @@
  parser%0A
+from plisp import types%0A
 %0A%0Aclass 
@@ -403,32 +403,69 @@
 Function(self),%0A
+                'nil': types.List(),%0A
             %7D%0A%0A%0A

define nil