资源描述:
《The Little Schemer》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、TheTenCommandmentsTheFirstCommandmentTheFifthCommandmentWhenrecurringonalistofatoms,lat,askWhenbuildingavaluewith+,alwaysusetwoquestionsaboutit:(null?lat)andelse.oforthevalueoftheterminatingline,forWhenrecurringonanumber,n,asktwoadding0doesnotchangethe
2、valueofanquestionsaboutit:(zero?n)andelse.addition.WhenrecurringonalistofS-expressions,I,Whenbuildingavaluewithx,alwaysuseaskthreequestionaboutit:(null?I),(atom?1forthevalueoftheterminatingline,for(carI)),andelse.multiplyingby1doesnotchangethevalueofam
3、ultiplication.TheSecondCommandmentWhenbuildingavaluewithcons,alwaysUseconstobuildlists.consider0forthevalueoftheterminatingline.TheThirdCommandmentWhenbuildingalist,describethefirsttypi-TheSixthCommandmentcalelement,andthenconsitontothenatu•Simplifyonl
4、yafterthefunctioniscorrect.ralrecursion.TheSeventhCommandmentTheFourthCommandmentRecuronthesubpartsthatareofthesameAlwayschangeatleastoneargumentwhilenature:recurring.Whenrecurringonalistofatoms,lat,use(cdrlat).Whenrecurringonanum••Onthesublistsofalist
5、.ber,n,use(sub1n).Andwhenrecurringon•OnthesubexpressionsofanarithmeticalistofS-expressions,I,use(carI)and(cdrexpression.I)ifneither(null?I)nor(atom?(carI))aretrue.TheEighthCommandmentItmustbechangedtobeclosertotermina•Usehelpfunctionstoabstractfromrepr
6、esen•tion.Thechangingargumentmustbetestedtations.intheterminationcondition:whenusingcdr,testterminationwithnull?TheNinthCommandmentandAbstractcommonpatternswithanewfunc•whenusingsub1,testterminationwithtion.zero?TheTenthCommandmentBuildfunctionstocolle
7、ctmorethanonevalueatatime.TheFiveRulesTheLawofCarTheprimitivecarisdefinedonlyfornon•emptylists.TheLawofCdrTheprimitivecdrisdefinedonlyfornon•emptylists.Thecdrofanynon-emptylistisalwaysanotherlist.TheLawofConsTheprimitiveconstakestwoarguments.Theseconda
8、rgumenttoconsmustbealist.Theresultisalist.TheLawofNull?Theprimitivenull?isdefinedonlyforlists.TheLawofEq?Theprimitiveeq'ltakestwoarguments.Eachmustbeanon-numericatom.TheLittleSchemerFourthEditionDanielP.FriedmanIndianaUniversityBlooming