资源描述:
《The.Little.Schemer.4th》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、TheLittleSchemerFourthEditionDanielP.FriedmanandMatthiasFelleisenForewordbfGenWJ.s-.n.aTheTenCommandmentsTheFirstCommandmentTheFifthCommandmentWhenrecurringonalistofatoms,lat,askWhenbuildingavaluewith+,alwaysusetwoquestionsaboutit:(null?lat)andelse.0forthevalueofthetermina
2、tingline,forWhenrecurringonanumber,n,asktwoadding0doesnotchangethevalueofanquestionsaboutit:(zero?n)andelse.addition.WhenrecurringonalistofS-expressions,l,Whenbuildingavaluewithx,alwaysuseaskthreequestionaboutit:(null?l),(atom?1forthevalueoftheterminatingline,for(carl)),an
3、delse.multiplyingby1doesnotchangethevalueofamultiplication.TheSecondCommandmentWhenbuildingavaluewithcons,alwaysUseconstobuildlists.consider()forthevalueoftheterminatingline.TheThirdCommandmentWhenbuildingalist,describethefirsttypi-TheSixthCommandmentcalelement,andthencons
4、itontothenatuSimplifyonlyafterthefunctioniscorrect.ralrecursion.TheSeventhCommandmentTheFourthCommandmentRecuronthesubpartsthatareofthesameAlwayschangeatleastoneargumentwhilenature:recurring.Whenrecurringonalistofatoms,lat,•Onthesublistsofalist.use(cdrlat).Whenrecurringona
5、number,n,use(sub1n).Andwhenrecurringon•OnthesubexpressionsofanarithmeticalistofS-expressions,l,use(carl)and(cdrexpression.l)ifneither(null?l)nor(atom?(carl))aretrue.TheEighthCommandmentItmustbechangedtobeclosertoterminaUsehelpfunctionstoabstractfromrepresention.Thechanging
6、argumentmustbetestedtations.intheterminationcondition:TheNinthCommandmentwhenusingcdr,testterminationwithnull?andAbstractcommonpatternswithanewfuncwhenusingsub1,testterminationwithtion.zero?.TheTenthCommandmentBuildfunctionstocollectmorethanonevalueatatime.TheFiveRulesTheL
7、awofCarTheprimitivecarisdefinedonlyfornonemptylists.TheLawofCdrTheprimitivecdrisdefinedonlyfornonemptylists.Thecdrofanynon-emptylistisalwaysanotherlist.TheLawofConsTheprimitiveconstakestwoarguments.Thesecondargumenttoconsmustbealist.Theresultisalist.TheLawofNull?Theprimiti
8、venull?isdefinedonlyforlists.TheLawofEq?Theprimitiveeq'ltakestwoarguments.Eachmustbeanon-