« Return to Thread: Tail calls via trampolining and an explicit instruction

Re: Tail calls via trampolining and an explicit instruction

by James Iry-2 :: Rate this Message:

Reply to Author | View in Thread

Okay, some thought gave me a case where it makes a difference

def foo(x : Boolean) : TailRec[Unit] = if(x) tailCall(foo(false)) else done(println("hello"))

val x = foo(true)

With either strict or c-b-n parameters on done "hello" isn't printed until you trampoline(x).  But...

val y = foo(false)

With c-b-n, you get the same behavior : it's waiting for trampoline(y) to evaluate.  But with strict arguments, "hello" is printed immediately without a call to trampoline(y).

On Wed, Nov 26, 2008 at 10:58 AM, martin odersky <martin.odersky@...> wrote:
> Also, my base case used call-by-name in its construction.  I did that to
> ensure side effects always occur in the expected order, but the more I think
> about it the more I think that strict evaluation achieves that too.
>
I'd think so, yes.

Cheers

 -- Martin

 « Return to Thread: Tail calls via trampolining and an explicit instruction