Expression-oriented programming language
An expression-oriented programming language is a programming language in which every (or nearly every) construction is an expression and thus yields a value.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The typical exceptions are macro definitions, preprocessor commands, and declarations, which expression-oriented languages often treat as statements.
Lisp<ref name=":0">Template:Cite journal</ref> and ALGOL 68 are expression-oriented languages. Pascal is not an expression-oriented language.
All functional programming languages are expression-oriented.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
Criticism and preventionEdit
Template:Synthesis Template:See also Critics, including language designers,<ref>Java Code Conventions "10.4 Variable Assignments"</ref>Template:Failed verification blame expression-orientation for an entire class of programming mistakes wherein a programmer accidentally codes an assignment expression, which replaces a variable with an expression rather than testing it for equality with that expression.
The designers of Ada and Java prevent this type of mistake by restricting control expressions to those that evaluate strictly to the boolean data type.<ref>The Java Language Specification, Java SE 8 Edition "14.9 The if Statement"</ref><ref>Introducing Ada</ref>
The designers of Python implemented assignment as a statement rather than an expression, thus prohibiting assignment from nesting inside any other statement or expression.<ref>The Python Language Reference "6.2. Assignment statements"</ref> (Until version 3.8 added 'assignment expressions', with a different syntax.<ref>"PEP 572: Assignment Expressions"</ref>)
In some expression-oriented languages, expressions that merely cause side effects return void types.
ExamplesEdit
Template:More citations needed Template:Expand section
- ALGOL 68
- BLISS
- Icon
- Lisp<ref name=":0" />
- ML
- Perl
- Rebol
- Ruby
- Elixir
- Erlang
- Haskell
- Rust<ref>{{#invoke:citation/CS1|citation
|CitationClass=web }}</ref>
|CitationClass=web }}</ref>