Lisp Programming

From Wikibooks, the open-content textbooks collection

(Redirected from Programming:Lisp)
Jump to: navigation, search


Lisp is a programming language. It is named after the collapsed phrase List Processing.

If you have programmed before and would like to see a little bit of how Lisp works and is different from other programming languages, you can get an overview.

Contents

[edit] Contents

[edit] Introduction

After FORTRAN, Lisp is the oldest programming language still in use today. It is a functional, imperative, dynamically strongly typed language, but markedly different from virtually every other language in existence. It can be compiled or interpreted, with good compilers producing code that runs almost as fast as C. The name "Lisp" is a contraction of List Processing, but, in the words of Paul Graham, Lisp is no more for processing lists than polo shirts are for polo.

Lisp has become known as a language for Artificial Intelligence systems, which was admittedly its original purpose. It has proven itself, however, to be a very versatile language, used in applications as diverse as web-applications, CAD software, and the Emacs text-editor.

Lisp code is very strange to look at at first, mainly because of its prefix notation. In infix notation, an expression is written with each binary operator between two operands:

2 + 3 + 4 + 5

In prefix notation, operators can take any number of operands, not just two. The operator comes first, followed by the operands:

(+ 2 3 4 5)

The parentheses are always required because they show where the arguments to the function start and end. This form of expression is known as an s-expression.

Function calls in Lisp also take the form of s-expressions: the first token in the parentheses specifies the function, and the remaining tokens and expressions in the parentheses are the arguments. For instance, a Lisp Hello, World program could be written:

(print "Hello, World")

(The function to print to standard output is called something other than print in some dialects of Lisp.)

[edit] History

Lisp was developed by John McCarthy at the Massachusetts Institute of Technology in 1958. He believed that the Turing model of computation was too crude, and designed, as a theoretical exercise, a language with nine operators. These included such things as an if-like statement (the first language to have one), functions to manipulate lists, and a lambda operator for creating functions. This notation and idea were largely from lambda calculus developed by Alonzo Church.

A student of McCarthy implemented Lisp on one of the college computers, something which McCarthy never intended. Despite this, Lisp soon became popular in the MIT environment, and soon attracted enthusiasts, including a certain Richard Stallman. Richard Stallman, and other hackers, such as Eric Raymond, often term Lisp their favorite language.

Lisp has always remained something of a niche language, but, most programmers who code in it regularly speak of it in glowing terms. Its low popularity and high customer satisfaction are probably explained by the fact that it is difficult to learn at first, or at least appears that way.

[edit] Dialects

Because Lisp itself is, technically, just nine operators, to become a useful language, much more needs to be implemented atop it. Common Lisp and Scheme are two such designs to create a useful programming language. Common Lisp is an ANSI standard, and features an extensive array of library functions. It is the more widely-used of the two. Scheme is designed in a minimalistic fashion, with a very small amount of built in functions. This is probably true, but Scheme lacks many of the time-saving built-in functions of Common Lisp.