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


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

            return
        }
        
        if let enclosing = enclosing {
            try enclosing.assign(name: name, value: value)
        }
        
        throw InterpreterError.runtime(name, "Undefined variable '\(name.lexeme)'.")
    }
}
