Pure Function - Pure Expressions

Pure Expressions

Pure functions are required to construct pure expressions. Constant expressions are pure by definition. An expression consisting of a function subexpression applied to one or more argument subexpressions is pure if both these statements about the subexpressions hold:

  1. The function and argument subexpressions are pure expressions.
  2. The function subexpression yields a pure function.

Typically the function subexpression is simply a function identifier. Pure expressions are often referred to as being referentially transparent.

Evaluation of a given pure expression will yield the same result regardless of when or how many times evaluation occurs during program execution. This property is what makes it meaningful to talk about an expression's "value". It also makes it possible to replace an expression with the corresponding value (or it with an equivalent alternative expression) without changing the meaning of a program.

Read more about this topic:  Pure Function

Famous quotes containing the words pure and/or expressions:

    “I’m telling the truth.
    I’m standing at death’s door
    and even today
    my sight falls
    on that thicket
    on the Tpt’s pure banks,
    just as before.”
    —Hla Stavhana (c. 50 A.D.)

    “Its idea of “production value” is spending a million dollars dressing up a story that any good writer would throw away. Its vision of the rewarding movie is a vehicle for some glamour-puss with two expressions and eighteen changes of costume, or for some male idol of the muddled millions with a permanent hangover, six worn-out acting tricks, the build of a lifeguard, and the mentality of a chicken-strangler.”
    —Raymond Chandler (1888–1959)