Impact (computer science)
In theoretical computer science , effect describes the change in the state in which an abstract machine is located. Sometimes also a side effect a term to speak, back-translation of the English side effect (German: side effect ) back.
Specified effects
A variable represents a very specific value at every point in time during the program sequence. The totality of all variables and their values defines the program state of an abstract machine (see operational semantics ). Operations with specified effects can change it.
A distinction must be made between these specified effects and the unspecified effects that are outside the scope of the system. Depending on the definition, this can also include the screen output, for example. These effects may not be taken into account for the abstract machine.
Programming languages
In most programming languages, evaluating an expression can have a specified effect. Expressions and functions can either have an effect or have no effect. The group of functions with effect, for example, usually includes everyone who has to do with the input or output of data. Non-effective functions in high-level languages are mathematical functions such as sine , cosine or square root .
Freedom of effect in purely functional programming
In purely functional programming languages , the evaluation of an expression, unlike other programming languages, never has a specified effect. There are no instructions in such languages , only expressions . No variables and no value assignments are used. An effect in the form of outputting a result is not a specified effect in this case. In purely functional programming, there are therefore no changes in state in the sense of the above definition and therefore no effects. The programming language is stateless and ineffective.
This property of a programming language is known as referential transparency . It says that the value of an expression depends only on its environment and not on the point in time or a certain order of evaluation. Examples of completely ineffective languages are the purely functional programming languages Haskell , Elm or pure Lisp ( pure Lisp ).
In other functional programming languages such as Scheme , procedure calls can change the values of variables or trigger screen outputs. The referential transparency is lost and Scheme is therefore not a purely functional language. In order to emphasize this property in the Scheme language used for teaching purposes, procedures with effects are marked with an exclamation mark, for example in the variable assignment (set! a 2)
.
example
The following sample program , with its brackets and the prefix notation, is typical for a language such as Lisp or Scheme and returns one of two possible calculation results depending on a condition.
(if (= a 0)
(+ a 1)
(* a 2))
The result is not assigned to a variable. In particular, however, the order of evaluation of the individual functions ( if
, =
, +
and *
) no influence on the result. Each expression can be replaced by its value at any point. That is referential transparency .
Individual evidence
- ↑ a b Hans-Jürgen Appelrath, Jochen Ludewig: Lecture notes for computer science - a conventional introduction . Version February 11, 1999; Retrieved August 10, 2008
- ^ A b P. Rechenberg, G. Pomberger: Informatik-Handbuch . Carl Hanser Verlag, Munich / Vienna 2006, ISBN 978-3-446-40185-3 .
- ↑ a b C. Wagenknecht: Programming paradigms . Teubner, Wiesbaden 2004, ISBN 978-3-519-00512-4 .
- ↑ a b C. Schiedermeier: Functional programming . ( Memento from May 22, 2005 in the Internet Archive ) (PDF) Nuremberg 2002.