Expression-oriented programming language: Difference between revisions

Content deleted Content added
m stub to compu-lang-stub
rewrite, -stub, +cat
Line 1:
An '''expression-oriented programming language''' is a [[programming language]] is one where (nearly) every construction inis thean language[[expression (exceptprogramming)|expression]] macroand yields a value. [[Macro]] definitions, pre-processor commands, and, perhaps, declarations), includingare thoseoften thattreated ''lookas like''[[statement statements(programming)|statement]]s in otherexpression-oriented languages,. can inSome principleexpression-oriented languages yieldintroduce a value[[void andreturn lettype]] itto be usedyielded accordinglyby expressions that have only side-effects.
 
[[ALGOL 68]] is an example of an expression-oriented language. [[Pascal (programming language)|Pascal]] is ''not''. All [[functional programming language]]s are expression-oriented.
 
Expression-orientation can be confusing in [[imperative programming language]]s, as many commands used normally as statements are in fact expressions. For example, assignment in the [[C programming language]] is an expression, not a statement. This allows for the following confusion:
{{compu-lang-stub}}
if (x = 1) {
...
} else {
/* this branch is never executed */
}
The condition of the '''if''' is the result of the expression <code>x = 1</code>, which is 1. Thus the if will always execute the true branch. The above is often confused with:
if (x == 1) {
... /* executed if x is 1 */
} else {
... /* executed if x is not 1 */
}
For this reason, many programmers write the constant first in conditionals, as <code>1 = x</code> is a [[syntax error]], and mistyping = for == will not result in a bug.
 
[[Category:Programming languages]]