Reputation: 361
I read in the book Land of Lisp that the lambda function is the only built-in function. However I don't really understand how that is possible because I thought you would at least need one command for addition, one for comparing numbers, and one for moving data from one variable to another. I was wondering if someone could explain to me how lisp does it. I'm not a mathematician so if it is possible could you also explain it without a whole lot of complex math?
Upvotes: 3
Views: 1551
Reputation: 921
What 'Land of Lisp' is saying here is not that lambda
is the only Lisp primitive, but rather that (according to Alonzo Church's lambda calculus, which Lisp has theoretical underpinnings) one could implement the rest of Lisp with lambda
, as the lambda calculus is equivalent to a Universal Turing Machine.
For most practical applications, lambda
is used to define anonymous functions.
Upvotes: 7
Reputation: 363587
You're confusing some things here. lambda
is not a function. It's a construct built into the Lisp language.
Any practical Lisp will have lots of built-in functions; it needs at least car
and cdr
to pick lists apart and some primitive arithmetic functions cannot be defined in terms of other functions.(*) Also, the "non-functional" parts of Lisp such as setf
need some primitives.
[*] You can do Church arithmetic in Lisp, but then you can't pretty-print the results due to Lisp's type system but whether you can properly print the result depends on the Lisp variant.
Upvotes: 3
Reputation: 139261
That's a difference between theory and a real programming language.
Lisp took ideas from Lambda Calculus, but does not implement it. The lambda calculus describes a system to do calculation using functions. It is useful to understand Lambda Calculus, but you won't program in pure Lambda Calculus when you use Lisp.
As a programming language, Lisp has all kinds of data types and operations for those (numbers, strings, characters, cons cells, symbols, functions, ...).
Compare that to Turing Machines and something like the programming language C.
Upvotes: 5