I was wondering about the origins of the “let” used in Lisp, Clojure, and Haskell. Does anyone know which language it appeared in first?
6
Well, BASIC had LET
for assignment as part of the syntax from the start in 1964, so that would predate the use of let
in Lisp, which as Chris Jester-Young points out didn’t appear until the 1970s according to Evolution of Lisp.
I don’t believe COBOL, Fortran, or ALGOL have LET
in their syntax either. So I’m going to go with BASIC.
9
I’d like to add a theoretical point of view: In classical lambda calculi, let
is just syntactic sugar. For example
let x = N in M
can be rewritten simply as
(λx.M)N
So its first appearance in early (functional) languages isn’t that interesting.
However, it become very important with the invention of Hindley-Milner type system and its type inference algorithm. In this type system let
is indispensable, because it’s polymorphic (unlike λ-abstraction in HM). For example, consider this simple expression:
let id = λx . x in id id
Here id
is polymorphic, it has type ∀α.α → α
, and therefore id id
type-checks – it’s type is id id : τ → τ
for arbitrary τ. (For the first id
we assign τ → τ
to α
and for the second id
we assign τ
for α
.)
However, we can’t rewrite it using λ abstraction and application. Expression
(λid . id id)(λx.x)
doesn’t type-check, because within the first λ abstraction id
must be assigned a monomorphic type id : σ
for some σ, and there is no σ such that we could apply id : σ
to id : σ
.
You can try this yourself in Haskell. While let id = x -> x in id id :: t -> t
type-checks, typing (id -> id id)(x -> x)
fails with
Occurs check: cannot construct the infinite type:
t0 = t0 -> t0
In the first argument ofid
, namelyid
In the expression:id id
In the expression:id -> id id
9
Lisp is the oldest language of these having LET now. But BASIC was the first that got it, for Lisp had obtained it much later.
In Ada Lovelace Analytical Engine (1843) – no LET, a program looks as:
N0 6 N1 1 N2 1 × L1 L0 S1 L0 L2 S0 L2 L0 CB?11 '
In Plankalkül of Zuse (1943-45) the program looks:
P1 max3 (V0[:8.0],V1[:8.0],V2[:8.0]) → R0[:8.0]
max(V0[:8.0],V1[:8.0]) → Z1[:8.0]
max(Z1[:8.0],V2[:8.0]) → R0[:8.0]
END
Short Code was proposed by John Mauchly in 1949
X3 = ( X1 + Y1 ) / X1 * Y1
Intermediate PL of Burks, 1950, used for assignment ->
Rutishauser in 1952 used =>=
Böhms compiler, 1952, used ->
At the University of Manchester, Alick Glennie developed Autocode
in the early 1950s. The first code and compiler was developed in 1952 for the Mark 1 computer at the University of Manchester and is considered to be the first compiled high-level programming language. Again, ->
for assignment
Charles Adams, FORTRAN 0 of Backus’s group , Brooker’s Autocode 2, ПП1 of Lubimsky and Kamynin; all in 1954, again =
BACAIC (Grems, Porter), 1954, *
for assignment!
Kompiler, ADES, 1955, =
IT, 1956, <-
FORTRAN, 1957, =
AT-3 (1956), Math-Matic (1957), again =
,
but Flow-Matic in 1957 had two assignments, and both are in words
TRANSFER a TO b
and MOVE a TO b
Bauer and Samelson’s machine, 1957: =>
Sorry, I can’t cover all languages between 1957 and 1964, but greater languages
1957 - COMTRAN (forerunner to COBOL)
1958 - LISP
1958 - ALGOL 58
1959 - FACT (forerunner to COBOL)
1959 - COBOL
1959 - RPG
1962 - APL
1962 - Simula
1962 - SNOBOL
1963 - CPL (forerunner to C)
have not LET for assignment. Or had not, in the case of LISP.
Dartmouth BASIC is the original version of the BASIC programming language. The first interactive version was made available to general users in June 1964;
LET / = — assign formula results to a variable
Well, between those three, Lisp definitely had it first. Haskell came about in the 80s, and Clojure in the 00s, and let
had been around long before either of those dates. 🙂
As to whether Lisp was the language to have invented it, I can’t vouch for that yet, but I’ll do some research and see. 🙂
Update: According to Evolution of Lisp (see page 46), it mentioned that let
was invented in the 70s:
LET
—itself a macro first invented and reinvented locally at each site—was a late-comer to the MacLisp world; according to Lisp Archive, it was retroactively absorbed into PDP-10 MacLisp from Lisp-Machine Lisp in 1979 at the same time asDEFMACRO
and the complex Lisp MachineDEFUN
argument syntax.
Still doesn’t quite answer whether it was invented in another language earlier, of course, but still another data point. 🙂
2
The first Revised Scheme report AIM-452 from January 1978 has LET
. Page 9.
note that Lisp used earlier a different construct PROG
to introduce local variables.
(let ((a 1)
(b 1))
(+ a b))
would have been written earlier approximately as
(prog (a b)
(setq a 1)
(setq b 1)
(+ a b))
3