11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LISP 281At the 1956 Dartmouth Summer Research Project onArtificial Intelligence, a gathering that brought together thekey early pioneers in the field, John McCarthy presented hisconcepts for a different kind <strong>of</strong> computer language. Sucha language, he believed, should be able to deal with mathematicalfunctions in their own terms—by manipulatingsymbols, not just calculating numbers.Together with Marvin Minsky, McCarthy began toimplement a language called LISP (for “list processor”). (SeeMcCarthy, John <strong>and</strong> Minsky, Marvin.) As the name suggests,the language uses lists to store data (see list processing)<strong>and</strong> features many functions for manipulatinglist elements. List can consist <strong>of</strong> single elements (called“atoms”) as in(A B C D)but lists can also include other lists, as in(A (B C) D)Each list item is stored as a “node” containing both a pointerto its data value <strong>and</strong> a pointer to the next item in the linkedlist. The LISP system typically includes housekeeping functionssuch as “garbage collection,” where the memory fromdiscarded list items is returned to the free memory pool forlater allocation.LISP programs look forbidding at first sight because theytend to have many nested parentheses. However, expressions<strong>and</strong> functions are actually constructed in a much simplerway than in most other languages. Without the needfor complicated parsing, the LISP interpreter (called “eval”because it evaluates its input) looks at the stream <strong>of</strong> data<strong>and</strong> first asks whether the next item is a constant (such as anumber, quoted symbol, string, quoted list, or keyword). Ifso, its value is returned. Otherwise, the interpreter checksto see if the item is a defined variable <strong>and</strong>, if so, returns itsvalue. Finally, the interpreter checks to see if there is a list.If so, the list is considered to be a function call followed byits arguments. The function is called, given the data, <strong>and</strong>the result is returned.The following table shows some items in a list program<strong>and</strong> how the interpreter will evaluate them:Examples <strong>of</strong> Lisp ItemsType <strong>of</strong> Item Example Evaluationinteger 24 24float 5.5 5.5ratio 3/4 0.75keyword defun defines functionquoted integer ’24 24quoted list ’(3 1 4 1 5) (3 1 4 1 5)boolean nil falsefunction call +2 4 6variable a its valuequoted variable ’a aLanguages such as Algol, Pascal or C emphasize statements<strong>and</strong> procedures. LISP, on the other h<strong>and</strong>, was thefirst functional language (see functional languages).The heart <strong>of</strong> a LISP program is functions that are evaluatedtogether with their arguments. LISP includes many builtin,or primitive functions. Besides the usual mathematicaloperations, there are primitives for basic list-processingfunctions. For example, the list function creates a list fromits arguments: (list 1 2 3) returns the list (1 2 3), while thecons function inserts an atom into the beginning <strong>of</strong> a list,<strong>and</strong> the append function tacks it onto the end. Programmersdefine their own functions using the defun keyword.LISP has two other features that make it a powerful<strong>and</strong> flexible language for manipulating symbols <strong>and</strong> data.LISP allows for recursive functions (see recursion). Forexample, the following function raises a variable x to thepower y:(defun power (x y)(if (= y 0) 1(* x (power x (1– y)))))Here the if expression checks to see whether y is 0. Ifnot, the second expression invokes the function (power)itself, which performs the same test. The result is that thefunction keeps calling itself, storing temporary values, untily gets down to 0. It then “winds itself back up,” multiplyingx by itself y times.But perhaps the most interesting feature <strong>of</strong> LISP is thatit makes no distinction between programs (functions) <strong>and</strong>data. Since a function call <strong>and</strong> its arguments themselvesconstitute a list, a function can be fed as data to other functions.This makes it easy to write programs that modifytheir own operation.Language DevelopmentLISP quickly caught on with artificial intelligence researchers,<strong>and</strong> the version called LISP 1.5 was considered robustenough for writing large-scale applications. While “mainstream”computer scientists <strong>of</strong>ten used Algol <strong>and</strong> its descendantsas a universal language for expressing algorithms,LISP became the lingua franca for AI people.However, a number <strong>of</strong> dialects such as Mac-LISP divergedas versions were written to support new hardware or werepromoted by companies such as LMI <strong>and</strong> Symbolics. Whileresearchers liked the interactive nature <strong>of</strong> interpreted LISP(where functions could be defined <strong>and</strong> immediately tried outat the keyboard), practical applications required compilationinto machine language to achieve adequate speed.A widely used LISP variant is Scheme, developed byMIT researchers in the mid-1970s. Scheme simplifies LISPsyntax (while still preserving the spirit), <strong>and</strong> at the sametime generalizes further by allowing functions to have allthe capabilities <strong>of</strong> data entities. That is, functions can bepassed as parameters to other functions, returned as values,<strong>and</strong> assigned to variables <strong>and</strong> lists.By the 1980s, personal computers became powerfulenough to run LISP, <strong>and</strong> the proliferation <strong>of</strong> LISP variantsrunning on different platforms led to a st<strong>and</strong>ardization movementthat resulted in Common LISP in 1984. Common LISPcombines the features <strong>of</strong> many existing dialects, includes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!