Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lisp (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===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 entering {{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|'}} (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 web|archive-date=2013-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 |url=http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf |url-status=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. <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]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)