views:

409

answers:

5

On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply.

http://hyperpolyglot.wikidot.com/lisp#ten-primitives

Stevey reckons there are seven (or five):

Its part of the purity of the idea of LISP: you only need the seven (or is 
it five?) primitives to build the full machine.

http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html

What is the minimum number of primitives to build a LISP machine (ie something that can run an eval/value function on LISP code)? (And which ones are they?)

(I can understand you could live without atom, label and apply)

+5  A: 

This faq states:

There is no single "best" minimal set of primitives; it all depends on the implementation. For example, even something as basic as numbers need not be primitive, and can be represented as lists. One possible set of primitives might include CAR, CDR, and CONS for manipulation of S-expressions, READ and PRINT for the input/output of S-expressions and APPLY and EVAL for the guts of an interpreter. But then you might want to add LAMBDA for functions, EQ for equality, COND for conditionals, SET for assignment, and DEFUN for definitions. QUOTE might come in handy as well.

That comes from the School of Computer Science, Carnegie Melon website.

bennybdbc
+3  A: 

McCarthy used seven operators to define the original Lisp: quote, atom, eq, car, cdr, cons and cond. This article retraces his steps.

Vijay Mathew
He actually also used `label`, though it wasn't necessary to have.
Isaac Hodes
And he needed `lambda` as well.
Isaac Hodes
+12  A: 

Basic Predicates/F-functions

McCarthy's Elementary S-functions and Predicates were:

1 atom

Which was necessary because car and cdr are undefined for lists, which means you cannot count on any sort of answer to indicate what was happening if you gave car an atom.

2 eq

For testing equality between atoms.

3 car

For returning the first half (address) of the cons cell. (Contents of address register).

4 cdr

For returning the second half (decrement) of the cons cell. (Contents of decrement register).

5 cons

For making a new cons cell, with the address half containing the first argument to cons, and the decrement half containing the second argument.

Tying it together: S-Functions

He then went on to add to his basic notation, to enable writing what he called S-functions:

1 quote

To represent an expression without evaluating it.

2 cond

The basic conditional to be used with the previously described predicates.

3 lambda

To denote a function.

4 label

Though he didn't need this for recursion, he might not have known about the Y-Combinator (according to Paul Graham), he added this for convenience and to enable easy recursion.


So you can see he actually defined 9 basic "operators" for his Lisp machine. In a previous answer to another one of your questions, I explained how you could represent and operate on numbers with this system.

But the answer to this question really depends on what you want out of your Lisp machine. You could implement one without the label function, as you could symply functionally compose everything, and obtain recursion through applying the Y-Combinator.

atom could be discarded if you defined the car operation on atoms to return NIL.

You could essentially have McCarthy's LISP machine with 7 of these 9 defined primitives, but you could ostensibly define a more concise version depending on how much inconvenience you'd want to inflict on yourself. I like his machine quite fine, or the many primitives in the newer languages like Clojure.

Isaac Hodes
+1 for detailed answer.
Vijay Mathew
A: 

Paul Graham implements eval using seven.

In McCarthy's Micro Manual for LISP he implements eval using ten.

hawkeye
A: 

See this other question to construct macros from Paul Graham's set of 7 primitives.

DomQ