top | item 25517004

(no title)

rabbut | 5 years ago

> (In the following, I assume that tail-calls, i.e. those where a function end with another function call, but without modifying its result, do not actually use stack space. Once all recursive function calls are tail calls, the code is equivalent to an imperative loop, as we will see.)

No, it’s not “tail call”, it’s “tail recursion” or “tail-end recursion”.

“Tail call” could be interpreted as any call from a function’s end, even one that adds to the stack.

discuss

order

joppy|5 years ago

“Tail call” has a specific meaning in computer science, and it is possible to execute such a call without adding to the stack. Tail calls may not be directly recursive, they may be mutually recursive, or not even recursive at all.

chriswarbo|5 years ago

> “Tail call” could be interpreted as any call from a function’s end, even one that adds to the stack.

Tail calls might add to the stack, or they might not; but they don't need to (whether or not they do depends on the particular language, implementation and possibly compiler options). If a call needs to use stack space (or equivalent, e.g. growing the term size in a rewrite system), then it's certainly not a tail call.

> No, it’s not “tail call”, it’s “tail recursion” or “tail-end recursion”.

I wouldn't be so dogmatic about terminology, especially since it's at odds with others' usage. This article is a particularly poor choice to get hung up on too, since most of the examples use a pair of mutually-recursive functions (go+eval or up+down), which both call each other and themselves (depending on which branch is taken). How do they fit into your overly-precise terminology?

What about the top-level 'map' definitions themselves? Most of them consist of a single call to the go/down function: that doesn't need to add to the stack. Would you insist on naming that 'tail recursion' or 'tail-end recursion', even though there are no calls back into these functions from anywhere else?

mst|5 years ago

> “Tail call” could be interpreted as any call from a function’s end, even one that adds to the stack

That's why he said "I assume that tail-calls ... do not actually use stack space".

Also, 'tail recursion' is more likely to be read by people as referring to a tail call to the same function as is currently executing, whereas 'tail call' refers to the general case.

balfirevic|5 years ago

Tail call doesn’t have to be recursive.