Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Functional programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Pure functions === {{main|Pure function}} [[Pure function]]s (or expressions) have no [[side effect (computer science)|side effects]] (memory or I/O). This means that pure functions have several useful properties, many of which can be used to optimize the code: * If the result of a pure expression is not used, it can be removed without affecting other expressions. * If a pure function is called with arguments that cause no side-effects, the result is constant with respect to that argument list (sometimes called [[referential transparency]] or [[idempotence]]), i.e., calling the pure function again with the same arguments returns the same result. (This can enable caching optimizations such as [[memoization]].) * If there is no data dependency between two pure expressions, their order can be reversed, or they can be performed in [[parallelization|parallel]] and they cannot interfere with one another (in other terms, the evaluation of any pure expression is [[thread-safe]]). * If the entire language does not allow side-effects, then any evaluation strategy can be used; this gives the compiler freedom to reorder or combine the evaluation of expressions in a program (for example, using [[deforestation (computer science)|deforestation]]). While most compilers for imperative programming languages detect pure functions and perform common-subexpression elimination for pure function calls, they cannot always do this for pre-compiled libraries, which generally do not expose this information, thus preventing optimizations that involve those external functions. Some compilers, such as [[GNU Compiler Collection|gcc]], add extra keywords for a programmer to explicitly mark external functions as pure, to enable such optimizations. [[Fortran 95]] also lets functions be designated ''pure''.<ref name=fortran95>{{cite web |title=ISO/IEC JTC 1/SC 22/WG5/N2137 β Fortran 2015 Committee Draft (J3/17-007r2) |publisher=International Organization for Standardization |date=July 6, 2017 |url=https://wg5-fortran.org/N2101-N2150/N2137.pdf |pages=336β338}}</ref> C++11 added <code>constexpr</code> keyword with similar semantics.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)