GetWiki
Assignment (computer science)
ARTICLE SUBJECTS
being →
database →
ethics →
fiction →
history →
internet →
language →
linux →
logic →
method →
news →
policy →
purpose →
religion →
science →
software →
truth →
unix →
wiki →
ARTICLE TYPES
essay →
feed →
help →
system →
wiki →
ARTICLE ORIGINS
critical →
forked →
imported →
original →
Assignment (computer science)
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
{{Short description|Setting or re-setting the value associated with a variable name}}{{for|assignment of letters to disk file systems|Drive letter assignment}}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 most imperative programming languages, the assignment statement (or expression) is a fundamental construct.Today, the most commonly used notation for this operation is x = expr (originally Superplan 1949â51, popularized by Fortran 1957 and C). The second most commonly used notation is x := expr (originally ALGOL 1958, popularised by Pascal).WEB,weblink Imperative Programming, uah.edu, 20 April 2018, 4 March 2016,weblink" title="web.archive.org/web/20160304035233weblink">weblink dead, Many other notations are also in use. In some languages, the symbol used is regarded as an operator (meaning that the assignment statement as a whole returns a value). Other languages define assignment as a statement (meaning that it cannot be used in an expression).Assignments typically allow a variable to hold different values at different times during its life-span and scope. However, some languages (primarily strictly functional languages) do not allow that kind of "destructive" reassignment, as it might imply changes of non-local state. 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. Modern programs in other languages also often use similar strategies, although less strict, and only in certain parts, in order to reduce complexity, normally in conjunction with complementing methodologies such as data structuring, structured programming and object orientation.- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
Semantics
An assignment operation is a process in imperative programming in which different values are associated with a particular variable name as time passes.WEB,weblink 2cs24 Declarative, www.csc.liv.ac.uk, 20 April 2018,weblink" title="web.archive.org/web/20060424045449weblink">weblink 24 April 2006, dead, The program, in such model, operates by changing its state using successive assignment statements.BOOK, Ruediger-Marcus Flaig, Bioinformatics programming in Python: a practical course for beginners,weblink 25 December 2010, 2008, Wiley-VCH, 978-3-527-32094-3, 98â99, Primitives of imperative programming languages rely on assignment to do iteration. At the lowest level, assignment is implemented using machine operations such as MOVE or STORE.Crossing borders: Explore functional programming with Haskell {{webarchive |url=https://web.archive.org/web/20101119190821weblink |date=November 19, 2010 }}, by Bruce TateVariables are containers for values. It is possible to put a value into a variable and later replace it with a new one. An assignment operation modifies the current state of the executing program. Consequently, assignment is dependent on the concept of variables. In an assignment:- The expression is evaluated in the current state of the program.
- The variable is assigned the computed value, replacing the prior value of that variable.
Single assignment
{{See also|Static single-assignment form}}Any assignment that changes an existing value (e.g. x := x + 1) is disallowed in purely functional languages. In functional programming, assignment is discouraged in favor of single assignment, more commonly known as 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.An evaluation of an expression does not have a side effect if it does not change an observable state of the machine,BOOK, Mitchell, John C., John C. Mitchell, Concepts in programming languages,weblink 3 January 2011, 2003, Cambridge University Press, 978-0-521-78098-8, 23, other than producing the result, and always produces same value for the same input. Imperative assignment can introduce side effects while destroying and making the old value unavailable while substituting it with a new one,WEB,weblink Imperative Programming Languages (IPL), gwu.edu, 20 April 2018, 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 but rather named constant values possibly of compound nature, with their elements progressively defined on-demand, for the lazy languages. 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.BOOK, John C. Mitchell, Concepts in programming languages,weblink 3 January 2011, 2003, Cambridge University Press, 978-0-521-78098-8, 81â82, 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 ("foo", 1);var (a, b) = f();// Rust tuple returnlet f = || ("foo", 1);let (a, b) = f();This provides an alternative to the use of output parameters for returning multiple values from a function. This dates to CLU (1974), and CLU helped popularize parallel assignment generally.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.WEB, Deconstructing tuples and other types,weblink Microsoft Docs, Microsoft, 29 August 2019, For example, one such method that would give the class it appears in the same behavior as the return value of f() above would bevoid Deconstruct(out string a, out int b) { a = "foo"; b = 1; }In C and C++, the comma operator is similar to parallel assignment in allowing multiple assignments to occur within a single statement, writing a = 1, b = 2 instead of a, b = 1, 2. This is primarily used in for loops, and is replaced by parallel assignment in other languages such as Go.Effective Go: for,"Finally, Go has no comma operator and ++ and -- are statements not expressions. Thus if you want to run multiple variables in a for you should use parallel assignment (although that precludes ++ and --)."However, the above C++ code does not ensure perfect simultaneity, since the right side of the following code a = b, b = a+1 is evaluated after the left side. In languages such as Python, a, b = b, a+1 will assign the two variables concurrently, using the initial value of a to compute the new b.Assignment versus equality
{{See also|Relational operator#Confusion with assignment operators}}The use of the equals sign = as an assignment operator has been frequently criticized, due to the conflict with equals as comparison for equality. This results both in confusion by novices in writing code, and confusion even by experienced programmers in reading code. The use of equals for assignment dates back to Heinz Rutishauser's language Superplan, designed from 1949 to 1951, and was particularly popularized by Fortran:{{blockquote|A notorious example for a bad idea was the choice of the equal sign to denote assignment. It goes back to Fortran in 1957{{efn|1=Use of = predates Fortran, though it was popularized by Fortran.}} and has blindly been copied by armies of language designers. Why is it a bad idea? Because it overthrows a century old tradition to let â=â denote a comparison for equality, a predicate which is either true or false. But Fortran made it to mean assignment, the enforcing of equality. In this case, the operands are on unequal footing: The left operand (a variable) is to be made equal to the right operand (an expression). x = y does not mean the same thing as y = x.WEB, 10.1.1.88.8309, Niklaus Wirth, Good Ideas, Through the Looking Glass,weblink |Niklaus Wirth|Good Ideas, Through the Looking Glass}}Beginning programmers sometimes confuse assignment with the relational operator for equality, as "=" means equality in mathematics, and is used for assignment in many languages. But assignment alters the value of a variable, while equality testing tests whether two expressions have the same value.In some languages, such as BASIC, a single equals sign ("=") is used for both the assignment operator and the equality relational operator, with context determining which is meant. Other languages use different symbols for the two operators. For example:- In ALGOL and Pascal, the assignment operator is a colon and an equals sign (":=") while the equality operator is a single equals ("=").
- In C, the assignment operator is a single equals sign ("=") while the equality operator is a pair of equals signs ("==").
- In R, the assignment operator is basically <-, as in x <- value, but a single equals sign can be used in certain contexts.
Notation
{{see also|Comparison of programming languages (variable and constant declarations)}}The two most common representations for the copying assignment are equals sign (=) and colon-equals (:=). Both forms may semantically denote either an assignment statement or an assignment operator (which also has a value), depending on language and/or usage.
{| class="wikitable"
Other possibilities include a left arrow or a keyword, though there are other, rarer, variants:
variable = expression > | Fortran, PL/I, C (programming language)>C (and (:Category:C programming language family | C++, Java (programming language)>Java, etc.), Bourne shell, Python (programming language) | , Go (programming language)>Go (assignment to pre-declared variables), R (programming language) | , PowerShell, Nim (programming language)>Nim, etc. |
variable := expression > | ALGOL (and derivatives), Simula, CPL (programming language)>CPL, BCPL, Pascal (programming language) | MOORE | YEAR=1980 | LOCATION=NEW YORK | ISBN=0-470-26939-1, (and descendants such as Modula), Mary (programming language) | , PL/M, Ada (programming language)>Ada, Smalltalk, Eiffel (programming language) | ,MEYER | AUTHOR-LINK=BERTRAND MEYER | TITLE=EIFFEL THE LANGUAGE | PUBLISHER=PRENTICE HALL INTERNATIONAL(UK) | YEAR=1996 | LOCATION=UPPER SADDLE RIVER, NEW JERSEY | ISBN=0-13-183872-5, Oberon (programming language) | , Dylan (programming language)>Dylan,FEINBERG >FIRST=NEAL | AUTHOR3= MATHEWS, ROBERT O. | YEAR=1997 | LOCATION=MASSACHUSETTS | ISBN=0-201-47976-1, Seed7, Python (programming language) | (an assignment expression),HTTPS://WWW.PYTHON.ORG/DEV/PEPS/PEP-0572/ | DATE=28 FEBRUARY 2018 | ACCESS-DATE=4 MARCH 2020, Go (programming language) | (shorthand for declaring and defining a variable),HTTP://GOLANG.ORG/REF/SPEC#SHORT_VARIABLE_DECLARATIONS | WEBSITE=GOLANG.ORG | Io (programming language)>Io, AMPL, ML (programming language) | (assigning to a reference value),ULLMAN | YEAR=1998 | LOCATION=ENGLEWOOD CLIFFS, NEW JERSEY | ISBN=0-13-790387-1, AutoHotkey etc. |
{| class="wikitable"