Iteration vs. Recursion
1
Name:
Anonymous
2010-12-09 7:10
kgo
2
Name:
Anonymous
2010-12-09 7:25
Iteration is like dodedodedo
but Recursion is like dddddoeoeo
3
Name:
Anonymous
2010-12-09 7:40
“To iterate is human, to recurse divine.” - L. Peter Deutsch
4
Name:
Anonymous
2010-12-09 7:53
Recur#SEGMENTATION FAULT
5
Name:
Anonymous
2010-12-09 13:34
Recursion HBTCO.
Thread ended peacefully.[/aa]
6
Name:
Anonymous
2010-12-09 20:58
Let's talk about languages that don't have recursion.
7
Name:
Anonymous
2010-12-09 21:13
Let's talk about recursions that don't have languages
8
Name:
Anonymous
2010-12-09 21:18
9
Name:
Anonymous
2010-12-09 21:29
Each can substitute for the other. I see no superior construct out of the two.
10
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.
11
Name:
Anonymous
2010-12-09 22:05
>>10
I meant when writing code. Although it is entirely possible.
12
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.
13
Name:
Anonymous
2010-12-10 21:15
recursion is recursion
14
Name:
Anonymous
2010-12-10 21:19
iter = ""; begin: iter+="iterative is " goto begin;
15
Name:
Anonymous
2010-12-10 21:42
16
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.
17
Name:
Anonymous
2010-12-11 1:18
18
Name:
Anonymous
2010-12-11 1:28
>>10
That's quite easy, actually. Implementing stack in bf is straightforward.
19
Name:
Anonymous
2010-12-11 1:35
>>16
You don't get stack overflows in
The G o P rogramming L anguage .
20
Name:
Anonymous
2010-12-11 1:42
>>19
You don't get laid
21
Name:
Anonymous
2010-12-11 5:50
22
Name:
Anonymous
2010-12-11 5:58
>>19
U MENA
The D Programming Language .
23
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.
24
Name:
Anonymous
2010-12-11 12:14
25
Name:
Anonymous
2010-12-11 12:53
>>21
static Dictionary resultHistory = new Dictionary();
Yeah. "Optimised."
26
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);
}
27
Name:
Anonymous
2010-12-12 1:58
>>26
print(s,i+1,c);
PIG DISGUSTING
28
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
29
Name:
Anonymous
2010-12-12 9:33
>>26
Why do you need the second variable?
if (c == 0)
return;
print (s, c-1);
30
Name:
Anonymous
2010-12-12 11:11
free beer as in free beer.
31
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?
32
Name:
Anonymous
2010-12-12 11:33
free pleasure as in sex
33
Name:
Anonymous
2010-12-12 11:35
34
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.
35
Name:
Anonymous
2011-02-04 16:16