Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Tail Recursion

Name: Anonymous 2011-10-19 21:09

How do i make this function tail recursive in java


public int fib(int n)
{
  return( n <= 1 ? n : fib(n-1) + fib(n-2) );
}

Name: Anonymous 2011-10-21 3:22

A tail call is just returning another function.


return fn();


Some compilers will optimize it to run in constant space.


This is not doing it right as you are returning an operation on the function result.


return n * fn();


Have a look at this:
http://stackoverflow.com/questions/5453376/tail-call-optimization-for-fibonacci-function-in-java

Name: Anonymous 2011-10-21 7:05

Java
GC is shit.

Name: 11 2011-10-21 7:10

>>37
Thanks.
>>17-19,30
umad

Name: Anonymous 2011-10-21 9:08

>>41
A tail call is just returning another function.
It's just returning the return value of another function.
Or better yet: a tail call is the last thing a procedure does before returning to its caller. In your second example, * is in tail position, thus you're tail calling *.

Name: Anonymous 2011-10-21 18:44

>>27
It was named 'Boost' to ``Boost the programming of C++ apps''.

But honestly, and I actually love C++, Boost makes programming tedious.

Mostly because boost got an obnoxious, pointlessly templated API, and because the people behind boost think that 'header-only library' are the OMG BEST THING EVUR. But only if you feel like waiting 2 hours each time you recompile your ``Hello World''.

Name: Anonymous 2011-10-21 19:02

>>45
What if C++ had a module system?

Name: Anonymous 2011-10-21 19:57

>>46
Even in that case the Boost people would find a way to slow down compilation by 10000%. Seriously.

Name: Anonymous 2011-10-21 21:43

>>45,47
Stop buying realdolls and spend your money on a better computer, faggot.

Name: Anonymous 2011-10-22 0:05

>>48
Hardware isn't getting faster anymore, faggot.
http://bunniestudios.com/blog/images/ohs11_clockscaling.png

Name: Anonymous 2011-10-22 0:45

>>49
Blame the shitty x86 architecture for that. POWER6 is at 4.7 GHz and POWER7 is 4.25 GHz but will only get faster when POWER7+ comes out.

Name: Anonymous 2011-10-22 0:54

>>50
<--- That's cool and all but check my dobz over there

Name: Anonymous 2011-10-22 4:52

>>38 funny in fact... until you get stackless

Name: Anonymous 2011-10-22 7:28

>>50
SPECint_base 2006:
3.4 GHz Core i7-2600 - 44.6
3.0 GHz C2D (E6850) - 20.2
4.7 GHz Power6 (p570) - 17.8

Reminds me of NetBurst. Frequency isn't everything.

POWER is also expensive as hell.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List