What is functional programming? Why is C language not a functional language?
Functional languages have two main characteristics: 1. Functions are "first class citizens". 2. The "immutability" of the data. The "no side effects" of the operation,
which circumvents the " lock".
The function of functional programming is an exponential function: given input, fixed output, no side effects. Any language can use a functional style,
but the difficulty is different.
For example, the function y = f(x). and the function t = g(z); In mathematics, when t is in the domain of f(x), it can form a composite function y=f(g(z));For the second question, why is C not a functional language?
Because this effect cannot be achieved in C.
int f(int x) { print x;} ===== y = f(x) int f1(int (*g)(int)) { print g(z);} ===== y = f1(g(z)) int g(int z) {return z;} ========= t = g(z)
From the above function definition, we can see that when the parameter of the function f(x) is defined as int, the function g(z) cannot be passed to it as a formal parameter.
On the other hand, the function f1() cannot accept int as a parameter.Therefore, C cannot achieve the kind of effect of mathematical functions.
But in clojure it does.
(defn f [x] (print x)) ======= y = f(x) (defn g [z] z) ======= t = g(z)
At this time, the results of (f (g 3)) and (f 3) are the same, achieving a mathematical effect.
Furthermore, C does not have the characteristics of a functional language 2.What are the common functional languages?
coljure、scala、Haskell。
Why are languages such as python/javascrip not functional languages, because they do not have the characteristics of functional languages 2.
What is functional programming? Why is C language not a functional language?
Guess you like
Origin blog.csdn.net/lx1848/article/details/77619881
Ranking