4 ms·
> Apparently this concept is not even believed by the majority of people on this thread if you read the whole thing. > I originally stated that for loops and H
by kbp 9y ago
> Apparently this concept is not even believed by the majority of people on this thread if you read the whole thing.
> I originally stated that for loops and HO functions are equivalent and this entire thread consists of people disputing that statement.
My read of the thread is that your posts seem to be going beyond saying they're functionally equivalent, and saying that there's no value in using reduce and friends because they're functionally equivalent.
Most of your posts aren't addressing that tail recursion is a form of iteration (yes, or alternately that recursion can be done without a lexically recursive function) and that map/reduce/etc can be implemented in terms of recursion or for loops; you're contrasting the HOF's with for loops like they're competitors. The HOF's are an abstraction over iteration, whatever syntax was used to write that iteration.
Most of the responses aren't disputing that they accomplish the same thing, they're just saying that there is value in using the HOF's. You would be getting the same kinds of replies if you were insisting there's no difference between HOF's and direct recursion.
> You're the one dude
I'm not a dude.
- crimsonalucard 9y agoI never said there's no value. I quote myself: > it's just a bit cooler or convenient to use map in place of a for >Most of your posts aren't addressing that tail recursion is a form of iteration (yes, or alternately that recursion can be done without a lexically recursive function) Why should I address this? This is not the main point. Even recursion without a tail can be considered a form of iteration. But how is this the topic of conversation? We are talking about the equivalency between HOFs and loops. Why are you bringing up the fixed point combinator? >you're contrasting the HOF's with for loops like they're competitors. The HOF's are an abstraction over iteration, whatever syntax was used to write that iteration. No I'm not! Not at all! I'm saying HOFs and LOOPS are ultimately the same thing!!! and thus when you use them in code you are not ultimately changing the paradigm of your programming to functional. The overall structure of your program is still imperative. >You would be getting the same kinds of replies if you were insisting there's no difference between HOF's and direct recursion. There's not much of a difference, I quote again: >> it's just a bit cooler or convenient to use map in place of ...
- kbp 9y ago> Why are you bringing up the fixed point combinator? I didn't mean the fixed point combinator, I was responding to "So all recursion is equivalent to a for loop + a stack." A recursive algorithm implemented with a for loop and a stack instead of function calls and the processor stack isn't equivalent to recursion, it is recursion, just not the lexical kind. This is just semantics and we agree with each other. > Why should I address this? We are talking about the equivalency between HOFs and loops. Because for loops are equivalent to recursive procedures, not to map and reduce; map and reduce are much more restricted. You can implement a for loop using pure function application, and you can implement recursive pure functions using a for loop. Map and reduce live on a higher abstraction level, and because the two lower level strategies are equivalent, which one is used is irrelevant. Saying that they're not functional because they can be implemented with a for loop makes as much sense as saying that a for loop is functional because it can be implemented with pure function application. To me, a for loop is an imperative construct, and map and reduce are functional constructs, regardless of how any of them are implemented.
- crimsonalucard 9y ago>To me, a for loop is an imperative construct, and map and reduce are functional constructs, regardless of how any of them are implemented. Well if the map is implemented using muteable variables then it is not a functional construct is it? If your entire program utilizes maps and filters and folds but is muteable then it is not a functional construct. Here is the definition of a functional language according to Wikipedia: "In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions[1] or declarations[2] instead of statements."