[SPARK-2762] SparkILoop leaks memory in multi-repl configurations

This pull request is a small refactor so that a partial function (hence a closure) is not created. Instead, a regular function is used. The behavior of the code is not changed.