In a recursive function, it is often effective to carry the result from step to step, to make for a tail call optimization. To signalize to the user, that he needn't provide a parameter, it can be reasonable to name a parameter "result":
def removeOccurence [A] (slice: Seq[A], original: Seq[A]) = {
@scala.annotation.tailrec
def remove (leftOriginal: Seq[A], result: Seq[A]) : Seq[A] =
trimStart (slice, leftOriginal) match {
case (h :: tail) => remove (tail, h +: result)
case (Nil) => result.reverse
}
remove (original, Nil)
}
But more often I use 'carry' and 'sofar', which I have seen in the wild, and which carry the idea even a bit better, in most cases.
A second reason is of course, if your topic suggest the word ''result'', for example if you do arithmetic evaluation. You might parse the formula, replace variables with values, and calculate a result in the end.
A third reason has already been stated, but I have a small deviation: You write a method which performs some job, let's say it evaluates a form of ''max''.
def max = {
val result = somethingElseToDo
if (foo) result else default
}
Instead of calling the result ''result'', we could call it ''max'', but in some languages you can omit parenthesis when calling a method, so max would be a recursive call to the method itself.
In general, I would prefer a name which tells, what the result is. But if that name is already taken, maybe by more than one variable, attribut or method, because there is a GUI-field, a string representation, a numerical and one for the database, using another one increases the probability of confusion. In short methods of 3 to 7 lines, ''result'' shouldn't be a problem for a name.