20 1024x768

20 1024x768



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.

IS.U Control of LISP EvaIuation: quote and eval

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»

(a be)

>    (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:

> *(• b c)

(a be)

>*(♦15)

(♦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))

(*7)

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.

15.13 Programming in LISP: Creating New Funclions

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


Wyszukiwarka

Podobne podstrony:
Jasalini trades of the member countries are too alarmist. Fixed pricing is not an ideological subjec
HISTORIA - WYKŁAD - 20.10.2011 killed by an arrow (perhaps it was a coincidence that Henry - his&nbs
S5006939 (2) by way of the Madarovce culture. An argument against linking thc piąte with casting act
PREMIERA    7 MARCA 20 W 1EA1R $LĄS<IPRZEMYSŁAW ANGERMAN. ]AN
DSC09867 Wrocław 20.11.08 r.Ił LUK . AN ATOMIA KI INK /\ # :£> tania do /alk/cni:^I. 1.  &nb
7 2 •i: X. ..WLAJ1SHORT TEST 3 A I UNIT 3 Namc: Score: / 20 points 1 Complete thc sentenccs with the
page65 how to make( P.20 58 ) ggl.5cm £41 an%i OGllt i. *<* , m a K2202
AN ASTOUNDING FANTASY SAGA! “Rousing and occiting. Action packed from the opening chapter to thc ult
page65 how to make( P.20 58 ) ggl.5cm £41 an%i OGllt i. *<* , m a K2202
fot (20) 77 \ T ** ** If * J f j*( ki. - 4 k ®£ Ki X - ł*-s^* Nł ^ •nj ^Kr^* 1 . U i
Co-funded by the Erasmus* Programme of thc Europę an Union motywów, figur, wersyfikacji r
23 (286) III. An action-bascd reprcsentation of thc Produccr/Consumer System: Producer: Altemates th
20. Co oznacza w rysunku technicznym budowlanym poniższy symbol?—jA/ A, 21. Obliczyć zbieżność eleme
35684 S5006937 (2) but one having a new and original symbolisra. Although it is expressed here in a

więcej podobnych podstron