|
|
Line 1: |
Line 1: |
| {{redirect|LISP|the Internet protocol|Locator/Identifier Separation Protocol|Lisp}}
| | Hi, everybody! My name is Marlon. <br>It is a little about myself: I live in United States, my city of Pine Bush. <br>It's called often Eastern or cultural capital of NY. I've married 1 years ago.<br>I have two children - a son (Bessie) and the daughter (Linette). We all like Bus spotting.<br><br>Visit my blog ... [http://Www.Deyrolle.com/component/k2/item/1-make-that-idea-your-life/1-make-that-idea-your-life After Effects Optical Flares Plugin Free Cs6] |
| {{Infobox programming language
| |
| | name = Lisp
| |
| | paradigm = [[multi-paradigm programming language|Multi-paradigm]]: [[functional programming|functional]], [[procedural programming|procedural]], [[Reflection (computer science)|reflective]], [[metaprogramming|meta]]
| |
| | year = 1958
| |
| | designer = [[John McCarthy (computer scientist)|John McCarthy]]
| |
| | developer = [[Steve Russell]], Timothy P. Hart, and Mike Levin| latest release version =
| |
| | latest release date =
| |
| | turing-complete = Yes
| |
| | typing = [[Type system|Dynamic]], [[Strongly typed programming language|strong]]
| |
| | implementations =
| |
| | dialects = [[Arc (programming language)|Arc]], [[AutoLISP]], [[Clojure]], [[Common Lisp]], [[Emacs Lisp]], [[EuLisp]], [[Franz Lisp]], [[Interlisp]], [[ISLISP]], [[LeLisp]], [[LFE (programming language)|LFE]], [[Maclisp]], [[MDL (programming language)|MDL]], [[Newlisp]], [[NIL (programming language)|NIL]], [[Picolisp]], [[Portable Standard Lisp]], [[Racket (programming language)|Racket]], [[Scheme (programming language)|Scheme]], [[Cadence SKILL|SKILL]], [[Spice Lisp]], [[T (programming language)|T]], [[XLISP]], [[Zetalisp]]
| |
| | influenced by = [[Information Processing Language|IPL]]
| |
| | influenced = [[CLIPS]], [[CLU (programming language)|CLU]], [[COWSEL]], [[Dylan (programming language)|Dylan]], [[Falcon (programming language)|Falcon]], [[Forth (programming language)|Forth]], [[Haskell (programming language)|Haskell]], [[Io (programming language)|Io]], [[Ioke (programming language)|Ioke]], [[JavaScript]], [[Julia (programming_language)|Julia]], [[Logo (programming language)|Logo]], [[Lua (programming language)|Lua]], [[Mathematica]], [[MDL (programming language)|MDL]], [[ML (programming language)|ML]], [[Nu (programming language)|Nu]], [[OPS5]], [[Perl]], [[POP-2]]/[[POP-11|11]], [[Python (programming language)|Python]], [[Qi (programming language)|Qi]], [[R (programming language)|R]], [[Shen (programming language)|Shen]], [[Rebol]], [[Racket (programming language)|Racket]], [[Ruby (programming language)|Ruby]], [[Smalltalk]], [[Tcl]]
| |
| }}
| |
| | |
| '''Lisp''' (historically, '''LISP''') is a family of [[computer]] [[programming language]]s with a long history and a distinctive, fully parenthesized [[Polish notation|Polish prefix]] notation.<ref>
| |
| {{cite book
| |
| | title = Milestones in computer science and information technology
| |
| | author = Edwin D. Reilly
| |
| | publisher = Greenwood Publishing Group
| |
| | year = 2003
| |
| | isbn = 978-1-57356-521-9
| |
| | pages = 156–157
| |
| | url = http://books.google.com/books?id=JTYPKxug49IC&pg=PA157
| |
| }}</ref>
| |
| Originally specified in 1958, Lisp is the second-oldest [[high-level programming language]] in widespread use today; only [[Fortran]] is older (by one year). Like Fortran, Lisp has changed a great deal since its early days, and a number of [[Programming language dialect|dialects]] have existed over its history. Today, the most widely known general-purpose Lisp dialects are [[Common Lisp]] and [[Scheme (programming language)|Scheme]].
| |
| | |
| Lisp was originally created as a practical mathematical notation for computer programs, influenced by the notation of [[Alonzo Church]]'s [[lambda calculus]]. It quickly became the favored programming language for [[artificial intelligence]] (AI) research. As one of the earliest programming languages, Lisp pioneered many ideas in [[computer science]], including [[tree data structure]]s, [[Garbage collection (computer science)|automatic storage management]], [[dynamic typing]], [[Conditional (computer programming)|conditionals]], [[higher-order function]]s, [[recursion]], and the [[self-hosting]] [[compiler]].<ref name="GRAHAM">{{cite web| title=Revenge of the Nerds| author=Paul Graham | url=http://www.paulgraham.com/icad.html | accessdate=2013-03-14}}</ref>
| |
| | |
| The name ''LISP'' derives from "LISt Processing". [[Linked list]]s are one of Lisp language's major [[data structure]]s, 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 (computer science)|macro]] systems that allow programmers to create new syntax or even new [[domain-specific language]]s embedded in Lisp.
| |
| | |
| The interchangeability of code and data also gives Lisp its instantly recognizable syntax. All program code is written as ''[[s-expression]]s'', 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 {{Lisp2|(f arg1 arg2 arg3)}}.
| |
| | |
| ==History==
| |
| {{Multiple image|image1 = John McCarthy Stanford.jpg|footer = John McCarthy and Steve Russell|image2 = Steve Russell.jpg|direction = vertical|align = left}}
| |
| | |
| Lisp was invented by [[John McCarthy (computer scientist)|John McCarthy]] in 1958 while he was at the [[Massachusetts Institute of Technology]] (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"<ref name="MCCARTHY">{{cite web| title=Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I| author=John McCarthy | url=http://www-formal.stanford.edu/jmc/recursive.html | accessdate=2006-10-13}}</ref> ("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.
| |
| | |
| [[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-expression]]s" that would be translated into [[S-expression]]s. As an example, the M-expression {{Lisp2|<nowiki>car[cons[A,B]]</nowiki>}} is equivalent to the S-expression {{Lisp2|(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]]<ref name="SMITH">{{cite web| title=MLISP Users Manual| author=David Canfield Smith | url=http://www.softwarepreservation.org/projects/LISP/stanford/Smith-MLISP-AIM-84.pdf | accessdate=2006-10-13}}</ref> by [[Horace Enea]] and [[CGOL]] by [[Vaughan Pratt]].
| |
| | |
| 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 Lisp ''eval'' function could be implemented in [[machine code]].<ref>According to what reported by [[Paul Graham (computer programmer)|Paul Graham]] in ''[[Hackers & Painters]]'', p. 185, McCarthy said: "Steve Russell said, look, why don't I program this ''eval''..., and I said to him, ho, ho, you're confusing theory with practice, this ''eval'' is intended for reading, not for computing. But he went ahead and did it. That is, he compiled the ''eval'' in my paper into [[IBM 704]] machine code, fixing [[Software bug|bug]], and then advertised this as a Lisp interpreter, which it certainly was. So at that point Lisp had essentially the form that it has today..."</ref> The result was a working Lisp interpreter which could be used to run Lisp programs, or more properly, 'evaluate Lisp expressions.'
| |
| | |
| Two assembly language macros for the [[IBM 704]] became the primitive operations for decomposing lists: [[Car and cdr|{{Lisp2|car}}]] (Contents of the Address part of Register number) and [[Car and cdr|{{Lisp2|cdr}}]] (Contents of the Decrement part of Register number).<ref name="PREHISTORY">{{cite web| title=LISP prehistory - Summer 1956 through Summer 1958| author=John McCarthy | url=http://www-formal.stanford.edu/jmc/history/lisp/node2.html | accessdate=2010-03-14}}</ref> From the context, it is clear that the term "Register" is used here to mean "Memory Register", nowadays called "Memory Location". Lisp dialects still use {{Lisp2|car}} and {{Lisp2|cdr}} ({{IPAc-en|ˈ|k|ɑr}} and {{IPAc-en|ˈ|k|ʊ|d|ər}}) for the operations that return the first item in a list and the rest of the list respectively.
| |
| | |
| The first complete Lisp compiler, written in Lisp, was implemented in 1962 by Tim Hart and Mike Levin at MIT.<ref name="LEVIN">{{cite web| title=AI Memo 39-The new compiler| author=Tim Hart and Mike Levin | url=ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-039.pdf | accessdate=2006-10-13}}</ref> 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.
| |
| | |
| Lisp was a difficult system to implement with the compiler techniques and stock hardware of the 1970s. [[Garbage collection (computer science)|Garbage collection]] routines, developed by then-[[MIT]] graduate student [[Daniel Edwards (programmer)|Daniel Edwards]], made it practical to run Lisp on general-purpose computing systems, but efficiency was still a problem.{{citation needed|date=October 2010}} This led to the creation of [[Lisp machine]]s: dedicated hardware for running Lisp environments and programs. Advances in both computer hardware and compiler technology soon made Lisp machines obsolete.{{citation needed|date=May 2011}}
| |
| | |
| During the 1980s and 1990s, a great effort was made to unify the work on new Lisp dialects (mostly successors to [[Maclisp]] like [[ZetaLisp]] and NIL (New Implementation of Lisp)) into a single language. The new language, [[Common Lisp]], was somewhat compatible with the dialects it replaced (the book [[Common Lisp the Language]] notes the compatibility of various constructs). In 1994, [[ANSI]] published the Common Lisp standard, "ANSI X3.226-1994 Information Technology Programming Language Common Lisp."
| |
| | |
| <timeline>
| |
| Preset = TimeHorizontal_AutoPlaceBars_UnitYear
| |
| ImageSize = width:1024
| |
| PlotArea = right:256
| |
| | |
| Define $bold = fontsize:L shift:(10,-4)
| |
| | |
| Colors =
| |
| id:offWhite value:rgb(0.97,0.97,0.97)
| |
| id:paleGray value:rgb(0.86,0.86,0.86)
| |
| id:darkGray value:gray(0.6)
| |
| | |
| BackgroundColors = canvas:offWhite
| |
| | |
| Period = from:1958 till:2013
| |
| ScaleMajor = unit:year increment:5 start:1958 gridcolor:paleGray
| |
| | |
| BarData=
| |
| barset:Dialects
| |
| | |
| PlotData=
| |
| | |
| # set defaults
| |
| width:15 fontsize:M textcolor:black align:left anchor:from shift:(0,-2) color:darkGray
| |
| barset:Dialects
| |
| | |
| from:1958 till:1965 text:"Lisp 1.5"
| |
| from:1965 till:1985 text:"[[Maclisp]]"
| |
| from:1970 till:1995 text:"[[ZetaLisp]]"
| |
| from:1970 till:1980 text:"[[NIL (programming language)|NIL]]"
| |
| from:1970 till:1990 text:"[[Interlisp]]"
| |
| from:1984 till:2013 text:"[[Common Lisp]]"
| |
| from:1975 till:2013 text:"[[Scheme (programming language)|Scheme]]"
| |
| from:1986 till:2013 text:"[[ISLISP]]"
| |
| from:2007 till:2013 text:"[[Clojure]]"
| |
| </timeline>
| |
| | |
| ===Connection to artificial intelligence===
| |
| Since its inception, Lisp was closely connected with the [[artificial intelligence]] research community, especially on [[PDP-10]]<ref>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. {{cite newsgroup | quote = The PDP-6 project started in early 1963, as a 24-bit machine. It grew to 36 bits for LISP, a design goal. | url = http://groups.google.com/group/alt.folklore.computers/browse_thread/thread/6e5602ce733d0ec/17597705ae289112 | title = The History of TOPS or Life in the Fast ACs | newsgroup = alt.folklore.computers | id = 84950@tut.cis.ohio-state.edu | date = 18 October 1990 | author = Peter J. Hurley}}</ref> systems. Lisp was used as the implementation of the programming language [[Planner programming language|Micro Planner]] which was used in the famous AI system [[SHRDLU]]. In the 1970s, as AI research spawned commercial offshoots, the performance of existing Lisp systems became a growing issue.{{Citation needed|date=March 2010}}
| |
| | |
| ===Genealogy and variants===
| |
| Over its 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 uses the keyword <code>defun</code> to name a function, but Scheme uses <code>define</code>.<ref>Common Lisp: <code>(defun f (x) x)</code><br/>Scheme: <code>(define f (lambda (x) x))</code> or <code>(define (f x) x)</code></ref> Within a dialect that is standardized, however, conforming implementations support the same core language, but with different extensions and libraries.
| |
| | |
| ====Historically significant dialects====
| |
| [[File:LISP machine.jpg|thumb|right|A Lisp machine in the [[MIT Museum]]]]
| |
| *LISP 1<ref>{{Cite journal
| |
| | last = McCarthy | first = J. | author-link = John McCarthy (computer scientist)
| |
| | last2 = Brayton | first2 = R. | author2-link = Robert Brayton (computer scientist)
| |
| | last3 = Edwards | first3 = D. | author3-link = Daniel Edwards (programmer)
| |
| | last4 = Fox | first4 = P. | author4-link = Phyllis Fox
| |
| | last5 = Hodes | first5 = L. | author5-link = Louis Hodes
| |
| | last6 = Luckham | first6 = D. | author6-link = David Luckham
| |
| | last7 = Maling | first7 = K. | author7-link = Klim Maling (programmer)
| |
| | last8 = Park | first8 = D. | author8-link = David Park (computer scientist)
| |
| | last9 = Russell | first9 = S. | author9-link = Steve Russell
| |
| | title = LISP I Programmers Manual
| |
| | place = [[Boston]], [[Massachusetts]]
| |
| | publisher = Artificial Intelligence Group, [[M.I.T. Computation Center]] and [[Research Laboratory of Electronics at MIT|Research Laboratory]]
| |
| | origyear =
| |
| |date=March 1960
| |
| | volume =
| |
| | edition =
| |
| | chapter =
| |
| | chapterurl =
| |
| | page =
| |
| | pages =
| |
| | url = http://history.siam.org/sup/Fox_1960_LISP.pdf
| |
| | archiveurl =
| |
| | archivedate =
| |
| | doi =
| |
| | id =
| |
| | isbn =
| |
| | postscript = <!--None--> }} Accessed May 11, 2010.</ref> – First implementation.
| |
| *LISP 1.5<ref>{{Cite book| url = http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf | title = LISP 1.5 Programmer's Manual | publisher = [[MIT Press]] | first1 = John | last1 = McCarthy | first2 = Paul W. | last2 = Abrahams | first3 = Daniel J. | last3 = Edwards | first4 = Timothy P. | last4 = Hart | first5 = Michael I. | last5 = Levin | isbn = 0-262-13011-4 | year = 1962; 2nd Edition, 15th printing, 1985}}</ref> – 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<ref>{{Cite book| url = http://www.softwarepreservation.org/projects/LISP/stanford/SAILON-28.6.pdf | format = PDF | title = Stanford LISP 1.6 Manual | first1 = Lynn H. | last1 = Quam | first2 = Whitfield | last2 = Diffle}}</ref> – 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 rendered obsolete by Maclisp and InterLisp.
| |
| *[[Maclisp|MACLISP]]<ref>{{cite web| url = http://zane.brouhaha.com/~healyzh/doc/lisp.doc.txt | title = Maclisp Reference Manual | date = March 3, 1979 | archiveurl = http://web.archive.org/web/20071214064433/http://zane.brouhaha.com/~healyzh/doc/lisp.doc.txt | archivedate = 2007-12-14}}</ref> – developed for MIT's [[Project MAC]] (no relation to Apple's [[Macintosh]], nor to [[John McCarthy (computer scientist)|McCarthy]]), direct descendant of LISP 1.5. It ran on the PDP-10 and [[Multics]] systems. (MACLISP would later come to be called Maclisp, and is often referred to as MacLisp.)
| |
| *[[InterLisp]]<ref>{{Cite book| url = http://www.bitsavers.org/pdf/xerox/interlisp/1974_InterlispRefMan.pdf | format = PDF | title = InterLisp Reference Manual | first = Warren | last = Teitelman | year = 1974 }}</ref> – developed at [[BBN Technologies]] for PDP-10 systems running the [[TOPS-20|Tenex]] operating system, later adopted as a "West coast" Lisp for the Xerox Lisp machines as [[InterLisp-D]]. A small version called "InterLISP 65" was published for [[Atari]]'s [[MOS Technology 6502|6502]]-based computer line. For quite some time Maclisp and InterLisp were strong competitors.
| |
| *[[Franz Lisp]] – originally a [[University of California, Berkeley|Berkeley]] project; later developed by Franz Inc. The name is a humorous deformation of the name "[[Franz Liszt]]", and does not refer to [[Allegro Common Lisp]], the dialect of Common Lisp sold by Franz Inc., in more recent years.
| |
| *[[XLISP]], which [[AutoLISP]] was based on.
| |
| *[[Standard Lisp]] and [[Portable Standard Lisp]] were widely used and ported, especially with the Computer Algebra System REDUCE.
| |
| *[[ZetaLisp]], also known as Lisp Machine Lisp – used on the [[Lisp machine]]s, direct descendant of Maclisp. ZetaLisp had big influence on Common Lisp.
| |
| *[[LeLisp]] is a French Lisp dialect. One of the first Interface Builders was written in LeLisp.
| |
| *[[Common Lisp]] (1984), as described by ''[[Common Lisp the Language]]'' – a consolidation of several divergent attempts (ZetaLisp, [[Spice Lisp]], [[NIL (programming language)|NIL]], and [[S-1 Lisp]]) to create successor dialects<ref>{{Cite book| chapterurl = http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node6.html | title = Common Lisp the Language | edition = 2nd | chapter = Purpose | first = Guy L., Jr. | last = Steele| isbn = 0-13-152414-3}}</ref> to Maclisp, with substantive influences from the Scheme dialect as well. This version of Common Lisp was available for wide-ranging platforms and was accepted by many as a [[de facto standard]]<ref>{{cite web| url = http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part2/faq-doc-13.html | title = History: Where did Lisp come from? | work = FAQ: Lisp Frequently Asked Questions 2/7 | date = 20 February 1996 | first1 = Mark | last1 = Kantrowitz | first2 = Barry | last2 = Margolin}}</ref> until the publication of ANSI Common Lisp (ANSI X3.226-1994).
| |
| *[[Dylan (programming language)|Dylan]] was in its first version a mix of Scheme with the Common Lisp Object System.
| |
| *[[EuLisp]] – attempt to develop a new efficient and cleaned-up Lisp.
| |
| *[[ISLISP]] – attempt to develop a new efficient and cleaned-up Lisp. Standardized as ISO/IEC 13816:1997<ref>{{cite web|url=http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=22987 |title=ISO/IEC 13816:1997 |publisher=Iso.org |date=2007-10-01 |accessdate=2013-11-15}}</ref> and later revised as ISO/IEC 13816:2007:<ref>{{cite web|url=http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=44338 |title=ISO/IEC 13816:2007 |publisher=Iso.org |date=2013-10-30 |accessdate=2013-11-15}}</ref> ''Information technology – Programming languages, their environments and system software interfaces – Programming language ISLISP''.
| |
| *IEEE [[Scheme (programming language)|Scheme]] – IEEE standard, 1178–1990 (R1995)
| |
| *ANSI [[Common Lisp]] – an [[American National Standards Institute]] (ANSI) [[Standardization|standard]] for Common Lisp, created by subcommittee [[X3J13]], chartered<ref>{{cite web| url = http://www.nhplace.com/kent/CL/x3j13-86-020.html | title = X3J13 Charter}}</ref> to begin with ''Common Lisp: The Language'' as a base document and to work through a public [[Consensus decision-making|consensus]] process to find solutions to shared issues of [[Portability (software)|portability]] of programs and [[Computer compatibility|compatibility]] of Common Lisp implementations. Although formally an ANSI standard, the implementation, sale, use, and influence of ANSI Common Lisp has been and continues to be seen worldwide.
| |
| *[[ACL2]] or "A Computational Logic for Applicative Common Lisp", an applicative (side-effect free) variant of Common LISP. ACL2 is both a programming language in which you can model computer systems and a tool to help proving properties of those models.
| |
| *[[Clojure]], a modern dialect of Lisp which compiles to the [[Java virtual machine]] and handles [[Concurrency (computer science)|concurrency]] very well.
| |
| | |
| ===2000-present===
| |
| After having declined somewhat in the 1990s, Lisp has recently experienced a resurgence of interest. Most new activity is focused around [[open source]] implementations of [[Common Lisp]], and includes the development of new portable libraries and applications. A new print edition of ''[[Practical Common Lisp]]'' by Peter Seibel, a tutorial for new Lisp programmers, was published in 2005.<ref>{{cite book |last=Siebel |first=Peter |title=Practical Common Lisp |publisher=Apress |year=2005| isbn=978-1-59059-239-7 |url=http://gigamonkeys.com/book/ }}</ref>
| |
| | |
| Many new Lisp programmers were inspired by writers such as [[Paul Graham (computer programmer)|Paul Graham]] and [[Eric S. Raymond]] to pursue a language others considered antiquated. New Lisp programmers often describe the language as an eye-opening experience and claim to be substantially more productive than in other languages.<ref>{{cite web| title=The Road To Lisp Survey | url=http://wiki.alu.org/The_Road_To_Lisp_Survey | accessdate=2006-10-13}}</ref> This increase in awareness may be contrasted to the "[[AI winter]]" and Lisp's brief gain in the mid-1990s.<ref>{{cite web|url=http://www.faqs.org/docs/artu/ch14s05.html |title=Trends for the Future |publisher=Faqs.org |date= |accessdate=2013-11-15}}</ref>
| |
| | |
| Dan Weinreb lists in his survey of Common Lisp implementations<ref>{{cite web|last=Weinreb|first=Daniel|title=Common Lisp Implementations: A Survey|url=http://common-lisp.net/~dlw/LispSurvey.html|accessdate=4 April 2012}}</ref> eleven actively maintained Common Lisp implementations. Scieneer Common Lisp is a new commercial implementation forked from CMUCL with a first release in 2002.
| |
| | |
| The open source community has created new supporting infrastructure: [[CLiki]] is a wiki that collects Common Lisp related information, the [[Common Lisp directory]] lists resources, #lisp is a popular IRC channel (with support by a Lisp-written Bot), [[lisppaste]] supports the sharing and commenting of code snippets, [[Planet Lisp]] collects the contents of various Lisp-related blogs, on [[LispForum]] users discuss Lisp topics, [[Lispjobs]] is a service for announcing job offers and there is a weekly news service, ''[[Weekly Lisp News]]''. ''Common-lisp.net'' is a hosting site for open source Common Lisp projects.
| |
| | |
| 50 years of Lisp (1958–2008) has been celebrated at LISP50@OOPSLA.<ref>{{cite web|url=http://www.lisp50.org/ |title=LISP50@OOPSLA |publisher=Lisp50.org |date= |accessdate=2013-11-15}}</ref> There are regular local user meetings in Boston, Vancouver, and Hamburg. Other events include the European Common Lisp Meeting, the European Lisp Symposium and an International Lisp Conference.
| |
| | |
| The Scheme community actively maintains [[Scheme (programming language)#Implementations|over twenty implementations]]. Several significant new implementations (Chicken, Gambit, Gauche, Ikarus, Larceny, Ypsilon) have been developed in the last few years. The Revised<sup>5</sup> Report on the Algorithmic Language Scheme<ref>[http://www.schemers.org/Documents/Standards/R5RS/ Documents: Standards: R5RS]. schemers.org (2012-01-11). Retrieved on 2013-07-17.</ref> standard of Scheme was widely accepted in the Scheme community. The [[Scheme Requests for Implementation]] process has created a lot of quasi standard libraries and extensions for Scheme. User communities of individual Scheme implementations continue to grow. A new language standardization process was started in 2003 and led to the R<sup>6</sup>RS Scheme standard in 2007. Academic use of Scheme for teaching computer science seems to have declined somewhat. Some universities, such as MIT, are no longer using Scheme in their computer science introductory courses.<ref>{{cite news|url=http://cemerick.com/2009/03/24/why-mit-now-uses-python-instead-of-scheme-for-its-undergraduate-cs-program/|title=Why MIT now uses python instead of scheme for its undergraduate CS program|first=|last=|date=March 24, 2009|work=cemerick.com|accessdate=November 10, 2013}}</ref><ref>{{cite news|url=http://mitadmissions.org/blogs/entry/the_end_of_an_era_1|title=The End of an Era|first=Evan|last=Broder|date=January 8, 2008|work=mitadmissions.org|accessdate=November 10, 2013}}</ref>
| |
| | |
| There are several new dialects of Lisp: [[Arc (programming language)|Arc]], [[Nu (programming language)|Nu]], [[Clojure]], [[Liskell]], [[LFE (programming language)|LFE]] (Lisp Flavored Erlang), and [[Shen (programming language)|Shen]].
| |
| | |
| ==Major dialects==
| |
| The two major dialects of Lisp used for general-purpose programming today are [[Common Lisp]] and [[Scheme (programming language)|Scheme]]. These languages represent significantly different design choices.
| |
| | |
| [[Common Lisp]] is a successor to [[MacLisp]]. The primary influences were [[Lisp Machine Lisp]], [[MacLisp]], [[NIL (programming language)|NIL]], [[S-1 Lisp]], [[Spice Lisp]], and Scheme.<ref>Chapter 1.1.2, History, ANSI CL Standard</ref> It has many of the features of Lisp Machine Lisp (a large Lisp dialect used to program [[Lisp Machine]]s), but was designed to be efficiently implementable on any personal computer or workstation. Common Lisp has a large language standard including many built-in data types, functions, macros and other language elements, as well as an object system ([[Common Lisp Object System]] or shorter CLOS). Common Lisp also borrowed certain features from Scheme such as [[lexical scoping]] and [[lexical closure]]s.
| |
| | |
| Scheme (designed earlier) 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 [[continuation]]s) not necessarily found in Common Lisp.
| |
| | |
| [[Scheme (programming language)|Scheme]] is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by [[Guy L. Steele, Jr.|Guy Lewis Steele Jr.]] and [[Gerald Jay Sussman]]. It was designed to have exceptionally clear and simple semantics and few different ways to form expressions. A wide variety of programming paradigms, including imperative, functional, and message passing styles, find convenient expression in Scheme. Scheme continues to evolve with a series of standards (Revised<sup>n</sup> Report on the Algorithmic Language Scheme) and a series of [[Scheme Requests for Implementation]].
| |
| | |
| [[Clojure]] is a recent dialect of Lisp that principally targets the [[Java Virtual Machine]], as well as the [[Common Language Runtime|CLR]], the [[Python (programming language)|Python VM]], the Ruby VM [[YARV]], and compiling to [[JavaScript]]. It is designed to be a pragmatic general-purpose language. Clojure draws considerable influences from [[Haskell (programming language)|Haskell]] and places a very strong emphasis on immutability.<ref name="clojure-immutability">[http://www.infoq.com/articles/in-depth-look-clojure-collections An In-Depth Look at Clojure Collections], Retrieved 2012-06-24</ref> Clojure is a compiled language, as it compiles directly to JVM bytecode, yet remains completely dynamic. Every feature supported by Clojure is supported at runtime. Clojure provides access to Java frameworks and libraries, with optional type hints and [[type inference]], so that calls to Java can avoid reflection and enable fast primitive operations.
| |
| | |
| In addition, Lisp dialects are used as [[scripting language]]s in a number of applications, with the most well-known being [[Emacs Lisp]] in the [[Emacs]] editor, [[AutoLisp]] and later [[Visual Lisp]] in [[AutoCAD]], Nyquist in [[Audacity (audio editor)|Audacity]]. The small size of a minimal but useful Scheme interpreter makes it particularly popular for embedded scripting. Examples include [[SIOD]] and [[TinyScheme]], both of which have been successfully embedded in the [[GIMP]] image processor under the generic name "Script-fu".<ref name="script-fu">[http://www.gimp.org/docs/script-fu-update.html Script-fu In GIMP 2.4], Retrieved 2009-10-29</ref> LIBREP, a Lisp interpreter by John Harper originally based on the [[Emacs Lisp]] language, has been embedded in the [[Sawfish (window manager)|Sawfish]] [[window manager]].<ref name="librep">[http://sawfish.wikia.com/wiki/Librep librep] at Sawfish Wikia, retrieved 2009-10-29</ref>
| |
| | |
| ==Language innovations==
| |
| Lisp was the first [[homoiconicity|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 regard to its expressive power, and makes the language amenable to [[metacircular evaluation]].
| |
| | |
| The 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. The Flavours object system (later CLOS) introduced multiple inheritance.
| |
| | |
| Lisp introduced the concept of [[Garbage collection (computer science)|automatic garbage collection]], in which the system walks the heap looking for unused memory. Most of the modern sophisticated garbage collection algorithms such as generational garbage collection were developed for Lisp.<ref>{{citation |last=Lieberman |first=Henry |last2=Hewitt |first2=Carl |title=A Real-Time Garbage Collector Based on the Lifetimes of Objects |url=http://web.media.mit.edu/~lieber/Lieberary/GC/Realtime/Realtime.html |journal=CACM |volume=26 |issue=6 |date=June 1983 |pages=419-429 |doi=10.1145/358141.358147}}</ref>
| |
| | |
| [[Edsger W. Dijkstra]] in his 1972 [[Turing Award]] lecture said,
| |
| :"With a few very basic principles at its foundation, it [LISP] has shown a remarkable stability. Besides that, LISP has been the carrier for a considerable number of in a sense our most sophisticated computer applications. LISP has jokingly been described as “the most intelligent way to misuse a computer”. I think that description a great compliment because it transmits the full flavour of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts."<ref>{{cite|url=http://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD340.html|author=Edsger W. Dijkstra|date=1972|title=The Humble Programmer (EWD 340)|}} (ACM Turing Award lecture).</ref>
| |
| | |
| 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 (programming language)|C]] language. Because of its suitability to complex and dynamic applications, Lisp is currently enjoying some resurgence of popular interest.
| |
| | |
| ==Syntax and semantics==
| |
| :'''''Note''': This article's examples are written in [[Common Lisp]] (though most are also valid in [[Scheme (programming language)|Scheme]]).''
| |
| | |
| ===Symbolic expressions (S-expressions)===
| |
| Lisp is an [[Expression (computer science)|expression]]-oriented language. Unlike most other languages, no distinction is made between "expressions" and [[Statement (programming)|"statements"]];{{dubious|date=April 2013}}<!-- (progn ...), (setq ...). There is no syntactic distinction, but sequential evaluation is there. --> all code and data are written as expressions. When an expression is ''evaluated'', it produces a value (in Common Lisp, possibly multiple values), which then can be embedded into other expressions. Each value can be any data type.
| |
| | |
| McCarthy's 1958 paper introduced two types of syntax: [[S-expression]]s (Symbolic expressions, also called "sexps"), which mirror the internal representation of code and data; and [[M-expression]]s (Meta Expressions), which express functions of S-expressions. M-expressions never found favor, 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''.<ref name="LEVIN2">{{cite web| title=The Jargon File - Lisp| url=http://www.catb.org/~esr/jargon/html/L/LISP.html| accessdate=2006-10-13}}</ref><!-- Do not insert more nicknames. People can look in the Jargon File for them. --> 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 [[Meta-object protocol|metaobject-protocol]] to integrate S-expressions with the [[Xml|Extensible Markup Language (XML)]].
| |
| | |
| The reliance on expressions gives the language great flexibility. Because Lisp [[function (programming)|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.
| |
| | |
| ===Lists===
| |
| A Lisp list is written with its elements separated by whitespace, and surrounded by parentheses. For example, {{Lisp2|(1 2 foo)}} is a list whose elements are three ''atoms'': the values {{Lisp2|1}}, {{Lisp2|2}}, and [[foo|{{Lisp2|foo}}]]. These values are implicitly typed: they are respectively two integers and a Lisp-specific data type called a "symbolic atom", and do not have to be declared as such.
| |
| | |
| The empty list {{Lisp2|()}} is also represented as the special atom {{Lisp2|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 {{Lisp2|list}} returns its arguments as a list, so the expression
| |
| <syntaxhighlight lang=Lisp>
| |
| (list '1 '2 'foo)
| |
| </syntaxhighlight>
| |
| evaluates to the list {{Lisp2|(1 2 foo)}}. The "quote" before the arguments in the preceding example is a "special operator" which prevents the quoted arguments from 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,
| |
| <syntaxhighlight lang=Lisp>
| |
| (list 1 2 (list 3 4))
| |
| </syntaxhighlight>
| |
| evaluates to the list {{Lisp2|(1 2 (3 4))}}. Note that the third argument is a list; lists can be nested.
| |
| | |
| ===Operators===
| |
| Arithmetic operators are treated similarly. The expression
| |
| <syntaxhighlight lang=Lisp>
| |
| (+ 1 2 3 4)
| |
| </syntaxhighlight>
| |
| evaluates to 10. The equivalent under [[infix notation]] would be "{{Lisp2|1 + 2 + 3 + 4}}". Arithmetic operators in Lisp are [[variadic function|variadic]] (or ''[[n-ary]]''), able to take any number of arguments.
| |
| | |
| "Special operators" (sometimes called "special forms") provide Lisp's control structure. For example, the special operator {{Lisp2|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
| |
| <syntaxhighlight lang=Lisp>
| |
| (if nil
| |
| (list 1 2 "foo")
| |
| (list 3 4 "bar"))
| |
| </syntaxhighlight>
| |
| evaluates to {{Lisp2|(3 4 "bar")}}. Of course, this would be more useful if a non-trivial expression had been substituted in place of {{Lisp2|nil}}.
| |
| | |
| ===Lambda expressions and function definition===
| |
| Another special operator, {{Lisp2|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 {{Lisp2|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
| |
| <syntaxhighlight lang=Lisp>
| |
| (lambda (arg) (+ arg 1))
| |
| </syntaxhighlight>
| |
| evaluates to a function that, when applied, takes one argument, binds it to {{Lisp2|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
| |
| <syntaxhighlight lang=Lisp>
| |
| ((lambda (arg) (+ arg 1)) 5)
| |
| </syntaxhighlight>
| |
| evaluates to {{Lisp2|6}}.
| |
| | |
| Named functions are created by storing a lambda expression in a symbol using the [[defun]] macro.
| |
| <syntaxhighlight lang=Lisp>
| |
| (defun foo (a b c d) (+ a b c d))
| |
| </syntaxhighlight>
| |
| | |
| {{Lisp2|(defun f (a) b...)}} defines a new function named {{Lisp2|f}} in the global environment. It is a shorthand for the expression:
| |
| | |
| <syntaxhighlight lang=Lisp>
| |
| (place-in-function-definition-slot-of-symbol 'f #'(lambda (a) b...))
| |
| </syntaxhighlight>
| |
| | |
| ===Atoms===
| |
| In the original '''LISP''' there were two fundamental [[data type]]s: 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 {{Lisp2|(FOO (BAR 1) 2)}} contains three elements: the symbol FOO, the list {{Lisp2|(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 exactly the same way represented the same object{{Citation needed|date=November 2008}}, 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 style]]s evolved, the concept of an atom lost importance.{{Citation needed|date=November 2008}} Many dialects still retained the predicate ''atom'' for [[legacy compatibility]]{{Citation needed|date=November 2008}}, defining it true for any object which is not a cons.
| |
| | |
| ===Conses and lists===
| |
| {{Main|Cons}}
| |
| [[File:Cons-cells.svg|thumb|right|300px|Box-and-pointer diagram for the list (42 69 613)]]
| |
| 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 [[pointer (computer programming)|pointer]]s, called the ''car'' and ''cdr''. These are equivalent to the {{Lisp2|data}} and {{Lisp2|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 {{Lisp2|nil}} (empty list) symbol, or a cons in which the {{Lisp2|car}} points to a datum (which may be another cons structure, such as a list), and the {{Lisp2|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 {{Lisp2|car}} and {{Lisp2|cdr}} functions are also called {{Lisp2|first}} and {{Lisp2|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 function]]s 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 ([[Array data type|arrays]]), hash tables, structures, and so forth.
| |
| | |
| ====S-expressions represent lists====
| |
| Parenthesized S-expressions represent linked list structures. There are several ways to represent the same list as an S-expression. A cons can be written in ''dotted-pair notation'' as {{Lisp2|(a . b)}}, where {{Lisp2|a}} is the car and {{Lisp2|b}} the cdr. A longer proper list might be written {{Lisp2|(a . (b . (c . (d . nil))))}} in dotted-pair notation. This is conventionally abbreviated as {{Lisp2|(a b c d)}} in ''list notation''. An improper list<ref>NB: a so-called "dotted list" is only one kind of "improper list". The other kind is the "circular list" where the cons cells form a loop. Typically this is represented using #n=(...) to represent the target cons cell that will have multiple references, and #n# is used to refer to this cons. For instance, (#1=(a b) . #1#) would normally be printed as ((a b) a b) (without circular structure printing enabled), but makes the reuse of the cons cell clear. #1=(a . #1#) cannot normally be printed as it is circular, the CDR of the cons cell defined by #1= is itself.</ref> may be written in a combination of the two – as {{Lisp2|(a b c . d)}} for the list of three conses whose last cdr is {{Lisp2|d}} (i.e., the list {{Lisp2|(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 the {{Lisp2|list}} procedure, which takes any number of arguments, and returns the list of these arguments.
| |
| <syntaxhighlight lang=Lisp>
| |
| (list 1 2 'a 3)
| |
| ;Output: (1 2 a 3)
| |
| </syntaxhighlight>
| |
| <syntaxhighlight lang=Lisp>
| |
| (list 1 '(2 3) 4)
| |
| ;Output: (1 (2 3) 4)
| |
| </syntaxhighlight>
| |
| Because of the way that lists are constructed from [[cons pair]]s, the {{Lisp2|cons}} procedure can be used to add an element to the front of a list. Note that the {{Lisp2|cons}} procedure is asymmetric in how it handles list arguments, because of how lists are constructed.
| |
| <syntaxhighlight lang=Lisp>
| |
| (cons 1 '(2 3))
| |
| ;Output: (1 2 3)
| |
| </syntaxhighlight>
| |
| <syntaxhighlight lang=Lisp>
| |
| (cons '(1 2) '(3 4))
| |
| ;Output: ((1 2) 3 4)
| |
| </syntaxhighlight>
| |
| The {{Lisp2|append}} procedure appends two (or more) lists to one another. Because Lisp lists are linked lists, appending two lists has [[Big O notation|asymptotic time complexity]] <math>O(n)</math>
| |
| <syntaxhighlight lang=Lisp>
| |
| (append '(1 2) '(3 4))
| |
| ;Output: (1 2 3 4)
| |
| </syntaxhighlight>
| |
| <syntaxhighlight lang=Lisp>
| |
| (append '(1 2 3) '() '(a) '(5 6))
| |
| ;Output: (1 2 3 a 5 6)
| |
| </syntaxhighlight>
| |
| | |
| ====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:
| |
| <syntaxhighlight lang=Lisp>
| |
| (setf foo (list 'a 'b 'c))
| |
| (setf bar (cons 'x (cdr foo)))
| |
| </syntaxhighlight>
| |
| the lists {{Lisp2|foo}} and {{Lisp2|bar}} are {{Lisp2|(a b c)}} and {{Lisp2|(x b c)}} respectively. However, the tail {{Lisp2|(b c)}} is the same structure in both lists. It is not a copy; the cons cells pointing to {{Lisp2|b}} and {{Lisp2|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 {{Lisp2|c}} with a {{Lisp2|goose}}, will affect the other:
| |
| <syntaxhighlight lang=Lisp>
| |
| (setf (third foo) 'goose)
| |
| </syntaxhighlight>
| |
| This changes {{Lisp2|foo}} to {{Lisp2|(a b goose)}}, but thereby also changes {{Lisp2|bar}} to {{Lisp2|(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 {{Lisp2|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 {{Lisp2|set-car!}} is named {{Lisp2|rplaca}} for "replace car." This function is rarely seen however as Common Lisp includes a special facility, {{Lisp2|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; {{Lisp2|(+ 2 3)}} evaluates to {{Lisp2|5}}. However, most other forms evaluate to themselves: if you enter {{Lisp2|5}} into Lisp, it returns {{Lisp2|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 {{Lisp2|quote}} special operator, or its abbreviation {{Lisp2|'}} (a single quotation mark). For instance, usually if you enter the symbol {{Lisp2|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 {{Lisp2|(quote foo)}} or, usually, {{Lisp2|'foo}}.
| |
| | |
| {{anchor|Backquote}}Both Common Lisp and Scheme also support the ''backquote'' operator (known as ''[[quasiquote]]'' in Scheme), entered with the {{Lisp2|`}} character ([[Grave accent#Use in programming|grave accent]]). 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 {{Lisp2|,}} ''unquote'' and comma-at {{Lisp2|,@}} ''splice'' operators. If the variable {{Lisp2|snue}} has the value {{Lisp2|(bar baz)}} then {{Lisp2|`(foo ,snue)}} evaluates to {{Lisp2|(foo (bar baz))}}, while {{Lisp2|`(foo ,@snue)}} evaluates to {{Lisp2|(foo bar baz)}}. The backquote is most frequently used in defining macro expansions.<ref>{{cite web|url=http://www.cs.washington.edu/education/courses/cse341/04wi/lectures/14-scheme-quote.html |title=CSE 341: Scheme: Quote, Quasiquote, and Metaprogramming |publisher=Cs.washington.edu |date=1999-02-22 |accessdate=2013-11-15}}</ref><ref>[http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf Quasiquotation in Lisp], Alan Bawden</ref>
| |
| | |
| Self-evaluating forms and quoted forms are Lisp's equivalent of literals. It may be 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 may alter the behavior of the function on subsequent iterations.
| |
| | |
| <syntaxhighlight lang=lisp>
| |
| (defun should-be-constant ()
| |
| '(one two three))
| |
| | |
| (let ((stuff (should-be-constant)))
| |
| (setf (third stuff) 'bizarre)) ; bad!
| |
| | |
| (should-be-constant) ; returns (one two bizarre)
| |
| </syntaxhighlight>
| |
| | |
| Modifying a quoted form like this is generally considered bad style, and is defined by ANSI Common Lisp as erroneous (resulting in "undefined" behavior in compiled files, because the file-compiler can coalesce similar constants, put them in write-protected memory, etc.).
| |
| | |
| Lisp's formalization of quotation has been noted by [[Douglas Hofstadter]] (in ''[[Gödel, Escher, Bach]]'') and others as an example of the [[philosophy|philosophical]] idea of [[self-reference]].
| |
| | |
| ===Scope and closure===
| |
| The modern Lisp family splits over the use of dynamic or static (aka lexical) [[scope (programming)|scope]]. Clojure, Common Lisp and Scheme make use of static scoping by default, while [[Newlisp]], [[Picolisp]] and the embedded languages in [[Emacs]] and [[AutoCAD]] use dynamic scoping.
| |
| | |
| ===List structure of program code; exploitation by macros and compilers===
| |
| A fundamental distinction between Lisp and other languages is that in Lisp, the textual representation of a program is simply a human-readable description of the same internal data structures (linked lists, symbols, number, characters, etc.) as would be used by the underlying Lisp system.
| |
| | |
| Lisp uses this to implement a very powerful macro system. Like other macro languages such as [[C (programming language)|C]], a macro returns code that can then be compiled. However, unlike C macros, the macros are Lisp functions and so can exploit the full power of Lisp.
| |
| | |
| Further, 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.
| |
| | |
| This feature makes it easy to develop ''efficient'' languages within languages. For example, the Common Lisp Object System can be implemented cleanly as a language extension using macros. This means that if an application requires a different inheritance mechanism, it can use a different object system. This is in stark contrast to most other languages; for example, Java does not support multiple inheritance and there is no reasonable way to add it.
| |
| | |
| In simplistic Lisp implementations, this list structure is directly [[interpreter (computing)|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 substantial Lisp systems also include a compiler. The compiler translates list structure into machine code or [[bytecode]] for execution. This code can run as fast as code compiled in conventional languages such as C.
| |
| | |
| Macros expand before the compilation step, and thus offer some interesting options. If a program needs a precomputed table, then a macro might create the table at compile time, so the compiler need only output the table and need not call code to create the table at run time. Some Lisp implementations even have a mechanism, <code>eval-when</code>, that allows code to be present during compile time (when a macro would need it), but not present in the emitted module.<ref>[http://www.gnu.org/software/emacs/manual/html_node/cl/Time-of-Evaluation.html Time of Evaluation - Common Lisp Extensions]. Gnu.org. Retrieved on 2013-07-17.</ref>
| |
| | |
| ===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 {{Lisp2|read}} function accepts textual S-expressions as input, and parses them into an internal data structure. For instance, if you type the text {{Lisp2|(+ 1 2)}} at the prompt, {{Lisp2|read}} translates this into a linked list with three elements: the symbol {{Lisp2|+}}, 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.
| |
| | |
| Note that a {{Lisp2|foo}} will be read as a single symbol. {{Lisp2|123}} will be read as the number one hundred and twenty-three. {{Lisp2|"123"}} will be read as the string "123".
| |
| | |
| The {{Lisp2|eval}} function evaluates the data, returning zero or more other Lisp data 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, {{Lisp2|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 {{Lisp2|(1 2)}} yields the answer {{Lisp2|3}}. This is the result of the evaluation.
| |
| | |
| The symbol {{Lisp2|foo}} evaluates to the value of the symbol foo. Data like the string "123" evaluates to the same string. The list {{Lisp2|(quote (1 2 3))}} evaluates to the list (1 2 3).
| |
| | |
| It is the job of the {{Lisp2|print}} function to represent output to the user. For a simple result such as {{Lisp2|3}} this is trivial. An expression which evaluated to a piece of list structure would require that {{Lisp2|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 {{Lisp2|eval}} will be complicated, since it must also implement all special operators like {{Lisp2|if}} or {{Lisp2|lambda}}.) This done, a basic REPL itself is but a single line of code: {{Lisp2|(loop (print (eval (read))))}}.
| |
| | |
| The Lisp REPL typically also provides input editing, an input history, error handling and an interface to the debugger.
| |
| | |
| Lisp is usually evaluated [[eager evaluation|eagerly]]. In [[Common Lisp]], arguments are evaluated in [[applicative order]] ('leftmost innermost'), while in [[Scheme programming language|Scheme]] order of arguments is undefined, leaving room for optimization by a compiler.
| |
| | |
| ===Control structures===
| |
| Lisp originally had very few control structures, but many more were added during the language's evolution. (Lisp's original conditional operator, {{Lisp2|cond}}, is the precursor to later {{Lisp2|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, but this is incorrect. All frequently seen Lisp dialects have imperative-style iteration constructs, from Scheme's {{Lisp2|do}} loop to [[Common Lisp]]'s complex {{Lisp2|loop}} expressions. Moreover, the key issue that makes this an objective rather than subjective matter is that Scheme makes specific requirements for the handling of [[tail call]]s, and consequently the reason that the use of tail recursion is generally encouraged for Scheme is that the practice is expressly supported by the language definition itself. By contrast, ANSI Common Lisp does not require<ref>[http://www.lispworks.com/documentation/HyperSpec/Body/03_bbc.htm 3.2.2.3 Semantic Constraints] in [http://www.lispworks.com/documentation/HyperSpec/Front/index.htm ''Common Lisp HyperSpec'']</ref> the optimization commonly referred to as tail call elimination. Consequently, the fact that tail recursive style as a casual replacement for the use of more traditional [[iteration]] constructs (such as {{Lisp2|do}}, {{Lisp2|dolist}} or {{Lisp2|loop}}) is discouraged<ref>4.3. Control Abstraction (Recursion vs. Iteration) in [http://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf Tutorial on Good Lisp Programming Style] by [[Kent Pitman|Pitman]] and [[Peter Norvig|Norvig]], August, 1993.</ref> in Common Lisp is not just a matter of stylistic preference, but potentially one of efficiency (since an apparent tail call in Common Lisp may not compile as a simple [[Branch (computer science)|jump]]) and program correctness (since tail recursion may increase stack use in Common Lisp, risking [[stack overflow]]).
| |
| | |
| 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 macro-expanded 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 [[continuation]]s'' using the {{Lisp2|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 (programming language)|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 {{Lisp2|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 {{Lisp2|map}} and in Common Lisp is called {{Lisp2|mapcar}}. Given a function and one or more lists, {{Lisp2|mapcar}} applies the function successively to the lists' elements in order, collecting the results in a new list:
| |
| <syntaxhighlight lang=Lisp>
| |
| (mapcar #'+ '(1 2 3 4 5) '(10 20 30 40 50))
| |
| </syntaxhighlight>
| |
| This applies the {{Lisp2|+}} function to each corresponding pair of list elements, yielding the result {{Lisp2|(11 22 33 44 55)}}.
| |
| | |
| ==Examples==
| |
| Here are examples of Common Lisp code.
| |
| | |
| The basic "[[Hello world]]" program:
| |
| <syntaxhighlight lang=Lisp>
| |
| (print "Hello world")
| |
| </syntaxhighlight>
| |
| 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]]:
| |
| <syntaxhighlight lang=Lisp>
| |
| (defun factorial (n)
| |
| (if (<= n 1)
| |
| 1
| |
| (* n (factorial (- n 1)))))
| |
| </syntaxhighlight>
| |
| An alternative implementation, often faster than the previous version if the Lisp system has [[tail recursion]] optimization:
| |
| <syntaxhighlight lang=Lisp>
| |
| (defun factorial (n &optional (acc 1))
| |
| (if (<= n 1)
| |
| acc
| |
| (factorial (- n 1) (* acc n))))
| |
| </syntaxhighlight>
| |
| Contrast with an iterative version which uses [[Common Lisp|Common Lisp's]] {{Lisp2|loop}} macro:
| |
| <syntaxhighlight lang=Lisp>
| |
| (defun factorial (n)
| |
| (loop for i from 1 to n
| |
| for fac = 1 then (* fac i)
| |
| finally (return fac)))
| |
| </syntaxhighlight>
| |
| | |
| The following function reverses a list. (Lisp's built-in ''reverse'' function does the same thing.)
| |
| <syntaxhighlight lang=Lisp>
| |
| (defun -reverse (list)
| |
| (let ((return-value '()))
| |
| (dolist (e list) (push e return-value))
| |
| return-value))
| |
| </syntaxhighlight>
| |
| | |
| ==Object systems==
| |
| Various object systems and models have been built on top of, alongside, or into Lisp, including:
| |
| *The [[Common Lisp Object System]], CLOS, is an integral part of ANSI Common Lisp. CLOS descended from New Flavors and CommonLOOPS. ANSI Common Lisp was the first standardized object-oriented programming language (1994, ANSI X3J13).
| |
| *ObjectLisp<ref>pg 17 of Bobrow 1986</ref> or [[Object Lisp]], used by [[Lisp Machines Incorporated]] and early versions of Macintosh Common Lisp
| |
| *LOOPS (Lisp Object-Oriented Programming System) and the later [[CommonLOOPS]]
| |
| *[[Flavors (computer science)|Flavors]], built at [[Massachusetts Institute of Technology|MIT]], and its descendant New Flavors (developed by [[Symbolics]]).
| |
| *KR (short for Knowledge Representation), a [[Constraint satisfaction|constraint]]s-based object system developed to aid the writing of Garnet, a GUI library for [[Common Lisp]].
| |
| *[[Knowledge Engineering Environment|KEE]] used an object system called UNITS and integrated it with an [[inference engine]]<ref>Veitch, p 108, 1988</ref> and a [[Truth maintenance systems|truth maintenance system]] (ATMS).
| |
| | |
| ==See also==
| |
| *[[Fexpr]]
| |
| *[[Maxima (software)|Maxima]]
| |
| *[[mod_lisp]]
| |
| *[[P convention]]
| |
| *[[Prolog]]
| |
| | |
| ==References==
| |
| {{Reflist|30em}}
| |
| | |
| ==Further reading==
| |
| {{Refbegin}}
| |
| *{{cite web
| |
| | last = McCarthy
| |
| | first = John
| |
| | authorlink =
| |
| | coauthors =
| |
| | title = The implementation of Lisp
| |
| | work = History of Lisp
| |
| | publisher = Stanford University
| |
| | date = 1979-02-12
| |
| | url = http://www-formal.stanford.edu/jmc/history/lisp/node3.html
| |
| | doi =
| |
| | accessdate = 2008-10-17}}
| |
| *{{Cite conference
| |
| | first = Guy L.
| |
| | last = Steele, Jr.
| |
| | authorlink =
| |
| | coauthors = Richard P. Gabriel
| |
| | title = The evolution of Lisp
| |
| | booktitle = The second ACM SIGPLAN conference on History of programming languages
| |
| | pages = 231–270
| |
| | publisher = ACM, ISBN 0-89791-570-4
| |
| | year = 1993
| |
| | location = New York, NY
| |
| | url = http://www.dreamsongs.com/NewFiles/HOPL2-Uncut.pdf
| |
| | doi =
| |
| | id =
| |
| | isbn = 0-89791-570-4
| |
| | accessdate = 2008-10-17}}
| |
| *{{Cite book
| |
| | first = Jim
| |
| | last = Veitch
| |
| | author-link =
| |
| | first2 =
| |
| | last2 =
| |
| | author2-link =
| |
| | editor-last = Salus
| |
| | editor-first = Peter H
| |
| | editor2-last =
| |
| | editor2-first =
| |
| | contribution = A history and description of CLOS
| |
| | contribution-url =
| |
| | title = Handbook of programming languages
| |
| | volume = Volume IV, Functional and logic programming languages
| |
| | edition = first
| |
| | year = 1998
| |
| | pages = 107–158
| |
| | place = Indianapolis, IN
| |
| | publisher = Macmillan Technical Publishing
| |
| | url =
| |
| | doi =
| |
| | id =
| |
| | isbn = 1-57870-011-6
| |
| | postscript = <!--None-->}}
| |
| *{{Cite book
| |
| |title= [[Structure and Interpretation of Computer Programs]]
| |
| |first= Harold
| |
| |last= Abelson
| |
| |author-link= Harold Abelson
| |
| |first2= Gerald Jay
| |
| |last2= Sussman
| |
| |author2-link= Gerald Jay Sussman
| |
| |first3= Julie
| |
| |last3= Sussman
| |
| |author3-link= Julie Sussman
| |
| |year= 1996
| |
| |edition= 2nd
| |
| |publisher= MIT Press
| |
| |isbn= 0-262-01153-0
| |
| |doi= }}
| |
| *[http://www.gnu.org/gnu/rms-lisp.html My Lisp Experiences and the Development of GNU Emacs], [[transcription (linguistics)|transcript]] of [[Richard Stallman]]'s speech, 28 October 2002, at the [[International Lisp Conference]]
| |
| *{{Cite book
| |
| |first= Paul
| |
| |last= Graham
| |
| |author-link= Paul Graham (computer programmer)
| |
| |title= [[Hackers & Painters| Hackers & Painters. Big Ideas from the Computer Age]]
| |
| |year= 2004
| |
| |publisher= O'Reilly
| |
| |isbn= 0-596-00662-4
| |
| |doi= }}
| |
| *{{Cite book
| |
| |editor-last= Berkeley
| |
| |editor-first= Edmund C.
| |
| |editor-link= Edmund Berkeley
| |
| |editor2-last= Bobrow
| |
| |editor2-first= Daniel G.
| |
| |editor2-link= Daniel G. Bobrow
| |
| |title= The Programming Language LISP: Its Operation and Applications
| |
| |url= http://www.softwarepreservation.org/projects/LISP/book/III_LispBook_Apr66.pdf
| |
| |date= March 1964
| |
| |publisher= MIT Press
| |
| |location= Cambridge, Massachusetts
| |
| |isbn=
| |
| |doi= }}
| |
| *{{Cite book
| |
| |last= Weissman
| |
| |first= Clark
| |
| |title= LISP 1.5 Primer
| |
| |year= 1967
| |
| |url= http://www.softwarepreservation.org/projects/LISP/book/Weismann_LISP1.5_Primer_1967.pdf
| |
| |publisher= Dickenson Publishing Company Inc.
| |
| |location= Belmont, California
| |
| |isbn=
| |
| |doi=}}
| |
| {{Refend}}
| |
| | |
| ==External links==
| |
| {{external links|date=June 2013}}
| |
| {{Sister project links|wikt=Lisp|commons=Category:Lisp (programming language)|n=no|q=Lisp programming language|b=Subject:Lisp programming language|v=Topic:Lisp|s=Lambda Papers}}
| |
| ;History
| |
| *[http://www-formal.stanford.edu/jmc/history/lisp/lisp.html History of Lisp] – [[John McCarthy (computer scientist)|John McCarthy]]'s history of 12 February 1979
| |
| *[http://www8.informatik.uni-erlangen.de/html/lisp-enter.html Lisp History]{{dead link|date=May 2013}} – Herbert Stoyan's history compiled from the documents (acknowledged by McCarthy as more complete than his own, see: [http://www-formal.stanford.edu/jmc/history/ McCarthy's history links])
| |
| *[http://www.softwarepreservation.org/projects/LISP/ History of LISP at the Computer History Museum]
| |
| | |
| ;Associations and meetings
| |
| *[http://www.alu.org/ Association of Lisp Users]
| |
| *[http://www.weitz.de/eclm2009/ European Common Lisp Meeting]
| |
| *[http://european-lisp-symposium.org/ European Lisp Symposium]
| |
| *[http://www.international-lisp-conference.org/ International Lisp Conference]
| |
| | |
| ; Books and tutorials
| |
| *''[http://www.lisperati.com/casting.html Casting SPELs in Lisp]'', a comic-book style introductory tutorial
| |
| *''[http://paulgraham.com/onlisptext.html On Lisp]'', a free book by [[Paul Graham (computer programmer)|Paul Graham]]
| |
| *''[http://www.gigamonkeys.com/book/ Practical Common Lisp]'', freeware edition by Peter Seibel
| |
| * [https://leanpub.com/lispweb Lisp for the web]
| |
| * [http://landoflisp.com/ Land of Lisp]
| |
| * [http://letoverlambda.com/ Let over Lambda]
| |
| | |
| ; Interviews
| |
| *[http://purl.umn.edu/107476 Oral history interview with John McCarthy] at [[Charles Babbage Institute]], University of Minnesota, Minneapolis. McCarthy discusses his role in the development of time-sharing at the Massachusetts Institute of Technology. He also describes his work in artificial intelligence (AI) funded by the Advanced Research Projects Agency, including logic-based AI (LISP) and robotics.
| |
| *[http://www.se-radio.net/2008/01/episode-84-dick-gabriel-on-lisp/ Interview] with [[Richard P. Gabriel]] (Podcast)
| |
| | |
| ;Resources
| |
| *[http://www.cliki.net/ CLiki: the common lisp wiki]
| |
| *[http://www.cl-user.net/ Common Lisp directory]
| |
| *[http://www.faqs.org/faqs/lisp-faq/ Lisp FAQ Index]
| |
| *[http://paste.lisp.org/ lisppaste]
| |
| *[http://planet.lisp.org/ Planet Lisp]
| |
| *[http://lispnews.wordpress.com/ Weekly Lisp News]
| |
| *{{dmoz|Computers/Programming/Languages/Lisp|Lisp}}
| |
| | |
| {{John McCarthy navbox}}
| |
| | |
| {{DEFAULTSORT:Lisp Programming Language}}
| |
| [[Category:1958 in computer science]]
| |
| [[Category:Academic programming languages]]
| |
| [[Category:American inventions]]
| |
| [[Category:Articles with example Lisp code]]
| |
| [[Category:Dynamically typed programming languages]]
| |
| [[Category:Functional languages]]
| |
| [[Category:Lisp programming language]]
| |
| [[Category:Lisp programming language family]]
| |
| [[Category:Programming languages created in 1958]]
| |
| [[Category:Programming languages created in the 1950s]]
| |
| [[Category:Extensible syntax programming languages]]
| |