Skip to main content

Timeline for Loop without 'looping'

Current License: CC BY-SA 3.0

13 events
when toggle format what by license comment
Jul 11, 2014 at 10:49 comment added Alex Celeste If you want pedantry, Scheme doesn't have "tail call optimisation", it has "proper tail calls". It is not an optimisation, it is a basic requirement of the language standard and failing to supply it is not permitted, so "optimisation" (or the suggestion that it has anything to do with recursion) is very much a discouraged term.
Jul 11, 2014 at 9:53 comment added Ord @millinon just to be super pedantic and to drag out this discussion longer, in the Scheme programming language, this optimization is a language feature. It's in the spec that if you make a tail-recursive call, the interpreter/compiler has to reuse the last stack frame. This is because Scheme has no built-in looping structures, so the only way to implement a loop in Scheme is to do tail-recursion, and it would kind of suck if you got stack overflows from trying to loop too many times :)
Jul 10, 2014 at 5:09 comment added millinon @Izkata What you describe is an optimization provided by compilers, not a language feature. Tail recursion optimization allows the compiler to produce code that re-uses the stack frame, while still providing recursive behavior. You're right that tail recursion optimization is an example of recursion that can be converted to a loop fairly easily. However, since an exec call does not provide the same behavior as launching a new process and waiting for it to terminate, it is not recursive.
Jul 10, 2014 at 3:16 comment added Izkata @millinon In a language that supports the optimization, tail recursion replaces the previous call in the call stack, similar to how exec replaces the previous process. It won't overflow, either.
Jul 10, 2014 at 2:42 comment added millinon @Izkata Tail recursion is still recursion, but this isn't recursion. Recursion implies a function (or process in this case) 'waiting' for another iteration of itself to terminate. In this case, exec causes the new process to replace the original one, so there's no call stack that will eventually return or overflow.
Jul 10, 2014 at 2:05 comment added Izkata @mniip Tail recursion, then, if it applied at the process level
S Jul 9, 2014 at 20:53 history suggested DatEpicCoderGuyWhoPrograms CC BY-SA 3.0
Improved formatting.
Jul 9, 2014 at 20:36 review Suggested edits
S Jul 9, 2014 at 20:53
Jul 9, 2014 at 16:41 comment added mniip @CailinP It's also not recursion because it does not contain a stack. execv replaces the current process with a new one.
Jul 9, 2014 at 14:10 comment added CailinP Thanks for the explanation. Since v[0] is the name of the executable and not the name of the function, I don't think this counts as recursion. I like this!
Jul 9, 2014 at 14:08 comment added kwokkie execv() executes the file named by the first argument. Since v[0] is the name of this executable, it executes itself again.
Jul 9, 2014 at 13:51 comment added CailinP Can you explain it a bit more? What exactly is it doing?
Jul 9, 2014 at 13:42 history answered kwokkie CC BY-SA 3.0