Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Functional programming
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Functional programming
(section)
Add topic