Assignment (computer science)

assignmentsingle assignmentassignment operatorassignment statementparallel assignmentassignedassignmentsassigndestructuring assignmentassigned once
In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable.wikipedia
194 Related Articles

Operator (computer programming)

operatoroperatorsOperator (programming)
In some languages the symbol used is regarded as an operator (meaning that the assignment statement as a whole returns a value) while others define the assignment as a statement (meaning that it cannot be used in an expression).
More involved examples include assignment (usually or ), field access in a record or object (usually ), and the scope resolution operator (often ).

Functional programming

functionalfunctional programming languagefunctional language
However, some languages (primarily strictly functional) do not allow that kind of "destructive" reassignment, as it might imply changes of non-local state.
In contrast, imperative programming changes state with statements in the source code, the simplest example being assignment.

C (programming language)

CC programming languageC language
Today, the most commonly used notation for this basic operation has come to be (originally Superplan 1949–51, popularized by Fortran 1957 and C) followed by (originally ALGOL 1958, popularised by Pascal), although there are many other notations in use. The case where the assigned value depends on a previous one is so common that many imperative languages, most notably C and the majority of its descendants, provide special operators called augmented assignment, like, so can instead be written as. In most expression-oriented programming languages (for example, C), the assignment statement returns the assigned value, allowing such idioms as, in which the assignment statement returns the value of, which is then assigned to.
The most common statement is an expression statement, consisting of an expression to be evaluated, followed by a semicolon; as a side effect of the evaluation, functions may be called and variables may be assigned new values.

Variable (computer science)

variablevariablesscalar
In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable.
In imperative programming languages, values can generally be accessed or changed at any time.

Imperative programming

imperativeimperative programming languageimperative language
In most imperative programming languages, the assignment statement (or expression) is a fundamental construct.
Assignment statements, in imperative paradigm, perform an operation on information located in memory and store the results in memory for later use.

Erlang (programming language)

ErlangErlang programming languageErlang/OTP
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, Lava, OCaml, Oz (for dataflow variables, not cells), Racket (for some data structures like lists, not symbols), SASL, Scala (for vals), SISAL, Standard ML.
The sequential subset of the Erlang language supports eager evaluation, single assignment, and dynamic typing.

SISAL

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, Lava, OCaml, Oz (for dataflow variables, not cells), Racket (for some data structures like lists, not symbols), SASL, Scala (for vals), SISAL, Standard ML.
SISAL ("Streams and Iteration in a Single Assignment Language") is a general-purpose single assignment functional programming language with strict semantics, implicit parallelism, and efficient array handling.

Augmented assignment

compound assignment
The case where the assigned value depends on a previous one is so common that many imperative languages, most notably C and the majority of its descendants, provide special operators called augmented assignment, like, so can instead be written as.
assignment operators in certain programming languages (especially those derived from C).

Scope (computer science)

scopelexical scopeLexical
Assignments typically allow a variable to hold different values at different times during its life-span and scope.
This complicates the use of conditional statements with single assignment.

Referential transparency

referentially transparentreferential safetyreferentially transparent positions
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.
However, in pure functional programming, destructive assignment is not allowed, and thus if the free variable is statically bound to a value, the function is still referentially transparent, as neither the non-local variable nor its value can change, due to static binding and immutability, respectively.

CLU (programming language)

CLUCLU languageCLU programming language
This dates to CLU (1974), and CLU helped popularize parallel assignment generally.
Key contributions include abstract data types, call-by-sharing, iterators, multiple return values (a form of parallel assignment), type-safe parameterized types, and type-safe variant types.

Perl

Perl 5Perl programming languagePerl Script
Some programming languages, such as APL, Common Lisp, Go, JavaScript (since 1.7), PHP, Maple, Lua, occam 2, Perl, Python, REBOL, Ruby, and Windows PowerShell allow several variables to be assigned in parallel, with syntax like:
The overall structure of Perl derives broadly from C. Perl is procedural in nature, with variables, expressions, assignment statements, brace-delimited blocks, control structures, and subroutines.

Expression-oriented programming language

expression-orientedexp-orientedexpression oriented
In most expression-oriented programming languages (for example, C), the assignment statement returns the assigned value, allowing such idioms as, in which the assignment statement returns the value of, which is then assigned to.
Critics, including language designers, blame expression-orientation for an entire class of programming mistakes wherein a programmer introduces an assignment expression where they meant to test for equality.

Equals sign

equal sign=equality
In Fortran, "=" serves as an assignment operator: sets the value of to 2.

Side effect (computer science)

side effectsside effectside-effects
An evaluation of expression does not have a side effect if it does not change an observable state of the machine, and produces same values for same input.
One common demonstration of side effect behavior is that of the assignment operator in C++.

Lava (programming language)

Lava
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, Lava, OCaml, Oz (for dataflow variables, not cells), Racket (for some data structures like lists, not symbols), SASL, Scala (for vals), SISAL, Standard ML.

Operator associativity

right-associativeleft-associativeassociativity
In this case chain assignment can be implemented by having a right-associative assignment, and assignments happen right-to-left.
Any assignment operators are typically right-associative.

Comma operator

operator
In C and C++, the comma operator is similar to parallel assignment in allowing multiple assignments to occur within a single statement, writing instead of.
The most common use is to allow multiple assignment statements without using a block statement, primarily in the initialization and the increment expressions of a for loop.

Parameter (computer programming)

parameterparametersargument
This provides an alternative to the use of output parameters for returning multiple values from a function.
Syntactically this is clearer if automatic sequence unpacking and parallel assignment can be used, as in Go or Python, such as:

Assignment operator (C++)

Copy assignment operatorassignment operatorAssignment operator in C++
In the C++ programming language, the assignment operator, is the operator used for assignment.

R (programming language)

RR programming languageCRAN
In R, the generally preferred assignment operator is an arrow made from two characters, although can usually be used instead.

Const (computer programming)

const-correctnessconstconst correctness
For an assignment operation, it is necessary that the value of the is well-defined (it is a valid rvalue) and that the represents a modifiable entity (it is a valid modifiable (non-const) lvalue).
A automatic variable (non-static local variable) means that single assignment is happening, though a different value may be used each time, such as A parameter in pass-by-reference means that the referenced value is not modified – it is part of the contract – while a parameter in pass-by-value (or the pointer itself, in pass-by-reference) does not add anything to the interface (as the value has been copied), but indicates that internally, the function does not modify the parameter (it is a single assignment).

Rebol

REBOL parse dialectREBOL scripts
Some programming languages, such as APL, Common Lisp, Go, JavaScript (since 1.7), PHP, Maple, Lua, occam 2, Perl, Python, REBOL, Ruby, and Windows PowerShell allow several variables to be assigned in parallel, with syntax like:
The set-word form of a word can be used for assignment.