logo       

Tail recursion elimination and logical shortcut operators: msg#00415

lang.scala

Subject: Tail recursion elimination and logical shortcut operators

It looks as tho' the current (2.3.3) Scala compiler's ability to
eliminate tail calls is frustrated by the logical shortcut operators.

Looking at the decompiled output, in this case,

def foo(n : Int) : Boolean =
n == 1 || foo(n-1)

the tail call isn't eliminated, but in the equivalent,

def foo(n : Int) : Boolean =
if(n == 1)
true
else
foo(n-1)

it is.

Or are they equivalent? Does the definition of || as,

def || (p: => Boolean): Boolean

carry any deeper significance which prevents the call of foo(n-1) in the
first case being identified as a tail call (rather than merely making
it more difficult)?

Cheers,


Miles



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise