Pure function

From CS 61A Wiki
Revision as of 16:08, 25 May 2014 by Axis (Talk | contribs)


Jump to: navigation, search

A pure function produces no effects other than returning a value. Its return value depends only on the inputs. Given the same arguments, it always returns the same value.

Contrast a pure function with a non-pure function.

Examples

  • add always returns the sum of the arguments and has no side effects.
  • square

Sources