2 ms·
The single most important characteristic of functional programming is that all control flow routing is done by function calls. Functional programming can inclu
by kazinator 8y ago
The single most important characteristic of functional programming is that all control flow routing is done by function calls.
Functional programming can include side effects.
This is still basically functional:
1> (let ((cntr 0))
(list (mapcar (lambda (x) (inc cntr) (* x x)) '(1 2 3)) cntr))
((1 4 9) 3)
Just not "purely functional". Functional means we work mostly by applying arguments to functions, and avoiding loops, ifs and gotos in favor of canned mapping operations that work with sequences and such. If an assignment sneaks in here and there, it's still functional.
(if antecedent consequent alternative)
is not functional because control flow is being diverted by a special operator without the use of functions. But if we have a function iff:
(iff f-antecedent f-consequent f-alternative)
such that iff will call the f-antecedent function and then either call f-consequent or f-alternative based on what f-antecedent returns, then that is functional.
Functional just means "obsessed with functions"; without further qualification, it has nothing to do with purity.
That's just certain politico-religious camps trying to hijack the word for their own agenda.