Lisp is one of the oldest "high level" programming languages; invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).
Lisp is extensible: It is mostly built in itself, and programs are written by extending the language. Like Forth, for example.
It is interactive; Lisp processes your source code as you type or load, however a stand alone program can be produced by most Lisps. This allows you to update pograms on the fly as you write them, and promotes a "test as you go" method.
Statements in Lisp are called expressions and specifically, "s-expressions" ("s" for symbolic). Lisp is expression based; using pre-fix notation (opposite of Forth), with the verb first, followed by the objects. Oh, and every expression must be enclosed in parentheses. Lots and lots of parentheses. For example: (+ 1 2) returns 3 in the Lisp REPL (Read Eval Print Loop).
The essence of a list is the data structure (inexplicably called) "cons" that is just a pair of any two items. But cons is used to make a list by having the first element of the pair be the first element of the list and the 2nd element of the pair being the REST of the list.
As a practical example, the following converts 'F into 'C in Lisp:
(defun FtoC(degF) (/ (* (- degF 32) 5) 9) )
Notice "defun" and how it is a very short contraction, instead of something more readable like "define" or "function". Lisp is terse and likes initials. At best. For example, cdr and car are functions that return the first element of a list and the remaining elements of a list.
(car (list 1 2 3)) => 1 (cdr (list 1 2 3)) => (2 3)
The popular explanation that CAR and CDR stand for "Contents of the Address Register" and "Contents of the Decrement Register" based on the addressing instructions of the computer on which it was first written, but that machine does not have a programmer-accessible address register and the three address modification registers are called "index registers." No real understanding of the source of these names exists. Why aren't they called "first" and "rest"? They are in some derivitives of Lisp. And cddr is (cdr (cdr x)) which gives the list items after the first 2 (cddr (list 1 2 3 4 5)) => (3 4 5)
Symbols in Lisp are quoted by a single quote, at the front only, and they end with a space. e.g. ('abc) returns ABC as a symbol. Sometimes, the quoting is assumed, as in define or defun where the name of the function or it's parameters don't have to be quoted. Or when we define a variable. For example:
(setq a 111)
(write 'a) => a (write a) => 111
Here is a good introduction to Lisp video:
This video does a good job of explaining how Lisp is interpreted. All the
code is at:
And there is a written out version of the video at:
Finding an approx Square Root via successive guesses:
(defun square-root (x) (defun square (x) (* x x)) (defun average (x y) (/ (+ x y) 2)) (defun improve (guess) (average guess (/ x guess)) ) (defun good-enough? (guess) (< (abs (- (square guess) x)) 0.001) ) (defun try (guess) (if (good-enough? guess) guess (try (improve guess)) ) ) (try 1) ) (write (square-root 2))
Comments on Lisp by Christopher Fry:
Lists are used for data structures (arrays) but they are also used for the data structure that represents a function call. So you can, for instance do
(eval (list '+ 1 2))
- Makes a list of 3 elements, the definition of +, and two numbers.
- calls it.
Lisp became the primary language for AI because:
- it is better than other languages in handling complexity
- it is better than other languages in writing code that writes code.
A comparison of Lisp and Forth by Gordon Charlton:
Forth and Lisp are mirror images. The opposites include postfix v. prefix, static allocation v. dynamic allocation, explicit v. Implicit stack.
The primary point of coincidence is that executing a Forth word and evaluating a Lisp function are both depth first tree traversal. They are both interactive and extensible.
Lisp comes from academia and the lambda calculus, a world where more abstract means more fundamental, and computing is mathematics made real with information processing technology.
Forth comes from pragmatism and electrical engineering, where more fundamental means closer to the physics, and software is hardware by other means.
In short, they are as different as Church and Turing, which is to say demonstrably equivalent.
|file: /Techref/language/lisps.htm, 8KB, , updated: 2020/6/24 22:29, local time: 2022/5/20 23:41,
|©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://piclist.com/techref/language/lisps.htm"> Lisp Language</A>
|Did you find what you needed?|
PICList 2022 contributors:
o List host: MIT, Site host massmind.org, Top posters @20220520
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to piclist.com!