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

Recursion is stupid and wasteful

Name: Anonymous 2013-05-23 4:36

There is nothing that recursion can do that can't be done simpler and more elegantly with a plain for loop.

Name: Anonymous 2013-05-25 20:50

>>36
Are you talking about the books? If so, than you are retarded. They all suck except Ring.

Name: Anonymous 2013-05-25 20:58

>>40
PC-98 is so kawaii.

Name: Anonymous 2013-05-25 21:11

/* like hell will I implement qsort down to width 1 */
why the fuck not faggot

Name: Anonymous 2013-05-25 22:09

>>43
Do it yourself.  The non-recursive version doesn't really require any added complexity to switch off sorting methods, because checking for completion is the same as checking for small problem size, and it would be suboptimal anyway, I'm pretty sure

As a side note, the stack used in the nonrecursive version requires only one argument pushed, whereas traditional recursive qsort requires much more (instruction pointer, data, length).  If the partition() method is sufficient, the maximum depth of the stack can be calculated beforehand to remove the irritating realloc() calls (I think my version bounds it as (to-from)/2).  Also, the touted multithreading of qsort can still be used, especially since the explicit stack allows forking/threading at a predetermined arbitrary level. So the non recursive version pretty much uses better than tail-recursion for both calls, and the only overhead is moving the stack from implicit to explicit representation.

Name: Anonymous 2013-05-26 8:44

>>44
WAT R U, A FUCKIN STACK BOY OR SUM SHIT?

Name: Anonymous 2013-05-26 10:11

>>45
HOW BOUT I POP U INNA MOUTH THEN PUSH YOU ON UR ASS!

Name: Anonymous 2013-05-26 15:43

Enjoy your stack overflows, recursive fagshits.

Name: Anonymous 2013-05-26 15:54

>>47
Tail call optimization ``in Lithp''

Name: Anonymous 2013-05-26 15:56

>>48
Any place a Tail Call optimization is used, it can be implemented just as well or better by a goto.  Furthermore, these gotos don't have to be at the very end of the function, so you don't have to rely on a magic position to make your code not suck.

Name: Anonymous 2013-05-27 15:32

>>1
(defmemo fast-fib (x) (if (< x 2) x (+ (fib (- x 2)) (fib (- x 1)))))

;; definition of defmemo cut out for simplicity (though it isn't hard to write)

Name: Anonymous 2013-05-27 15:43

Any place a goto is used, it can be implemented just as well or better by a jump instruction.  Furthermore, these jumps don't have to be local to a function, so you don't have to rely on a magic position to make your code not suck.

Name: Anonymous 2013-05-27 15:50

>>50

*(defmemo fast-fib (x) (if (< x 2) x (+ (fast-fib (- x 2)) (fast-fib (- x 1)))))

Name: Anonymous 2013-05-27 16:01

nested for loops are at the top of elegance.

Name: Anonymous 2013-05-27 16:57

>>50
that's not fast, that's just not horrendously slow.

you went from exponential to linear but you can still go logarithmic - if you knew how..

Name: Anonymous 2013-05-27 19:45

that's not hot, that's just not horrendously plain.

you went from my mouth to my vagina, but you can still go anal - if you knew how..

Name: Anonymous 2013-05-27 22:00

>>54
I wasn't saying it was very fast, but it is probably simpler and more elegant than an iterative solution.

Name: Anonymous 2013-05-27 22:00

>>56
nevermind, i did call it fast-fib.

Name: Anonymous 2013-05-28 3:31

>>44
This optimization is easy for any function that only makes calls to itself. It might be possible in more general scenarios too but I need to think about it.

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