             return values[name.lexeme]!
         }
         
+        if let enclosing = enclosing {
+            return try enclosing.valueFor(name: name)
+        }
+        
         throw InterpreterError.runtime(name, "Undefined variable '\(name.lexeme)'.")
     }
     

            return
        }
        
        throw InterpreterError.runtime(name, "Undefined variable '\(name.lexeme)'.")
    }
}


final class Environment {
    
    var enclosing: Environment?
    
    // Any is optional because uninitialized variables are nil.
    private var values = Dictionary<String, Any?>()
    
    init() {
        self.enclosing = nil
    }
    
    init(enclosing: Environment) {
        self.enclosing = enclosing
    }
    
    func define(name: String, value: Any?) {
//        assert(value is Result) // compiler segmentation fault
