Expression-oriented programming language explained

An expression-oriented programming language is a programming language in which every (or nearly every) construction is an expression and thus yields a value.[1] The typical exceptions are macro definitions, preprocessor commands, and declarations, which expression-oriented languages often treat as statements.

Lisp[2] and ALGOL 68 are expression-oriented languages. Pascal is not an expression-oriented language.

All functional programming languages are expression-oriented.[3]

Criticism and prevention

Critics, including language designers,[4] 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.[5] [6]

The designers of Python implemented assignment as a statement rather than an expression, thus prohibiting assignment from nesting inside any other statement or expression.[7] (Until version 3.8 added 'assignment expressions', with a different syntax.[8])

In some expression-oriented languages, expressions that merely cause side effects return void types.

Examples

See also

Notes and References

  1. Web site: Glossary - The Rust Programming Language . 2022-07-06 . web.mit.edu.
  2. Syme . Don . 2020-06-14 . The early history of F# . Proceedings of the ACM on Programming Languages . en . 4 . HOPL . 1–58 . 10.1145/3386325 . 2475-1421. free .
  3. Web site: 2018-02-08 . Expression Oriented Programming . 2023-08-07 . Knoldus - Technical Insights . en.
  4. https://www.oracle.com/java/technologies/javase/codeconventions-programmingpractices.html#547 Java Code Conventions "10.4 Variable Assignments"
  5. https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.9 The Java Language Specification, Java SE 8 Edition "14.9 The if Statement"
  6. https://www.adaic.org/learn/materials/intro/part4/ Introducing Ada
  7. https://docs.python.org/3/reference/simple_stmts.html#assignment The Python Language Reference "6.2. Assignment statements"
  8. https://www.python.org/dev/peps/pep-0572/ "PEP 572: Assignment Expressions"
  9. Web site: Functions - The Rust Programming Language . 2022-07-06 . web.mit.edu.
  10. Web site: COS 326: Functional Programming . 2022-07-06 . www.cs.princeton.edu.