Content deleted Content added
→References: {{foldoc|Expression}} |
Added some examples of expressions |
||
Line 1:
An '''expression''' in a [[programming language]] is a combination of [[value (computer science)|value]]s, [[variable (programming)|variable]]s, [[operator (programming)|operator]]s, and [[function (programming)|function]]s that are interpreted (''[[Evaluation (disambiguation)|evaluated]]'') according to the particular [[Order of operations|rules of precedence]] and of association for a particular programming language, which computes and then produces (''returns'', in a [[state (computer science)|stateful]] environment) another value. The expression is said to ''evaluate to'' that value
For example 2+3 is an arithmetic and programming expression which evaluates to 5. The assignment expression x=2+3 also evaluates to 5 and is a programming expression, but is an equation in mathematics and not a [[mathematical expression]]. An example of a programming relational expression would be 4==4 which evaluates to true.<ref> [https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions Javascript expressions, Mozilla]Accessed July 6, 2009</ref><ref> [https://www.cs.drexel.edu/~rweaver/COURSES/ISTC-2/TOPICS/expr.html Programming in C]Accessed July 6, 2009</ref>
Expressions may or may not have [[Side effect (computer science)|side effect]]s. An expression with side effects does not normally have the property of [[referential transparency (computer science)|referential transparency]]. In many languages (e.g. C++) statements may be ended with a semicolon ';' to turn the expression into an expression [[Statement (programming)|statement]]. This asks the implementation to evaluate the expression for its side-effects only, and disregard the result of the expression.▼
It is reported for the C language that functions are expressions too unless they are the void return type<ref> [http://www.d.umn.edu/~gshute/C/expressions.html C expressions, Gary Shute]Accessed July 6, 2009</ref>. However, for the Java language Bill Venners reports that void return type method calls are also expressions<ref> [http://www.artima.com/objectsandjava/webuscript/ExpressionsStatements1.html Objects and Java by Bill Venners]Accessed July 6, 2009</ref>.
As in [[Expression (mathematics)|math]], the expression ''is'' (or can be said to ''have'') its evaluated value; the expression is a representation of that value. So, in mathematics, an expression is a representation of a value{{fact|date = July 2009}}.
▲Expressions may or may not have [[Side effect (computer science)|side effect]]s. An expression with side effects does not normally have the property of [[referential transparency (computer science)|referential transparency]]. In many languages (e.g. C++) statements may be ended with a semicolon ';' to turn the expression into an expression [[Statement (programming)|statement]]. This asks the implementation to evaluate the expression for its side-effects only, and disregard the result of the expression{{fact|date = July 2009}}.
==See also==
Line 10 ⟶ 16:
==References==
{{reflist}}
==External links==
* {{foldoc|Expression}}
|