5 class Env(val outer: Env?, binds: Sequence<MalSymbol>?, exprs: Sequence<MalType>?) {
6 val data = HashMap<String, MalType>()
9 if (binds != null && exprs != null) {
10 val itb = binds.iterator()
11 val ite = exprs.iterator()
12 while (itb.hasNext()) {
15 set(b, if (ite.hasNext()) ite.next() else NIL)
17 if (!itb.hasNext()) throw MalException("expected a symbol name for varargs")
18 set(itb.next(), MalList(ite.asSequence().toLinkedList()))
25 constructor() : this(null, null, null)
26 constructor(outer: Env?) : this(outer, null, null)
28 fun set(key: MalSymbol, value: MalType): MalType {
29 data.put(key.value, value)
33 fun find(key: MalSymbol): MalType? = data.getOrElse(key.value) { outer?.find(key) }
35 fun get(key: MalSymbol): MalType = find(key) ?: throw MalException("'${key.value}' not found")