1 from mal_types
import MalType
, MalSym
, MalList
, throw_str
5 def __init__(self
, outer
=None, binds
=None, exprs
=None):
7 self
.outer
= outer
or None
10 assert isinstance(binds
, MalList
) and isinstance(exprs
, MalList
)
11 for i
in range(len(binds
)):
13 if not isinstance(bind
, MalSym
):
14 throw_str("env bind value is not a symbol")
15 if bind
.value
== u
"&":
17 if not isinstance(bind
, MalSym
):
18 throw_str("env bind value is not a symbol")
19 self
.data
[bind
.value
] = exprs
.slice(i
)
22 self
.data
[bind
.value
] = exprs
[i
]
25 assert isinstance(key
, MalSym
)
26 if key
.value
in self
.data
: return self
27 elif self
.outer
: return self
.outer
.find(key
)
30 def set(self
, key
, value
):
31 assert isinstance(key
, MalSym
)
32 assert isinstance(value
, MalType
)
33 self
.data
[key
.value
] = value
37 assert isinstance(key
, MalSym
)
39 if not env
: throw_str("'" + str(key
.value
) + "' not found")
40 return env
.data
[key
.value
]