Some Useful Lisp Algorithms: Part 1

Some Useful Lisp Algorithms: Part 1

MITSUBISHI ELECTRIC RESEARCH LABORATORIES http://www.merl.com Some Useful Lisp Algorithms: Part 1 Richard C. 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 witsuishi iletri eserh vortories ehnil eport WIEHR hemeer ISD IWWI y ihrd gF ters estrt his tehnil report gthers together three ppers tht were written during IWWI nd sumitted for pulition in egw visp ointersF ih pper desries useful visp lgorithmF ghpter I upporting the egression esting of visp rogrms4 presents system lled rt tht mintins dtse of tests nd utomtilly runs them when requestedF his n tke lot of omputer timeD ut does not tke ny of the progrmmer9s timeF es resultD ny ugs found y running the tests|nd this is lot more ugs thn you might think|re essentilly found for freeF ghpter P hetermining the goverge of est uite4 presents system lled over tht n help ssess the overge of suite of test sesF hen suite of test ses for progrm is run in onjuntion with overD sttistis re kept on whih onditions in the ode for the progrm re exerised nd whih re notF fsed on this informtionD over n print report of wht hs een missedF fy devising tests tht exerise these onditionsD progrmmer n extend the test suite so tht it hs more omplete overgeF ghpter Q smplementing ueues in visp4 @oEuthored y F xorvigA presents severl dierent lgorithms for implementing queues in vispF st disusses why the ovious listEsed implementtion of queues is ineient nd the prtiulr situE tions where more omplex implementtions re ppropriteF umitted to egw visp ointersD tnuryD xovemerD nd heemer IWWIF PHI frodwy gmridge wsshusetts HPIQW ulition ristoryXE IF pirst printingD WIEHRD heemer IWWI PF ghpter I pulished s upporting the egression esting of visp rogrms4D egw visp ointersD R@PAXRU{SQD tune IWWIF gopyright witsuishi iletri eserh vortoriesD IWWI PHI frodwyY gmridge wsshusetts HPIQW his work my not e opied or reprodued in whole or in prt for ny ommeril purposeF ermission to opy in whole or in prt without pyment of fee is grnted for nonprot edE utionl nd reserh purposes provided tht ll suh whole or prtil opies inlude the followingX notie tht suh opying is y permission of witsuishi iletri eserh vE ortories of gmridgeD wsshusettsY n knowledgment of the uthors nd individul ontriutions to the workY nd ll pplile portions of the opyright notieF gopyingD reprodutionD or repulishing for ny other purpose shll require liense with pyment of fee to witsuishi iletri eserh vortoriesF ell rights reservedF visp elgorithms I IF upporting the egression esting of visp rogrms ihrd gF ters row often hve you mde hnge in sysE ser9s wnul for tem to x ug or dd feture nd een toE tlly sure tht the hnge did not et nyE he funtionsD mrosD nd vriles tht thing elseD only to disover weeks or months mke up the rt regression tester re in pkE lter tht the hnge roke somethingc ge lled 44F he ten exported symols re sn my personl experieneD the single most doumented elowF sf you wnt to refer to these vlule softwre mintenne tool is regresE symols without pkge prexD you hve to sion testerD whih mintins suite of tests for use9 the pkgeF system nd n run them utomtilly when he si unit of onern of rt is the testF the system is hngedF he term regression ih test hs n identifying nme nd ody testing4 is usedD euse eh version of the sysE tht speies the tion of the testF puntions tem eing tested is ompred with the previous re provided for deningD redeningD removingD version to mke sure tht the new version hs nd performing individul tests nd the test not regressed y losing ny of the tested pE suite s wholeF sn dditionD informtion is ilitiesF he more omprehensive the test suite mintined out whih tests hve sueeded isD the more vlule this omprison eomesF nd whih hve filedF greting omprehensive test suite for system requires signint eortD nd running deftest nme form 8rest vlues test suite n require signint mounts of sndividul tests re dened using the mro omputer timeF roweverD given omprehenE deftestF he identifying nme is typilly sive test suiteD regression testing detets n imE numer or symolD ut n e ny visp formF pressive numer of ugs with remrkly little sf the test suite lredy ontins test with the humn eortF sme @equlA nmeD then this test is redened he rt regression tester presented here supE nd wrning messge printedF @his wrning ports the regression testing of systems written is importnt to lert the user when test suite in gommon vispF sn ddition to eing vluE denition le ontins two tests with the sme le toolD rt is n interesting exmple of the nmeFA hen the test is new oneD it is dded power of vispF to the end of the suiteF sn either seD nme is he unied nture of the visp progrmming returned s the vlue of deftest nd stored in environment nd the ft tht visp progrms the vrile BtestBF n e mnipulted s dt llows rt to e imE @deftest tEI @floor ISGUA P IGUA A tEI plemented in two pges of odeF werely impleE @deftest @t PA @list IA @IAA A @t PA menting thEmode regression tester using @deftest d @IC IA IA A d n elgolElike lnguge in typil progrmE @deftest good @IC IA PA A good ming environment would require muh more odeF smplementing highly intertive system he form n e ny kind of visp formF he like rt would e mjor undertkingF zero or more vlues n e ny kind of visp P FgF ters ojetsF he test is performed y evluting every test from the test suite nd returns nilF form nd ompring the results with the vluesF qenerllyD it is dvisle for the whole test suite he test sueeds if nd only if form produes to pply to some one systemF hen swithing the orret numer of results nd eh one is from testing one system to testing notherD it is equl to the orresponding vlueF wise to remove ll the old tests efore eginning to dene new onesF BtestB nmeEofEurrentEtest he vrile BtestB ontins the nme of doEtests 8optionl @out BstndrdEoutputBA the test most reently dened or performedF st his funtion uses doEtest to run eh of is set y deftest nd doEtestF the tests in the test suite nd prints report of the results on outD whih n either e n outE doEtest 8optionl @nme BtestBA put strem or the nme of leF sf out is omitE he funtion doEtest performs the test idenE tedD it defults to BstndrdEoutputBF hoEtests tied y nmeD whih defults to BtestBF fefore returns t if every test sueeded nd nil if ny running the testD doEtest stores nme in the test filedF vrile BtestBF sf the test sueedsD doEtest es illustrted elowD the rst line of the reE returns nme s its vlueF sf the test filsD port produed y doEtests shows how mny doEtest returns nilD fter printing n error reE tests need to e performedF he lst line shows port on BstndrdEoutputBF he following exE how mny tests filed nd lists their nmesF mples show the results of performing two of hile the tests re eing performedD doEtests the tests dened oveF prints the nmes of the suessful tests nd the error reports from the unsuessful testsF @doEtest 9@t PAA A @t PA @doEtest 9dA A nil Y fter printingX @doEtests 4reportFtxt4A A nil est feh filed Y the le 4reportFtxt4 ontinsX pormX @IC IA hoing R pending tests of R tests totlF ixpeted vlueX I EI @ PA etul vlueX PF est feh filed pormX @IC IA ixpeted vlueX I BdoEtestsEwhenEdefinedB defult vlue nil etul vlueX PF sf the vlue of this vrile is nonEnullD eh qyyh I out of R totl tests filedX fehF test is performed t the moment tht it is deE nedF his is helpful when intertively onE st is est if the individul tests in the suite struting suite of testsF roweverD when lodE re totlly independent of eh otherF roweverD ing test suite for lter useD performing tests should the need rise for some interdependeneD s they re dened is not lile to e helpfulF you n rely on the ft tht doEtests will run tests in the order they were originlly denedF getEtest 8optionl @nme BtestBA his funtion returns the nmeD formD nd pendingEtests vlues of the speied testF hen test is dened or redenedD it is mrked s pendingF sn dditionD doEtest mrks @getEtest 9@t PAA A @@t PA @list IA @IAA the test to e run s pending efore running it remEtest 8optionl @nme BtestBA nd doEtests mrks every test s pending eE fore running ny of themF he only time test sf the indited test is in the test suiteD this is mrked s not pending is when it ompletes funtion removes it nd returns nmeF ytherE suessfullyF he funtion pendingEtests reE wiseD nil is returnedF turns list of the nmes of the urrently pendE remEllEtests ing testsF his funtion reinitilizes rt y removing @pendingEtestsA A @dA visp elgorithms Q ontinueEtesting row orks his funtion

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    31 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us