Today, the most commonly used notation for this operation is x = expr (originally Superplan 1949–51, popularized by Fortran 1957 and C).
In some languages, the symbol used is regarded as an operator (meaning that the assignment statement as a whole returns a value).
The purpose is to enforce referential transparency, i.e. functions that do not depend on the state of some variable(s), but produce the same results for a given set of parametric inputs at any point in time.
An assignment operation is a process in imperative programming in which different values are associated with a particular variable name as time passes.
Purely functional languages can provide an opportunity for computation to be performed in parallel, avoiding the von Neumann bottleneck of sequential one step at a time execution, since values are independent of each other.
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 (for data structures, not vars), Erlang (it accepts multiple assignment if the values are equal, in contrast to Haskell), F#, Haskell, JavaScript (for constants), Lava, OCaml, Oz (for dataflow variables, not cells), Racket (for some data structures like lists, not symbols), SASL, Scala (for vals), SISAL, Standard ML.
In other programming languages, Scheme for example, the return value of an assignment is undefined and such idioms are invalid.
[3] Beyond syntactic sugar, this assists the task of the compiler by making clear that in-place modification of the variable a is possible.
Some programming languages, such as APL, Common Lisp,[10] Go,[11] JavaScript (since 1.7), PHP, Maple, Lua, occam 2,[12] Perl,[13] Python,[14] REBOL, Ruby,[15] and PowerShell allow several variables to be assigned in parallel, with syntax like: which simultaneously assigns 0 to a and 1 to b.
In languages without parallel assignment, this would have to be written to use a temporary variable since a := b; b := a leaves both a and b with the original value of b.
C# additionally allows generalized deconstruction assignment with implementation defined by the expression on the right-hand side, as the compiler searches for an appropriate instance or extension Deconstruct method on the expression, which must have output parameters for the variables being assigned to.
Because it overthrows a century old tradition to let “=” denote a comparison for equality, a predicate which is either true or false.
[22] For example: The similarity in the two symbols can lead to errors if the programmer forgets which form ("=", "==", ":=") is appropriate, or mistypes "=" when "==" was intended.
This is a common programming problem with languages such as C (including one famous attempt to backdoor the Linux kernel),[23] where the assignment operator also returns the value assigned (in the same way that a function returns a value), and can be validly nested inside expressions.
Some language processors (such as gcc) can detect such situations, and warn the programmer of the potential error.
Other possibilities include a left arrow or a keyword, though there are other, rarer, variants: Mathematical pseudo code assignments are generally depicted with a left-arrow.
Some platforms put the expression on the left and the variable on the right: Some expression-oriented languages, such as Lisp[34][35] and Tcl, uniformly use prefix (or postfix) syntax for all statements, including assignment.