|
|
|
|
|
by dxbydt
653 days ago
|
|
> Functional programming is about finding the formula for a particular program. Can be disproved trivially. Anyone can code up a program that generates the nth prime for some n, by iteratively accumulating n primes starting from 2 using trial division. otoh, an actual formula that produces the nth prime would be an earth shaking event. |
|
So I ask you... how does a functional program do the algorithm you ask for above?
Recursion and the ternary operator. All iterative programs can be written in recursion and vice versa.
Another way of thinking about this is rather then formula, think expression. Functional programming is about coding up an expression that can fit on one line.
Anything that breaks the program into multiple lines means you're turning your functional expression into a list of procedures.