Timeline for Is it possible to use functional paradigm in imperative languages?
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 13, 2015 at 18:16 | comment | added | ALXGTV | In that case I believe it is silly to write tail-recursive functions as opposed to loops just for the sake of being functional, and for the sake of "avoiding side-effects" which aren't even avoided since a tail-recursive function is transformed into a loop + side effects anyway. | |
| Jun 13, 2015 at 18:14 | comment | added | ALXGTV | Either way my point was that TCO/PTC is an assembly-level detail not a high-level language detail which determines whether a languages is functional or not. Loops do not complicate the language, in-fact they often are simpler than writing a tail-recursive function with lots of arguments especially if only a few of them are actually mutated, this function then has to be wrapped up in another function in order to hide the extra "implementation" arguments. | |
| Jun 13, 2015 at 18:09 | comment | added | ALXGTV | I'm not sure what you mean by your distinction between tail-call optimization and "Proper Tail Calls", my assumption is that your referring to the semantics of languages whose standards guarantee tail-call optimization e.g. Scheme. In that case C does not enforce that tail-calls are eliminated however decent compilers will perform the optimization. | |
| Jun 13, 2015 at 15:34 | comment | added | Jörg W Mittag | that object-oriented data abstraction is impossible to achieve without Proper Tail Calls. Continuation Passing Style is also impossible without PTC, because again, subroutines never return, instead the call a subroutine which represents the next step in the computation. Loops are also hard to implement without Proper Tail Calls, they have to be added as a separate language feature, needlessly complicating the language. | |
| Jun 13, 2015 at 15:33 | comment | added | Jörg W Mittag | TCO is a compiler optimization, but Proper Tail Calls are not, they are a language feature. You cannot rely on compiler optimizations, because they aren't part of the language's semantics. But if the language semantics guarantee Proper Tail Calls, then you can write code that takes advantage of that. For example, State Machines can be trivially implemented using subroutine calls for state transititions, but those subroutines never return, they go from state to state. Without Proper Tail Calls, you will blow the stack. Another example is OO, Steele, Cook and others have repeatedly demonstrated | |
| Jun 13, 2015 at 14:12 | comment | added | ALXGTV | P.S. iterating over an infinite list will freeze your computer, nobody ever iterates over an infinite list, what you probably call iteration is the construction of a generator which can be done in C | |
| Jun 13, 2015 at 14:11 | comment | added | ALXGTV | Tail call elimination is an optimisation feature of the compiler not the language, most decent compilers eliminate tail calls. IMHO trying to go out of your way to express iteration as tail recursion just for the sake of being functional and "cool" is silly, I wouldn't consider mutating a non-shared local variable a a significant side-effect, most functional languages do that, behind the hood, anyway if they can detect that the variable is only used in one place. | |
| Dec 12, 2014 at 2:02 | vote | accept | mip | ||
| Dec 11, 2014 at 19:13 | history | edited | Jörg W Mittag | CC BY-SA 3.0 |
added 218 characters in body
|
| Dec 11, 2014 at 18:35 | history | answered | Jörg W Mittag | CC BY-SA 3.0 |