Lisp (programming language): Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Line 364:
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|'}} (one quotation mark). For instance, usually if entering the symbol {{Lisp2|foo}}, it returns the value of the corresponding variable (or an error, if there is no such variable). To refer to the literal symbol, enter {{Lisp2|(quote foo)}} or, usually, {{Lisp2|'foo}}.
 
{{anchor|Backquote}}Both Common Lisp and Scheme also support the ''backquote'' operator (termed ''[[quasiquote]]'' in Scheme), entered with the {{Lisp2|`}} character ([[Backtick]]). 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 often used in defining macro expansions.<ref name="cTQAG">{{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=University of Washington Computer Science & Engineering |date=Winter 2004 |access-date=2013-11-15}}</ref><ref name="waVLs">{{cite we web|urlarchive-statusdate=dead2013-06-03 |archive-url=https://web.archive.org/web/20130603114956/http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf |first1=Alan |last1=Bawden |title=Quasiquotation in Lisp |archive-url=https://web.archive.org/web/20130603114956/http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf |archiveurl-datestatus=2013-06-03 |first1= Alan |last1=Bawden dead}}</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 invocations.