Lisp (programming language): Difference between revisions

Content deleted Content added
MOS:PSEUDOHEAD
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=Cs.washington.eduUniversity of Washington Computer Science & Engineering |date=1999-02-22Winter 2004 |access-date=2013-11-15}}</ref><ref name="waVLs">[{{cite we |url-status=dead |url=http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf |title=Quasiquotation in Lisp] {{Webarchive|archive-url=https://web.archive.org/web/20130603114956/http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf |archive-date=2013-06-03}}, |first1= Alan |last1=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 invocations.
Line 396:
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 name="0iFgm">"[https://www.gnu.org/software/emacs/manual/html_node/cl/Time-of-Evaluation.html Time of Evaluation - (Common Lisp Extensions)]". Gnu.orgGNU. Retrieved on 2013-07-17.</ref>
 
===Evaluation and the read–eval–print loop===