Evaluates replacement function only when needed.