The document discusses the value returned by assignment statements in different programming languages. In expression-oriented languages like C, assignment statements return the assigned value, allowing idioms like x = y = a. However, in languages like Scheme, the return value of an assignment is undefined, invalidating such idioms. Haskell also differs in that there is no variable assignment, but operations similar to assignment usually return the unit type, which contains no information. The document then briefly mentions variant forms of assignment like augmented assignment that have special syntax to reduce redundancy.
The document discusses the value returned by assignment statements in different programming languages. In expression-oriented languages like C, assignment statements return the assigned value, allowing idioms like x = y = a. However, in languages like Scheme, the return value of an assignment is undefined, invalidating such idioms. Haskell also differs in that there is no variable assignment, but operations similar to assignment usually return the unit type, which contains no information. The document then briefly mentions variant forms of assignment like augmented assignment that have special syntax to reduce redundancy.
The document discusses the value returned by assignment statements in different programming languages. In expression-oriented languages like C, assignment statements return the assigned value, allowing idioms like x = y = a. However, in languages like Scheme, the return value of an assignment is undefined, invalidating such idioms. Haskell also differs in that there is no variable assignment, but operations similar to assignment usually return the unit type, which contains no information. The document then briefly mentions variant forms of assignment like augmented assignment that have special syntax to reduce redundancy.
In some programming languages, an assignment statement returns a value, while in others it
does not. In most expression-oriented programming languages (for example, C), the assignment statement returns the assigned value, allowing such idioms as x = y = a , in which the assignment statement y = a returns the value of a , which is then assigned to x . In a statement such as while ((ch = getchar()) != EOF) {…} , the return value of a function is used to control a loop while assigning that same value to a variable. In other programming languages, Scheme for example, the return value of an assignment is undefined and such idioms are invalid. In Haskell,[8] there is no variable assignment; but operations similar to assignment (like assigning to a field of an array or a field of a mutable data structure) usually evaluate to the unit type, which is represented as () . This type has only one possible value, therefore containing no information. It is typically the type of an expression that is evaluated purely for its side effects.
Variant forms of assignment[edit]
Certain use patterns are very common, and thus often have special syntax to support them. These are primarily syntactic sugar to reduce redundancy in the source code, but also assists readers of the code in understanding the programmer's intent, and provides the compiler with a clue to possible optimization.