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

Pages: 1-4041-

One recursion to loop them all

Name: Anonymous 2011-04-01 11:52

Why do you need any loop constructs if you have recursion

Name: Anonymous 2011-04-01 11:55

Why do you need any words if you have letters‽

Name: Anonymous 2011-04-01 12:00

Why do you need TCO if you are GvR?

Name: Anonymous 2011-04-01 12:05

Why do you need any recursion if you have recursion‽

Name: Anonymous 2011-04-01 12:23

Loops are communist.

Name: Anonymous 2011-04-01 12:34

Why do you need any sword if you have MY AXE!!

Name: Anonymous 2011-04-01 13:13

>>6
back to /b/, please

Name: Anonymous 2011-04-01 14:48

>>7
fuck you faggot

Name: Anonymous 2011-04-01 17:06

because doing a 'call' creates overhead (new stack frame, passing parameters, storing off registers)

Name: Anonymous 2011-04-01 17:14

>>9
I was going to ask, which will crash faster: a program that iterates, initializing a new integer with each pass, or a program that does the same thing recursively?

Name: Anonymous 2011-04-01 17:16

using recursion for a great number of calls will eventually deplete the stack memory causing a crash. for example, a default native c++ program compiled with VS2010 will only have a 1MB stack

Name: Anonymous 2011-04-01 17:18

>>9

long fact (long x) {
  long r = 1;
  while (x) r *= x--;
  return r;
}
long fact_rec (long x, long r) {
  return x? fact_rec(x-1,x*r) : r;
}

Name: Anonymous 2011-04-01 17:50

Because sometimes writing a recursive version of a loop is a pain in the F*ing ass.

Name: Anonymous 2011-04-01 18:13

>>13
Have you read your SICP today?

Name: Anonymous 2011-04-01 19:19

>>12

long fact(long n) { return n ? n * fact(n-1) : 1; }

Name: Anonymous 2011-04-01 19:39

>>15
Not tail recursive.

Name: Anonymous 2011-04-01 20:01

>>16
therefore it is good. the BDFL would be proud

Name: Anonymous 2011-04-01 20:10

>>17
huge faggot detected

Name: Anonymous 2011-04-01 20:13

>>17
Let us overflow our stacks.

Name: Anonymous 2011-04-01 20:20

>>18,19

have fun debugging your stack traces

oh wait

Name: Anonymous 2011-04-01 20:33

Because loop iteration is generally faster than recursion, even when tail recursion optimizations can be made.

Name: Anonymous 2011-04-01 20:40

>>21
and as we all know, that's why python is fast as fuck

Name: Anonymous 2011-04-01 20:51

>>22
Red herring. Python is slow as fuck due to dynamic duck typing and the global interpreter lock.

C/C++ or assembly code iteration is fast as fuck when compared to recursion.

Name: Anonymous 2011-04-01 20:51

>>21
no, but not all programmers can understand recursion, which is why Lisp and Haskell are dead dogs

Name: Anonymous 2011-04-01 21:00

Long live /prog/!

Name: Anonymous 2011-04-01 21:02

Long live /prog/!

Name: Anonymous 2011-04-01 21:03

/prog/ is dead

Name: Anonymous 2011-04-01 21:05

/prog/ is dead

Name: Anonymous 2011-04-01 21:06

Long live /prog/!

Name: Anonymous 2011-04-01 21:08

Long live /prog/!

Name: Anonymous 2011-04-01 21:10

Long live /prog/!

Name: Anonymous 2011-04-01 21:11

/prog/ is dead

Name: Anonymous 2011-04-01 21:13

/prog/ is dead

Name: Anonymous 2011-04-01 21:14

Long live /prog/!

Name: Anonymous 2011-04-01 21:16

Long live /prog/!

Name: Anonymous 2011-04-01 21:18

/prog/ is dead

Name: Anonymous 2011-04-01 21:21

/prog/ is dead

Name: Anonymous 2011-04-01 21:22

Long live /prog/!

Name: Anonymous 2011-04-01 21:24

Long live /prog/!

Name: Anonymous 2011-04-01 21:26

/prog/ is dead

Name: Anonymous 2011-04-01 21:27

Long live /prog/!

Name: Anonymous 2011-04-01 21:29

Long live /prog/!

Name: Anonymous 2011-04-01 21:30

/prog/ is dead

Name: Anonymous 2011-04-01 21:32

Long live /prog/!

Name: Anonymous 2011-04-01 21:33

Long live /prog/!

Name: Anonymous 2011-04-01 21:35

Long live /prog/!

Name: Anonymous 2011-04-01 21:37

/prog/ is dead

Name: Anonymous 2011-04-01 21:38

/prog/ is dead

Name: Anonymous 2011-04-01 21:40

/prog/ is dead

Name: Anonymous 2011-04-01 21:41

Long live /prog/!

Name: Anonymous 2011-04-01 21:43

Long live /prog/!

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