M-expression


In computer programming, M-expressions were an early proposed syntax for the Lisp programming language, inspired by contemporary languages such as Fortran and ALGOL. The notation was never implemented into the language and, as such, it was never finalized.
Compared to S-expressions, M-expressions introduce function notation, infix operators, and shorthands for and into the language.

Background

published the first paper on Lisp in 1960 while a research fellow at the Massachusetts Institute of Technology. In it he described a language of symbolic expressions that could represent complex structures as lists. Then he defined a set of primitive operations on the S-expressions, and a language of meta-expressions that could be used to define more complex operations. Finally, he showed how the meta-language itself could be represented with S-expressions, resulting in a system that was potentially self-hosting. The draft version of this paper is known as "AI Memo 8".
Expression typeMathematical notationM-expressionModern Lisp S-expression
List value
Function application
Function definition
Conditional expression

McCarthy had planned to develop an automatic Lisp compiler using M-expressions as the language syntax and S-expressions to describe the compiler's internal processes. Stephen B. Russell read the paper and suggested to him that S-expressions were a more convenient syntax. Although McCarthy disapproved of the idea, Russell and colleague Daniel J. Edwards hand-coded an interpreter program that could execute S-expressions. This program was adopted by McCarthy's research group, establishing S-expressions as the dominant form of Lisp.
McCarthy reflected on the fate of M-expressions in 1979:

Implementations

A form of sugared M-expressions has been implemented in the Wolfram language of Wolfram Mathematica since 1988:
Expression typeSugared syntax Function form
List value
Function application
Function definition

For LISP

was a contemporary project to implement an M-expression-like frontend for Lisp. A few extra features like hygienic macros, pattern matching, and backtracking were incorporated. It eventually evolved into an abandoned LISP70 draft. M-LISP from 1989 was another attempt to blend M-expressions with Scheme.
A parser for the "AI Memo 8" M-expression is available in Common Lisp, but the author intends it as a case against M-expressions due to its perceived inability to cope with macros.

Further development

A CGOL was implemented in MacLisp and follows a similar goal of introducing Algol-like syntax with infix operators. It is known to work on Armed Bear Common Lisp.
A more recent variant is the I-expression, which use indentation to indicate parentheses implicitly, and are thus in some ways intermediate between S-expressions and M-expressions. I-expressions were introduced in Scheme Request For Implementation 49 as an auxiliary syntax for Scheme, but they have not been widely adopted.
A further development is the "sweet" t-expression, which has infix operators without precedence. Like I-expressions, t-expressions are only a simple transformation away from S-expressions, so that theoretically they can be used on any Lisp dialect and not interfere with features like macros.
Additional syntax-related include Apple's Dylan and Clojure's addition of other literal syntaxes.