Download Downlaod File

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Nuclear magnetic resonance spectroscopy of proteins wikipedia , lookup

Transcript
Single assignment
See also: Static single assignment form
In pure functional programming, destructive assignment is not allowed, because of
side effects[5]
Any assignment that changes an existing value (e.g. x := x + 1) is disallowed in
purely functional languages.[4] In functional programming, assignment is discouraged
in favor of single assignment, also called initialization. Single assignment is an
example of name binding and differs from assignment as described in this article in
that it can only be done once, usually when the variable is created; no subsequent reassignment is allowed. Once created by single assignment, named values are not
variables but immutable objects.
An evaluation of expression does not have a side effect if it does not change an
observable state of the machine,[6] and produces same values for same input.[4]
Imperative assignment can introduce side effects while destroying and making the old
value unavailable while substituting it with a new one,[5] and is referred to as
destructive assignment for that reason in LISP and functional programming, similar to
destructive updating.
Single assignment is the only form of assignment available in purely functional
languages, such as Haskell, which do not have variables in the sense of imperative
programming languages[4] but rather named constant values possibly of compound
nature with their elements progressively defined on-demand. Purely functional
languages can provide an opportunity for computation to be performed in parallel,
avoiding von Neumann bottleneck of sequential one step at time execution, since
values are independent of each other.[7]
Impure functional languages provide both single assignment as well as true
assignment (though true assignment is typically used with less frequency than in
imperative programming languages). For example, in Scheme, both single assignment
(with let) and true assignment (with set!) can be used on all variables, and
specialized primitives are provided for destructive update inside lists, vectors, strings,
etc. In OCaml, only single assignment is allowed for variables, via the let name =
value syntax; however destructive update can be used on elements of arrays and
strings with separate <- operator, as well as on fields of records and objects that have
been explicitly declared mutable (meaning capable of being changed after their initial
declaration) by the programmer.
Functional programming languages that use single assignment include Clojure,
Erlang, F#, Haskell, Lava, OCaml, Oz, SASL, Scala (for vals), SISAL, Standard ML.
Non-backtracking Prolog code can be considered explicit single-assignment, explicit
in a sense that its (named) variables can be in explicitly unassigned state, or be set
exactly once. In Haskell, by contrast, there can be no unassigned variables, and every
variable can be thought of as being implicitly set to its value (or rather to a
computational object that will produce its value on demand) when it is created.