UP | HOME

Uniformity

Decent languages are (and must be) as uniform as pure mathematics.

Everything is a value

Referencing (bindings) are uniform in decent languages - everything is a value.

This is best illustrated in scheme, which uses two distinct special forms - one for creating a closure (lambda) and another for binding it to a symbol (define).

A symbol becomes a name (reference) to the function (closure).

(define double (lambda (x) (* x x)))

Languages of the ML-family have let-bindings, explicit and implicit. LISPs can bind functions in let expressions too.

let double = \x -> x * x

Immutability

Nothing is over-written (destructively updated). New bindings are created (shadowing) and new values are linked instead.

Referential transparency

This is the fundamental property of arithmetic expressions, which leads to algebraic (equational) reasoning.

Any form of an algebra is possible in principle only with this referential transparency.

One, of course, wants to have a simple algebra and equation reasoning for his functions. Since early LISPs, the ML-family of languages and Scheme we strive for this.

Pattern-matching everywhere

Just like in Erlang, everything on the left-hand side (including function .arguments) is a pattern.

The rules of a formally defined pattern-matching expression (“case”) are applicable everywhere uniformly, including bindings (=).

Passing arguments to a function produces implicit bindings for its formal parameters, so a pattern-matching is performed

This nice generalized into a multiple-clause function syntax, where each clause is tried in order until a match succeeds (a runtime exception if not).

Notice each individual clause is just a partial function.

Erlang’s receive

The receive expression in Erlang is just the same as generalized pattern-matching case expression or a multi-clause function, defined using pattern-matching (with all the usual destructuring and binding properties).

It is a pure expression with respect to the contents of the “mailbox” (same input - same output) and, remarkably, it introduces no new semantics to the language.

This is the major innovation of Erlang.

List comprehensions

Haskell and Erlang have a generalized list-comprehension notation. Every comprehension is an expression, of course.

This unifies the fundamental notions of an observer (selection based on a well-defined property (such that), logical conjunction (and also) which together is called “filtering”, and “mapping”, which is a uniform transformation - any pure unary function, or an “arrow”).

This, by the way, is a half of all programming.

Author: <schiptsov@gmail.com>

Email: lngnmn2@yahoo.com

Created: 2023-08-08 Tue 18:40

Emacs 29.1.50 (Org mode 9.7-pre)