Skip to content

Commit

Permalink
Merge pull request #292 from 3noch/patch-1
Browse files Browse the repository at this point in the history
Clarify "purity" when globals are involved
  • Loading branch information
mrocklin committed Feb 27, 2016
2 parents 1a451dd + ddff9cd commit 4637d59
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions doc/source/purity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ The function ``min`` is pure. It always produces the same result given the
same inputs and it doesn't affect any external variable.

The function ``powers`` is impure for two reasons. First, it depends on a
global variable, ``exponent``. Second, it changes the input ``L`` which may
have external state. Consider the following execution:
global variable, ``exponent``, which can change[*]_. Second, it changes the
input ``L`` which may have external state. Consider the following execution:

.. code::
Expand Down Expand Up @@ -70,6 +70,8 @@ that we need to keep track of the ``exponent`` variable separately whenever we
use ``powers``. As we use more functions these extra variables become a
burden.

.. [*] A function depending on a global value can be pure if the value never
changes, i.e. is immutable.
State
-----
Expand Down

0 comments on commit 4637d59

Please sign in to comment.