• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
PicoLisp   ARadicalApproachtoApplicationDevelopment  
SoftwareLab.AlexanderBurgeBahnhofstr.24a,D-86462Langweiabu@software-lab.de(www.software-lab.de) +49-(0)821-9907090 June22,200
Abstrac
Criteriaforproductiveapplicationdevelopmentareconsidered(yetagain),and apointismadewhyweregardLispasthe 
onl
languagesuitedforthattask.Pico Lispispresentedasasuccessfulexample,usedincommercialapplicationsformany years,andadaptedtothistask(arguably)betterthananyotherLisp. 
1Introduction 
Iamworkingasaconsultantandfreesoftwaredeveloper.DuringthepasttwentyyearmypartnersandIworkedonprojectsasdiverseaspre-pressimageprocessing,computeaideddesign,simulations,andvariousnancialandbusinessapplicationsForalmostalltheseprojectsweusedLisp. Mydailyjobistolistentocustomerrequests,toanalyzebusinessprocesses,anddevelop softwareaccordingtothoseneedsTypically{inbusinessapplicationslikeERPorCRM{thisisaprocessofpermanent change.Atthebeginningofanewproject,neitherthedevelopernorthecustomerknow forsurewhatisneeded,norhowexactlythenalproductshouldlookItwillbefoundbyaniterativeprocess(somecallit\extremeprogramming"):Thecustomerevaluateseachnewversion,thenwediscussfurtherstrategies.Itisnotuncommon thatunanticipatedrequirementsmaycauselargepartsoftheprojecttoberewritten. Thisdoesnotnecessarilyimplybadplanning,becausetheprocessIdescribeher
i
thplanning.Inanidealworld,softwaredevelopmenti
onl
planning{thetimespentfor actuallywritingcodeshouldconvergetowardszero. Weneedaprogramminglanguagewhichletsusdirectlyexpresswhatwewanttheprogram todo,inapragmaticandexibleway.Andwebelievethateverythingshouldbeassimplaspossible,sothattheprogrammerisabletounderstandatanytimewhatisgoingon underthehood. Overtheyears,thePicoLisp[1]systemevolvedfromaminimalistLispimplementationtadedicatedapplicationserver.Pleasenotethatwearenottalkingofarapidprototyping tool.Ateachdevelopmentstep,theresultisalwaysafullyfunctionalprogram,notprototype,growingtowardsthe(possiblynal)productionversion.Instead,youmay callitapowertoolfortheprofessionalprogrammer,wholikestokeepincontrolofhievironment,andwantstoexpresshisapplicationlogicanddatastructuresinaconcisnotation
 
FirstwewanttointroducePicoLisp,explainwhyPicodiersinitslowerlevelsquitradicallyfromotherLispsordevelopmentsystems,andthenshowitsbenetatthehigher levels. 
2ARadicalApproac
The(Common-)LispcommunitywillprobablynotbeenthusiasticaboutPicoLisp,be- causeitdisposesofseveraltraditionalLispbeliefsanddogmas.Somearejustmyths,but theycancauseLisptobecometoocomplicated,heavyandslow.ThepracticalexperiencewithPicoLispprovesthatalightweightandfastLispisoptimalformanykindsof productiveapplicationdevelopment
2.1Myth1:LispNeedsaCompile
Thisisinfactthemostsignicantmyth.IfyoulistentoLispdiscussiongroups,the compilerplaysacentralrole.Youmightgettheimpressionthatitisalmostasynonym fortheexecutionenvironment.Peopleworryaboutwhatthecompilerdoestotheircode, andhoweectiveitis.IfyourLispprogramappearstobeslow,youaresupposedtogeabettercompilerTheideaofa
interpreted 
Lispisregardedasanoldmisconception.AmodernLispneeds acompiler;theinterpreterisjustausefuladd-on,andmainlyaninteractivedebugging aid.ItistooslowandbloatedforexecutingproductionlevelprogramsWebelievethattheoppositeistrue.Foronething(andnotjustfromaphilosophical pointofview)acompiledLispprogramisnolongerLispatall.Itbreaksthefundamental ruleof\formalequivalenceofcodeanddata".TheresultingcodedoesnotconsistofS- Expressions,andcannotbehandledbyLisp.Thesourcelanguage(Lisp)wastransformetoanotherlanguage(machinecode),withinevitableincompatibilitiesbetweendierent virtualmachines. Practically,acompilercomplicatesthewholesystem.Featureslikemultiplebinding strategies,typedvariablesandmacroswereintroducedtosatisfytheneedsofcompilersThesystemgetsbloated,becauseitalsohastosupporttheinterpreterandthustwratherdierentarchitectures. Butisitworththeeort?Sure,thereissomegaininrawexecutionspeed,andcompileconstructionisinterestingforacademicwork.Butweclaimthatindailylifeawelldesigned\interpreter"canoftenoutperformacompiledsystemYouunderstandthatwearenotreallytalkingabout\interpretation".ALispsysteimmediatelyconvertsallinputtointernalpointerstructurescalled\S-Expressions".True \interpretation"woulddealwithone-dimensionalcharactercodes,considerablyslowing downtheexecutionprocess.Lisp,however,\evaluates"theS-Expressionsbyquicklfollowingthesepointerstructures.Therearenosearchesorlookupsinvolved,sonothing isreally\interpreted".Butoutofhabitwe'llsticktothattermALispprogramasanS-Expressionformsatreeofexecutablenodes.ThecodeinthesnodesistypicallywritteninoptimizedCorassembly,sothetaskoftheinterpreterisimplytopasscontrolfromonenodetotheother.Becausemanyofthosebuilt-inlisfunctionsareverypowerfulanddoalotofprocessing,mostofthetimeisspentinthe nodes.Thetreeitselffunctionsasakindofglue. ALispcompilerwillremovesomeofthatglue,andreplacesomenodeswithprimitive orowfunctionalitydirectlywithmachinecode.Butbecausemostofthetimeisspeninbuilt-infunctionsanyway,theimprovementswillnotbeasdramaticasforexamplinaJavabytecodecompiler,whereeachnode(abytecode)hasjustacomparativel
 
primitivefunctionality. Ofcourse,thecompilationitselfisalsoquitetime-consuming.Anapplicationserveroften executessingle-passLispsourcelesonthey,andimmediatelydiscardsthecodewhen itisdone.Inthesecases,eithertheinherentlyslowerinterpreterofacompiler-basedLissystem,ortheadditionaltimespentbythecompilerwillnoticeabledegradetheoveralperformancePicoLisp'sinternalstructuresweredesignedforconvenientinterpretationfromthebegin- ning.ThoughitiscompletelywritteninC,andwasnotspeciallyoptimizedforspeed,lackofperformancewasneveranissue:TherstcommercialproductionsystemwritteinPicoLispwasanimageprocessing,retouch,andpagelayoutprogramfortheprinting andpre-pressindustry,in1988,onaMacIIwitha12MHzCPUand8MBofRAM.NLispcompiler,ofcourse,justthelowlevelpixelmanipulationsandbezierroutineswerwritteninC.Eventhen,onahardwarehundredsoftimesslowerthantoday's,nobody complainedabouttheperformanceJustoutofinterestIinstalledCLisptheotherday,andcompareditwithPicoLispfor somesimplebenchmarks.Ofcourse,theresultsarenotmeanttoreecttheusefulnessof eithersystemasanapplicationserver,buttheygivearoughindicationabouttherelative performancesFirstItriedthesimplerecursivebonaccifunction
(defunfibo(N(if(<N2((fibo(-N1)(fibo(-N2))))
Whencalleda
(fibo30
,Igetthefollowingexecutiontimes(ona266MHzPentium-notebook): Pico(interpreted)12seCLispinterpreted37seCLispcompiled7seTheCLispinterpreterisaboutthreetimesslower,thecompilerroughlytwiceasfastas PicoLisp. However,thebonaccifunctionisnotagoodexampleofatypicalLispprogram.Iconsistsonlyofprimitiveowandarithmeticfunctions,iseasyforacompilertooptimizeandmightbewrittendirectlyi
ifitweretime-critical(inthatcase,itwouldtakeonl0.2sec)Therefore,Iwenttotheotherextreme,withafunctiondoingextensivelistprocessings: 
(defuntst((mapcar (lambda(X(cons (carX(reverse(delete(carX)(cdrX))))'((abcabc)(bcdbcd)(cdecde)(defdef)))
Whencalle
onemilliontimes,Igot
ForaPicoLispversion,replace 
defun 
with 
d
an
lambda 
with 
quote 
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...