|
This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. (help, get involved!) Any material not supported by sources may be challenged and removed at any time. This article has been tagged since May 2007. In computer science the assignment statement sets or re-sets the value stored in the storage location(s) denoted by a variable name. In most imperative computer programming languages the assignment statement is one of the basic statements. Computer scaence, or computing science, is the study of the theoretical foundations of information and computation and their implementation and application in computer systems. ...
It has been suggested that value (programming) be merged into this article or section. ...
In computer science and mathematics, a variable (IPA pronunciation: ) (sometimes called a pronumeral) is a symbolic representation denoting a quantity or expression. ...
A name is a label for a human, thing, place, product (as in a brand name) and even an idea or concept, normally used to distinguish one from another. ...
In computer science, imperative programming, as opposed to declarative programming, is a programming paradigm that describes computation in terms of a program state and statements that change the program state. ...
A BlueGene supercomputer cabinet. ...
A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. ...
A statement is the minimal unit of structuring in imperative programming languages. ...
The assignment statement often allows that the same variable name to contain different values at different times during program execution. Program or Programme may refer to: Computer program Radio programming Television program(me), Webcast Program (management) 12-step program Program (The Animatrix), a short film in The Animatrix series Event programme British tabloid form of comic book, called prog in short. ...
In some languages (e.g., C) assignment is classified as an operator. C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use in designing the Unix operating system. ...
In mathematics, an operator is a function that performs some sort of operation on a number, variable, or function. ...
Notation
Common textual representations of the assignment operator include an equals sign (“=”), “:=”, or a left-arrow; this last is less common in modern languages as this character is not available on most standard keyboard layouts. e.g. Programming languages generally have a set of operators that are similar to operators in mathematics: they are somehow special functions. ...
The equal sign, equals sign, or = is a mathematical symbol used to indicate equality. ...
-
Some expression-oriented languages uniformly use functional syntax for all statements, including assignment: Fortran (previously FORTRAN[1]) is a general-purpose[2], procedural,[3] imperative programming language that is especially suited to numeric computation and scientific computing. ...
C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
Algol (β Per / Beta Persei) is a bright star in the constellation Perseus. ...
Wikibooks has a book on the topic of Pascal Pascal is an imperative computer programming language, developed in 1970 by Niklaus Wirth as a language particularly suitable for structured programming. ...
Ada is a structured, statically typed imperative computer programming language designed by a team led by Jean Ichbiah of CII Honeywell Bull under contract to the United States Department of Defense during 1977â1983. ...
Dylan is a dynamic programming language created by a group led by Apple Computer. ...
S is a statistical programming language developed primarily by John Chambers and (in earlier versions) Rick Becker and Allan Wilks of Bell Laboratories. ...
Screenshot of Mac OS X RAqua desktop The R programming language, sometimes described as GNU S, is a programming language and software environment for statistical computing and graphics. ...
APL (for A Programming Language) is an array programming language based on a notation invented in 1957 by Kenneth E. Iverson while at Harvard University. ...
COBOL is a third-generation programming language, and one of the oldest programming languages still in active use. ...
AppleScript is a scripting language devised by Apple, Inc. ...
-
(setq variable expression) | Lisp, Scheme (set!), … | set variable expression | Tcl | Lisp is a family of computer programming languages with a long history and a distinctive fully-parenthesized syntax. ...
The Scheme programming language is a functional programming language and a dialect of Lisp. ...
Tcl (originally from Tool Command Language, but nonetheless conventionally rendered as Tcl rather than TCL; and pronounced tickle) is a scripting language created by John Ousterhout. ...
Operation Semantically, an assignment operation modifies the current state of the executing program: The introduction to this article provides insufficient context for those unfamiliar with the subject matter. ...
- 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. Example: Assuming that a is a numeric variable, the assignment a := 2*a means that the content of the variable a is doubled after the execution of the statement. An example segment of C code: C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
int x=10; float y; x=23; y=32.4; In this sample, the variable x is first declared as an int, and is then assigned the value of 10. Notice that the declaration and assignment occur in the same statement. In the second line, y is declared without an assignment. In the 3rd line, x is reassigned the value of 23. Finally, y is assigned the value of 32.4. For an assignment operation, it is necessary that the value of the expression is well-defined (it is a valid rvalue) and that the variable represent a modifiable entity (it is a valid modifiable (non-const) lvalue). In some languages, such as Perl, it is not necessary to declare a variable prior to assigning it a value. In computer science, a value may be a number, literal string, array and anything that can be treated as if it were a number. ...
Const-correctness is a programming language feature that allows the programmer to indicate when an object can and cannot change by declaring the object const (or non-const). ...
In computer science, a value may be a number, literal string, array and anything that can be treated as if it were a number. ...
Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
Parallel assignment Some programming languages, such as Python, Perl, Ruby, OCaml and JavaScript (since 1.7), allow several variables to be assigned in parallel. In pseudocode: Python is a high-level programming language first released by Guido van Rossum in 1991. ...
Perl is a dynamic programming language created by Larry Wall and first released in 1987. ...
Ruby is a reflective, object-oriented programming language. ...
Objective Caml (OCaml) is a general-purpose programming language descended from the ML family, created by Xavier Leroy, Jérôme Vouillon, Damien Doligez, Didier Rémy and others in 1996. ...
JavaScript is a scripting language most often used for client-side web development. ...
a,b := 0,1 Simultaneously assigns 0 to a and 1 to b. More interestingly, a,b := b,a Swaps the values of a and b. In languages without parallel assignment, this would have to be written to use a temporary variable var t := a a := b b := t since a:=b ; b:=a leaves both a and b with the original value of b.
Value In most expression-oriented programming languages, the assignment statement returns the assigned value, allowing such idioms as x = y = a, which assigns the value of a to both x and y. In Scheme, however, the return value is undefined. An expression-oriented programming language is one where every construction in the language (except macro definitions, pre-processor commands and, perhaps, declarations), including those that look like statements in other languages, can in principle yield a value and let it be used accordingly. ...
Assignment versus equality Beginning programmers sometimes confuse assignment with comparison 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. A comparison operator in computer programming is a binary operator. ...
In mathematics, two mathematical objects are considered equal if they are precisely the same in every way. ...
In many languages, the assignment operator is a single equals sign ("=") while the equivalence operator is a pair of equals signs ("=="); in some languages, such as BASIC, a single equals sign is used for both, with context determining which is meant. BASIC (Beginners All-purpose Symbolic Instruction Code) is a family of high-level programming languages. ...
This can lead to errors if the programmer forgets which form ("=", "==", ":=") is appropriate, particularly in languages such as C, where the assignment operator also returns the value assigned, and can be validly nested inside expressions (in the same way that a function returns a value). If the intention was to compare two values in an if statement, for instance, an assignment is quite likely to return a value interpretable as TRUE, in which case the then clause will be executed, leading the program to behave unexpectedly. Some language processors can detect such situations, and warn the programmer of the potential error. C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
The Data Movement Dilemma [1] How to achieve “movement” of data values between variables is a technical problem that needs to be faced by all imperative-language software engineering disciplines that concern themselves with component-level design details. Because there is no way to avoid this problem, and because traditional approaches to dealing with it make trade-offs that introduce serious technical difficulties, we call it the data movement dilemma. To explain why there is a dilemma, we start with a simple question: How does one make some variable (say, x) get the value of another variable (say, y)? For example, suppose x and y are variables of type Integer, a type whose mathematical model is a mathematical integer. This means we want to think of the value of x as being something like 17 (i.e., not as a string of 32 bits), and the value of y as being something like 42. The obvious answer is that we use an assignment statement, like this:
x = y This works fine for Fortran and C programs and for C++ programs with no user-defined types. A problem arises, though, in modern object-oriented software systems. What if x and y are variables of a type T, where T’s mathematical model is relatively complex so its representation is potentially large? Suppose, for example, that T is Set <Integer>; we wish to think of the value of x as being something like {1, 34, 16, 13} and the value of y as being some-thing like {2, -9, 45, 67, 15, 16, 942, 0}. There are now two options, neither of which is especially attractive: - Consider the assignment operator for Set to perform “deep” copy, so that after the assignment statement we can think of both x and y as having the same abstract value. Logically, x and y must behave independently, too, so changes to x do not side-effect the value of y and vice versa. This can be terribly inefficient, because without using fancy data-structure tricks that frequently do not apply, the assignment operator takes time linear in the size of y’s representation. Big sets simply take a long time to copy and hence to assign.
- Retreat from viewing x and y as having values that are mathematical sets of mathematical integers, and consider their values to be pointers or references to sets of integers. This certainly fixes the efficiency problem. But it introduces a distressing non-uniformity in reasoning about program behavior: some variables denote values and others denote references. It also means that the assignment operator and copy constructor create aliases, which complicates reasoning about program behavior.
The latter approach has been codified into some modern languages, notably Java. We observe, however, that it is actually far worse than the former from the software engineering standpoint. One reason is that the programmer now must be aware that variables of some types have ordinary values while variables of other types hold object references (it’s the objects that have the values). For template components this creates a serious problem. Inside a component that is parameterized by a type (say, Item), there is no way to know before instantiation time whether an assignment of one Item to another will assign a value or an object reference. Of course, this can be “fixed” as it is in Java: introduce otherwise-redundant object types such as Integer to shadow value types such as int. We could then require that all actual template parameters be object types. This is not a language-enforced rule in C++, however, so some discipline is required to make it a reality there. A more serious problem is that the “reference semantics” approach makes aliases run rampant, and aliasing breaks modular reasoning Uncontrolled Reference Semantics Thwart Local Certifiability | The diagram to the right summarizes the data movement dilemma faced by someone who wants efficient software about whose behavior it is easy to reason. The conclusion seems to be that this is only attainable by sticking to built-in scalar types — not incidentally, the only types available when the assignment operator was introduced into programming languages — or, at best, by inventing only new user-defined types that admit “small” representations. |
| Image File history File links No higher resolution available. ...
See also |