def to_letrec(x, env):
    parms = list(map(lambda pair: pair[0], x[0]))
    args  = list(map(lambda pair: pair[1], x[0]))
    new_env = Environment(dict(zip(parms, args)), env)
    vals = []
    for parm, arg in zip(parms, args):
        val = eval(arg, new_env)
        new_env[parm] = val
        vals.append(val)
    body = x[1]
    lambda_ = Procedure(parms, body, env)
    return lambda_(*vals)
Exemple #2
0
 def __call__(self, *args):
     env = Environment(dict(zip(self.parms, args)), self.env)
     return eval(self.body, env)
Exemple #3
0
 def __call__(self, *args):
     "Remember: Environment == ChainMap, creates list of dicts to search sequentially"
     "first index is parms:args, second is env where proc def"
     env = Environment(dict(zip(self.parms, args)), self.env)
     return eval(self.body, env)
 def __call__(self, *args):
     env =  Environment(dict(zip(self.parms, args)), self.env)
     call = eval(self.body, env)
     print('>>>', call)
     return call
Exemple #5
0
 def __call__(self, *args):
     # Create a dictionary with the params as keys and the function call arguments as values -- use this and the specified environment for the Procedure as the evaluation environment and call eval()
     env = Environment(dict(zip(self.params, args)), self.env)
     return eval(self.body, env)
Exemple #6
0
 def __call__(self, *arguments):
     environment = Environment(dict(zip(self.parameters, arguments)),
                               self.environment)
     return evaluate(self.body, environment)
Exemple #7
0
        'list?':   lambda x: isinstance(x,list), 
        'map':     lambda *args: list(map(*args)), #maybe this way lambda proc, *args: list(map(proc, args))
        'max':     max,
        'min':     min,
        'not':     op.not_,
        'null?':   lambda x: x == [], 
        'number?': lambda x: isinstance(x, Number),   
        'procedure?': callable,
        'round':   round,
        'symbol?': lambda x: isinstance(x, Symbol),
        'display': print,
    })
    return env

global_env = standard_env()

class Environment:
    
    def __init__(self, procs):
        self.env = dict()
        self.env.update(procs)
    
    def __getitem__(self, key):
        item = self.env[key]
        if isnstance(item, Delayed):
            return force(item)
        else:
            return item
        
Env = Environment(global_env)