<<

MITSUBISHI ELECTRIC RESEARCH LABORATORIES http://www.merl.com

Some Useful Lisp Algorithms: Part 1

Richard . Waters

TR91-04 December 1991

Abstract Richard C. Waters Chapter 3 Implementing¨ Queues in Lisp(co-authored¨ by P. Norvig) presents several different algorithms for implementing queues in Lisp. It discusses why the obvious list- based implementation of queues is inefficient and the particular situations where more complex implementations are appropriate.

This work may not be copied or reproduced in whole or in part for any commercial purpose. Permission to copy in whole or in part without payment of fee is granted for nonprofit educational and research purposes provided that all such whole or partial copies include the following: a notice that such copying is by permission of Mitsubishi Electric Research Laboratories, Inc.; an acknowledgment of the authors and individual contributions to the work; and all applicable portions of the copyright notice. Copying, reproduction, or republishing for any other purpose shall require a license with payment of fee to Mitsubishi Electric Research Laboratories, Inc. All rights reserved.

Copyright c Mitsubishi Electric Research Laboratories, Inc., 1991 201 Broadway, Cambridge, Massachusetts 02139 MERLCoverPageSide2 witsu˜ishi ile™tri™ ‚ese—r™h v—˜or—tories

„e™hni™—l ‚eport WIEHR he™me˜er ISD IWWI

˜y

‚i™h—rd gF ‡—ters

e˜str—™t

„his te™hni™—l report g—thers together three p—pers th—t were written during IWWI —nd su˜mitted for pu˜li™—tion in egw visp €ointersF i—™h p—per des™ri˜es — useful visp —lgorithmF gh—pter I ’ƒupporting the ‚egression „esting of visp €rogr—ms4 presents — system ™—lled rt th—t m—int—ins — d—t—˜—se of tests —nd —utom—ti™—lly runs them when requestedF „his ™—n t—ke — lot of ™omputer timeD ˜ut does not t—ke —ny of the progr—mmer9s timeF es — resultD —ny ˜ugs found ˜y running the tests|—nd this is — lot more ˜ugs th—n you might think|—re essenti—lly found for freeF gh—pter P ’hetermining the gover—ge of — „est ƒuite4 presents — system ™—lled ™over th—t ™—n help —ssess the ™over—ge of — suite of test ™—sesF ‡hen — suite of test ™—ses for — progr—m is run in ™onjun™tion with ™overD st—tisti™s —re kept on whi™h ™onditions in the ™ode for the progr—m —re exer™ised —nd whi™h —re notF f—sed on this inform—tionD ™over ™—n print — report of wh—t h—s ˜een missedF fy devising tests th—t exer™ise these ™onditionsD — progr—mmer ™—n extend the test suite so th—t it h—s more ™omplete ™over—geF gh—pter Q ’smplementing ueues in visp4 @™oE—uthored ˜y €F xorvigA presents sever—l dierent —lgorithms for implementing queues in vispF st dis™usses why the o˜vious listE˜—sed implement—tion of queues is ine™ient —nd the p—rti™ul—r situ—E tions where more ™omplex implement—tions —re —ppropri—teF

ƒu˜mitted to egw visp €ointersD t—nu—ryD xovem˜erD —nd he™em˜er IWWIF

PHI fro—dw—y g—m˜ridge w—ss—™husetts HPIQW €u˜li™—tion ristoryXE IF pirst printingD „‚ WIEHRD he™em˜er IWWI PF gh—pter I pu˜lished —s ’ƒupporting the ‚egression „esting of visp €rogr—ms4D egw visp €ointersD R@PAXRU{SQD tune IWWIF

gopyright ™ witsu˜ishi ile™tri™ ‚ese—r™h v—˜or—toriesD IWWI PHI fro—dw—yY g—m˜ridge w—ss—™husetts HPIQW

„his work m—y not ˜e ™opied or reprodu™ed in whole or in p—rt for —ny ™ommer™i—l purposeF €ermission to ™opy in whole or in p—rt without p—yment of fee is gr—nted for nonprot edE u™—tion—l —nd rese—r™h purposes provided th—t —ll su™h whole or p—rti—l ™opies in™lude the followingX — noti™e th—t su™h ™opying is ˜y permission of witsu˜ishi ile™tri™ ‚ese—r™h v—˜E or—tories of g—m˜ridgeD w—ss—™husettsY —n —™knowledgment of the —uthors —nd individu—l ™ontri˜utions to the workY —nd —ll —ppli™—˜le portions of the ™opyright noti™eF gopyingD reprodu™tionD or repu˜lishing for —ny other purpose sh—ll require — li™ense with p—yment of fee to witsu˜ishi ile™tri™ ‚ese—r™h v—˜or—toriesF ell rights reservedF visp elgorithms I

IF ƒupporting the ‚egression „esting of visp €rogr—ms

‚i™h—rd gF ‡—ters

row often h—ve you m—de — ™h—nge in — sysE ser9s w—nu—l for ‚„ tem to x — ˜ug or —dd — fe—ture —nd ˜een toE t—lly sure th—t the ™h—nge did not —e™t —nyE „he fun™tionsD m—™rosD —nd v—ri—˜les th—t thing elseD only to dis™over weeks or months m—ke up the rt regression tester —re in — p—™kE l—ter th—t the ™h—nge ˜roke somethingc —ge ™—lled 4‚„4F „he ten exported sym˜ols —re sn my person—l experien™eD the single most do™umented ˜elowF sf you w—nt to refer to these v—lu—˜le softw—re m—inten—n™e tool is — regresE sym˜ols without — p—™k—ge prexD you h—ve to sion testerD whi™h m—int—ins — suite of tests for — –use9 the p—™k—geF system —nd ™—n run them —utom—ti™—lly when „he ˜—si™ unit of ™on™ern of rt is the testF the system is ™h—ngedF „he term ’regression i—™h test h—s —n identifying n—me —nd — ˜ody testing4 is usedD ˜e™—use e—™h version of the sysE th—t spe™ies the —™tion of the testF pun™tions tem ˜eing tested is ™omp—red with the previous —re provided for deningD redeningD removingD version to m—ke sure th—t the new version h—s —nd performing individu—l tests —nd the test not regressed ˜y losing —ny of the tested ™—p—E suite —s — wholeF sn —dditionD inform—tion is ˜ilitiesF „he more ™omprehensive the test suite m—int—ined —˜out whi™h tests h—ve su™™eeded isD the more v—lu—˜le this ™omp—rison ˜e™omesF —nd whi™h h—ve f—iledF gre—ting — ™omprehensive test suite for — system requires signi™—nt eortD —nd running  deftest n—me form 8rest v—lues — test suite ™—n require signi™—nt —mounts of sndividu—l tests —re dened using the m—™ro ™omputer timeF roweverD given — ™omprehenE deftestF „he identifying n—me is typi™—lly — sive test suiteD regression testing dete™ts —n imE num˜er or sym˜olD ˜ut ™—n ˜e —ny visp formF pressive num˜er of ˜ugs with rem—rk—˜ly little sf the test suite —lre—dy ™ont—ins — test with the hum—n eortF s—me @equ—lA n—meD then this test is redened „he rt regression tester presented here supE —nd — w—rning mess—ge printedF @„his w—rning ports the regression testing of systems written is import—nt to —lert the user when — test suite in gommon vispF sn —ddition to ˜eing — v—luE denition le ™ont—ins two tests with the s—me —˜le toolD rt is —n interesting ex—mple of the n—meFA ‡hen the test is — new oneD it is —dded power of vispF to the end of the suiteF sn either ™—seD n—me is „he unied n—ture of the visp progr—mming returned —s the v—lue of deftest —nd stored in environment —nd the f—™t th—t visp progr—ms the v—ri—˜le BtestBF ™—n ˜e m—nipul—ted —s d—t— —llows rt to ˜e imE @deftest tEI @floor ISGUA P IGUA A tEI plemented in two p—ges of ™odeF werely impleE @deftest @t PA @list IA @IAA A @t PA menting — ˜—t™hEmode regression tester using @deftest ˜—d @IC IA IA A ˜—d —n elgolElike l—ngu—ge in — typi™—l progr—mE @deftest good @IC IA PA A good ming environment would require mu™h more ™odeF smplementing — highly inter—™tive system „he form ™—n ˜e —ny kind of visp formF „he like rt would ˜e — m—jor undert—kingF zero or more v—lues ™—n ˜e —ny kind of visp P ‚FgF ‡—ters

o˜je™tsF „he test is performed ˜y ev—lu—ting every test from the test suite —nd returns nilF form —nd ™omp—ring the results with the v—luesF qener—llyD it is —dvis—˜le for the whole test suite „he test su™™eeds if —nd only if form produ™es to —pply to some one systemF ‡hen swit™hing the ™orre™t num˜er of results —nd e—™h one is from testing one system to testing —notherD it is equ—l to the ™orresponding v—lueF wise to remove —ll the old tests ˜efore ˜eginning to dene new onesF  BtestB n—meEofE™urrentEtest „he v—ri—˜le BtestB ™ont—ins the n—me of  doEtests 8option—l @out Bst—nd—rdEoutputBA the test most re™ently dened or performedF st „his fun™tion uses doEtest to run e—™h of is set ˜y deftest —nd doEtestF the tests in the test suite —nd prints — report of the results on outD whi™h ™—n either ˜e —n outE  doEtest 8option—l @n—me BtestBA put stre—m or the n—me of — leF sf out is omitE „he fun™tion doEtest performs the test idenE tedD it def—ults to Bst—nd—rdEoutputBF hoEtests tied ˜y n—meD whi™h def—ults to BtestBF fefore returns t if every test su™™eeded —nd nil if —ny running the testD doEtest stores n—me in the test f—iledF v—ri—˜le BtestBF sf the test su™™eedsD doEtest es illustr—ted ˜elowD the rst line of the reE returns n—me —s its v—lueF sf the test f—ilsD port produ™ed ˜y doEtests shows how m—ny doEtest returns nilD —fter printing —n error reE tests need to ˜e performedF „he l—st line shows port on Bst—nd—rdEoutputBF „he following exE how m—ny tests f—iled —nd lists their n—mesF —mples show the results of performing two of ‡hile the tests —re ˜eing performedD doEtests the tests dened —˜oveF prints the n—mes of the su™™essful tests —nd the error reports from the unsu™™essful testsF @doEtest 9@t PAA A @t PA @doEtest 9˜—dA A nil Y —fter printingX @doEtests 4reportFtxt4A A nil „est feh f—iled Y the le 4reportFtxt4 ™ont—insX pormX @IC IA hoing R pending tests of R tests tot—lF ixpe™ted v—lueX I „EI @„ PA e™tu—l v—lueX PF „est feh f—iled pormX @IC IA ixpe™ted v—lueX I  BdoEtestsEwhenEdefinedB def—ult v—lue nil e™tu—l v—lueX PF sf the v—lue of this v—ri—˜le is nonEnullD e—™h qyyh I out of R tot—l tests f—iledX fehF test is performed —t the moment th—t it is deE nedF „his is helpful when inter—™tively ™onE st is ˜est if the individu—l tests in the suite stru™ting — suite of testsF roweverD when lo—dE —re tot—lly independent of e—™h otherF roweverD ing — test suite for l—ter useD performing tests should the need —rise for some interdependen™eD —s they —re dened is not li—˜le to ˜e helpfulF you ™—n rely on the f—™t th—t doEtests will run tests in the order they were origin—lly denedF  getEtest 8option—l @n—me BtestBA „his fun™tion returns the n—meD formD —nd  pendingEtests v—lues of the spe™ied testF ‡hen — test is dened or redenedD it is m—rked —s pendingF sn —dditionD doEtest m—rks @getEtest 9@t PAA A @@t PA @list IA @IAA the test to ˜e run —s pending ˜efore running it  remEtest 8option—l @n—me BtestBA —nd doEtests m—rks every test —s pending ˜eE fore running —ny of themF „he only time — test sf the indi™—ted test is in the test suiteD this is m—rked —s not pending is when it ™ompletes fun™tion removes it —nd returns n—meF ytherE su™™essfullyF „he fun™tion pendingEtests reE wiseD nil is returnedF turns — list of the n—mes of the ™urrently pendE  remE—llEtests ing testsF „his fun™tion reiniti—lizes rt ˜y removing @pendingEtestsA A @˜—dA visp elgorithms Q

 ™ontinueEtesting row ‚„ ‡orks „his fun™tion is identi™—l to doEtests ex™ept „he ™ode for rt is shown in pigures I 8 PF th—t it only runs the tests th—t —re pending —nd „he rst gure shows the fun™tions for m—inE —lw—ys writes its output on Bst—nd—rdEoutputBF t—ining the suite of testsF por the most p—rtD @™ontinueEtestingA A nil Y —fter printingX the ™ode is self expl—n—toryF roweverD sever—l hoing I pending test out of R tot—l testsF points —re worthy of noteF „est feh f—iled „he test suite is represented —s — list of test pormX @IC IA ixpe™ted v—lueX I entries stored in the v—ri—˜le BentriesBF „he e™tu—l v—lueX PF list ˜egins with — dummy entry of nil so th—t I out of R tot—l tests f—iledX fehF insertion —nd deletion of entries ™—n ˜e done ˜y sideEee™t without h—ving to h—ndle —n empty gontinueEtesting h—s — spe™i—l me—ning if test suite —s — spe™i—l ™—seF i—™h test entry ™—lled —t — ˜re—kpoint gener—ted while — test is ™ont—ins ve pie™es of inform—tionX ˜eing performedF „he f—ilure of — test to reE turn the ™orre™t v—lue does not trigger —n error pend e —g th—t is nonEnull when the ˜re—kF roweverD there —re m—ny kinds of things test is pendingF th—t ™—n go wrong while — test is ˜eing perE n—me „he n—me of the test represented formed @eFgFD dividing ˜y zeroA th—t will ™—use ˜y the test entryF ˜re—ksF form „he form to ev—lu—te when sf ™ontinueEtesting is ev—lu—ted in — ˜re—k performing the testF gener—ted during testingD it —˜orts the ™urrent v—ls „he v—lues spe™ifying wh—t the test @whi™h rem—ins pendingA —nd for™es the form should returnF pro™essing of tests to ™ontinueF xote th—t in defn e list ™ont—ining the n—meD formD su™h — ˜re—kpointD BtestB is ˜ound to the n—me —nd v—lsF of the test ˜eing performed —nd @getEtestA ™—n ˜e used to look —t the testF por e™ien™yD the entry d—t— stru™ture is ‡hen ˜uilding — systemD it is —dvis—˜le to represented —s — list where the pendD n—meD —nd st—rt ™onstru™ting — test suite for it —s soon —s form elds —re dened in the norm—l w—yD —nd possi˜leF ƒin™e individu—l tests —re r—ther we—kD the v—ls —nd defn elds —re overl—pping t—ils of — ™omprehensive test suite requires l—rge numE the listF ˜ers of testsF roweverD these ™—n ˜e —™™umuE qetEentry is ˜roken out —s — sep—r—te fun™E l—ted over timeF sn p—rti™ul—rD whenever — ˜ug tionD r—ther th—n ˜eing p—rt of getEtestD˜eE is found ˜y some me—ns other th—n testingD it ™—use it is — ™—lled ˜y doEtest —s wellF is wise to —dd — test th—t would h—ve found the „he re—son why deftest is — m—™ro inste—d ˜ug —nd therefore will ensure th—t the ˜ug will of — fun™tion is to —llow tests to ˜e dened withE not re—ppe—rF out expli™itly quoting the v—rious p—rts of the ivery time the system is ™h—ngedD the entire denitionF test suite should ˜e run to m—ke sure th—t no „he ™opyElist in —ddEentry is needed to enE unintended ™h—nges h—ve o™™urredF „ypi™—llyD sure th—t ev—lu—ting — deftest — se™ond time some tests will f—ilF ƒometimesD this merely ™re—tes — fresh entryF me—ns th—t tests h—ve to ˜e ™h—nged to ree™t e desire to keep the entries on BentriesB ™h—nges in the system9s spe™i™—tionF yther in the order th—t the tests —re initi—lly dened timesD it indi™—tes ˜ugs th—t h—ve to ˜e tr—™ked m—kes the m—in loop in —ddEentry somewh—t down —nd xedF huring this ph—seD ™ontinueE ™omplexF „he loop se—r™hes through BentriesB testing is useful for fo™using on the tests th—t to see if there is — preEexisting test with the —re f—ilingF roweverD for s—fety s—keD it is —lw—ys s—me n—me —s the one ˜eing denedF sf there wise to reiniti—lize rtD redene the entire test isD the entry is repl—™edF sf notD the new entry suiteD —nd run doEtests one more time —fter you is pl—™ed —t the end of BentriesBF think —ll of the tests —re workingF „he error reporting done ˜y getEentry —nd R ‚FgF ‡—ters

@inEp—™k—ge 4‚„4 Xuse 9@4vsƒ€4AA @defun getEtest @8option—l @n—me BtestBAA @defn @getEentry n—meAAA @provide 4‚„4A @defun getEentry @n—meA @export @let @@entry @find n—me @™dr BentriesBA 9@deftest getEtest doEtest remEtest Xkey 59n—me remE—llEtests doEtests pendingEtests Xtest 59equ—lAAA ™ontinueEtesting BtestB @when @null entryA BdoEtestsEwhenEdefinedBAA @reportEerror t @defv—r BtestB nil 4gurrent test n—me4A 4~7xo test with n—me ~Xd@~ƒ~AF4 @defv—r BdoEtestsEwhenEdefinedB nilA n—meAA @defv—r BentriesB 9@nilA 4„est d—t—˜—se4A entryAA @defv—r BinEtestB nil 4 sed ˜y „iƒ„4A @defm—™ro deftest @n—me form 8rest v—luesA @defv—r Bde˜ugB nil 4por de˜ugging4A –@—ddEentry 9@t Dn—me Dform FDv—luesAAA @defstru™t @entry @X™on™En—me nilA @defun —ddEentry @entryA @Xtype listAA @setq entry @™opyElist entryAA pend n—me formA @do @@l BentriesB @™dr lAAA @nilA @defm—™ro v—ls @entryA –@™dddr DentryAA @when @null @™dr lAA @setf @™dr lA @list entryAA @defm—™ro defn @entryA –@™dr DentryAA @return nilAA @defun pendingEtests @A @when @equ—l @n—me @™—dr lAA @do @@l @™dr BentriesBA @™dr lAA @n—me entryAA @r nilAA @setf @™—dr lA entryA @@null lA @nreverse rAA @reportEerror nil @when @pend @™—r lAA 4‚edefining test ~dX@~ƒ~A4 @push @n—me @™—r lAA rAAAA @n—me entryAA @return nilAAA @defun remE—llEtests @A @when BdoEtestsEwhenEdefinedB @setq BentriesB @list nilAA @doEentry entryAA nilA @setq BtestB @n—me entryAAA @defun remEtest @8option—l @n—me BtestBAA @defun reportEerror @errorc 8rest —rgsA @do @@l BentriesB @™dr lAAA @™ond @Bde˜ugB @@null @™dr lAA nilA @—pply 59form—t t —rgsA @when @equ—l @n—me @™—dr lAA n—meA @if errorc @throw 9Bde˜ugB nilAAA @setf @™dr lA @™ddr lAA @errorc @—pply 59error —rgsAA @return n—meAAAA @t @—pply 59w—rn —rgsAAAA

pigure IX „he ™ode for the p—rt of rt th—t m—int—ins the test suiteF

—ddEentry is ˜roken out into the sep—r—te fun™E is used —s —n interlo™k to m—ke sure th—t the tion reportEerror to provide gre—ter uniformity fun™tion ™ontinueEtesting will only do — throw —nd f—™ilit—ting the testing of rtF when the —ppropri—te ™—t™h existsF „he w—y st is often —dvis—˜le to insert — few hooks doEentry rst sets the pend eld of the entry to in — system th—t f—™ilit—te testingF es illusE t —nd then resets it to ree™t whether the test tr—ted in the se™tionD the use of the v—riE h—s su™™eeded ™—uses the pend eld to rem—in t —˜le Bde˜ugB —nd the —sso™i—ted throw m—kes it when — test is —˜ortedF possi˜le to test the error ™he™king done ˜y rt fe™—use it does — lot of outputD doEentries without ™—using error ˜re—ks —t testing timeF looks ™omplexF roweverD it —™tu—lly does little pigure P shows the ™ode for running testsF more th—n ™—ll doEentry on e—™h pending testF ix™ept for the form—t ™ontrol strings|whi™hD st w—s de™ided th—t gontinueEtesting did —s —lw—ysD —re ™onvenient ˜ut ins™rut—˜le|most not need to h—ve — stre—m —rgumentD ˜e™—use of the ™ode is self expl—n—toryF xeverthelessD — ™ontinueEtesting is only useful when using rt ™ouple of points —re interestingF inter—™tivelyF „he ™—t™h set up ˜y doEentry is used ˜y yne might ˜e moved to s—y th—t the ™ode in ™ontinueEtesting to —˜ort out of — test th—t h—s pigures I 8 P is too trivi—l to ˜e —n impressive ™—used —n error ˜re—kF „he v—ri—˜le BinEtestB ex—mple of the power of vispF roweverD this visp elgorithms S

@defun doEtest @8option—l @n—me BtestBAA @defun doEtests @8option—l @doEentry @getEentry n—meAAA @out Bst—nd—rdEoutputBAA @dolist @entry @™dr BentriesBAA @defun doEentry @entry 8option—l @setf @pend entryA tAA @s Bst—nd—rdEoutputBAA @if @stre—mp outA @™—t™h 9BinEtestB @doEentries outA @setq BtestB @n—me entryAA @withEopenEfile @setf @pend entryA tA @stre—m out Xdire™tion XoutputA @letB @@BinEtestB tA @doEentries stre—mAAAA @B˜re—kEonEw—rningsB tA @r @multipleEv—lueElist @defun doEentries @sA @ev—l @form entryAAAAA @form—t s 4~8hoing ~e pending test~X€ ~ @setf @pend entryA of ~e tests tot—lF~74 @not @equ—l r @v—ls entryAAAA @™ount t @™dr BentriesBA @when @pend entryA Xkey 59pendA @form—t s 4~8„est ~Xd@~ƒ~A f—iled~ @length @™dr BentriesBAAA ~7pormX ~ƒ~ @dolist @entry @™dr BentriesBAA ~7ixpe™ted v—lue~€X ~ @when @pend entryA ~f~ƒ~”~7~IUt~g~ @form—t s 4~d‘~`~7~XY ~Xd@~ƒ~A~b~“4 ~7e™tu—l v—lue~€X ~ @doEentry entry sAAAA ~f~ƒ~”~7~ISt~gF~74 @let @@pending @pendingEtestsAAA BtestB @form entryA @if @null pendingA @length @v—ls entryAA @form—t s 4~8xo tests f—iledF4A @v—ls entryA @form—t s 4~8~e out of ~e ~ @length rA rAAAA tot—l tests f—iledX ~ @when @not @pend entryAA BtestBAA ~Xd@~f~`~7 ~IXY~ƒ~b~ ~”D ~g~AF4 @defun ™ontinueEtesting @A @length pendingA @if BinEtestB @length @™dr BentriesBAA @throw 9BinEtestB nilA pendingAA @doEentries Bst—nd—rdEoutputBAAA @null pendingAAA

pigure PX „he ™ode for the p—rt of rt th—t performs testsF would ˜e t—king too n—rrow — viewF „he imE inter—™tive running of individu—l test ™—ses —nd pressive thing —˜out pigures I 8 P is not wh—t reporting of the resultsD — userEinterf—™e modE they ™ont—inD ˜ut wh—t the do not h—ve to ™onE ule would h—ve to ˜e writtenF „o go ˜eyond this t—inF sn p—rti™ul—rD most of wh—t you would —nd —llow the inter—™tive @reAdenition of testsD h—ve to write to implement rt in other l—nE some es™—pe to the surrounding oper—ting sysE gu—ges is provided ˜y the visp environment —nd tem would ˜e required to —™™ess the ™ompilerF does not h—ve to ˜e written —t —llF „o t—ke the n—l step of —llowing the testing gonsider wh—t it would ˜e like to impleE of — system to ˜e intermixed with de˜uggingD ment rt in — l—ngu—ge su™h —s ed—F fe™—use the implement—tion would h—ve to ˜e ˜uilt —s of the strong typing in ed—D one would pro˜E —n extension to —n inter—™tive progr—mming enE —˜ly ˜e prevented from t—king the simple —pE vironmentF vike —ny visp systemD rt gets the pro—™h of storing e—™h test —s — ™om˜in—tion of ˜enet of this —t no ™ost to the implementor — testing fun™tion to ™—ll —nd — group of d—t— wh—teverF v—luesF ‚—therD one would pro˜—˜ly h—ve to en ix—mple „est ƒuite dene e—™h test —s — sep—r—te fun™tion of no —rgumentsF „his would —llow you to use the ‚eturning to the question of how rt ™—n st—nd—rd ed— ™ompiler to prep—re the tests for ˜est ˜e usedD ™onsider pigure QD whi™h shows exe™utionY howeverD you would h—ve to write the ˜eginnings of — test suite for rt itselfF „here some —mount of ™ode outside of ed— @eFgFD shell is — ˜it of gr—tuitous ™omplexity ˜e™—use the s™ripts in — systemA to m—n—ge the pro™ess system is ˜eing used to test itselfF xeverthelessD of dening —nd running testsF the gure is — good ex—mple of wh—t — typi™—l por —n ed— implement—tion to support the test suite looks likeF „he rst three lines of the T ‚FgF ‡—ters

@inEp—™k—ge 4 ƒi‚4A gure spe™ify th—t the test suite is in the 4 ƒi‚4 @require 4‚„4A p—™k—ge —nd prep—re rt for useF @useEp—™k—ge 4‚„4A „he fun™tion setup is used ˜y the tests to @defm—™ro setup @8rest ˜odyA ™re—te — s—fe environment where experiments –@doEsetup 9@progn FD ˜odyAAA ™—n ˜e performed without —e™ting the overE @defun doEsetup @formA —ll test suite in the gureF sn prep—r—tion for @let @@BtestB nilA these experimentsD setup denes two ex—mple @BdoEtestsEwhenEdefinedB nilA @rtXXBentriesB @list nilAA tests @tI —nd @t PAAF ƒetup ™—ptures —ny outE @rtXXBde˜ugB tA put ™re—ted ˜y form in — string —nd returns — resultA list of the lines of output —s its rst v—lueF ƒetup @deftest tI R RA @deftest @t PA R QA ˜inds rtXXBde˜ugB to t @see pigure IA —nd inE @v—lues ™ludes —n —ppropri—te ™—t™h so th—t the error @norm—lize ™he™king done ˜y rt ™—n ˜e testedF @withEoutputEtoEstring @Bst—nd—rdEoutputBA „he fun™tion norm—lize over™omes — minor @setq result pro˜lem in the port—˜ility of gommon vispF @™—t™h 9rtXXBde˜ugB ƒever—l of the form—t ™ontrol strings in doEentry @ev—l formAAAAA resultAAA —nd doEentries use the ™ontrol ™ode ~8 @see pigure PAF nfortun—telyD while this is ˜etter @defun norm—lize @stringA @let @@l nilAA th—n ~7 in m—ny situ—tionsD it is not gu—r—nE @withEinputEfromEstring @s stringA teed to ˜eh—ve dierentlyD —nd gommon visp @loop @push @re—dEline s nil sA lA @when @eq @™—r lA sA implement—tions v—ry widely in wh—t they doF @setq l @nreverse @™dr lAAA xorm—lize removes —ny ˜l—nk lines th—t result @return nilAAAA from ~8 —™ting like ~7F @delete 44 l Xtest 59equ—lAAA „he rst ve tests in pigure Q test the fun™E @remE—llEtestsA tion getEtestF iven for this trivi—l fun™tionD @deftest getEtestEI sever—l tests —re required to get re—son—˜le ™ovE @setup @getEtest 9tIAA er—ge of its ™—p—˜ilitiesF qetEtestESD ™he™ks @A @tI R RAA @deftest getEtestEP th—t getEtest reports —n error when given the @setup @getEtest 9tIA BtestBA n—me of — nonEexistent testF @A @t PAA „he l—st three tests in pigure Q test the fun™E @deftest getEtestEQ @setup @getEtest 9@t PAAA tion doEtestF „he full test suite for rt ™ont—ins @A @@t PA R QAA sever—l more tests of getEtest —nd doEtestsD @deftest getEtestER —nd some twenty more tests over—llF @setup @let @@BtestB 9tIAA @getEtestAAA @A @tI R RAA e™knowledgments @deftest getEtestES @setup @getEtest 9tHAA „he ™on™ept of regression testing is —n old @4xo test with n—me „HF4A nilA oneD —nd m—ny @if not mostA l—rge progr—mming @deftest doEtestEI org—niz—tions h—ve regression testersF rt is the @setup @doEtest 9tIAA @A tIA result of ten ye—rs of pr—™ti™—l use —nd evoluE @deftest doEtestEP tionF w—ny of the ide—s in it ™—me from ™onverE @setup @doEtest 9tIA BtestBA s—tions with gh—rles ‚i™h —nd uent €itm—nD @A tIA @deftest doEtestEQ who implemented simil—r systemsF @setup @doEtest 9@t PAAA „his p—per des™ri˜es rese—r™h done —t the @4„est @„ PA f—iled4 mit —i v—˜or—toryF ƒupport w—s provided ˜y 4pormX R4 4ixpe™ted v—lueX Q4 d—rp—D nsfD i˜mD nynexD ƒiemensD ƒperryD —nd 4e™tu—l v—lueX RF4A m™™F „he views —nd ™on™lusions presented here nilA —re those of the —uthor —nd should not ˜e interE preted —s representing the poli™iesD expressed or pigure QX ƒome tests of rt itselfF impliedD of these org—niz—tionsF visp elgorithms U

y˜t—ining ‚„ rt is written in port—˜le gommon visp —nd h—s ˜een tested in sever—l dierent gommon visp implement—tionsF „he ™omplete sour™e for rt is shown in pigures I{PF sn —dditionD the sour™e ™—n ˜e o˜t—ined over the internet ˜y using ftpF gonne™tion should ˜e m—de to the p„€FesFws„Fih m—™hine @internet numE ˜er IPVFSPFQPFTAF vogin —s ’—nonymous4 —nd ™opy the les shown ˜elowF st is —dvis—˜le to run the tests in rtEtestFlisp —fter ™ompiling rt for the rst time on — new systemF

sn the dire™tory Gpu˜GlptrsG rtFlisp sour™e ™ode rtEtestFlisp test suite reEdo™Ftxt ˜rief do™ument—tion

„he ™ontents of pigures I 8 P —nd the les —˜ove —re ™opyright IWWH ˜y the w—ss—™husetts snstitute of „e™hnologyD g—m˜ridge weF €erE mission to useD ™opyD modifyD —nd distri˜ute this softw—re for —ny purpose —nd without fee is here˜y gr—ntedD provided th—t this ™opyright —nd permission noti™e —ppe—r in —ll ™opies —nd supporting do™ument—tionD —nd th—t the n—mes of ws„ —ndGor the —uthor —re not used in —dE vertising or pu˜li™ity pert—ining to distri˜ution of the softw—re without spe™i™D written prior permissionF ws„ —nd the —uthor m—ke no repE resent—tions —˜out the suit—˜ility of this softE w—re for —ny purposeF st is provided ’—s is4 without express or implied w—rr—ntyF ws„ —nd the —uthor dis™l—im —ll w—rr—nties with reg—rd to this softw—reD in™luding —ll imE plied w—rr—nties of mer™h—nt—˜ility —nd tnessD in no event sh—ll ws„ or the —uthor ˜e li—˜le for —ny spe™i—lD indire™t or ™onsequenti—l d—mE —ges or —ny d—m—ges wh—tsoever resulting from loss of useD d—t— or protsD whether in —n —™tion of ™ontr—™tD negligen™e or other tortious —™tionD —rising out of or in ™onne™tion with the use or perform—n™e of this softw—reF V ‚FgF ‡—ters visp elgorithms W

PF hetermining the gover—ge of — „est ƒuite

‚i™h—rd gF ‡—ters

„he v—lue of — suite of test ™—ses depends —ny test suite th—t f—ils to exer™ise the ™ondition ™riti™—lly on its ™over—geF sde—lly — suite should where y is neg—tive will f—il to dete™t the ˜ug in test every f—™et of the spe™i™—tion for — proE the next to l—st line of the fun™tionF gr—m —nd every f—™et of the —lgorithms used @es —n ex—mple of the f—™t th—t ™overing to implement the spe™i™—tionF nfortun—telyD —ll the ™onditions in — progr—m does not gu—rE there is no pr—™ti™—l w—y to ˜e sure th—t ™omE —ntee th—t every f—™et of either the —lgorithm plete ™over—ge h—s ˜een —™hievedF roweverD or the spe™i™—tion will ˜e ™overedD ™onsider something should ˜e done to —ssess the ™overE the f—™t th—t the two test ™—ses @myB PFI QA —ge of — test suiteD ˜e™—use — test suite with —nd @myB EIGP EIGPA ™over —ll four ™onditionsF poor ™over—ge h—s little v—lueF roweverD they do not dete™t the ˜ug on the e tr—dition—l —pproxim—te method of —ssessE next to l—st line —nd they do not dete™t the f—™t ing the ™over—ge of — test suite is to ™he™k th—t th—t myB f—ils to work on ™omplex num˜ersFA every ™ondition tested ˜y the progr—m is exerE „he ™over system determines whi™h ™onE ™isedF por every predi™—te in the progr—mD there ditions tested ˜y — progr—m —re exer™ised ˜y — should ˜e —t le—st one test ™—se th—t ™—uses the given test suiteF „his is no su˜stitute for thinkE predi™—te to ˜e true —nd one th—t ™—uses it to ing h—rd —˜out the ™over—ge of the test suiteF ˜e f—lseF gonsider the fun™tion myB in pigure RD roweverD it provides — useful st—rting point —nd whi™h uses — ™onvoluted —lgorithm to ™ompute ™—n indi™—te some —re—s where —ddition—l test the produ™t of two num˜ersF ™—ses should ˜e devisedF „he fun™tion myB ™ont—ins two predi™—tesD @minusp xA —nd @minusp yAD whi™h le—d to four ser9s w—nu—l for gy†i‚ ™onditionsX x is neg—tiveD x is not neg—tiveD y is neg—tiveD —nd y is not neg—tiveF „o ˜e —t —ll „he fun™tionsD m—™rosD —nd v—ri—˜les th—t thoroughD — test suite must ™ont—in tests exerE m—ke up the ™over system —re in — p—™k—ge ™ising —ll four of these ™onditionsF por inst—n™eD ™—lled 4gy†i‚4F „he six exported sym˜ols —re do™umented ˜elowF

@defun myB @x yA @let @@sign IAA  ™overX—nnot—te tEorEnil @when @minusp xA @setq sign @E signAA iv—lu—ting @™overX—nnot—te tA triggers the @setq x @E xAAA pro™essing of fun™tion —nd m—™ro denitions ˜y @when @minusp yA the ™over systemF i—™h su˜sequent inst—n™e @setq sign @E signAA @setq y @E xAAA of defun or defm—™ro is —ltered ˜y —dding —nE @B sign x yAAA not—tion th—t m—int—ins inform—tion —˜out the v—rious ™onditions tested in the ˜odyF pigure RX en ex—mple progr—mF iv—lu—ting @™overX—nnot—te nilA stops the IH ‚FgF ‡—ters

spe™i—l pro™essing of fun™tion —nd m—™ro deE @setq ™overXBlineElimitB RQA A RQ nitionsF ƒu˜sequent denitions —re not —nnoE @™overXresetA A „ t—tedF roweverD if — fun™tion or m—™ro th—t is @™overXreportA A Y —fter printingX ™urrently —nnot—ted is redenedD the new deE YE X‚iegr @hip x w‰B @ˆ ‰AA `Ib nition is —nnot—ted —s wellF @myB P PA A R „he m—™ro ™overX—nnot—te should only ˜e used —s — topElevel formF ‡hen —nnot—tion is @™overXreportA A Y —fter printingX YC X‚iegr @hip x w‰B @ˆ ‰AA `Ib triggeredD — w—rning mess—ge is printedD —nd t Y C X‚iegr @‡rix @wsx ƒ€ ˆA @ƒi„ ƒ `Pb is returnedF ytherwiseD nil is returnedF Y E XxyxEx vv @wsx ƒ€ ˆA `Rb Y C X‚iegr @‡rix @wsx ƒ€ ‰A @ƒi„ ƒ `Tb @™overX—nnot—te tA A tY—fter printingX Y E XxyxEx vv @wsx ƒ€ ‰A `Vb YYY ‡—rningX gover—ge —nnot—tion —ppliedF @myB EP PA A ER  ™overXforgetE—ll @™overXreportA A Y —fter printingX YC X‚iegr @hip x w‰B @ˆ ‰AA `Ib „his fun™tionD whi™h —lw—ys returns tD h—s Y C X‚iegr @‡rix @wsx ƒ€ ‰A @ƒi„ ƒ `Tb the ee™t of removing —ll ™over—ge —nnot—tion Y E XxyxEx vv @wsx ƒ€ ‰A `Vb from every fun™tion —nd m—™roF st is —pproE @™overXreport X—ll tA A Y —fter printingX pri—te to do this ˜efore ™ompletely re™ompiling YC X‚iegr @hip x w‰B @ˆ ‰AA `Ib Y C X‚iegr @‡rix @wsx ƒ€ ˆA @ƒi„ ƒ `Pb the system ˜eing tested or ˜efore swit™hing to Y C XxyxEx vv @wsx ƒ€ ˆA `Rb — dierent system to ˜e testedF Y C Xx vv @wsx ƒ€ ˆA `Sb Y C X‚iegr @‡rix @wsx ƒ€ ‰A @ƒi„ ƒ `Tb  ™overXreset Y E XxyxEx vv @wsx ƒ€ ‰A `Vb Y C Xx vv @wsx ƒ€ ‰A `Wb i—™h ™ondition tested ˜y —n —nnot—ted fun™E tion —nd m—™ro is —sso™i—ted with — —g th—t pigure SX ix—mple ™over reportsF trips when the ™ondition is exer™isedF „he fun™E tion ™overXreset resets —ll these —gsD —nd reE turns tF st is —ppropri—te to do this ˜efore reE trun™—ted to ensure th—t it is no wider th—n running — test suite to reev—lu—te its ™over—geF ™overXBlineElimitBF en ex—mpleF ƒuppose th—t the fun™tion  ™overXreport 8key fn out —ll myB in pigure R h—s ˜een —nnot—ted —nd th—t no „his fun™tion displ—ys the inform—tion m—inE other fun™tions or m—™ros h—ve ˜een —nnot—tedF t—ined ˜y ™overD returning no v—luesF pn must pigure S illustr—tes the oper—tion of ™over —nd ˜e the n—me of —n —nnot—ted fun™tion or m—™roF the reports printed ˜y ™overXreportF sf fn is spe™iedD — report is printed showing inE i—™h line in — report ™ont—ins three pie™es of form—tion —˜out th—t fun™tion or m—™ro onlyF inform—tion —˜out — point in — denitionX CGE ytherwiseD reports —re printed —˜out every —nE spe™ifying th—t the point either h—s @CAorh—s not—ted fun™tion —nd m—™roF not @EA ˜een exer™isedD — mess—ge indi™—ting the yutD whi™h def—ults to Bst—nd—rdEoutputBD physi™—l —nd logi™—l pl—™ement of the point in must either ˜e —n output stre—m or the n—me the denitionD —nd in —ngle ˜r—™kets `bD —n inE of — leF st spe™ies where the reports should teger th—t is — unique identier for the pointF ˜e printedF sndent—tion is used to indi™—te th—t some points sf —llD whi™h def—ults to nilD is nonEnull then —re su˜ordin—te to others in the sense th—t the the reports printed ™ont—in inform—tion —˜out su˜ordin—te points ™—nnot ˜e exer™ised without every ™onditionF ytherwiseD the reports —re —˜E —lso exer™ising their superiorsF „he order of the ˜revi—ted to highlight key ™onditions th—t h—ve lines of the report is the s—me —s the order of not ˜een exer™isedF the points in the denitionF i—™h mess—ge ™ont—ins — l—˜el @eFgFD X‚iegrD  ™overXBlineElimitB def—ult v—lue US Xx vvA —nd — pie™e of ™odeF „here is — point l—E „he output produ™ed ˜y ™overXreport is ˜eled X‚iegr ™orresponding to e—™h denition —s visp elgorithms II

— whole —nd e—™h ™ondition—l form within e—™h ell inform—tion —˜out the spe™ied points @—nd denitionF ƒu˜ordin—te points ™orresponding their su˜ordin—tesA is forgottenF prom the point to the ™onditions — ™ondition—l form tests —re of view of ™overXreportD the ee™t is —s if the grouped under the point ™orresponding to the points never existedF @e forgotten point ™—n formF es dis™ussed in det—il in the next su˜se™E ˜e retrieved ˜y reev—lu—ting or re™ompiling the tionD the mess—ges for the su˜ordin—te points fun™tion or m—™ro denition ™ont—ining itFA „he des™ri˜e the situ—tions in whi™h the ™onditions ex—mple ˜elowD whi™h follows on —fter the end —re exer™isedF vines th—t would otherwise ˜e of pigure SD shows the —™tion of ™overXforgetF too long to t on one line h—ve their mess—ges trun™—ted @eFgFD points `Pb —nd `Tb in pigure SAF @™overXforget TA A „ „he rst three reports in pigure S —re —˜E @™overXreport X—ll tA A Y —fter printingX ˜revi—ted ˜—sed on two prin™iplesF pirstD if — YC X‚iegr @hip x w‰B @ˆ ‰AA `Ib Y C X‚iegr @‡rix @wsx ƒ€ ˆA @ƒi„ ƒ `Pb point p —nd —ll of its su˜ordin—tes h—ve ˜een Y C XxyxEx vv @wsx ƒ€ ˆA `Rb exer™isedD then p —nd —ll of its su˜ordin—tes —re Y C Xx vv @wsx ƒ€ ˆA `Sb omitted from the reportF „his is done to fo™us @™overXreportA A Y —fter printing the user9s —ttention on the points th—t h—ve not Yell points exer™isedF ˜een exer™isedF ƒe™ondD if — point p h—s not ˜een exer™isedD „he —˜˜revi—ted report —˜ove does not deE then —ll of the points su˜ordin—te to it —re omitE s™ri˜e —ny pointsD ˜e™—use every point in myB ted from the reportF „his ree™ts the f—™t th—t th—t h—s not ˜een forgotten h—s ˜een exer™isedF it is not possi˜le for —ny of these su˜ordin—te st is —ppropri—te to forget — point if there is points to h—ve ˜een exer™ised —nd one ™—nnot some re—son th—t no test ™—se ™—n possi˜ly exE devise — test ™—se th—t exer™ises —ny of the su˜E er™ise the pointF roweverD it is mu™h ˜etter to ordin—te points without rst guring out how write your ™ode so th—t every ™ondition ™—n ˜e to exer™ise pF testedF en —ddition—l ™ompli™—ting f—™tor is th—t @€oint num˜ers —re —ssigned ˜—sed on the ™over oper—tes in —n in™rement—l f—shion —nd order in whi™h points —re entered into ™over9s does notD in gener—lD h—ve full inform—tion —˜out d—t—˜—seF sn gener—lD whenever — denition is the su˜ordin—tes of points th—t h—ve not ˜een reev—lu—ted or re™ompiledD the num˜ers of the exer™isedF es — resultD it is not —lw—ys possi˜le points within it ™h—ngeFA to present — ™omplete reportF roweverD one ™—n „he w—y ™ondition—ls —re —nnot—tedF h—ve tot—l ™onden™e th—t if the report s—ys th—t pigure T shows — le th—t m—kes use of ™overF every point h—s ˜een exer™isedD this st—tement pigure U shows the kind of report th—t might ˜e is ˜—sed on ™omplete inform—tionF produ™ed ˜y lo—ding the leF fe™—useD m—y˜eE „he rst report in pigure S shows th—t none —nd g —re the only denitions th—t h—ve ˜een of the points within myB h—s ˜een exer™isedF „he —nnot—tedD these —re the only denitions th—t se™ond report displ—ys most of the points in myBD —re reported onF „he order of the reports is to set the ™ontext for the two points th—t h—ve the s—me —s the order in whi™h the denitions not ˜een exer™isedF „he third report omits `Pb were ™ompiledF „he report on g indi™—tes th—t —nd its su˜ordin—tesD sin™e they h—ve —ll ˜een the tests performed ˜y runEtests exer™ise most exer™isedF „he fourth report shows — ™omplete of the ™onditions tested ˜y gF roweverD they report ™orresponding to the third —˜˜revi—ted do not exer™ise the situ—tion in whi™h the ™—se reportF st—tement is re—™hedD ˜ut neither of its ™l—uses is sele™tedF  ™overXforget 8rest ids „here —re no points within m—y˜eED ˜e™—use „his fun™tion gives the user gre—ter ™onE the ™ode for m—y˜eE does not ™ont—in —ny ™onE trol over the reports produ™ed ˜y ™overXreportF dition—l formsF st is interesting to ™onsider the i—™h id must ˜e —n integer identifying — pointF pre™ise points th—t ™over in™ludes for gF IP ‚FgF ‡—ters

@inEp—™k—ge 4 ƒi‚4A YC X‚iegr @hipweg‚y we‰fiE @ˆ ‰AA `Ib YC X‚iegr @hip x q @ˆ ‰AA `Pb @require 4gy†i‚4 FFFA Y C X‚iegr @gyxh @@exh 5 ‰A ‰A @‰ @ `Qb @defm—™ro m—y˜eC @x yA Y C X‚iegr @exh @x vv ˆA ‰A `Wb –@if @num˜erp DxA @C Dx DyAAA Y C Xps‚ƒ„Ex vv @x vv ˆA `IIb Y C Xi†evEevv ‰ `IPb @™overX—nnot—te tA Y C Xps‚ƒ„ExyxEx vv @exh @x vv ˆA `Sb @defm—™ro m—y˜eE @x yA Y C Xps‚ƒ„ExyxEx vv ‰ `Ub –@if @num˜erp DxA @E Dx DyAAA Y C X‚iegr @geƒi ‰ @I @we‰fiE ˆ ‰ `IQb Y C Xƒivig„ I `ISb @defun g @x yA Y C X‚iegr @sp @x wfi‚€ ˆA @E ˆ `IVb @™ond @@—nd @null xA yA yA Y C XxyxEx vv @x wfi‚€ ˆA `PHb @y @™—se y Y C Xx vv @x wfi‚€ ˆA `PIb @I @m—y˜eE x yAA Y C Xƒivig„ P `ITb @P @m—y˜eC x yAAAAAA Y E Xƒivig„Exyxi `IUb Y C XevvEx vv `Vb @™overX—nnot—te nilA @defun h @x yA FFFA pigure UX „he report ™re—ted ˜y pigure TF @™overXresetA @runEtestsA „here —re two su˜points ™orresponding to the @™overXreport Xout 4report4 X—ll tA two ™l—uses of the ™—seF sn —dditionD sin™e the l—st ™l—use does not ˜egin with t or otherwiseD pigure TX ix—mple of — le using ™overF there is —n —ddition—l point ™orresponding to the situ—tion where none of the ™l—uses of the —re exe™utedF ‡hen ™over pro™esses — denitionD — ™lusE ™—se „he p—ttern of mess—ges —sso™i—ted with — ter of points is gener—ted ™orresponding to e—™h ™ond is illustr—ted ˜y the portion @reprodu™ed ™ondition—l form @iFeFD ifD whenD untilD ™ondD ˜elowA of pigure U th—t des™ri˜es the ™ond in gF ™—seD type™—seD —ndD —nd orA th—t is liter—lly present in the progr—mF sn —dditionD points —re Y C X‚iegr @gyxh @@exh 5 ‰A ‰A @‰ @ `Qb gener—ted ™orresponding to ™ondition—l forms Y C X‚iegr @exh @x vv ˆA ‰A `Wb th—t —re produ™ed ˜y m—™ros th—t —re —nnot—ted Y C Xps‚ƒ„ExyxEx vv @exh @x vv ˆA `Sb Y C Xps‚ƒ„ExyxEx vv ‰ `Ub @eFgFD the if produ™ed ˜y the m—y˜eE in the rst Y C XevvEx vv `Vb ™—se ™l—use in gAF roweverD —nnot—tion is not —pplied to ™ondition—ls th—t ™ome from other „here —re su˜ordin—te points ™orresponding to sour™es @eFgFD from m—™ros th—t —re dened outE the two ™l—uses —nd the situ—tion where neither side of the system ˜eing testedAF „hese ™ondiE ™l—use is exe™utedF „here is —lso — point `Wb tion—ls —re omittedD ˜e™—use there is no re—sonE ™orresponding to the —nd th—t is the predi™—te —˜le w—y for the user to know how they rel—te of the rst ™ond ™l—useF „his point is pl—™ed to the ™odeD —nd therefore there is no re—sonE dire™tly under `QbD ˜e™—use it is not su˜ordin—te —˜le w—y for the user to devise — test ™—se th—t to —ny of the individu—l ™ond ™l—usesF will exer™ise themF „he tre—tment of —nd @—nd orA is p—rti™uE „he mess—ges —sso™i—ted with — point9s su˜E l—rly interestingF ƒometimes —nd is used —s — ordin—tes des™ri˜e the situ—tions under whi™h ™ontrol ™onstru™t on — p—r with ™ondF sn th—t the su˜ordin—tes —re exer™isedF „he p—ttern of situ—tionD it is ™le—r th—t —nd should ˜e tre—ted mess—ges —sso™i—ted with ™—se —nd type™—se is —n—logously to ™ondF roweverD —t other timesD illustr—ted ˜y the portion @reprodu™ed ˜elowA —nd is used to ™ompute — v—lue th—t is tested of pigure U th—t des™ri˜es the ™—se in gF ˜y —nother ™ondition—l formF sn th—t situ—tionD ™over ™ould ™hoose to tre—t —nd —s — simple Y C X‚iegr @geƒi ‰ @I @we‰fiE ˆ ‰ `IQb fun™tionF roweverD it is nevertheless still re—E Y C Xƒivig„ I `ISb Y C Xƒivig„ P `ITb son—˜le to think of —n —nd —s h—ving ™ondition—l Y E Xƒivig„Exyxi `IUb points th—t ™orrespond to dierent re—sons why visp elgorithms IQ the —nd returns — true or f—lse v—lueF st is wise in the hit eld of the pointF „his method of opE to in™lude tests ™orresponding to e—™h of these er—tion m—kes it possi˜le to reset the hit —gs dierent re—sonsF of —ll the points ™urrently in existen™e withE „he p—ttern of mess—ges —sso™i—ted with —n out visiting —ny of them @see the denition of —nd is illustr—ted ˜y the portion @reprodu™ed ™overXresetAF ˜elowA of pigure U th—t des™ri˜es the —nd in gF „he id is printed in reports —nd used to identify points when ™—lling ™overXforgetF „he @™overXreport X—ll tA v—ri—˜le B™ountB is used to gener—te the v—luesF Y C X‚iegr @exh @x vv ˆA ‰A `Wb Y C Xps‚ƒ„Ex vv @x vv ˆA `IIb „he st—tus ™ontrols the reporting of — pointF Y C Xi†evEevv ‰ `IPb st is either Xƒry‡ @shown in reportsAD Xrshhix @not shown in reportsD ˜ut its su˜ordin—tes m—y „he n—l su˜point ™orresponds to the situ—tion ˜eAD or Xpy‚qy„„ix @neither it nor its su˜orE where —ll of the —rguments of the —nd h—ve ˜een din—tes —re shown in reportsAF @™overXforget ev—lu—tedF „he —nd then returns wh—tever the ™h—nges the st—tus of the indi™—ted points to n—l —rgument returnedF Xpy‚qy„„ixFA pigure T illustr—tes — ˜—t™hEoriented use of „he n—me of — point p des™ri˜es its position ™overF roweverD ™over is most ee™tively in the denition ™ont—ining itF e n—me h—s the used in —n inter—™tive w—yF st is re™ommended formX @l—˜el ™ode F superiorEn—meA where l—E th—t you rst ™re—te —s ™omprehensive — test ˜el is —n expl—n—tory l—˜el su™h —s X‚iegr or suite —s you ™—n —nd ™—pture it using — tool su™h Xx vvD ™ode is — pie™e of ™odeD —nd superiorE —s rt ‘I“F „he tests should then ˜e run in ™onE n—me is the n—me of the point ™ont—ining p @if jun™tion with ™over —nd repe—ted reports from —nyAF „—ken togetherD the l—˜el —nd ™ode inE ™over gener—ted —s —ddition—l tests —re ™re—ted di™—te the position of p in — denition —nd the until ™omplete ™over—ge of ™onditions h—s ˜een ™ondition under whi™h it is exer™ised @see the —™hievedF „o ro˜ustly support this mode of opE dis™ussion of pigure UAF er—tionD ™over h—s ˜een ™—refully designed so et —ny given momentD the v—ri—˜le BpointsB th—t it will work with ˜—t™hE™ompiled deniE ™ont—ins — list of points ™orresponding to the tionsD in™rement—llyE™ompiled denitionsD —nd —nnot—ted denitions known to ™overF @„he interpreted denitionsF fun™tion ™overXforgetE—ll resets BpointsB to nilFA es —n illustr—tion of the point d—t— stru™E row gy†i‚ ‡orks tureD pigure W shows the ™ontents of BpointsB „he ™ode for ™over is shown in pigures VD ™orresponding to the se™ond report in pigure SF IHD IID —nd IQF pigure V shows the denition of st is —ssumed th—t BhitB h—s the v—lue IF the prim—ry d—t— stru™ture used ˜y ™over —nd „he fun™tion —ddEtopEpoint —dds — new topE some of the ™entr—l oper—tionsF e point stru™E level point ™orresponding to — denition to the ture ™ont—ins ve pie™es of inform—tion —˜out — list BpointsBF sf there is —lre—dy — point for position in the ™ode for — denitionF the denitionD the new point is put in the s—me pl—™e in the listF hit pl—g indi™—ting whether the point „he fun™tion re™ordEhit re™ords the f—™t h—s ˜een exer™isedF th—t — point h—s ˜een exer™isedF „his m—y id nique integer identierF require lo™—ting the point in BpointsB using st—tus pl—g th—t ™ontrols reportingF lo™—te or —dding the point into BpointsB usE n—me vogi™—l n—meF ing —ddEpointF re™ordEhit is optimized so th—t su˜s vist of su˜ordin—te pointsF it is extremely f—st when the point h—s —lre—dy ˜een exer™isedF „his —llows ™over to run with „he hit —g oper—tes —s — ’time st—mp4F rel—tively little overhe—dF @„he det—ils of the ‡hen — point is exer™isedD this is re™orded ˜y w—y re™ordEhit —nd —ddEpoint oper—te —re disE storing the ™urrent v—lue of the v—ri—˜le BhitB ™ussed further in ™onjun™tion with pigure IQFA IR ‚FgF ‡—ters

@inEp—™k—ge 4gy†i‚4 Xuse 9@4vsƒ€4AA @lispXdefun —ddEtopEpoint @pA @setq p @™opyEtree pAA @provide 4gy†i‚4A @let @@old @find @fnEn—me pA BpointsB @sh—dow 9@defun defm—™roAA Xkey 59fnEn—meAAA @™ond @old @setf @id pA @id oldAA @export 9@—nnot—te report reset forget @nsu˜stitute p old BpointsBAA forgetE—ll BlineElimitBAA @t @setf @id pA @in™f B™ountBAA @defstru™t @point @X™on™En—me nilA @setq BpointsB @Xtype listAA @n™on™ BpointsB @hit HA @list pAAAAAAA @id nilA @lispXdefun re™ordEhit @pA @st—tus XshowA @unless @a @hit pA BhitBA @n—me nilA @setf @hit pA BhitBA @su˜s nilAA @let @@old @lo™—te @n—me pAAAA @defv—r B™ountB HA @if old @defv—r BhitB IA @setf @hit oldA BhitBA @defv—r BpointsB nilA @—ddEpoint pAAAAA @defv—r B—nnot—tingB nilA @lispXdefun lo™—te @n—meA @defv—r BtestingB nilA @find n—me @lispXdefun forget @8rest idsA @if @not @™dr n—meAA @forgetI ids BpointsBA BpointsB tA @let @@p @lo™—te @™dr n—meAAAA @if p @su˜s pAAAA @lispXdefun forgetI @n—mes psA Xkey 59n—me Xtest 59equ—lAA @dolist @p psA @when @mem˜er @id pA n—mesA @lispXdefun —ddEpoint @pA @setf @st—tus pA XforgottenAA @let @@sup @lo™—te @™dr @n—me pAAAAA @forgetI n—mes @su˜s pAAAA @when sup @setq p @™opyEtree pAA @lispXdefun forgetE—ll @A @setf @su˜s supA @setq BpointsB nilA @n™on™ @su˜s supA @list pAAA @setq BhitB IA @setf @id pA @in™f B™ountBAA @setq B™ountB HA @dolist @p @su˜s pAA tA @setf @id pA @in™f B™ountBAAAAAA @lispXdefun reset @A @in™f BhitBA tA

pigure VX „he ˜—si™ d—t— stru™ture used ˜y ™overF

@@I Xƒry‡ I @5Ia@X‚iegr @hip x w‰B @ˆ ‰AAAA @@P Xƒry‡ I @5Pa@X‚iegr @‡rix @wsx ƒ€ ˆA @ƒi„ ƒsqx @E ƒsqxAA @ƒi„ ˆ @E ˆAAAA 5I5A @@Q Xrshhix I @@X‚iegr @wsx ƒ€ ˆAA 5P5 5I5A xsvA @R Xƒry‡ H @@XxyxEx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvA @S Xƒry‡ I @@Xx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvAAA @T Xƒry‡ I @5Ta@X‚iegr @‡rix @wsx ƒ€ ‰A @ƒi„ ƒsqx @E ƒsqxAA @ƒi„ ‰ @E ˆAAAA 5I5A @@U Xrshhix I @@X‚iegr @wsx ƒ€ ‰AA 5T5 5I5A xsvA @V Xƒry‡ H @@XxyxEx vv @wsx ƒ€ ‰AA 5T5 5I5A xsvA @W Xƒry‡ I @@Xx vv @wsx ƒ€ ‰AA 5T5 5I5A xsvAAAAAA

pigure WX „he ™ontents of BpointsB ™orresponding to the se™ond report in pigure SF

pigure IH shows the ™ode th—t prints reE ennot—ting denitionsF pigure II shows portsF es ™—n ˜e seen ˜y — ™omp—rison of pigE the ™ode th—t ™ontrols the —nnot—tion of deniE ures S —nd WD reports —re — rel—tively str—ightE tions ˜y ™overF „he rst time ™overX—nnot—te forw—rd printout of p—rts of BpointsB with nestE is ™—lledD it uses sh—dowingEimport to inst—ll new ing indi™—ted ˜y indent—tion —nd only the rst denitions for defun —nd defm—™roF ‡hether or p—rt of e—™h point9s n—me shownF „he fun™tion not —nnot—tion is in ee™t is re™orded in the reportP supports the —˜˜revi—tion des™ri˜ed in v—ri—˜le B—nnot—teBF „he v—ri—˜le BtestingB ™onjun™tion with pigure SF is used to m—ke it e—sier to test ™over using visp elgorithms IS

@defv—r BlineElimitB USA @lispXdefun reportP @pA @™—se @st—tus pA @pro™l—im 9@spe™i—l BdepthB B—llB @Xforgotten nilA BoutB BdoneBAA @Xhidden @m—p™ 59reportP @su˜s pAAA @lispXdefun report @Xshow @8key @fn nilA @™ond @@report—˜leEsu˜s pA @out Bst—nd—rdEoutputBA @reportQ pA @—ll nilAA @let @@BdepthB @IC BdepthBAAA @let @pA @m—p™ 59reportP @su˜s pAAAA @™ond @@report—˜le pA @@not @stre—mp outAA @reportQ pAAAAAA @withEopenEfile @lispXdefun report—˜le @pA @s out Xdire™tion XoutputA @—nd @eq @st—tus pA XshowA @report Xfn fn X—ll —ll Xout sAAA @or B—llB @@null BpointsBA @not @a @hit pA BhitBAAAAA @form—t out 4~7xo definitions —nnot—tedF4AA @lispXdefun report—˜leEsu˜s @pA @@not fnA @—nd @not @eq @st—tus pA XforgottenAA @reportI BpointsB —ll outAA @or B—llB @not @report—˜le pAAA @@setq p @find fn BpointsB @some 59@l—m˜d— @sA Xkey 59fnEn—meAA @or @report—˜le sA @reportI @list pA —ll outAA @report—˜leEsu˜s sAAA @t @form—t out 4~7~e is not —nnot—tedF4 @su˜s pAAAA fnAAAA @v—luesAA @lispXdefun reportQ @pA @setq BdoneB nilA @lispXdefun fnEn—me @pA @letB @@BprintEprettyB nilA @let @@form @™—dr @™—r @n—me pAAAAA @BprintElevelB QA @—nd @™onsp formA @BprintElengthB nilA @™onsp @™dr formAA @m @form—t nil @™—dr formAAAA 4Y~†d„~X‘E~YC~“~f ~ƒ~g4 BdepthB @lispXdefun reportI @ps B—llB BoutBA @a @hit pA BhitBA @let @@BdepthB HA @BdoneB tAA @™—r @n—me pAAAA @m—p™ 59reportP psA @limit @E BlineElimitB VAAA @when BdoneB @when @b @length mA limitA @form—t BoutB @setq m @su˜seq m H limitAAA 4~7Yell points exer™isedF4AAAA @form—t BoutB 4~7~e `~ƒb4 m @id pAAAA pigure IHX „he ™ode for the p—rt of ™over th—t prints reportsF

rt ‘I“F into defm—™roF „hey —re indire™tly supported ‚edening defun —nd defm—™ro is — ™onveE ˜y ™overD —s long —s their denitions —re re—d nient —ppro—™h to use for supporting ™overD —fter ™overX—nnot—te h—s ˜een ev—lu—tedF howeverD it is in gener—l — r—ther d—ngerous yn the f—™e of itD it is not ™orre™t to use thing to doF yne pro˜lem is th—t for ™over su˜lis to ren—me forms in ™odeD ˜e™—use every to oper—te ™orre™tlyD ™overX—nnot—te must ˜e inst—n™e of the indi™—ted sym˜ols is ™h—ngedD exe™uted ˜efore —ny of the denitions you wish whether or not they —re —™tu—lly uses of the to —nnot—te —re re—dF por inst—n™eD pigure T indi™—ted forms —nd whether or not they —re in would not work if —n ev—lEwhen were wr—pped quoted listsF xeverthelessD ™over uses su˜lis —round the topElevel forms —s — groupF for two re—sonsF ‡hen —nnot—tion is in ee™tD the new defE pirstD in ™ontr—st to — ™ode w—lkerD su˜lis is initions of defun —nd defm—™ro use su˜lis to very simpleF @„he only underst—nding of visp repl—™e every inst—n™e of ifD ™ondD et™F with speE stru™ture th—t ™over needs is how to sep—r—te ™i—l m—™ros ™EifD ™E™ondD et™F @see pigure IQAF the de™l—r—tions from the ˜ody of — denitionD hening forms ™re—ted ˜y the user @eFgFD def see the fun™tion p—rseE˜odyFA in pigure IQA —re typi™—lly m—™ros th—t exp—nd wost pro˜lems ™—n e—sy ˜e —void ˜y resistE IT ‚FgF ‡—ters

@lispXdefm—™ro —nnot—te @tEorEnilA @defv—r B™he™kB –@ev—lEwhen @ev—l lo—d ™ompileA 9@@or F ™EorA @—nd F ™E—ndA @—nnot—teI DtEorEnilAAA @if F ™EifA @when F ™EwhenA @unless F ™EunlessA @lispXdefun —nnot—teI @fl—gA @™ond F ™E™ondA @™—se F ™E™—seA @sh—dowingEimport @type™—se F ™Etype™—seAAA @setEdifferen™e 9@defun defm—™roA @p—™k—geEsh—dowingEsym˜ols Bp—™k—geBAAA @lispXdefun pro™ess @™def def fn —rgl ˜A @when @—nd fl—g @not BtestingBAA @if @not @or B—nnot—tingB @w—rn 4gover—ge —nnot—tion —ppliedF4AA @find fn @setq B—nnot—tingB @not @null fl—gAAAA BpointsB Xkey 59fnEn—meAAA @lispXdefm—™ro defun @n —rgl 8˜ody ˜A –@Ddef Dfn D—rgl FD ˜A @pro™ess 9defun 9lispXdefun n —rgl ˜AA @multipleEv—lueE˜ind @de™ls ˜A @lispXdefm—™ro defm—™ro @n — 8˜ody ˜A @p—rseE˜ody ˜A @pro™ess 9defm—™ro 9lispXdefm—™ro n — ˜AA @setq ˜ @su˜lis B™he™kB ˜AA @let @@n—me @lispXdefun p—rseE˜ody @˜odyA –@@Xre—™h @let @@de™ls nilAA @D™def Dfn D—rglAAAAA @when @stringp @™—r ˜odyAA –@ev—lEwhen @ev—l lo—d ™ompileA @push @pop ˜odyA de™lsAA @—ddEtopEpoint @loop @unless @—nd @™onsp @™—r ˜odyAA 9D@m—keEpoint Xn—me n—meAA @eq @™——r ˜odyA @Ddef Dfn D—rgl Dd de™ls 9de™l—reAA D@™H @m—keEpoint Xn—me @return nilAA n—meA @push @pop ˜odyA de™lsAA n—me ˜AAAAAAA @v—lues @nreverse de™lsA ˜odyAAA

pigure IIX „he ™ode for the p—rt of ™over th—t —nnot—tes denitionsF

@i†evE‡rix @i†ev vyeh gyw€sviA @gy†i‚XXehhE„y€E€ysx„ 9@xsv Xƒry‡ H @5Ia@X‚iegr @hip x w‰B @ˆ ‰AAAA xsvAA @vsƒ€Xhip x w‰B @ˆ ‰A @gy†i‚XX‚igy‚hErs„ 9@xsv Xƒry‡ H @5I5A xsvAA @vi„ @@ƒsqx IAA @gy†i‚XX‚igy‚hErs„ 9@xsv Xƒry‡ H @5Pa@X‚iegr @‡rix @wsx ƒ€ ˆA @ƒi„ ƒsqx @E ƒsqxAA @ƒi„ ˆ @E ˆAAAA 5I5A @@xsv Xrshhix H @@X‚iegr @wsx ƒ€ ˆAA 5P5 5I5A xsvA @xsv Xƒry‡ H @@XxyxEx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvA @xsv Xƒry‡ H @@Xx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvAAAA @sp @€‚yqx @gy†i‚XX‚igy‚hErs„ 9@xsv Xrshhix H @@X‚iegr @wsx ƒ€ ˆAA 5P5 5I5A xsvAA @wsx ƒ€ ˆAA @€‚yqx @gy†i‚XX‚igy‚hErs„ 9@xsv Xƒry‡ H @@XxyxEx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvAA @ƒi„ ƒsqx @E ƒsqxAA @ƒi„ ˆ @E ˆAAA @€‚yqx @gy†i‚XX‚igy‚hErs„ 9@xsv Xƒry‡ H @@Xx vv @wsx ƒ€ ˆAA 5P5 5I5A xsvAA xsvAA FFFAAA

pigure IPX €—rt of the —nnot—ted denition of myB from pigure RF

ing the tempt—tion to use ifD ™ondD et™F —s v—riE ƒe™ondD the use of su˜lis supports two key —˜le n—mesF eny rem—ining di™ulties ™—n ˜e fe—tures of ™over th—t would ˜e very di™ult toler—ted ˜e™—use ™over is merely p—rt of s™—fE to support using — ™ode w—lkerF st insures th—t folding for testing — system r—ther th—n p—rt of only ™ondition—l forms th—t liter—lly —ppe—r in the system to ˜e deliveredF e su˜tle di™ulty the denition —re —nnot—ted @—s opposed to ones ™on™erns —nd —nd orF „hey —re used —s type th—t ™ome from m—™ro exp—nsionsAD —nd yetD spe™iers —s well —s ™ondition—l formsF „his ™ondition—ls th—t ™ome from the exp—nsion of di™ulty is p—rtly over™ome ˜y the type deE —nnot—ted m—™ros —re —nnot—tedF @xote th—t nitions —t the end of pigure IQF the liter—ls th—t turn into ™ondition—ls in the visp elgorithms IU

@defv—r BfixB @def ™Eif @pred then 8option—l @else nilAA 9@@™Eor F orA @™E—nd F —ndA @™Eif F ifA –@if D@™Ehide predA @™Ewhen F whenA @™Eunless F unlessA D@™ then XnonEnull predA @™E™ond F ™ondA @™E™—se F ™—seA D@™ else Xnull predAAA @™Etype™—se F type™—seAAA @def ™Ewhen @pred 8rest —™tionsA @pro™l—im 9@spe™i—l Bsu˜sB BsupBAA –@if D@™Ehide predA D@™ –@progn FD —™tionsA @lispXdefm—™ro supEm—™ @A nilA XnonEnull predA @lispXdefm—™ro def @n—me —rgs formA D@™ nil Xnull predAAA –@lispXdefm—™ro Dn—me @8whole w Dd —rgs @def ™Eunless @pred 8rest —™tionsA 8environment envA –@if @not D@™Ehide predAA @letB @@Bsu˜sB nilA D@™ –@progn FD —™tionsA Xnull predA @BsupB D@™ nil XnonEnull predAAA –@@Xre—™h D@su˜lis BfixB wAA FD@m—™roexp—ndEI @def ™E™ond @8rest ™sA @list 9supEm—™A envAAA @™E™ondH @gensymA ™sAA @p @m—keEpoint Xn—me BsupBAA @form DformAA @lispXdefun ™E™ondH @v—r ™sA @setf @su˜s pA @nreverse Bsu˜sBAA @™ond @@null ™sA @™ nil X—llEnullAA @™H p BsupB @list formAAAAA @@eq @™——r ™sA tA @™ @if @™d—r ™sA @lispXdefm—™ro ™ @˜ody 8rest msgA –@progn FD@™d—r ™sAA @™I –@list D˜odyA msg XshowAA tA XfirstEnonEnull tAA @lispXdefm—™ro ™Ehide @˜A @@™d—r ™sA @™I –@list D˜A @list Xre—™h ˜A XhiddenAA –@if D@™Ehide @™——r ™sAA D@™ –@progn FD@™d—r ™sAA @ev—lEwhen @ev—l lo—d ™ompileA XfirstEnonEnull @™——r ™sAA @lispXdefun ™I @˜ m sA D@™E™ondH v—r @™dr ™sAAAA –@let @@n @™ons @su˜lis BfixB @t –@let @@Dv—r @list FDmAA D@™Ehide @™——r ™sAAAA BsupBAAA @if Dv—r @push @m—keEpoint Xn—me n Xst—tus DsA D@™ v—r XfirstEnonEnull Bsu˜sBA @™——r ™sAA @™H @m—keEpoint Xn—me n Xst—tus DsA D@™E™ondH v—r n D˜AAA @™dr ™sAAAAAAA @lispXdefun ™H @p sup ˜A @def ™Eor @8rest psA @™EorH psAA –@m—™rolet @@supEm—™ @A 9DsupAA @re™ordEhit 9DpA @lispXdefun ™EorH @psA FD˜AA A @if @null @™dr psAA @™ @™—r psA Xev—lE—ll @™—r psAA @def ™E™—se @key 8rest ™sA @let @@v—r @gensymAAA –@™—se D@™Ehide keyA –@let @@Dv—r D@™Ehide @™—r psAAAA FD@™E™—seH ™sAAA @if Dv—r @def ™Etype™—se @key 8rest ™sA D@™ v—r XfirstEnonEnull –@type™—se D@™Ehide keyA @™—r psAA FD@™E™—seH ™sAAA D@™EorH @™dr psAAAAAAA @lispXdefun ™E™—seH @™sA @def ™E—nd @8rest psA @let @@stuff @m—p™—r 59™E™—seI ™sAAA –@™ond FD@m—plist 59™E—ndH @when @not @mem˜er @™——r @l—st ™sAA @or ps @list tAAAAA 9@t otherwiseAAA @lispXdefun ™E—ndH @psA @setq stuff @if @null @™dr psAA @n™on™ stuff –@t D@™ @™—r psA Xev—lE—ll @™—r psAAA –@@t D@™ nil Xsele™tEnoneAAAAAA –@@not D@™Ehide @™—r psAAA stuffAA D@™ nil XfirstEnull @™—r psAAAAA @lispXdefun ™E™—seI @™l—useA @deftype ™E—nd @8rest ˜A –@—nd FD ˜AA –@D@™—r ™l—useA D@™ –@progn FD @™dr ™l—useAA Xsele™t @deftype ™Eor @8rest ˜A –@or FD ˜AA @™—r ™l—useAAAA

pigure IQX „he ™ode for the p—rt of ™over th—t —nnot—tes ™ondition—lsF IV ‚FgF ‡—ters

™ode gener—ted ˜y — m—™ro —re quoted in the er™isedF roweverD it is essenti—l th—t pro™essing ˜ody of the m—™roFA ˜e very f—st when —n exer™ised point is exer™ised pigure IP shows p—rt of the results of —nE — se™ond timeFA not—ting the fun™tion myB from pigure RF „he ƒe™ondD the s™heme must work reli—˜ly with —nnot—ted denition is pre™eded ˜y — ™—ll on interpreted ™odeD with ™ompiled ™ode lo—ded —ddEtopEpointD whi™h enters — point des™ri˜ing from lesD —nd with ™ode th—t is in™rement—lly the denition into BpointsBF ‡ithin the defE ™ompiled on the yF „his introdu™es — num˜er initionD ™—lls on re™ordEhit —re introdu™ed —t of strong ™onstr—intsF sn p—rti™ul—rD you ™—nnot str—tegi™ lo™—tionsF i—™h ™—ll ™ont—ins — quoted depend on using some des™riptive d—t— stru™E point th—t is essenti—lly — templ—te for wh—t ture ˜uilt up during ™ompil—tionD ˜e™—use you should ˜e introdu™ed into BpointsBF „he rst ™—nnot —ssume th—t ™ompil—tion will o™™urF yn when in myB is ™onverted into —n if th—t h—s the other h—ndD if you use quoted d—t— stru™E ™—ses ™orresponding to the su™™ess —nd f—ilure tures —s in pigure IPD you ™—nnot m—ke —ny of the predi™—te tested ˜y the whenF „he ™—ll —ssumptions —˜out wh—t sh—ring will exist or on re™ordEhit th—t pre™edes this if ™ont—ins — whether they will ˜e ™opiedD ˜e™—use some visp point with su˜points th—t est—˜lishes the ™—ses ™ompilers feel free to m—ke m—jor ™h—nges in of the ifF „his ensures th—t ˜oth ™—ses of the quoted listsF if will ˜e present in BpointsB —s soon —s the „o —™hieve high e™ien™yD re™ordEhit @see if is exer™isedD even if only one of the ™—ses is pigure VA —lters its —rgument ˜y sideEee™t to exer™isedF m—rk it exer™isedF ƒideEee™ting — ™ompiled „he hidden point —sso™i—ted with the prediE ™onst—nt is inherently d—ngerousD ˜ut is rel—E ™—te tested ˜y the when est—˜lishes —n —ppropriE tively s—fe hereD ˜e™—use the ™h—nged v—lue is —te ™ontext for points within the predi™—te itE —n integerD —nd the point d—t— stru™ture ™—nnot selfF st is unne™ess—ry in this ex—mpleD ˜e™—use ˜e sh—red with —ny other point d—t— stru™tureD there —re no su™h pointsF sn the ™ond in the ˜e™—use no two points ™—n h—ve the s—me n—meF fun™tion g in pigure TD — simil—r hidden point „he rst time — given ™—ll on re™ordEhit —sso™i—ted with the rst predi™—te tested serves is en™ounteredD it enters the point whi™h is its to ™orre™tly position the points —sso™i—ted with —rgument into BpointsBF „his is done ˜y rst the —nd @see pigure UAF looking to see if the point is —lre—dy there @eFgFD ˜e™—use it w—s entered ˜y —n —ddEtopEpoint or por the most p—rtD the m—™ros in pigure IQ is — su˜ordin—te point th—t w—s expli™itly enE oper—te in str—ightforw—rd w—ys to gener—te —nE tered —s p—rt of its superior pointAF sf it is not not—ted ™ondition—lsF roweverD defD ™D ™ID —nd thereD it is ™opied —nd inserted —s — su˜ordiE ™H inter—™t in — somewh—t su˜tle w—y using n—te point of the —ppropri—te superior pointF m—™rolet to ™ommuni™—te the n—me of — suE @fy this pro™essD BpointsB is dyn—mi™—lly ˜uilt perior point to its su˜ordin—tesF „his ™ould up in ex—™tly the s—me w—y when exe™uting inE h—ve ˜een done more simply with ™ompilerEletY terpreted —nd ™ompiled ™odeFA sf the superior howeverD ™ompilerElet is sl—ted to ˜e removed point ™—nnot ˜e foundD nothing is doneF @„his from gommon vispF ™—n only h—ppen when the —nnot—tion of the nderlying —ppro—™hF „he —nnot—tion ™urrently exe™uting fun™tion h—s ˜een forgotE s™heme used ˜y ™over is designed to meet two tenFA go—lsF pirstD it must introdu™e —s little overE „he se™ond time — ™—ll on re™ordEhit is enE he—d —s possi˜le when the —nnot—ted fun™tion ™ountered the only thing it h—s to do is ™he™k runsF @st does not m—tter if the pro™ess of inE th—t the point h—s ˜een exer™isedF sf it h—sD serting —nnot—tion is expensive —nd it does not nothing needs to ˜e doneF sf — ™overXreset h—s m—tter if the pro™ess of printing reports is exE ˜een doneD then the ™he™k will f—ilD —nd re™ordE pensiveF st does not even m—tter if pro™essing is hit relo™—tes the point in BpointsBD —nd sets the rel—tively expensive the rst time — point is exE hit —gF @„his se™ond lookup ™ould ˜e —voided visp elgorithms IW if the quoted point h—d ˜een dire™tly inserted y˜t—ining gy†i‚ into BpointsB inste—d of ™opiedF roweverD this ™over is written in port—˜le gommon visp is uns—fe for two re—sonsF pirstD the sh—ring —nd h—s ˜een tested in sever—l dierent gomE would me—n th—t sideEee™ts to BpointsB would mon visp implement—tionsF „he full sour™e for tr—nsl—te into sideEee™ts to ™ompiled list ™onE ™over is shown in pigures VD IHD IID —nd IQF st—ntsF „his will ™—use m—ny visp systems to sn —dditionD the sour™e ™—n ˜e o˜t—ined over ˜low up in unexpe™ted w—ysF ƒe™ondD in some the internet ˜y using ftpF gonne™tion should visp systems ™ompiling —n interpreted fun™tion ˜e m—de to p„€FesFws„Fih @internet num˜er ™—n ™—use the quoted lists in it to ˜e ™opiedF IPVFSPFQPFTAF vogin —s ’—nonymous4 —nd ™opy es — resultD you ™—nnot depend th—t —ny sh—rE the les shown ˜elowF ing set up ˜etween — glo˜—l d—t— stru™ture —nd quoted ™onst—nts will ˜e preservedFA sn the dire™tory Gpu˜GlptrsG „he oper—tion of ™over requires th—t e—™h ™overFlisp sour™e ™ode point ˜e given — unique identifying n—meF „he ™overEtestFlisp test suite ™overEdo™Ftxt ˜rief do™ument—tion n—ming s™heme used —ssumes th—t — given ™onE dition—l form will not h—ve two predi™—tes th—t „he ™ontents of pigures VD IHD IID —nd IQ —re equ—l —nd th—t — ™hunk of str—ightline ™ode —nd the les —˜ove —re ™opyright IWWI ˜y the will not ™ont—in two ™ondition—l forms th—t —re w—ss—™husetts snstitute of „e™hnologyD g—mE equ—lF sf this —ssumption is viol—tedD ™over ˜ridge weF €ermission to useD ™opyD modifyD will merge the two resulting points into oneF —nd distri˜ute this softw—re for —ny purpose —nd „he power of vispF ™over is — good exE without fee is here˜y gr—ntedD provided th—t —mple of the power of visp —s — tool for ˜uildE this ™opyright —nd permission noti™e —ppe—r in ing progr—mming environmentsF fe™—use visp —ll ™opies —nd supporting do™ument—tionD —nd ™ont—ins — simple represent—tion for visp proE th—t the n—mes of ws„ —ndGor the —uthor —re gr—msD it is e—sy to write systems th—t ™onE not used in —dvertising or pu˜li™ity pert—ining vert progr—ms into other progr—msF fe™—use to distri˜ution of the softw—re without spe™i™D visp en™omp—sses ˜oth the l—ngu—ge denition written prior permissionF ws„ —nd the —uthor —nd the runEtime environmentD it is e—sy to m—ke no represent—tions —˜out the suit—˜ility write systems th—t ˜oth m—nipul—te the l—nE of this softw—re for —ny purposeF st is provided gu—ge —nd extend the runEtime environmentF ’—s is4 without express or implied w—rr—ntyF ƒystems like ™over —re regul—rly written for ws„ —nd the —uthor dis™l—im —ll w—rr—nties ™ —nd other elgolElike l—ngu—gesY howeverD this with reg—rd to this softw—reD in™luding —ll imE is mu™h h—rder to do th—n in vispF plied w—rr—nties of mer™h—nt—˜ility —nd tnessF sn no event sh—ll ws„ or the —uthor ˜e li—˜le for —ny spe™i—lD indire™t or ™onsequenti—l d—mE e™knowledgments —ges or —ny d—m—ges wh—tsoever resulting from loss of useD d—t— or protsD whether in —n —™tion „he ™on™ept of ™ode ™over—ge is —n old oneD of ™ontr—™tD negligen™e or other tortious —™tionD whi™h is used ˜y m—ny @if not mostA l—rge proE —rising out of or in ™onne™tion with the use or gr—mming org—niz—tionsF ™over is the result perform—n™e of this softw—reF of sever—l ye—rs of pr—™ti™—l use —nd evolutionF „his p—per des™ri˜es rese—r™h done —t the ‚eferen™es mit —i v—˜or—toryF ƒupport w—s provided ˜y d—rp—D nsfD i˜mD nynexD ƒiemensD ƒperryD —nd ‘I“ ‚FgF ‡—tersD ’ƒupporting the ‚egression m™™F „he views —nd ™on™lusions presented here „esting of visp €rogr—msD4 egw visp —re those of the —uthor —nd should not ˜e interE €ointersD R@PAXRU{SQD tune IWWIF preted —s representing the poli™iesD expressed or impliedD of these org—niz—tionsF PH ‚FgF ‡—ters visp elgorithms PI

QF smplementing ueues in visp

‚i™h—rd gF ‡—ters —nd €eter xorvig

e queue is — d—t— stru™ture where items —re entered one —t — time —nd removed one —t — time in the s—me order|iFeFD rst in rst outF „hey —re the s—me —s st—™ks ex™ept th—t in — st—™kD items —re removed in the reverse of the order they —re entered|iFeFD l—st in rst outF ueues —re most pre™isely des™ri˜ed ˜y the fun™tions th—t —™t on themX

@m—keEqueueA gre—tes —nd returns — new empty queueF @queueEelements queueA ‚eturns — list of the elements in queue with the oldest element rstF „he list returned m—y sh—re stru™ture with queue —nd therefore m—y ˜e —ltered ˜y su˜sequent ™—lls on enqueue —ndGor dequeueF @emptyEqueueEp queueA ‚eturns t if queue does not ™ont—in —ny elements —nd nil otherwiseF @queueEfront queueA ‚eturns the oldest element in queue @iFeFD the element th—t h—s ˜een in the queue the longestAF ‡hen queue is emptyD the results —re undenedF @dequeue queueA ueue is —ltered @˜y sideEee™tA ˜y removing the oldest element in queueF „he removed element is returnedF ‡hen queue is emptyD the results —re undenedF @enqueue queue itemA ueue is —ltered @˜y sideEee™tA ˜y —dding the element item into queueF „he return v—lue @if —nyA is undenedF

@emptyEqueueEp @setq q @m—keEqueueAAA A t @progn @enqueue q 9—A @enqueue q 9˜A @queueEfront qAA A — @progn @enqueue q 9™A @enqueue q 9dA @dequeue qAA A — @queueEelements qA A @˜ ™ dA

r—ving enqueue —nd dequeue —lter queue ˜y sideEee™t is ™onvenient for most uses of queues —nd —llows for e™ient implement—tionsF roweverD it me—ns th—t ™—re must ˜e t—ken when queues —re m—nipul—tedF por inst—n™eD if the output of queueEelements must ˜e preserved ˜eyond — su˜sequent use of enqueue or dequeue it must ˜e ™opied @eFgFD with ™opyElistAF

ueues smplemented ‡ith vists visp9s eponymous d—t— stru™tureD the listD ™—n ˜e used to represent — wide v—riety of d—t— stru™tures in™luding queuesF „he implement—tion of queues in pigure IR represents — queue —s — ™ons ™ell whose ™—r is — list of the elements in the queueD ordered with the oldest rstF „he implement—tion in pigure IR is simple —nd e—sy to underst—ndF „he ™lose simil—rity of queues —nd st—™ks is highlighted ˜y the f—™t th—t dequeue is implemented using pop —nd enqueue is implemented in — w—y th—t is very simil—r to pushF „he one thing th—t m—y not ˜e immedi—tely ™le—r —˜out the implement—tion in pigure IR is the re—son why — he—der ™ell is ne™ess—ryD inste—d of just using the list of elements in the queue to represent the queueF „he he—der ™ell is needed so th—t —n element ™—n ˜e —dded into —n empty queue @—nd the l—st element removed from — oneEelement queueA purely ˜y sideEee™tF por this to workD —n empty queue must ˜e some kind of mut—˜le stru™ture th—t ™—n ˜e pointed to @eFgFD not PP ‚FgF ‡—ters

@defun m—keEqueue @A @list nilAA @defun queueEelements @qA @™—r qAA Ysp—™e time @defun emptyEqueueEp @qA @null @™—r qAAA Y P P @defun queueEfront @qA @™——r qAA Y P P @defun dequeue @qA @pop @™—r qAAA Y R R @defun enqueue @q itemA @setf @™—r qA @n™on™ @™—r q A @list itemAAAA Y R y@nA @setq q @m—keEqueueAA A @nilA @progn @enqueue q 9—A @enqueue q 9˜A @enqueue q 9™A qA A @@— ˜ ™AA

pigure IRX ueue implement—tion using n™on™F just nilAF „he fun™tions in pigure IR —re divided into two groups to ree™t the f—™t th—t the l—st four fun™tions —re ™—lled mu™h more often th—n the rst twoF es — resultD it is more import—nt th—t they ˜e e™ientF „he rst ™olumn of num˜ers on the right of pigure IR shows the size of the ™ode required if the ™orresponding fun™tion is ™ompiled in line —t the point of useF „he size is spe™ied —s the num˜er of primitive oper—tions @™—rD ™drD ™onsD listD nullD rpl—™—D rpl—™dD setqD ˜r—n™hingD gener—ting — ™onst—nt nilD —nd ™—lling —n outEofEline fun™tionA th—t —re ne™ess—ryF por inst—n™eD dequeue requires R ˜—si™ oper—tions @— ™—rD two ™drs —nd — rpl—™dAF „he sp—™e num˜ers ™—nnot ˜e t—ken —s ex—™tly ree™ting —ny p—rti™ul—r visp implement—tionD ˜e™—use — given visp ™ompiler m—y ™re—te ™ode th—t performs unne™ess—ry oper—tionsD —nd — given h—rdw—re pl—tform m—y require multiple instru™tions to support some of the primitive oper—tionsF roweverD this does not m—tter — gre—t de—lD ˜e™—use the rel—tive ™ode size of fun™tions is the key thing th—t is import—nt in the ™ontext of this p—perF @„he v—lidity of the num˜ers in pigure IR —s — ˜—sis for this kind of ™omp—rison h—s ˜een veried ˜y looking —t the ™ode produ™ed ˜y the ™ompilers for the „s ixplorer —nd the ƒym˜oli™s visp w—™hineFA en import—nt virtue of the implement—tion of queues in pigure IR is th—t the fun™tions —re ™oded ™omp—™tly enough th—t it is pr—™ti™—l to ™ompile —ll of them in line @iFeFD ˜y de™l—ring them inlineAF sn most gommon visp implement—tionsD this is signi™—ntly more e™ient then using outEofEline fun™tion ™—llsF „he se™ond ™olumn of num˜ers on the right of pigure IR shows the num˜er of ˜—si™ oper—tions th—t h—ve to ˜e exe™uted —t run timeF sf there is —ny ˜r—n™hing requiredD the num˜er ree™ts the ™ontrol p—th th—t is most likely to ˜e t—kenF „hese num˜ers reve—l th—t there is — pro˜lem with the implement—tionF wost of the fun™tions h—ve sm—ll xed ™osts th—t —re independent of the size of the queueF roweverD the time required to perform the n™on™ in enqueue is proportion—l to the size of the queueF

ueeping — €ointer to the ind of the ueue

„he pro˜lem with n™on™ is not th—t it m—kes —n expensive ™h—nge @it merely performs one rpl—™dAD ˜ut th—t it h—s to se—r™h down the entire list to lo™—te the ™ons ™ell ™ont—ining the l—st queue elementF „his ine™ien™y ™—n ˜e over™ome ˜y m—int—ining — pointer to the end of the list of queue elementsF sn p—rti™ul—rD ffx visp supported — queue d—t— stru™ture ex—™tly like the one in pigure IR ex™ept th—t the ™dr of the he—der ™ell w—s used —s — pointer to the list ™ell ™ont—ining the l—st element in the queue @if —nyAF sing this pointerD the six queue fun™tions ™—n ˜e supported —s shown in pigure ISF @sn ffx vispD the fun™tion enqueue w—s ™—lled t™on™FA „he only dieren™e ˜etween pigure IS —nd pigure IR is in the implement—tion of enqueueFst visp elgorithms PQ

@defun m—keEqueue @A @list nilAA @defun queueEelements @qA @™—r qAA Ysp—™e time @defun emptyEqueueEp @qA @null @™—r qAAA Y P P @defun queueEfront @qA @™——r qAA Y P P @defun dequeue @qA @pop @™—r qAAA Y R R @defun enqueue @q itemA Y W V @let @@newEl—st @list itemAAA @if @null @™—r qAA @setf @™—r qA newEl—stA @setf @™ddr qA newEl—stAA @setf @™dr qA newEl—stAAA @setq q @m—keEqueueAA A @nilA @progn @enqueue q 9—A @enqueue q 9˜A @enqueue q 9™A qA A @@— ˜ F 5Ia@™AA F 5I5A

pigure ISX ƒimple queue implement—tion using —n end pointerF is tr—nsformed into — ™onst—ntEtime oper—tion —nd is therefore very mu™h f—sterF nfortun—telyD enqueue is now too l—rge to ˜e ™omfort—˜ly ™ompiled in lineF „he implement—tion of enqueue in pigure IS is l—rger th—n in pigure IR prim—rily ˜e™—use it h—s to test for — spe™i—l ˜ound—ry ™onditionF ‡hen the input queue is emptyD enqueue h—s to do — rpl—™— to insert the @one elementA list of queue elements in the ™—r of the he—der ™ellY otherwise it h—s to do — rpl—™d to extend the list of queue elementsF

woving the found—ry „est to — fetter €l—™e

st is possi˜le to remove the ˜ound—ry test from enqueue ˜y re—rr—nging the queue d—t— stru™ture —s followsF pirstD the two ™omponents of the he—der ™ell —re inter™h—ngedD putting the pointer to the end of the queue in the ™—rF ƒe™ondD — ™onvention ™—n ˜e —dopted th—t —n empty queue9s end pointer points to the queue itselfF „hese two ™h—nges —llow the s—me ™ode to ˜e used for inserting —n element into — queue whether or not the queue is emptyD see pigure ITF nfortun—telyD while the two ™h—nges —˜ove simplify enqueueD they m—ke it more di™ult to implement dequeueF „he pro˜lem is th—t dequeue now h—s — spe™i—l ˜ound—ry ™ondition to test for|if the queue ˜e™omes emptyD the queue9s l—st pointer h—s to ˜e m—de to point to the queue itselfF roweverD ˜e™—use this is — simpler spe™i—l ™—se th—n the one in enqueue in pigure ISD it does not le—d to —s mu™h overhe—dF elsoD sin™e some —ppli™—tions do signi™—ntly more enqueues th—n dequeues —nd no —ppli™—tion does more dequeuesD the tr—deEo is worthwhileF „he implement—tion —ppro—™h in pigure IT t—kes su˜tle —dv—nt—ge of the typeless n—ture of

@defun m—keEqueue @A @let @@q @list nilAAA @setf @™—r qA qAAA @defun queueEelements @qA @™dr qAA Ysp—™e time @defun emptyEqueueEp @qA @null @™dr qAAA Y P P @defun queueEfront @qA @™—dr qAA Y P P @defun dequeue @qA Y U T @let @@elements @™dr qAAA @unless @setf @™dr qA @™dr elementsAA @setf @™—r qA qAA @™—r elementsAAA @defun enqueue @q itemA @setf @™—r qA @setf @™d—r qA @list itemAAAA Y R R @setq q @m—keEqueueAA A 5Ia@5I5A @progn @enqueue q 9—A @enqueue q 9˜A @enqueue q 9™A qA A @5Ia@™A — ˜ F 5I5A

pigure ITX e ™omp—™t —nd e™ient queue implement—tionF PR ‚FgF ‡—ters

@defun m—keEqueue @A @let @@q @list nilAAA @™ons q qAAA @defun queueEelements @qA @™d—r qAA Ysp—™e time @defun emptyEqueueEp @qA @null @™d—r qAAA Y Q Q @defun queueEfront @qA @™—d—r qAA Y Q Q @defun dequeue @qA @™—r @setf @™—r qA @™d—r qAAAA Y R R @defun enqueue @q itemA @setf @™dr qA @setf @™ddr qA @list itemAAAA Y R R @setq q @m—keEqueueAA A @5Ia@nilA F 5IA @progn @enqueue q 9—A @enqueue q 9˜A @enqueue q 9™A qA A @@nil — ˜ F 5Ia@™AA F 5I5A

pigure IUX enother ™omp—™t —nd e™ient queue implement—tionF vispF sn most other l—ngu—gesD the he—der ™ell for — queue would ˜e — dierent type of stru™ture from the ™ells forming the of queue elementsF „his would ˜lo™k enqueue from tre—ting the ™dr of the he—der ™ell the s—me —s the ™dr of — linked list ™ellF @sn some l—ngu—gesD this pro˜lem ™ould ˜e over™ome ˜y judi™ious use of type unioning or typeE™he™k ˜yp—ssingFA

ilimin—ting the found—ry „est ˜y edding — gell e dierent w—y to improve on pigure IS is to elimin—te the need for —ny ˜ound—ry tests —t —llD ˜y —dding — dummy ™ell into the list holding the elements in the queue —s shown in pigure IUF „his —llows enqueue —nd dequeue to oper—te essenti—lly —s if the queue were never emptyF roweverD the other fun™tions h—ve to ˜e —djusted to skip over the dummy ™ellD —nd therefore ˜e™ome — ˜it longerF ‡hether or not the implement—tion in pigure IU is ˜etter th—n the one in pigure IT depends on the det—ils of your visp implement—tion —nd whi™h queue oper—tions you use mostF por inst—n™eD if ™—lls on dequeue —re p—rti™ul—rly infrequent @eFgFD ˜e™—use — list of the items queued is the prim—ry result desiredAD then the implement—tion in pigure IT is ˜etterF sn ™ontr—stD if the visp smplemenE t—tion h—s spe™i—l h—rdw—re support for following ™h—ins of pointers through ™ons ™ells @eFgFD the „s ixplorerAD pigure IU is ˜etterF

ueues smplemented ‡ith †e™tors

vists —re — ™onvenient ˜—sis for queuesF sn p—rti™ul—rD the inter—™tion of ™ons —nd g—r˜—ge ™olle™tion provides support for queues of un˜ounded length without —ny spe™i—l provisions h—ving to ˜e m—deF roweverD listE˜—sed implement—tions —re w—steful of memoryD ˜e™—use —n entire ™ons ™ell h—s to ˜e used to store e—™h element in the queueD —nd —s elements —re enqueued —nd dequeuedD new ™ons ™ells ™ontinu—lly h—ve to ˜e —llo™—tedF wemory e™ient implement—tions of queues —re possi˜le using ve™torsF „his —ppro—™h is often t—ken in other l—ngu—gesF pigure IV shows —n implement—tion like those usu—lly shown in introdu™E tory d—t—Estru™ture textsF „he ˜—si™ —ppro—™h is to store the elements of — queue —s — se™tion of — ve™tor tre—ted —s — ringF „he elements —re stored in reverse order in the ve™tor so th—t — ™omp—rison with zero ™—n ˜e used to dete™t when either the front or end pointers re—™h the edge of the ve™torF „he prim—ry —dv—nt—ge of — ve™torE˜—sed implement—tion is th—t it requires only —˜out h—lf the memory to store the ™ontents of the queueF sf the queue elements —re shorter th—n — word @eFgFD ™h—r—™ters or ˜itsA even more s—vings —re possi˜leF sn —dditionD enqueuing —nd dequeuing elements does not gener—te —ny g—r˜—ge —t —ll @unless the queue size gets so l—rge th—t —n enl—rged ve™tor h—s to ˜e —llo™—tedAF „he prim—ry dis—dv—nt—ge of — ve™torE˜—sed implement—tion is th—t it is more ™ompli™—tedF sn p—rti™ul—rD it h—s to do —ll its own memory m—n—gementF „his me—ns th—t the queue still t—kes up — lot of sp—™e even when it is emptyF sn —dditionD provision h—s to ˜e m—de for extending the ve™tor holding the queue if it ˜e™omes fullF @sn gure IVD this is supported ˜y the fun™tion extendEqueue visp elgorithms PS

@defstru™t q front end size elementsA @defun m—keEqueue @8option—l @size PHAA @m—keEq Xfront @IE sizeA Xend @IE sizeA Xsize size Xelements @m—keEsequen™e 9simpleEve™tor sizeAAA @defun queueEelements @qA @when @not @emptyEqueueEp qAA @do @@i @IC @qEend qAA @IC iAA @result nilAA @nilA @when @a i @qEsize qAA @setq i HAA @push @svref @qEelements qA iA resultA @when @a i @qEfront qAA @return resultAAAAA Ysp—™e time @defun emptyEqueueEp @qA @a @qEfront qA @qEend qAAA Y Q Q @defun queueEfront @qA @svref @qEelements qA @qEfront qAAA Y Q Q @defun dequeue @qA Y U T @let @@front @qEfront qAAA @progI @svref @qEelements qA frontA @when @zerop frontA @setq front @qEsize qAAA @setf @qEfront qA @IE frontAAAAA @defun enqueue @q itemA Y IH V @let @@end @qEend qAAA @setf @svref @qEelements qA endA itemA @when @zerop endA @setq end @qEsize qAAA @when @a @setf @qEend qA @IE endAA @qEfront qAA @extendEqueue qAAAA @defun extendEqueue @qA @letB @@elements @qEelements qAA @size @qEsize qAA @newEsize @B P sizeAA @divide @IC @qEfront qAAA @newEend @C divide size EIAA @new @m—keEsequen™e 9simpleEve™tor newEsizeAAA @repl—™e new elements XendP divideA @repl—™e new elements Xst—rtI @IC newEendA Xst—rtP divideA @setf @qEelements qA newA @setf @qEend qA newEendA @setf @qEsize qA newEsizeAAA @progn @setq q @m—keEqueueAA @dotimes @i IUA @enqueue q 9EA @dequeue qAA @dotimes @i SA @enqueue q iAA qA A 5ƒ@queue front IU end P size PH elements 5@PIHEEEEEEEEEEEEEEERQAA

pigure IVX e tr—dition—l ve™torE˜—sed queue implement—tionF

—nd — fullness test in enqueueFA ‡henever possi˜leD it is good to st—rt the queue —t — size th—t is su™ient to hold the m—xiE mum expe™ted sizeD r—ther th—n st—rting —t —n —r˜itr—ry size like PHF por this re—son the fun™tion m—keEqueue is extended ˜y giving it —n option—l size —rgumentF qiven rm m—ximumEsize inform—E tion one ™ould go further —nd dispense with extendEqueue —nd the fullness test in enqueueF roweverD this is — d—ngerous pr—™ti™e —nd s—ves rel—tively littleF st is worthy of note th—t it would ˜e — mist—ke to use —n —djust—˜le —rr—y in the queue d—t— stru™tureF „his would m—ke extending the —rr—y — little ˜it e—sierD ˜ut would slow up —ll of the other oper—tions on the ve™torF edjust—˜le —rr—ys —re only helpful when there m—y ˜e m—ny pointers dire™tly to the —rr—y th—t h—s to ˜e extendedF ‡heneverD —s hereD there is known to ˜e only one pointerD it is mu™h ˜etter to ™h—nge the pointer to point to — new —rr—yD th—n to extend the —rr—y itselfF PT ‚FgF ‡—ters

@defstru™t q front end size elementsA @defun m—keEqueue @8option—l @size PHAA @m—keEq Xfront @E size IA Xend @E size IA Xsize size Xelements @m—keEsequen™e 9simpleEve™tor sizeAAA @defun queueEelements @qA @do @@i @IC @qEend qAA @IC iAA @result nilAA @@b i @qEfront qAA resultA @push @svref @qEelements qA iA resultAAA Ysp—™e time @defun emptyEqueueEp @qA @a @qEfront qA @qEend qAAA Y Q Q @defun queueEfront @qA @svref @qEelements qA @qEfront qAAA Y Q Q @defun dequeue @qA Y S S @progI @svref @qEelements qA @qEfront qAA @de™f @qEfront qAAAA @defun enqueue @q itemA Y V U @setf @svref @qEelements qA @qEend qAA itemA @when @minusp @de™f @qEend qAAA @shiftEqueue qAAA @defun shiftEqueue @qA @letB @@elements @qEelements qAA @new elementsAA @when @b @qEfront qA @G @qEsize qA PAA @setq new @m—keEsequen™e 9simpleEve™tor @B P @qEsize qAAAA @setf @qEelements qA newA @setf @qEsize qA @B P @qEsize qAAAA @setf @qEend qA @E @qEsize qA P @qEfront qAAA @repl—™e new elements Xst—rtI @IC @qEend qAAA @setf @qEfront qA @IE @qEsize qAAAAA @progn @setq q @m—keEqueueAA @dotimes @i IUA @enqueue q 9EA @dequeue qAA @dotimes @i SA @enqueue q iAA qA A 5ƒ@queue front IW end IR size PH elements 5@PIHEEEEEEEEEEEERQPIHAA

pigure IWX e f—ster ve™torE˜—sed queue implement—tionF

enother pro˜lem is th—t queueEelements ˜e™omes —n y@nA oper—tionD sin™e it h—s to ™opy the queue ™ontents into — listF sf you w—nt to ˜e —˜le to e—sily get — list of the elements in — queueD it is ˜etter to st—rt with — listE˜—sed implement—tionF e n—l pro˜lem with pigure IV is the ine™ien™y of some of the key oper—tionsF „he fun™tions emptyEqueue —nd queueEfront —re sm—ll —nd ™ould ˜e ™oded in lineF roweverD dequeue is on the ˜orderline in size —nd enqueue is quite l—rgeF

ƒhifting ss fetter „h—n sing — ‚ing pigure IW shows the kind of improvements th—n ™—n ˜e o˜t—ined using — little ingenuityF „he key dieren™e ˜etween pigure IW —nd pigure IV is th—t the implement—tion does not tre—t the ve™tor —s — ringF ‚—therD whenever the queue re—™hes the end of the ve™torD it is shifted over @˜y the fun™tion shiftEqueueD whi™h —lso extends the ve™tor if ne™ess—ryAF yne might well im—gine th—t oper—ting on the ve™tor —s — ring h—d to ˜e ˜etter th—n shifting everything over every time the queue re—™hes the edge of the ve™torF roweverD —s long —s the queue is signi™—ntly shorter th—n the ve™tor @s—y only PGQ the length or lessA then shifting does not h—ve to o™™ur very oftenD —nd performing o™™—sion—l shifts ends up ˜eing ™he—per th—n ™omplex de™rementing of the pointers —ll of the timeF hequeue —nd enqueue ˜oth ˜e™ome signi™—ntly more e™ientD —nd dequeue ˜e™omes short enough to e—sily ™ode in lineF ell in —llD ex™ept for the f—™t th—t the queue stru™ture h—s to ˜e — ˜it ˜igger for things to work visp elgorithms PU out e™ientlyD the implement—tion in pigure IW is ˜etter th—n the one in pigure IV in —ll respe™tsF qiven its memory e™ien™y —nd quite re—son—˜le speedD it is worth ™onsidering pigure IW —s —n —ltern—tive to — listE˜—sed implement—tion in —ny situ—tion where the fun™tion queueEelements is not usedF

gon™lusion visp provides —n —llEpurpose d—t— stru™ture|the list|whi™h is often —dequ—te for r—pid proE totypingF fut when —n e™ient solution is requiredD visp progr—mmers must ™hoose their d—t— stru™tures ™—refullyF pigures IT{IW show two e™ient list ˜—sed implement—tions of queues —nd two e™ient ve™torE˜—sed implement—tionsF ‡hi™h is —ppropri—te to use depends on the det—ils of the ex—™t situ—tion in questionF „he v—rious implement—tions presented —˜ove illustr—te sever—l gener—l issues to keep in mind when seeking e™ient —lgorithmsF sntrodu™ing —lignments of ™omponents ™—n often elimin—te spe™i—l ™—ses @eFgFD the w—y the queue d—t— stru™ture is re—rr—nged in pigure ITAF ƒometimes — ™omput—tion ™—n ˜e moved from —n expensive ™ontext to — less expensive one @eFgFD moving the ˜ound—ry test from enqueue to dequeue in pigure ITAF w—ny timesD it is ˜etter to do — little extr— work —ll the timeD then do —n expensive ™he™k to determine when extr— work is re—lly needed @eFgFD indexing through the extr— ™ell in pigure IU is ˜etter in m—ny situ—tions th—n testing for whether the list is emptyAF yther timesD it is ˜etter to introdu™e extr— work some of the time to elimin—te — ste—dy ˜—™kground of work @eFgFD o™™—sion—l wholes—le shifting in pigure IW is ˜etter th—n ™ontinu—l performing ™omplex pointer steppingAF ƒlimming fun™tions down to inElineE—˜le size ™—n p—y ˜ig pr—gm—ti™ dividendsF e˜ove —llD the only w—y to get — re—lly e™ient —lgorithm is to experiment with m—ny —ltern—tivesF