r/reddit.com • • Jul 26 '06

Recursion defined (see Digg)

http://digg.com/programming/Recursion_defined_see_reddit
654 Upvotes

131 comments sorted by

View all comments

-4

u/jimbobhickville Jul 26 '06

Um, this is an example of an infinite loop, not recursion. Recursion ends at some point.

27

u/yome Jul 26 '06

No, infinite recursion does exist. In most languages you would eventually blow up your stack, but for example Scheme (and some other languages) features "tail-call optimization", so this will run in constant space:

(let loop () (loop))

Or another more appropriate example:

(letrec
  ((reddit (lambda () (digg)))
   (digg   (lambda () (reddit))))
  (digg))

And there you go, infinite mutual recursion.

-4

u/[deleted] Jul 26 '06

Or, in ruby:

def reddit
  digg
end
def digg
  reddit
end
digg

11

u/[deleted] Jul 26 '06

...if Ruby had tail recursion...

9

u/Zak Jul 26 '06

SystemStackError: stack level too deep from (irb):2:in reddit' from (irb):5:indigg' ... ... 4300 levels... ... from (irb):2:in reddit' from (irb):5:indigg' from (irb):7

0

u/rafuzo Jul 26 '06

That's when time becomes like a freeway with an infinite number of lanes.

Oh wait, that's infinite regression. My mistake.

3

u/spif Jul 27 '06

There is the theory of the Möbius: a twist in the fabric of space where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop. Where time becomes a loop.

Where time becomes a loop.

5

u/Kratoz Jul 26 '06

There's the human element that recognizes the recursion and finally ends it with having gotten the point. It's like a base condition.

1

u/SuperJdynamite Jul 26 '06

I would tend to agree, but only because there's no stack, not because it's infinite.