Information about Lisp Programming Language
| Paradigm: | multi-paradigm: functional, procedural, reflective |
|---|---|
| Appeared in: | 1958 |
| Designed by: | John McCarthy |
| Developer: | Steve Russell, Timothy P. Hart, and Mike Levin |
| Typing discipline: | dynamic, strong |
| Dialects: | Common Lisp, Scheme, Emacs Lisp |
| Influenced: | Logo, Smalltalk, Ruby, Dylan, Mathematica |
Lisp was originally created as a practical mathematical notation for computer programs, based on Alonzo Church's lambda calculus. It quickly became the favored programming language for artificial intelligence research. As one of the earliest programming languages, Lisp pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, object-oriented programming, and the self-hosting compiler.
The name Lisp derives from "List Processor". Linked lists are one of Lisp languages' major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or even new "little languages" embedded in Lisp.
The interchangeability of code and data also gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized lists. A function call or syntactic form is written as a list with the function or operator's name first, and the arguments following; for instance, a function f that takes three arguments might be called using
(f x y z).
The invention of Lisp
Lisp was invented by John McCarthy in 1958 while he was at MIT. McCarthy published its design in a paper in Communications of the ACM in 1960, entitled "Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I"[1] (Part II was never published). He showed that with a few simple operators and a notation for functions, one can build a Turing-complete language for algorithms.Lisp was first implemented by Steve Russell on an IBM 704 computer. Russell had read McCarthy's paper, and realized (to McCarthy's surprise) that the eval function could be implemented as a Lisp interpreter.
The first complete Lisp compiler, written in Lisp, was implemented in 1962 by Tim Hart and Mike Levin at MIT.[2] This compiler introduced the Lisp model of incremental compilation, in which compiled and interpreted functions can intermix freely. The language used in Hart and Levin's memo is much closer to modern Lisp style than McCarthy's earlier code.
Curiosities of the early history
Information Processing Language was the first AI language, from 1955 or 1956, and already included many of the concepts, such as list-processing and recursion, which came to be used in Lisp.McCarthy's original notation used bracketed "M-expressions" that would be translated into S-expressions. As an example, the M-expression
car[cons[A,B]] is equivalent to the S-expression (car (cons A B)). Once Lisp was implemented, programmers rapidly chose to use S-expressions, and M-expressions were abandoned. M-expressions surfaced again with short-lived attempts of MLISP[3] by Horace Enea and CGOL by Vaughan Pratt.
Two assembly language macros for the IBM 704 became the primitive operations for decomposing lists:
car (Contents of Address Register) and cdr (Contents of Decrement Register). Lisp dialects still use car and cdr (pronounced: [kɑr] and ['kʊdər]) for the operations that return the first item in a list and the rest of the list respectively.
Genealogy and variants
Over its almost fifty-year history, Lisp has spawned many variations on the core theme of an S-expression language. Moreover, each given dialect may have several implementations – for instance, there are more than a dozen implementations of Common Lisp.Differences between dialects may be quite visible – for instance, Common Lisp and Scheme use different keywords to define functions. Within a dialect that is standardized, however, conforming implementations support the same core language, but with different extensions and libraries.
Historically significant dialects
- LISP 1.5 http://community.computerhistory.org/scc/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf – First widely distributed version, developed by McCarthy and others at MIT. So named because it contained several improvements on the original "LISP 1" interpreter, but was not a major restructuring as the planned LISP 2 would be.
- Stanford LISP 1.6 http://community.computerhistory.org/scc/projects/LISP/stanford/SAILON-28.6.pdf – This was a successor to LISP 1.5 developed at the Stanford AI Lab, and widely distributed to PDP-10 systems running the TOPS-10 operating system. It was obsoleted by Maclisp and InterLisp.
- MACLISP http://zane.brouhaha.com/~healyzh/doc/lisp.doc.txt – developed for MIT's Project MAC (no relation to Apple's Macintosh, nor to McCarthy), direct descendant of LISP 1.5. It ran on the PDP-10 and Multics systems.
- InterLisp http://www.bitsavers.org/pdf/xerox/interlisp/1974_InterlispRefMan.pdf – developed at BBN for PDP-10 systems running the Tenex operating system, later adopted as a "West coast" Lisp for the Xerox Lisp machines. A small version called "InterLISP 65" was published for Atari's 6502-based computer line. For quite some time MacLisp and InterLisp were strong competitors.
- Franz Lisp – originally a Berkeley project; later developed by Franz Inc. The name is a humorous deformation of 'Franz Liszt'.
- ZetaLisp – used on the Lisp machines, direct descendant of MacLisp.
- EuLisp – attempt to develop a new efficient and cleaned-up Lisp.
- ISLisp – attempt to develop a new efficient and cleaned-up Lisp. Standardized.
- IEEE Scheme – IEEE standard, 1178-1990 (R1995)
- ANSI Common Lisp – mostly, a cleaned up subset of ZetaLisp incorporating CLOS.
Lisp and AI
Since its inception, Lisp was closely connected with the artificial intelligence research community, especially on PDP-10[4] systems. Lisp was used as the implementation of the programming language Micro Planner that was the foundation for the famous AI system SHRDLU. In the 1970s, as AI research spawned commercial offshoots, the performance of existing Lisp systems became a growing issue.Lisp was a difficult system to implement with the compiler techniques and stock hardware of the 1970s. Garbage collection routines, developed by then-MIT graduate student Daniel Edwards, made it practical to run Lisp on general-purpose computing systems, but efficiency was still a problem. This led to the creation of Lisp machines: dedicated hardware for running Lisp environments and programs. Advances in both computer hardware and compiler technology soon made Lisp machines obsolete, to the detriment of the Lisp market.
During the 1980s and 1990s, a great effort was made to unify the numerous Lisp dialects (most notably, InterLisp, Maclisp, ZetaLisp, and Franz Lisp) into a single language. The new language, Common Lisp, was essentially a compatible subset of the dialects it replaced. In 1994, ANSI published the Common Lisp standard, "ANSI X3.226-1994 Information Technology Programming Language Common Lisp." At that time the world market for Lisp was much smaller than it is today.
Lisp today
Having declined somewhat in the 1990s, Lisp has experienced a regrowth of interest since 2000. Most new activity is focused around open source implementations of Common Lisp, and includes the development of new portable libraries and applications.Many new Lisp programmers were inspired by writers such as Paul Graham and Eric S. Raymond to pursue a language others consider antiquated. New Lispers often describe the language as an eye-opening experience and claim to be substantially more productive than in other languages. [5] Graham is developing a new Lisp dialect called Arc.
Peter Seibel's Practical Common Lisp, a tutorial for new Lisp programmers published in 2004, was briefly Amazon.com's second most popular programming book.
Major modern dialects
The two major dialects of Lisp used for general-purpose programming today are Common Lisp and Scheme. These languages represent significantly different design choices.Common Lisp, descended mainly from MacLisp, Interlisp, and Lisp Machine Lisp, is an expanded superset of earlier Lisp dialects, with a large language standard including many built-in data types and syntactic forms, as well as an object system. Scheme is a more minimalist design, with a much smaller set of standard features but with certain implementation features (such as tail-call optimization and full continuations) not necessarily found in Common Lisp. Common Lisp also borrowed certain features from Scheme such as lexical scoping and lexical closures.
In addition, Lisp dialects are used as scripting languages in a number of applications, with the most well-known being Emacs Lisp in the Emacs editor and Autolisp in AutoCAD.
Language innovations
Lisp was the first homoiconic programming language: the primary representation of program code is the same type of list structure that is also used for the main data structures. As a result, Lisp functions can be manipulated, altered or even created within a Lisp program without extensive parsing or manipulation of binary machine code. This is generally considered one of the primary advantages of the language with regards to its expressiveness, and makes the language amenable to metacircular evaluation.The now-ubiquitous if-then-else structure, now taken for granted as an essential element of any programming language, was invented by McCarthy for use in Lisp, where it saw its first appearance in a more general form (the cond structure). It was inherited by Algol, which popularized it.
Lisp deeply influenced Alan Kay, the leader of the research on Smalltalk, and then in turn Lisp was influenced by Smalltalk, by adopting object-oriented programming features (classes, instances, etc.) in the late 1970s.
Largely because of its resource requirements with respect to early computing hardware (including early microprocessors), Lisp did not become as popular outside of the AI community as Fortran and the ALGOL-descended C language. Newer languages such as Java and Python have incorporated some limited versions of some of the features of Lisp, but are necessarily unable to bring the coherence and synergy of the full concepts found in Lisp. Because of its suitability to ill-defined, complex, and dynamic applications, Lisp is currently enjoying some resurgence of popular interest.
See also "The evolution of Lisp"[6], a paper written by Guy L. Steele, Jr. and Richard P. Gabriel.
Syntax and semantics
- Note: This article's examples are written in Common Lisp (though most are also valid Scheme).
Lisp is an expression-oriented language. Unlike most other languages, no distinction is made between "expressions" and "statements"; all code and data are written as expressions. When an expression is evaluated, it produces a value (or list of values), which then can be embedded into other expressions.
McCarthy's 1958 paper introduced two types of syntax: S-expressions (Symbolic Expressions, also called "sexps"), which mirror the internal representation of code and data; and M-expressions (Meta Expressions), which express functions of S-expressions. M-expressions never found favour, and almost all Lisps today use S-expressions to manipulate both code and data.
The use of parentheses is Lisp's most immediately obvious difference from other programming language families. As a result, students have long given Lisp nicknames such as Lost In Stupid Parentheses, or Lots of Irritating Superfluous Parentheses[2]. However, the S-expression syntax is also responsible for much of Lisp's power; the syntax is extremely regular, which facilitates manipulation by computer. However, the syntax of Lisp is not limited to traditional parentheses notation. It can be extended to include alternative notations. XMLisp, for instance, is a Common Lisp extension that employs the metaobject-protocol to integrate S-expressions with the Extensible Markup Language (XML).
The reliance on expressions gives the language great flexibility. Because Lisp functions are themselves written as lists, they can be processed exactly like data. This allows easy writing of programs which manipulate other programs (metaprogramming). Many Lisp dialects exploit this feature using macro systems, which enables extension of the language almost without limit.
A Lisp list is written with its elements separated by whitespace, and surrounded by parentheses. For example,
(1 2 foo) is a list whose elements are three atoms, the values 1, 2, and foo. These values are implicitly typed: they are respectively two integers and a Lisp-specific data type called a "symbol", and do not have to be declared as such.
The empty list
() is also represented as the special atom nil. This is the only entity in Lisp which is both an atom and a list.
Expressions are written as lists, using prefix notation. The first element in the list is the name of a form, i.e., a function, operator, macro, or "special operator" (see below.) The remainder of the list are the arguments. For example, the function
list returns its arguments as a list, so the expression
> (list '1 '2 'foo)evaluates to the list
(1 2 foo). The "quote" before the arguments in the preceding example is a "special operator" which prevents the quoted arguments being evaluated (not strictly necessary for the numbers, since 1 evaluates to 1, etc). Any unquoted expressions are recursively evaluated before the enclosing expression is evaluated. For example,
> (list 1 2 (list 3 4))evaluates to the list
(1 2 (3 4)). Note that the third argument is a list; lists can be nested.
Arithmetic operators are treated similarly. The expression
> (+ 1 2 3 4)evaluates to 10. The equivalent under infix notation would be "
1 + 2 + 3 + 4". Arithmetic operators in Lisp are variadic (or n-ary), able to take any number of arguments.
"Special operators" (sometimes called "special forms" by older users) provide Lisp's control structure. For example, the special operator
if takes three arguments. If the first argument is non-nil, it evaluates to the second argument; otherwise, it evaluates to the third argument. Thus, the expression
> (if nil (list 1 2 "foo") (list 3 4 "bar"))evaluates to
(3 4 "bar"). Of course, this would be more useful if a non-trivial expression had been substituted in place of nil.
Lambda expressions
Another special operator,lambda, is used to bind variables to values which are then evaluated within an expression. This operator is also used to create functions: the arguments to lambda are a list of arguments, and the expression or expressions to which the function evaluates (the returned value is the value of the last expression that is evaluated). The expression
> (lambda (arg) (+ arg 1))evaluates to a function that, when applied, takes one argument, binds it to
arg and returns the number one greater than that argument. Lambda expressions are treated no differently from named functions; they are invoked the same way. Therefore, the expression
> ((lambda (arg) (+ arg 1)) 5)evaluates to
6.
Atoms
In the original LISP there were two fundamental data types: atoms and lists. A list was a finite ordered sequence of elements, where each element is in itself either an atom or a list, and an atom was a number or a symbol. A symbol was essentially a unique named item, written as an Alphanumeric string in source code, and used either as a variable name or as a data item in symbolic processing. For example, the list(FOO (BAR 1) 2) contains three elements: the symbol FOO, the list (BAR 1), and the number 2.
The essential difference between atoms and lists was that atoms were immutable and unique. Two atoms that appeared in different places in source code but were written in the exact same way represented the same object, whereas each list was a separate object that could be altered independently of other lists and could be distinguished from other lists by comparison operators.
As more data types were introduced in later Lisp dialects, and programming styles evolved, the concept of an atom lost importance. Many dialects still retained the predicate atom for legacy compatibility, defining it as true for anything that is not a cons cell (ie. a list or a partial list).
Conses and lists
A Lisp list is a singly-linked list. Each cell of this list is called a cons (in Scheme, a pair), and is composed of two pointers, called the car and cdr. These are equivalent to the
data and next fields discussed in the article linked list, respectively.
Of the many data structures that can be built out of cons cells, one of the most basic is called a proper list. A proper list is either the special
nil (empty list) symbol, or a cons in which the car points to a datum (which may be another cons structure, such as a list), and the cdr points to another proper list.
If a given cons is taken to be the head of a linked list, then its car points to the first element of the list, and its cdr points to the rest of the list. For this reason, the
car and cdr functions are also called first and rest when referring to conses which are part of a linked list (rather than, say, a tree).
Thus, a Lisp list is not an atomic object, as an instance of a container class in C++ or Java would be. A list is nothing more than an aggregate of linked conses. A variable which refers to a given list is simply a pointer to the first cons in the list. Traversal of a list can be done by "cdring down" the list; that is, taking successive cdrs to visit each cons of the list; or by using any of a number of higher-order functions to map a function over a list.
Because conses and lists are so universal in Lisp systems, it is a common misconception that they are Lisp's only data structures. In fact, all but the most simplistic Lisps have other data structures – such as vectors (arrays), hash tables, structures, and so forth.
S-expressions represent lists
Parenthesized S-expressions represent linked list structure. There are several ways to represent the same list as an S-expression. A cons can be written in dotted-pair notation as(a . b), where a is the car and b the cdr. A longer proper list might be written (a . (b . (c . (d . nil)))) in dotted-pair notation. This is conventionally abbreviated as (a b c d) in list notation. An improper list may be written in a combination of the two – as (a b c . d) for the list of three conses whose last cdr is d (i.e., the list (a . (b . (c . d))) in fully-specified form).
List-processing procedures
Lisp provides many built-in procedures for accessing and controlling lists. Lists can be created directly with thelist procedure, which takes any number of arguments, and returns the list of these arguments.
> (list 1 2 'a 3) ;Output: (1 2 a 3)
> (list 1 '(2 3) 4) ;Output: (1 (2 3) 4)Because of the way that lists are constructed from cons pairs, the
cons procedure can be used to add an element to the front of a list. Note that the cons procedure is asymmetric in how it handles list arguments, because of how lists are constructed.
> (cons 1 '(2 3)) ;Output: (1 2 3)
> (cons '(1 2) '(3 4)) ;Output: ((1 2) 3 4)The
append procedure appends two (or more) lists to one another. Because Lisp lists are linked lists, appending two lists has asymptotic time complexity
.
> (append '(1 2) '(3 4)) ;Output: (1 2 3 4)
> (append '(1 2 3) '() '(a) '(5 6)) ;Output: (1 2 3 a 5 6)
Shared structure
Lisp lists, being simple linked lists, can share structure with one another. That is to say, two lists can have the same tail, or final sequence of conses. For instance, after the execution of the following Common Lisp code:> (setq foo (list 'a 'b 'c)) (setq bar (cons 'x (cdr foo)))the lists
foo and bar are (a b c) and (x b c) respectively. However, the tail (b c) is the same structure in both lists. It is not a copy; the cons cells pointing to b and c are in the same memory locations for both lists.
Sharing structure rather than copying can give a dramatic performance improvement. However, this technique can interact in undesired ways with functions that alter lists passed to them as arguments. Altering one list, such as by replacing the
c with a goose, will affect the other:
> (setf (third foo) 'goose)This changes
foo to (a b goose), but thereby also changes bar to (x b goose) – a possibly unexpected result. This can be a source of bugs, and functions which alter their arguments are documented as destructive for this very reason.
Aficionados of functional programming avoid destructive functions. In the Scheme dialect, which favors the functional style, the names of destructive functions are marked with a cautionary exclamation point, or "bang" — such as
set-car! (read set car bang), which replaces the car of a cons. In the Common Lisp dialect, destructive functions are commonplace; the equivalent of set-car! is named rplaca for "replace car." This function is rarely seen however as Common Lisp includes a special facility, setf, to make it easier to define and use destructive functions. A frequent style in Common Lisp is to write code functionally (without destructive calls) when prototyping, then to add destructive calls as an optimization where it is safe to do so.
Self-evaluating forms and quoting
Lisp evaluates expressions which are entered by the user. Symbols and lists evaluate to some other (usually, simpler) expression – for instance, a symbol evaluates to the value of the variable it names;(+ 2 3) evaluates to 5. However, most other forms evaluate to themselves: if you enter 5 into Lisp, it returns 5.
Any expression can also be marked to prevent it from being evaluated (as is necessary for symbols and lists). This is the role of the
quote special operator, or its abbreviation ' (a single quotation mark). For instance, usually if you enter the symbol foo you will get back the value of the corresponding variable (or an error, if there is no such variable). If you wish to refer to the literal symbol, you enter (quote foo) or, usually, 'foo.
Both Common Lisp and Scheme also support the backquote operator (often called quasiquote by Schemers), entered with the
` character. This is almost the same as the plain quote, except it allows expressions to be evaluated and their values interpolated into a quoted list with the comma and comma-at operators. If the variable snue has the value (bar baz) then `(foo ,snue) evaluates to (foo (bar baz)), while `(foo ,@snue) evaluates to (foo bar baz). The backquote is most frequently used in defining macro expansions.
Self-evaluating forms and quoted forms are Lisp's equivalent of literals. It is possible to modify the values of (mutable) literals in program code. For instance, if a function returns a quoted form, and the code that calls the function modifies the form, this will alter the behavior of the function on subsequent iterations.
> (defun should-be-constant '(one two three)) (let ((stuff (should-be-constant))) (setf (third stuff) 'bizarre)) ; bad! (should-be-constant) ; returns (one two bizarre)
Modifying a quoted form like this is generally considered bad style, and is defined by some implementations as erroneous (resulting in "undefined" behavior in compiled files, because the file-compiler can coalesce similar constants, put them in write-protected memory, etc). When behavior like this is intentional, using a closure is the explicit way to do it.
Lisp's formalization of quotation has been noted by Douglas Hofstadter (in Gödel, Escher, Bach) and others as an example of the philosophical idea of self-reference.
Scope and closure
The modern Lisp family splits over the use of dynamic or static (aka lexical) scope. Scheme and Common Lisp make use of static scoping by default, while the more primitive Lisp systems used as embedded languages in Emacs and AutoCAD use dynamic scoping.List structure of program code
A fundamental distinction between Lisp and other languages is that in Lisp, program code is not simply text. Parenthesized S-expressions, as depicted above, are the printed representation of Lisp code, but as soon as these are entered into a Lisp system they are translated by the parser (called theread function) into linked list and tree structures in memory.
Lisp macros operate on these structures. Because Lisp code has the same structure as lists, macros can be built with any of the list-processing functions in the language. In short, anything that Lisp can do to a data structure, Lisp macros can do to code. In contrast, in most other languages the parser's output is purely internal to the language implementation and cannot be manipulated by the programmer. Macros in C, for instance, operate on the level of the preprocessor, before the parser is invoked, and cannot re-structure the program code in the way Lisp macros can.
In simplistic Lisp implementations, this list structure is directly interpreted to run the program; a function is literally a piece of list structure which is traversed by the interpreter in executing it. However, most actual Lisp systems (including all conforming Common Lisp systems) also include a compiler. The compiler translates list structure into machine code or bytecode for execution.
Evaluation and the Read-Eval-Print Loop
Lisp languages are frequently used with an interactive command line, which may be combined with an integrated development environment. The user types in expressions at the command line, or directs the IDE to transmit them to the Lisp system. Lisp reads the entered expressions, evaluates them, and prints the result. For this reason, the Lisp command line is called a "read-eval-print loop", or REPL.The basic operation of the REPL is as follows. This is a simplistic description which omits many elements of a real Lisp, such as quoting and macros.
The
read function accepts textual S-expressions as input, and parses them into list structure. For instance, if you type the string (+ 1 2) at the prompt, read translates this into a linked list with three elements – the symbol +, the number 1, and the number 2. It so happens that this list is also a valid piece of Lisp code; that is, it can be evaluated. This is because the car of the list names a function – the addition operation.
The
eval function evaluates list structure, returning some other piece of structure as a result. Evaluation does not have to mean interpretation; some Lisp systems compile every expression to native machine code. It is simple, however, to describe evaluation as interpretation: To evaluate a list whose car names a function, eval first evaluates each of the arguments given in its cdr, then applies the function to the arguments. In this case, the function is addition, and applying it to the argument list (1 2) yields the answer 3. This is the result of the evaluation. Evaluation is performed in applicative order.
It is the job of the
print function to represent output to the user. For a simple result such as 3 this is trivial. An expression which evaluated to a piece of list structure would require that print traverse the list and print it out as an S-expression.
To implement a Lisp REPL, it is necessary only to implement these three functions and an infinite-loop function. (Naturally, the implementation of
eval will be complicated, since it must also implement all special operators like if.) This done, a basic REPL itself is but a single line of code: (loop (print (eval (read)))).
Control structures
Lisp originally had very few control structures, but many more were added during the language's evolution. (Lisp's original conditional operator,cond, is the precursor to later if-then-else structures.)
Programmers in the Scheme dialect often express loops using tail recursion. Scheme's commonality in academic computer science has led some students to believe that tail recursion is the only, or the most common, way to write iterations in Lisp; this is incorrect. All frequently-seen Lisp dialects have imperative-style iteration constructs, from Scheme's
do loop to Common Lisp's complex loop expressions.
Some Lisp control structures are special operators, equivalent to other languages' syntactic keywords. Expressions using these operators have the same surface appearance as function calls, but differ in that the arguments are not necessarily evaluated -- or, in the case of an iteration expression, may be evaluated more than once.
In contrast to most other major programming languages, Lisp allows the programmer to implement control structures using the language itself. Several control structures are implemented as Lisp macros, and can even be macroexpanded by the programmer who wants to know how they work.
Both Common Lisp and Scheme have operators for non-local control flow. The differences in these operators are some of the deepest differences between the two dialects. Scheme supports re-entrant continuations using the
call/cc procedure, which allows a program to save (and later restore) a particular place in execution. Common Lisp does not support re-entrant continuations, but does support several ways of handling escape continuations.
Frequently, the same algorithm can be expressed in Lisp in either an imperative or a functional style. As noted above, Scheme tends to favor the functional style, using tail recursion and continuations to express control flow. However, imperative style is still quite possible. The style preferred by many Common Lisp programmers may seem more familiar to programmers used to structured languages such as C, while that preferred by Schemers more closely resembles pure-functional languages such as Haskell.
Because of Lisp's early heritage in list processing, it has a wide array of higher-order functions relating to iteration over sequences. In many cases where an explicit loop would be needed in other languages (like a
for loop in C) in Lisp the same task can be accomplished with a higher-order function. (The same is true of many functional programming languages.)
A good example is a function which in Scheme is called
map and in Common Lisp is called mapcar. Given a function and one or more lists, mapcar applies the function successively to the lists' elements in order, collecting the results in a new list:
> (mapcar #'+ '(1 2 3 4 5) '(10 20 30 40 50))This applies the
+ function to each corresponding pair of list elements, yielding the result (11 22 33 44 55).
Examples
Here are examples of Common Lisp code. While unlike Lisp programs used in industry, they are similar to Lisp as taught in computer science courses.The basic "Hello world" program:
> (print "Hello world")As the reader may have noticed from the above discussion, Lisp syntax lends itself naturally to recursion. Mathematical problems such as the enumeration of recursively-defined sets are simple to express in this notation.
Evaluate a number's factorial:
> (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1)))))An alternative implementation, often faster than the previous version if the Lisp system has tail recursion optimization:
> (defun factorial (n &optional (acc 1)) (if (<= n 1) acc (factorial (- n 1) (* acc n))))Contrast with an iterative version which uses Common Lisp's
loop macro:
> (defun factorial (n) (loop for i from 1 to n for fac = 1 then (* fac i) finally (return fac)))The following function reverses a list. (Lisp's built-in reverse function does the same thing.)
> (defun -reverse (l &optional acc) (if (atom l) acc (-reverse (cdr l) (cons (car l) acc))))
Object systems
Various object systems and models have been built on top of, alongside, or into Lisp, including:- ObjectLisp[8] or Object Lisp, favored by Lisp Machines Incorporated
- LOOPS (Lisp Object-Oriented Programming System) and the later CommonLOOPS
- Flavors, built at MIT, and its descendant New Flavors, which were favored by Symbolics
- The Common Lisp Object System, CLOS (descended from New Flavors and CommonLOOPS)
- KR (short for Knowledge Representation), a constraints-based object system developed to aid the writing of Garnet, a GUI library for Common Lisp
- KEE was written similarly, but incorporating an inference engine.[9]
- Lush is an object-oriented lisp code with a goal of extensive programming capabilites, as it interfaces with many data libraries for math and science, but also interfaces with C code in-line, is still dynamic, and has graphics and hardware support.
- SageCLOS, an Object Oriented Interface to AutoLISP invented by Ralph Gimenez
Quotations
- SQL, Lisp, and Haskell are the only programming languages that I've seen where one spends more time thinking than typing.
- I suppose I should learn Lisp, but it seems so foreign.
- One can even conjecture that Lisp owes its survival specifically to the fact that its programs are lists, which everyone, including me, has regarded as a disadvantage.
- — John McCarthy, Inventor of Lisp, "Early History of Lisp"
- Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp.
- — Philip Greenspun, often called Greenspun's Tenth Rule of Programming[10]
- Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list.
- Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in.
- — Larry Wall, creator of the Perl programming language
- LISP being the most powerful and cleanest of languages, that's the language that the GNU project always prefers.
- the greatest single programming language ever designed
- — Alan Kay
- [Emacs] is written in Lisp, which is the only computer language that is beautiful.
- A LISP programmer knows the value of everything, but the cost of nothing.
Comics
- Webcomic xkcd: Lisp, Lisp Cycles, With Apologies to Robert Frost
Notes
1. ^ John McCarthy. Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I. Retrieved on 2006-10-13.
2. ^ Tim Hart and Mike Levin. AI Memo 39-The new compiler. Retrieved on 2006-10-13.
3. ^ David Canfield Smith. MLISP Users Manual. Retrieved on 2006-10-13.
4. ^ The 36-bit word size of the PDP-6/PDP-10 was influenced by the usefulness of having two Lisp 18-bit pointers in a single word. "The PDP-6 project started in early 1963, as a 24-bit machine. It grew to 36 bits for LISP, a design goal." [2]
5. ^ . Retrieved on 2006-10-13.
6. ^ Guy L Steele Jr, Richard P Gabriel. The evolution of Lisp. Retrieved on 2006-10-12.
7. ^ The Jargon File - Lisp. Retrieved on 2006-10-13.
8. ^ pg 17 of Bobrow 1986
9. ^ pg 108 of Veitch 1988
10. ^ Phillip Greenspun. Research. Retrieved on 2006-10-13.
2. ^ Tim Hart and Mike Levin. AI Memo 39-The new compiler. Retrieved on 2006-10-13.
3. ^ David Canfield Smith. MLISP Users Manual. Retrieved on 2006-10-13.
4. ^ The 36-bit word size of the PDP-6/PDP-10 was influenced by the usefulness of having two Lisp 18-bit pointers in a single word. "The PDP-6 project started in early 1963, as a 24-bit machine. It grew to 36 bits for LISP, a design goal." [2]
5. ^ . Retrieved on 2006-10-13.
6. ^ Guy L Steele Jr, Richard P Gabriel. The evolution of Lisp. Retrieved on 2006-10-12.
7. ^ The Jargon File - Lisp. Retrieved on 2006-10-13.
8. ^ pg 17 of Bobrow 1986
9. ^ pg 108 of Veitch 1988
10. ^ Phillip Greenspun. Research. Retrieved on 2006-10-13.
References
- "A History and Description of CLOS", by Jim Veitch. Pages 107-158 of Handbook of Programming Languages, Volume IV: Functional and Logic Programming Languages, ed. Peter H. Salus. 1998 (1st edition), Macmillian Technical Publishing; ISBN 1-57870-011-6
- Structure and Interpretation of Computer Programs, by Harold Abelson, Gerald Jay Sussman and Julie Sussman. 1996 (2nd edition), MIT Press; ISBN 0262011530.
- Lispers.org - Choice selection of Lisp quotes by eminent Lispers.
- The implementation of LISP
- My Lisp Experiences and the Development of GNU Emacs, transcript of Richard Stallman's speech, 28 Oct 2002, at the International Lisp Conference
- The Nature of Lisp
External links
- comp.lang.lisp Usenet group on Google Groups
- Association of Lisp Users
- , a general discussion of things Lispish
- History of LISP at the Computer History Museum
- LispMachine.net - Lisp books and information
- On Lisp, a free book by Paul Graham
A programming paradigm is a fundamental style of programming regarding how solutions to problems are to be formulated in a programming language. (Compare with a methodology, which is a style of solving specific software engineering problems).
..... Click the link for more information.
..... Click the link for more information.
A multiparadigm programming language is a programming language that supports more than one programming paradigm. As Leda designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in a variety of styles, freely
..... Click the link for more information.
..... Click the link for more information.
Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast with the imperative programming style that emphasizes changes in state.
..... Click the link for more information.
..... Click the link for more information.
Procedural programming is sometimes used as a synonym for imperative programming (specifying the steps the program must take to reach the desired state), but can also refer (as in this article) to a programming paradigm based upon the concept of the procedure call.
..... Click the link for more information.
..... Click the link for more information.
In computer science, reflection is the process by which a computer program of the appropriate type can be modified in the process of being executed, in a manner that depends on abstract features of its code and its runtime behavior.
..... Click the link for more information.
..... Click the link for more information.
19th century - 20th century - 21st century
1920s 1930s 1940s - 1950s - 1960s 1970s 1980s
1955 1956 1957 - 1958 - 1959 1960 1961
Year 1958 (MCMLVIII
..... Click the link for more information.
1920s 1930s 1940s - 1950s - 1960s 1970s 1980s
1955 1956 1957 - 1958 - 1959 1960 1961
Year 1958 (MCMLVIII
..... Click the link for more information.
John McCarthy
John McCarthy at a summit in 2006
Born September 4 1927
..... Click the link for more information.
John McCarthy at a summit in 2006
Born September 4 1927
..... Click the link for more information.
A software developer is a person who is concerned with one or more facets of the software development process, a somewhat broader scope of computer programming or a specialty of project managing.
..... Click the link for more information.
..... Click the link for more information.
Stephen Russell
Born 1937
Residence U.S.
Field computer science
Alma mater Dartmouth College
Known for Spacewar! Steve "Slug" Russell
..... Click the link for more information.
Born 1937
Residence U.S.
Field computer science
Alma mater Dartmouth College
Known for Spacewar! Steve "Slug" Russell
..... Click the link for more information.
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact.
..... Click the link for more information.
..... Click the link for more information.
In computer science, a type system defines how a programming language classifies values and expressions into types, how it can manipulate those types and how they interact.
..... Click the link for more information.
..... Click the link for more information.
In computer science and computer programming, the term strong typing is used to describe those situations where programming languages specify one or more restrictions on how operations involving values having different datatypes can be intermixed.
..... Click the link for more information.
..... Click the link for more information.
A dialect of a programming language is a (relatively small) variation or extension of the language that does not change its intrinsic nature. With languages such as Scheme and Forth, standards may be considered insufficient, inadequate or even illegitimate by implementors, so often
..... Click the link for more information.
..... Click the link for more information.
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard X3.226-1994. Developed to standardize the divergent variants of Lisp which predated it, it is not an implementation but rather a language specification.
..... Click the link for more information.
..... Click the link for more information.
Scheme
Paradigm: multi-paradigm
Appeared in: 1970s
Designed by: Guy L. Steele and Gerald Jay Sussman
Typing discipline: strong, dynamic
Major implementations: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk,
..... Click the link for more information.
Paradigm: multi-paradigm
Appeared in: 1970s
Designed by: Guy L. Steele and Gerald Jay Sussman
Typing discipline: strong, dynamic
Major implementations: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk,
..... Click the link for more information.
Emacs Lisp is a dialect of the Lisp programming language used by the GNU Emacs and XEmacs text editors (which will be collectively referred to as Emacs in this article.) It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C.
..... Click the link for more information.
..... Click the link for more information.
Logo
Paradigm: functional, educational
Appeared in: 1967
Designed by: Wally Feurzeig & Seymour Papert
Developer: Wally Feurzeig & Seymour Papert
Typing discipline: dynamic
Major implementations: UCBLogo, many others
Influenced by: Lisp
..... Click the link for more information.
Paradigm: functional, educational
Appeared in: 1967
Designed by: Wally Feurzeig & Seymour Papert
Developer: Wally Feurzeig & Seymour Papert
Typing discipline: dynamic
Major implementations: UCBLogo, many others
Influenced by: Lisp
..... Click the link for more information.
Smalltalk
Paradigm: object-oriented
Appeared in: Development started in 1969
Publicly available in 1980
Designed by: Alan Kay, Dan Ingalls, Adele Goldberg
Developer: Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and Xerox PARC
..... Click the link for more information.
Paradigm: object-oriented
Appeared in: Development started in 1969
Publicly available in 1980
Designed by: Alan Kay, Dan Ingalls, Adele Goldberg
Developer: Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Scott Wallace, and Xerox PARC
..... Click the link for more information.
Ruby
Paradigm: multi-paradigm (functional, imperative, logic, object-oriented (class-based))
Appeared in: 1995
Designed by: Yukihiro Matsumoto
Developer: Yukihiro Matsumoto (among others)
Latest release: 1.8.
..... Click the link for more information.
Paradigm: multi-paradigm (functional, imperative, logic, object-oriented (class-based))
Appeared in: 1995
Designed by: Yukihiro Matsumoto
Developer: Yukihiro Matsumoto (among others)
Latest release: 1.8.
..... Click the link for more information.
Dylan
Paradigm: multi-paradigm: functional, object-oriented
Appeared in: Early 1990s
Developer: Apple Computer
Typing discipline: Strong, dynamic
Major implementations: Open Dylan, Gwydion Dylan
Influenced by: CLOS, C++, ALGOL, Scheme
..... Click the link for more information.
Paradigm: multi-paradigm: functional, object-oriented
Appeared in: Early 1990s
Developer: Apple Computer
Typing discipline: Strong, dynamic
Major implementations: Open Dylan, Gwydion Dylan
Influenced by: CLOS, C++, ALGOL, Scheme
..... Click the link for more information.
Maintainer: Wolfram Research
OS: Cross-platform (list)
Use: Computer algebra, numerical computations, Information visualization, statistics, user interface creation
License: Proprietary
Website: Mathematica homepage Mathematica
..... Click the link for more information.
OS: Cross-platform (list)
Use: Computer algebra, numerical computations, Information visualization, statistics, user interface creation
License: Proprietary
Website: Mathematica homepage Mathematica
..... Click the link for more information.
computer is a machine which manipulates data according to a list of instructions.
Computers take numerous physical forms. The first devices that resemble modern computers date to the mid-20th century (around 1940 - 1941), although the computer concept and various machines
..... Click the link for more information.
Computers take numerous physical forms. The first devices that resemble modern computers date to the mid-20th century (around 1940 - 1941), although the computer concept and various machines
..... Click the link for more information.
Computer programming (often shortened to programming or coding) is the process of writing, testing, and maintaining the source code of computer programs. The source code is written in a programming language.
..... Click the link for more information.
..... Click the link for more information.
A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. Programming languages, like natural languagess, are defined by syntactic and semantic rules which describe their structure and meaning respectively.
..... Click the link for more information.
..... Click the link for more information.
19th century - 20th century - 21st century
1920s 1930s 1940s - 1950s - 1960s 1970s 1980s
1955 1956 1957 - 1958 - 1959 1960 1961
Year 1958 (MCMLVIII
..... Click the link for more information.
1920s 1930s 1940s - 1950s - 1960s 1970s 1980s
1955 1956 1957 - 1958 - 1959 1960 1961
Year 1958 (MCMLVIII
..... Click the link for more information.
A high-level programming language is a programming language that, in comparison to low-level programming languages, may be more abstract, easier to use, or more portable across platforms.
..... Click the link for more information.
..... Click the link for more information.
Fortran
Paradigm: multi-paradigm: procedural, imperative, structured, object-oriented
Appeared in: 1957
Designed by: John W. Backus
Developer: John W.
..... Click the link for more information.
Paradigm: multi-paradigm: procedural, imperative, structured, object-oriented
Appeared in: 1957
Designed by: John W. Backus
Developer: John W.
..... Click the link for more information.
A dialect of a programming language is a (relatively small) variation or extension of the language that does not change its intrinsic nature. With languages such as Scheme and Forth, standards may be considered insufficient, inadequate or even illegitimate by implementors, so often
..... Click the link for more information.
..... Click the link for more information.
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard X3.226-1994. Developed to standardize the divergent variants of Lisp which predated it, it is not an implementation but rather a language specification.
..... Click the link for more information.
..... Click the link for more information.
Scheme
Paradigm: multi-paradigm
Appeared in: 1970s
Designed by: Guy L. Steele and Gerald Jay Sussman
Typing discipline: strong, dynamic
Major implementations: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk,
..... Click the link for more information.
Paradigm: multi-paradigm
Appeared in: 1970s
Designed by: Guy L. Steele and Gerald Jay Sussman
Typing discipline: strong, dynamic
Major implementations: PLT Scheme, MIT/GNU Scheme, Scheme 48, Chicken, Gambit, Guile, Bigloo, Chez Scheme, STk,
..... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus