MCPcopy
hub / github.com/fluentpython/example-code-2e / Env

Class Env

18-with-match/lispy/original/lispy.py:122–138  ·  view source on GitHub ↗

An environment: a dict of {'var':val} pairs, with an outer Env.

Source from the content-addressed store, hash-verified

120################ Environment class
121
122class Env(dict):
123 "An environment: a dict of {'var':val} pairs, with an outer Env."
124 def __init__(self, parms=(), args=(), outer=None):
125 # Bind parm list to corresponding args, or single parm to list of args
126 self.outer = outer
127 if isa(parms, Symbol):
128 self.update({parms:list(args)})
129 else:
130 if len(args) != len(parms):
131 raise TypeError('expected %s, given %s, '
132 % (to_string(parms), to_string(args)))
133 self.update(zip(parms,args))
134 def find(self, var):
135 "Find the innermost Env where var appears."
136 if var in self: return self
137 elif self.outer is None: raise LookupError(var)
138 else: return self.outer.find(var)
139
140def is_pair(x): return x != [] and isa(x, list)
141def cons(x, y): return [x]+y

Callers 3

__call__Method · 0.85
lispy.pyFile · 0.85
evalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected