Lisp: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Johan Förberg
(Moved "a brief look at"... chapter to the middle of the article.)
imported>Johan Förberg
Line 47: Line 47:
For instance, the <tt>+</tt> function evaluates to the sum of its arguments.  
For instance, the <tt>+</tt> function evaluates to the sum of its arguments.  


==== A Better Hello World ====
=== A Better Hello World for LISP ===


We proposed earlier that Hello World was not the best way to showcase LISP to first-time users. We shall now provide a slightly better example, which shows some of the langauge's distincitve features:
We proposed earlier that Hello World was not the best way to showcase LISP to first-time users. We shall now provide a slightly better example, which shows some of the langauge's distincitve features:

Revision as of 09:52, 9 February 2011

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

This article is about the programming language. For the speech disorder, see Lisp (impediment).

Lisp, created by John McCarthy in 1958, is one of the oldest extant, high-level computer programming languages, dating from the same era as Fortran and COBOL. Lisp takes its name from "List Processing", since one of its prominently featured data structures is the linked list. Lisp is still used, and sometimes taught, in universities, and has had enormous influence on the field of computer programming. Lisp derives some of its ideas from Alonzo Church's lambda calculus, although the language is not a literal implementation of that formalism. Features in the spirit of the lambda calculus are probably easiest to see in Scheme.

At McCarthy's request, the word Lisp now designates the family of languages that has resulted from his original design, and no longer any specific language, dialect, or implementation. For this reason, the American National Standards Institute (ANSI) relating to Lisp, X3.226/1994, is a standard for the language Common Lisp, in order that other members of the Lisp language family not be affected. Likewise, the ISO standard, ISO/IEC 13816:1997(E), defines a language named ISLISP.

Language properties

The following list represents a series of powerful software language concepts in which Lisp was really the pioneer.

Others

A Brief Look at LISP

The Hello World program is traditionally the first program an aspiring programmer writes when learning a new language. Its function is to write some short text to some output device (often a computer screen). It turns out that Hello World is a rather bad way to introduce someone to the LISP programming language, since it shows almost none of the features which make LISP important. Computer custom dictates that we write it down, however:

; This is one of the simplest possible LISP programs. 
; It prints the words "Hello, World!" to standard output.

(print "Hello, World!")

Analysis: print is a function which prints text strings to standard output. Lisp programs are written as lists, so this program consists of a list with two elements. The first is the symbol print and the second is the text string "Hello World!". Lists which are part of a program commonly start with a function name:

(function arg1 arg2 arg3 ...)

Note also the difference between a symbol and a string. For symbols, the case does not matter. We could have written PRINT or even pRiNT, and these are the same as far as LISP is concerned. This is a remnant from the time when some computers handled only UPPER CASE TEXT, and has been kept in order not to break legacy code. For strings however, the case is significant.

Sidetrack: Evaluation

If you entered the above program into a LISP interpreter (go ahead and try!) you will probably see two Hello Worlds printed. This is because every LISP object evaluates to a value! In this case, the print function evaluates to its argument, and the interpreter has been configured to always print the resulting value. Evaluation is recursive, starting at the innermost level and going outwards. It works such that:

  • Literals such as 1, 7/4, "ape" evaluate to themselves,
  • Functions provide rules for evaluating their arguments recursively.

For instance, the + function evaluates to the sum of its arguments.

A Better Hello World for LISP

We proposed earlier that Hello World was not the best way to showcase LISP to first-time users. We shall now provide a slightly better example, which shows some of the langauge's distincitve features:

; Factorial: calculates the factorial of its argument. 
; Recall the definition of the factorial:
;
;     n! = n * (n - 1) * (n - 2) * ... * 2 * 1.
;
; And additionally: 0! = 1.

(defun fact (n) 
  (if (= n 0)
    1
    (* n (fact (- n 1)))))

Analysis:

Popular Myths About Lisp

Lisp is sometimes mischaracterized as an "interpreted" language. In fact, Lisp compilers have been available for decades. Some very important and influential research in compiler design has been done in Lisp. For example, the notion of continuation-passing style was invented for Scheme.

Lisp is sometimes mischaracterized as a language that only has lists for container types. In fact, for several decades, all major Lisps have had a rich variety of container types, such as arrays, strings, hash tables, and user-defined class instances.

Members of the Lisp Language Family

There have been many members of the Lisp language family. Some of the more prominent Lisps are:

Lisps in more recent use are:


Languages which were inspired by Lisp:

Significant Applications

Some of the many historically important applications that have been created in Lisp:

  • ELIZA (emulator/parody of human therapist)
  • MACSYMA (symbolic algebra)
  • SHRDLU (natural language understanding)
  • Lisp Machine (Lisp-based hardware and operating systems)

External Links

References