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

Pages: 1-

Iteration vs. Recursion

Name: Anonymous 2010-12-09 7:10

kgo

Name: Anonymous 2010-12-09 7:25

Iteration is like dodedodedo
but Recursion is like dddddoeoeo

Name: Anonymous 2010-12-09 7:40

“To iterate is human, to recurse divine.” - L. Peter Deutsch

Name: Anonymous 2010-12-09 7:53

Recur#SEGMENTATION FAULT

Name: Anonymous 2010-12-09 13:34

Recursion HBTCO.
Thread ended peacefully.[/aa]

Name: Anonymous 2010-12-09 20:58

Let's talk about languages that don't have recursion.

Name: Anonymous 2010-12-09 21:13

Let's talk about recursions that don't have languages

Name: Anonymous 2010-12-09 21:18

>>6
Brainfuck.

Name: Anonymous 2010-12-09 21:29

Each can substitute for the other. I see no superior construct out of the two.

Name: Anonymous 2010-12-09 21:52

>>9
Then implement a compiler that translates a minimalistic language that can do recursion to Brainfuck. Have fun.

Name: Anonymous 2010-12-09 22:05

>>10
I meant when writing code. Although it is entirely possible.

Name: Anonymous 2010-12-09 22:11

Hm, it would be cool to implement a virtual CPU in Brainfuck and have it execute from its own memory, which would be loaded before boot-up. I might actually do this if I get too bored.

Name: Anonymous 2010-12-10 21:15

recursion is recursion

Name: Anonymous 2010-12-10 21:19

iter = ""; begin: iter+="iterative is " goto begin;

Name: Anonymous 2010-12-10 21:42

>>14
s/ve/on/

Name: Anonymous 2010-12-11 1:01

iteration > recursion

Iteration might produce larger code, but you're pretty much guaranteed never to cause a stack overflow. Also, with iteration, your code would probably be faster as well.

Name: Anonymous 2010-12-11 1:18

>>16
Not if YHBTCO.

Name: Anonymous 2010-12-11 1:28

>>10
That's quite easy, actually. Implementing stack in bf is straightforward.

Name: Anonymous 2010-12-11 1:35

>>16
You don't get stack overflows in The Go Programming Language.

Name: Anonymous 2010-12-11 1:42

>>19
You don't get laid                                                                                          

Name: Anonymous 2010-12-11 5:50

Name: Anonymous 2010-12-11 5:58

>>19
U MENA The D Programming Language.

Name: Anonymous 2010-12-11 6:03

>>21
More like "naive recursion vs memoized-but-still-naive recursion vs iteration".

As someone mentioned in this thread, tail-call recursion with TCO gets optimised to a simple jump, like a loop.

Name: Anonymous 2010-12-11 12:14

Name: Anonymous 2010-12-11 12:53

>>21
static Dictionary resultHistory = new Dictionary();
Yeah. "Optimised."

Name: Anonymous 2010-12-11 21:50


//Shit code
void main(void){
    int i;
    for(i=0;i<10;i++)
        fprintf(stdout,"IHBT");
}
[code]

[code]
//Best code
void print(char[] s, int i,int c){
    fprintf(s);
    if(i>c)
        return;
    print(s,i+1,c);
}

void main(void){
    print("IHBT",0,9);
}

Name: Anonymous 2010-12-12 1:58

>>26
print(s,i+1,c);

PIG DISGUSTING

Name: Anonymous 2010-12-12 6:27

I'M A FUNCTIONAL PROGRAMMING
SON OF A BITCH IMPERATIVE PROGRAMMING
IMPERATIVE PROGRAMMING IS PIG
DO YOU WANT A STATE?
DO YOU WANT SIDE EFFECTS?
IMPERATIVE PROGRAMMING IS PIG DISGUSTING
C IS A MURDERER
FUCK IMPERATIVE PROGRAMMING

Name: Anonymous 2010-12-12 9:33

>>26
Why do you need the second variable?


if (c == 0)
   return;
print (s, c-1);

Name: Anonymous 2010-12-12 11:11

free beer as in free beer.

Name: Anonymous 2010-12-12 11:32

Doesn't recursion suck in terms of performance, in each turn of recursion pushing the local state to stack, making things uglier and uglier?

Name: Anonymous 2010-12-12 11:33

free pleasure as in sex

Name: Anonymous 2010-12-12 11:35

Name: Anonymous 2010-12-12 22:16

>>31
only if the lower items have to be accessed in later iterations. Any recursive function in C shouldn't give you any problems if you turn on optimization. But if it does you'd better refactor it anyway.
It's also very practical to write a recursive function in forth first to test it out.

Name: Anonymous 2011-02-04 16:16

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