Functional programming
lastmod 2025-12-10created 2015-05-0513 edits
Functional programming is a programming paradigm that treats data processing as the evaluation of mathematical functions and avoids state and mutable data. Unlike imperative programming, which emphasizes changing state, functional programming emphasizes the application of functions. Functional programming is rooted in lambda calculus, a formal system developed in the 1930s to study computability, the decision problem, function definition, function application, and recursion. Many functional programming languages can be viewed as elaborations on lambda calculus.
Mathematical functions differ from the functions used in imperative programming: imperative functions can have side effects that change the value of program state. Because of this, imperative functions lack referential transparency, and the same code can produce different results depending on the state of the running program. In functional code, by contrast, a function's output depends only on the arguments passed to it, so calling a function f with the same value for argument x always yields the result f(x). Eliminating side effects makes it much easier to understand and predict a program's behavior. This is one of the key motivations for developing with functional programming.
The earliest purely functional languages, such as Hope, received more attention in academia than in commercial software development. However, major functional languages such as Common Lisp, Scheme, ISLISP, Clojure, Racket, Erlang, OCaml, Haskell, Scala, and F# are used to develop industrial and commercial applications at a wide range of organizations. Functional languages are also used in domain-specific programming languages (Domain Specific Language) such as R (statistics), Mathematica (symbolic and number-theoretic mathematics), J, K, and Q from Kx Systems (financial systems), XQuery/XSLT (XML), and Opal. Widely used domain-specific declarative languages such as SQL and lex/Yacc use elements of functional languages, particularly in avoiding mutable values.
Programming in a functional style is also possible in languages not specifically designed as functional languages. For example, the imperative Perl programming language has been the subject of a book explaining how to apply functional programming concepts [citation needed]. C# 3.0 added syntax that allows writing in a functional style.
Lambda vs Closure
- New in PHP v5.3: What are lambda functions and closures
- Lambda Expressions and Closures
- Difference between lambda and closure?
- [Recommended] Stackoverflow: What is the difference between a 'closure' and a 'lambda'?
- [Recommended] Stackoverflow: JavaScript closures vs. anonymous functions
- Lambda
- A function without a name (Anonymous function).
- See more: Lambda calculus
- Closure
- A function executed (or evaluated) in an environment with one or more bound (Bound) variables.
Closure Examples
package main
func nextValue() func() int {
i := 0
return func() int {
i++
return i
}
}
func main() {
next := nextValue()
println(next()) // 1
println(next()) // 2
println(next()) // 3
anotherNext := nextValue()
println(anotherNext()) // 1 다시 시작
println(anotherNext()) // 2
}
Programming language
See also
Favorite site
References
-
Why_functional_programming_matters_-_John_Hughes_1989.pdf ↩