If thc s-c\pnrvsion i* an atomie symbol, return the valuc bound to tbat symbol; if it is not bound it U an error.
If thc s-c\pressi«*n is a list. c\aluatc thc sccond through thc last argumentu and apply thc function indicatcd by thc first argument to thc rcsults.
LISP represents both program* and data as s-cxprcssions. Not only docs (his simplify thc >>ma\ of thc languagc but ałso. when combincd \vith thc nbility to control the cva!uation of s-ciptcssions, it make* it casy to writc programs that trcal other LISP programs as data. This stmplifics thc impicmentation of interpreters in LISP.
In the prwious scction. sevcrol of thc cxamplcs includcd list arguments prcccdcd by a nagle quotation mark: The *. w hien can also be represented by thc function Quo(t,isiąK> ciał function uhich docs not cvaluate its argument but prevcms cvaluation. oflen bccausc its argument is to be treated as data rather than an evaluablc form.
When eva)iiating an s-cxprcssion. LISP will first try to cvaiimtc all of its argument*. If the interpreter is gtvcn thc espression (nth 0 (a b c d)). it will first try to eva!uate the argument (a b C d). This attempted osluation will result in an error, bccausc a. the fint demem of this s-cxpre.*sion. docs not represent any known LISP function. To provcm this. LISP procides the uscr with tlić built-in function quote. quote takes one argument and retums that argument without cvaluating it. For cxample:
> (quoto (a b c»
> (quote (♦ 1 3))
(♦13)
Bccausc quot# is uscd sooften. LISP allows it to be abbreviated by a single quocabon mark. Tbus. the preceding cxamples could be written:
(a be)
(♦13)
In generał, quote is uscd to prcvent thc evaluation of arguments to a function ahen thcsc arguments arc intended to be treated as data rather than cvaluabłc forms. la ik eariicr cxampłcs of snnplc arithmctic. quote was not nccdcd. bccausc numbers ahray* cvaluatc to thcmschcs. Consider the effect of quote in the following calls to thc IW function:
> (ll*f (♦ 1 2) (♦ 3 4))
PART VI / LANGU AGES FOR Al PROBLEM SOLVlNG
> (list •<♦ 1 2) •(♦ 3 4)) «♦ 1 2) (+ 3 4))
In thc first cxamplc. thc arguments arc not quotcd: they arc thcrcforc oaluMed and paswd to list according to thc defaułt cvaluation schcmc. In thc second exampic. quote prcvcnts this cvaluation. with the s-oepressions thcmsclvc* betng passed as arguments to list. Evcn though (♦ 1 2) is a mcaninglul LISP ferm. quote prcvcnts its cvaluaiion. The ability to prcvent evn!uation of program and manipulatc thern as data is an importanf fcature of LISP.
«>4
As a complcmcnt to quote. LISP also provides a function. eval. that allows prugrnnimcr to cvaluatc an s-cxpression at will. eval takes one s^apression as argument: this argument is evałuated as is usual for arguments to functions: hosocr. rcsult is then cvaluatcd ogain and this finał resuh is retumed as the value of the eval twpression. Fxamplcs of the behavior of eval and quote inelude:
> (quote (♦ 2 3))
(♦23)
; eval undoes the effect of quota ; this conslructs an evaluabte Mxpr«Mion : this constructs and «vaiuatas it
> (oval (quoto (♦ 2 3»)
5
»(list’* 2 5)
C25)
> (eval (list '• 2 5))
10
The eval function is prcciseły what is uscd in thc ordinary csaluatioo of s-exprcssions. By mnking quote and eval availablc to thc programmer. LISP grcatly timpliflcs thc dcvclopmcnt of meta-interpirterr. variątions on thc standard LISP interpreter that dcfinc altcmntive or extended behn iors for thc LISP languagc. This importani programming mcthodology is illustratcd in thc * infix-intcrprctcr" of Seciion 15.7 and thc design of an cxpcrt system Shell in Scction 15.10.
Common LISP includcs a large numberof built-in funclions. including:
A fuli rangę of ariihmctk functions. supporting integer. rational. rcal and complc* arithmetic.
A varicty of looping and program control functions.
List manipulation and other data structuring fbnetions.
Input/output functions.
Forms for thc control of Ainction evaluation.
Functions for thc control of thc cnvironmcnt and operating system.
685
CMAf»TER 15/ANINTROOUCTION TOLlSP