by rntz · 9y ago · 0 comments
> John McCarthy wrote 6 easy things in machine code, then combined them to make a programming language.
John McCarthy didn't implement Lisp in machine code. Steve Russell did. Implementing Lisp properly in machine code is not easy; you have to write a garbage collector. To do that in the early 60s, you had to first invent garbage collection. Lisp was and is brilliant, but not as easily bootstrappable as this makes it out to be.
> It's not obvious that these six things are computationally complete (AKA Turing Complete).
`lambda` and function application alone are Turing-complete, as McCarthy would have known. The credit here belongs with Turing and Church, not McCarthy. `atom`, `cons`, `car` and all the rest are just icing on the cake of the lambda calculus when it comes to computability.
> All other meaning can be defined in terms of them.
Yes, and you can build everything on top of the SK combinator calculus if you like, but that doesn't make it a good idea. Lisp is surprisingly practical given how few core constructs it has, but real Lisp implementations have always added more primitives (eg. numbers and addition) for reasons of practicality.
> The language was defined in terms of itself as an interpreter. This is a proof by construction that the language is computationally complete.
No, it isn't. To prove Turing-completeness you need to show that you are as powerful as Turing machines. To do this it suffices to show that you can interpret a language already known to be Turing-complete. Showing you can interpret yourself does not suffice. It's easy to define a language which can do nothing useful except interpret itself, for example. (See also wyager's comment.)
> Well, Lisp is defined as an interpreter in terms of itself from the get-go, just like a Universal Turing Machine.
No. Defining a language only in itself is nonsense, for exactly the reason given above: it means nothing yet! It's like writing in a dictionary:
qyzzyghlm, v. intr. To qyzzyghlm.
It explains nothing unless you already understand it!> Lisp is a universal language because it can interpret its own code. While you can certainly write a JavaScript interpreter in JavaScript, none of the work is done for you.
Almost none of the work is done for you in Lisp either. The core of Lisp is just a relatively easy language to implement, while Javascript is a difficult one. Lisp is easy to implement because it has simple syntax (s-expressions) and few core constructs. The only thing that is special about implementing Lisp in Lisp is that Lisp uses s-expressions as its core data structure, so you don't have to invent an AST representation. The article, to its credit, explores this idea later.
I have sometimes pedantically quibbled with people that it is properly named the Church-Turing Theorem (of Computation) and that that distinction of including both esteemed mathematicians helps to push people towards the realization of how groundbreaking that effort was (two mathematicians separated by an ocean and using vastly different approaches to the mathematics of computation realizing how intricately linked they were), and also how the Lambda Calculus truly was integral in the definition of "Turing-complete".
Without Church's work on the Lambda calculus and without the Lambda calculus being so very different from the Turing "imperative" model of machine, we'd probably have a much narrower view of what "Turing-complete" even means, if we even had the concept at all.
This point reminds me of something interesting that I noticed recently despite having been familiar with basic LISP ideas for a long time.
If you carefully read McCarthy's original presentation of LISP, you can see that he seemed to be influenced at least as much by Kurt Gödel's work as by Alonzo Church's work.
In Church's lambda calculus, functions are abstract values that can only be used by means of function application. LISP evolved toward this style over time, but in the early history of LISP, functions were not abstract values but were represented by encoding into S-expressions. This encoding process resembles Gödel numbering.
Also, recursion arises in a different form in lambda calculus than it does in the approach to computability that is based on general recursive functions. Again, I think that LISP is closer to Gödel here than to Church.
I think I understand most of the rest of your post, but I got lost here. Could you describe what difference you see here, and how it applies to LISP?
Example:
odd 0 = False
odd n = even (n - 1)
even 0 = True
even n = odd (n - 1)
I think "rewriting system" is something similar. (I'm not an expert in this stuff so I'm providing hints for further reading more than anything else).In these systems, recursion is "built in" to the formal language itself.
On the other hand, lambda calculus does not have recursion "built in". All variables are bound by function application so it is not possible to have recursive bindings like you see in these recursive function systems. You can define recursive functions using mechanisms like the Y combinator but these work by reconstructing something over and over as the computation evolves. It's different.
In McCarthy's paper, there is a system of toplevel recursive functions and there is a LABELS form that behaves in a similar way. Lambda calculus has neither of these.
One resource that describes recursive function systems of the kind I'm thinking of is the book "Lambda-Calculus and Combinators, an Introduction" by Hindley and Seldin (especially chapter 4).
I don't think it was meant to be an encyclopedic reference on the language.
I think its odd that you spent that much effort tearing it apart. I for one enjoyed reading it while I was waiting for a coffee.
Who actually wrote the machine code is arcana that's lost to the dust bin of history anyway. What isn't lost are the high level ideas presented here.
I think that attribution matters; albeit probably more the attribution to Church and Turing than to Steve Russell over McCarthy. It matters because if someone finds the ideas the article brings up interesting and wants to dig into them, they should know where to turn. The history of ideas informs future ideas to come.
I also think understanding the details of high-level ideas matters. The misconceptions about self-interpretation, for example, are quite deep: no language can ultimately be defined in terms of itself, but always in terms of something lower-level. Chase this thread far enough and you start studying transistors; or, in another direction, Goedel's incompleteness theorems.
[1] http://www-formal.stanford.edu/jmc/history/lisp/node3.html
[2] https://www.csee.umbc.edu/courses/331/resources/papers/Evolu...
"... decisions ... later proved unfortunate. These included ... the use of the number zero to denote the empty list NIL and the truth value false. Besides encouraging pornographic programming, giving a special interpretation to the address 0 has caused difficulties in all subsequent implementations." -John McCarthy
Maybe he considered NIL to be his own billion dollar mistake.
Tony Hoare / Historically Bad Ideas: "Null References: The Billion Dollar Mistake" [1]
"Abstract: I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. In recent years, a number of program analysers like PREfix and PREfast in Microsoft have been used to check references, and give warnings if there is a risk they may be non-null. More recent programming languages like Spec# have introduced declarations for non-null references. This is the solution, which I rejected in 1965." -Tony Hoare
But of course, I've had malloc return NULL - very finite.
Do you have a source giving additional details of what happened?
However Wikipedia says that there is a second, and the person that I was responding to indicated that Steve Russell had to create a garbage collector to make it work. Those are things that I had not previously heard, and I'm curious about.
McCarthy also didn't expect S-expressions to be a concrete form. He expected everybody would write in M-expressions.
The fact that S-expressions worked as the language itself is again due to Steve Russell's insight.
What are M-expressions? Basically this:
(a b c) (quote (a b c))
car[x] (car x)
car[append[(a b c); (d e f)]] (car (append (quote (a b c)) (quote (d e f))))
Parentheses implicitly quote. Square brackets are non-quoting, but the first element goes outside. Inside square brackets, pointlessly superfluous semicolons appear.S-expressions developed the ' notation for quoting, almost eliminating the slight advantage of M-expressions there:
(a b c) '(a b c)
car[x] (car x)
car[append[(a b c); (d e f)]] (car (append '(a b c) '(d e f))))
The apostrophe notation is smarter; I don't see a way in M-exps to quote an individual atom. Though M-exps give us this: (x) (quote (x))
if we want (quote x) it looks as if we have to write: quote[x] 'x
whose lameness is self-evident.I think MacCarthy was exploiting M-expressions for the way that most trivial instances of them look different from S-expressions, which was a useful distinction to have in the papers about Lisp. With an M-exp you could whack the reader over the head and say "hey reader, this is character syntax: what you enter into the machine" and then with S-exps you say "this is a textual picture of internal structure".
There are other ways for that though, like different fonts, or upper/lower case and whatnot, or some REPL convention where we show the prompt in front of what is typed in, plus the "result arrow" and such.
> if we want (quote x) it looks as if we have to write: ... quote[x]
I think that you could just write X in that case. Uppercase text was for symbolic atoms.
Also, you didn't mention conditionals:
M-expressions:
ff[x] = [atom[x] → x; T → ff[car[x]]]
S-expressions: (defun ff (x) (cond ((atom x) x) (T (ff (car x)))))
The semicolon and the infix arrow have the benefit of reducing the need for parentheses in that case. And you can avoid writing "defun" and "cond".That's not actually true: you could, instead, just fill up memory and crash when you're out. It's not ideal, but it does work.
> How quickly that happens and how it handles it is just a matter of how good of a garbage collector you have.
It depends on the object size, how well objects are packed, and how much memory you have. Waste cannot be better than zero, so we have an upper bound on hitting OOM.
The lower bound (under non-compacting allocation) depends on the size ratio between the smallest and largest object. This is explored in paper by J.M. Robson (JACM 18, 416-423, [1971]) where Robson shows (IIRC, using only power of two block sizes, but arguing that the result is general) that an allocator client can be so contrived as to bring about the worst case whereby the heap consists only of the smallest objects, spaced apart just close enough that a request for the largest object can then be made, which fails. The memory utilization at that OOM moment is then the ratio between the size of the smallest and largest object. Robson's important argument is that an allocator has no way to defend against this problem. Regardless of its strategy for placing requests, the client can be contrived to tickle the worst case.
Fragmentation is not necessarily GC's fault; some objects just can't be moved. Objects which are opaque memory managed by a foreign library API pose an intractable problem in this area. There are good rationales for a non-compacting GC; non-compacting doesn't make it "bad".
Without GC, there is no lower bound on the amount of reachable data which exists under OOM. A tight loop which repeatedly calls cons will hit OOM.
If you write a JS interpreter in JS, a heck of a lot of work is in fact done for you.
That's why every teenager and his dog has a transpiler from something (resembling JS or not) to JavaScript.
http://stackoverflow.com/questions/3482389/how-many-primitiv...