Upload
akash-pandey
View
220
Download
0
Embed Size (px)
Citation preview
8/14/2019 Teach Yourself Scheme in Fixnum Days
1/120
]ejdh Youpteca Tdhege in Aixnug Mjyt
Mopji Ti}jpjg# :998'022=Jcc Pifh}t Petepqem
mt01j}f}e.dog
Don}en}t
Rpeajde
: En}ep Tdhege
0 Mj}j }yret0.: Tigrce mj}j }yret
0.:.: @oocejnt
0.:.0 Nug`ept
0.:.4 Dhjpjd}ept
0.:.= Tyg`oct
0.0 Dogrounm mj}j }yret
0.0.: T}pinft0.0.0 Qed}opt
0.0.4 Mo}}em rjipt jnm cit}t
0.0.= Donqeptiont e}veen mj}j }yret
0.4 O}hep mj}j }yret
0.= T'exrpettiont
4 Aopgt4.: Rpodemupet
4.:.: Rpodemupe rjpjge}ept
4.:.0 Qjpij`ce nug`ep oa jpfugen}t4.0 jrrcy
4.4 Tezuendinf
= Donmi}ionjct=.: vhen jnm uncett
=.0 donm
8/14/2019 Teach Yourself Scheme in Fixnum Days
2/120
=.4 djte
=.= jnm jnm op
5 Cexidjc qjpij`cet5.: ce} jnm ce},
5.0 acuim'ce}
1 Peduption1.: ce}ped
1.0 Njgem ce}
1.4 I}epj}ion
1.= Gjrrinf j rpodemupe jdpott j cit}
6 I/O6.: Pejminf
6.0 Vpi}inf6.4 Aice rop}t
6.4.: Ju}ogj}id oreninf jnm dcotinf oa aice rop}t
6.= T}pinf rop}t
6.5 Cojminf aicet
8 Gjdpot8.: Trediayinf }he exrjntion jt j }egrcj}e
8.0 Jqoiminf qjpij`ce djr}upe intime gjdpot
8.4 acuim'ce}
9 T}pud}upet9.: Meajuc} ini}ijci|j}iont
9.0 meat}pud} meainem
:2 Jcit}t jnm }j`cet
:: Tyt}eg in}epajde::.: Dhedkinf aop jnm mece}inf aicet
::.0 Djccinf orepj}inf'tyt}eg doggjnmt
::.4 Enqipongen} qjpij`cet
:0 O`led}t jnm dcjttet:0.: J tigrce o`led} tyt}eg
:0.0 Dcjttet jpe int}jndet }oo
:0.4 Guc}irce inhepi}jnde
8/14/2019 Teach Yourself Scheme in Fixnum Days
3/120
:4 Lugrt:4.: djcc'vi}h'duppen}'don}inuj}ion
:4.0 Etdjrinf don}inuj}iont
:4.4 ]pee gj}dhinf
:4.= Dopou}inet
:4.=.: ]pee'gj}dhinf vi}h dopou}inet
:= Nonme}epginitg:=.: Metdpir}ion oajg`
:=.0 Igrcegen}inf jg` in Tdhege
:=.4 Utinf jg` in Tdhege
:=.= Cofid ru||cet
:=.=.: ]he Kjco}jn ru||ce
:=.=.0 Gjr docopinf
:5 Enfinet:5.: ]he dcodk
:5.0 Acj} enfinet
:5.4 Net}j`ce enfinet
:1 Thecc tdpir}t:1.: Hecco# Vopcm*# jfjin
:1.0 Tdpir}t vi}h jpfugen}t
:1.4 Exjgrce
:6 DFI tdpir}t:6.: Exjgrce< Mitrcjyinf enqipongen} qjpij`cet
:6.0 Exjgrce< Mitrcjyinf teced}em enqipongen} qjpij`ce
:6.4 DFI tdpir} u}ici}iet
:6.= J djcducj}op qij DFI
J Tdhege mijced}tJ.: Inqodj}ion jnm ini} aicet
J.0 Thecc tdpir}t
J.4 meaine'gjdpo
J.= cojm'pecj}iqe
@ MOT `j}dh aicet in Tdhege
D Nugepidjc }edhnizuetD.: Tigrton&t puce
8/14/2019 Teach Yourself Scheme in Fixnum Days
4/120
D.0 Jmjr}iqe in}epqjc ti|et
D.4 Igrporep in}efpjct
M J dcodk aop inaini}y
E Peaependet
A Inmex
8/14/2019 Teach Yourself Scheme in Fixnum Days
5/120
Rpeajde
]hit it jn in}pomud}ion }o }he Tdhege rpofpjgginf cjnfujfe. I} it in}enmem jt jzuidk't}jp} fuime# toge}hinf j noqide djn ute }o fe} j non'}piqijc vopkinf knovcemfe
oa }he cjnfujfe# `eaope goqinf on }o gope dogrpehentiqe jnm in'mer}h }ex}t.
]he }ex} metdpi`et jn jrrpojdh }o vpi}inf j dpitr jnm u}ici}jpijn Tdhege. Jc}houfh ve
vicc no} doqep Tdhege apog j`t }o |epo?# ve vicc no} thy jvjy apog }hote jtred}t oa
}he cjnfujfe }hj} jpe miaaiduc}# getty# nont}jnmjpm# op unutujc# `u} neqep}hecett uteauc
jnm utj`ce. Tudh jtred}t indcume djcc'vi}h'duppen}'don}inuj}ion# tyt}eg in}epajde#
jnm mijced} miqepti}y. Oup mitduttiont vicc `e inaopgem `y oup aodut on rpo`ceg'
tocqinf# no} `y j zuet} aop ge}jcinfuit}id intifh}. I hjqe }hepeaope cea} ou} gjny oa }he
t}jrcet oa }pjmi}ionjc Tdhege }u}opijct. ]hepe vicc `e no in'mer}h remjfofy; nomveccinf on }he tegjn}id jrrejc oa Tdhege; no ge}jdipducjp in}eprpe}ept; no
mitduttion oa }he unmepcyinf igrcegen}j}ion; jnm no eqjnfeci|inf j`ou} Tdhege&t
qip}uet. ]hit it no} }o tuffet} }hj} }hete }hinft jpe unigrop}jn}. Hoveqep# }hey jpe
jpfuj`cy no} iggemij}ecy peceqjn} }o togeone teekinf j zuidk in}pomud}ion.
Hov zuidk }houfh? I mo no} knov ia one djn }ejdh oneteca Tdhege in 0: mjyt:#
jc}houfh I hjqe hejpm i} tjim }hj} }he pumigen}t oa Tdhege thoucm `e j gj}}ep oa jn
ja}epnoon&t t}umy. ]he Tdhege t}jnmjpm [04W i}teca# aop jcc i}t exjd}inf
dogrpehentiqenett# it j gepe aia}y rjfet conf. I} gjy vecc `e }hj} }he intifh}# vhen i}
doget# vicc jppiqe in i}t en}ipe}y in one ja}epnoon# }houfh }hepe it no }eccinf hov gjnyja}epnoont oa git}piet gut} rpedeme i}. Un}ic }hj} |en gogen}# hepe it gy fen}ce
in}pomud}ion.
Jdknovcemfgen}. I }hjnk Gj}}hijt Aecceiten aop in}pomudinf ge }o Tdhege jnm
hifhep'opmep rpofpjgginf; jnm Gj}}hev Acj}} aop dpej}inf }he po`ut} jnm rcejtjn}
G|Tdhege igrcegen}j}ion utem }hpoufhou} }hit `ook.
'' m
: Jaixnug it j gjdhine&t imej oa j bbtgjcc&& in}efep. Eqepy gjdhine hjt i}t ovn imej oa
hov `if j aixnug djn `e.
8/14/2019 Teach Yourself Scheme in Fixnum Days
6/120
Dhjr}ep :
En}ep Tdhege
]he djnonidjc aipt} rpofpjg it }he one }hj} tjyt "Hecco# Vopcm*" on }he dontoce. Utinf
youp ajqopi}e emi}op# dpej}e j aice djccem hecco.tdg vi}h }he aoccovinf don}en}t# `u} doucm `e toge}hinf ecte.
J} }he cit}enep rpogr}# cojm}he aice hecco.tdg. ]hit it mone `y }yrinf
(cojm"hecco.tdg")
8/14/2019 Teach Yourself Scheme in Fixnum Days
7/120
Tdhege vicc nov exedu}e }he don}en}t oahecco.tdg# ou}ru}}inf Hecco#
Vopcm* aoccovem `y j djppijfe pe}upn. Ja}ep }hit# you vicc fe} }he cit}enep rpogr} jfjin#
vji}inf aop gope inru} apog you.
Tinde you hjqe tudh jn ejfep cit}enep# you neem no} jcvjyt vpi}e youp rpofpjgt in j
aice jnm cojm }heg. Toge}iget# i} it ejtiep# etredijccy vhen you jpe in jn exrcopinfgoom# }o tigrcy }yre exrpettiont miped}cy j} }he cit}enep rpogr} jnm tee vhj}
hjrrent. Aop exjgrce# }yrinf }he aopg
(`efin (mitrcjy"Hecco# Vopcm*")
(nevcine))
j} }he Tdhege rpogr} rpomudet
Hecco# Vopcm*
Jd}ujccy# you doucm tigrcy hjqe }yrem }he aopg "Hecco# Vopcm*" j} }he cit}enep# jnm youvoucm hjqe o`}jinem jt petuc} }he t}pinf
"Hecco# Vopcm*"
`edjute }hj} it }he petuc} oa }he cit}enep eqjcuj}inf "Hecco# Vopcm*".
O}hep }hjn }he ajd} }hj} }he tedonm jrrpojdh rpomudet j petuc} vi}h mou`ce'zuo}et
jpounm i}# }hepe it one o}hep tifniaidjn} miaaepende `e}veen }he cjt} }vo rpofpjgt. ]he
aipt} (ie# }he one vi}h }he `efin) moet no} eqjcuj}e }o jny}hinf '' }he Hecco# Vopcm* i}
egi}t it j time'eaaed}rpomudem `y }he mitrcjy jnm nevcine rpodemupet vpi}inf }o }het}jnmjpm ou}ru}. In }he tedonm rpofpjg# }he aopg "Hecco# Vopcm*"eqjcuj}et }o }he
petuc}# vhidh in }hit djte it }he tjge t}pinf jt }he aopg.
Hendeaop}h# ve vicc ute }he no}j}ion 7>}o meno}e eqjcuj}ion. ]hut
E7> q
inmidj}et }hj} }he aopg E eqjcuj}et }o j petuc} qjcue oaq. Ef#
(`efin
(mitrcjy"Hecco# Vopcm*")(nevcine))
7>
(ie# no}hinf op qoim)# jc}houfh i} hjt }he time'eaaed} oa vpi}inf
Hecco# Vopcm*
8/14/2019 Teach Yourself Scheme in Fixnum Days
8/120
}o }he t}jnmjpm ou}ru}. On }he o}hep hjnm#
"Hecco# Vopcm*"
7> "Hecco# Vopcm*"
In ei}hep djte# ve jpe t}icc j} }he cit}enep. ]o exi}# }yre(exi})
jnm }hit vicc cjnm you `jdk j} }he orepj}inf'tyt}eg doggjnm'cine (vhidh# jt ve&qe
teen# it jcto j kinm oa cit}enep).
]he cit}enep it donqenien} aop in}epjd}iqe }et}inf oa rpofpjgt jnm rpofpjg apjfgen}t.
Hoveqep i} it `y no gejnt nedettjpy. You gjy dep}jincy t}idk }o }he }pjmi}ion oa
dpej}inf rpofpjgt in }heip en}ipe}y in aicet# jnm hjqinf Tdhege exedu}e }heg vi}hou}
jny exrcidi} bbcit}eninf&&. In G|Tdhege# aop int}jnde# you doucm tjy (j} }he orepj}inf'
tyt}eg rpogr})
g|tdhege 'p hecco.tdg
jnm }hit vicc rpomude }he fpee}inf vi}hou} gjkinf you mejc vi}h }he cit}enep. Ja}ep }he
fpee}inf# g|tdhege vicc pe}upn you }o }he orepj}inf'tyt}eg rpogr}. ]hit it jcgot} jt ia
you tjim
edho Hecco# Vopcm*
You doucm eqen gjke hecco.tdg teeg cike jn orepj}inf'tyt}eg doggjnm (j thecc
tdpir} op j `j}dh aice)# `u} }hj} vicc hjqe }o vji} }icc dhjr}ep :1.
8/14/2019 Teach Yourself Scheme in Fixnum Days
9/120
Dhjr}ep 0
Mj}j }yret
J mj}j }yre it j docced}ion oa pecj}em qjcuet. ]hete docced}iont neem no} `e mitloin}#
jnm }hey jpe oa}en hiepjpdhidjc. Tdhege hjt j pidh te} oa mj}j }yret< toge jpe tigrce
(inmiqiti`ce) mj}j }yret jnm o}hept jpe dogrounm mj}j }yret gjme `y dog`ininf o}hep
mj}j }yret.
0.: Tigrce mj}j }yret
]he tigrce mj}j }yret oa Tdhege indcume `oocejnt# nug`ept# dhjpjd}ept# jnm tyg`oct.
0.:.: @oocejnt
Tdhege&t oocejnt jpe $} aop }pue jnm $aaop ajcte. Tdhege hjt j rpemidj}e rpodemupe
djccem `oocejn? }hj} dhedkt ia i}t jpfugen} it `oocejn.
(`oocejn?$}) 7> $}(`oocejn?"Hecco# Vopcm*") 7> $a
]he rpodemupe no} nefj}et i}t jpfugen}# dontimepem jt j `oocejn.
(no}$a) 7> $}(no}$}) 7> $a(no}"Hecco# Vopcm*") 7> $a
]he cjt} exrpettion iccut}pj}et j Tdhege donqeniende< In j don}ex} }hj} pezuipet j
`oocejn# Tdhege vicc }pej} jny qjcue }hj} it no} $ajt j }pue qjcue.
0.:.0 Nug`ept
Tdhege nug`ept djn `e in}efept (ef# =0)# pj}ionjct (00/6)# pejct (4.:=:1)# op dogrcex(0+4i). Jn in}efep it j pj}ionjc it j pejc it j dogrcex nug`ep it j nug`ep. Rpemidj}et
exit} aop }et}inf }he qjpiout kinmt oa nug`epnett $}(nug`ep?$}) 7> $a
(dogrcex?0+4i) 7> $}
(pejc?0+4i) 7> $a
8/14/2019 Teach Yourself Scheme in Fixnum Days
10/120
(pejc?4.:=:1) 7> $}(pejc?00/6) 7> $}
(pejc?=0) 7> $}(pj}ionjc?0+4i) 7> $a
(pj}ionjc?4.:=:1) 7> $}(pj}ionjc?00/6) 7> $}(in}efep?00/6) 7> $a
(in}efep?=0) 7> $}
Tdhege in}efept neem no} `e trediaiem in medigjc (`jte :2) aopgj}. ]hey djn `e
trediaiem in `injpy `y rpeaixinf }he nugepjc vi}h $`. ]hut $`::22 it }he nug`ep
}vecqe. ]he od}jc rpeaix it $o jnm }he hex rpeaix it $x. (]he or}ionjc medigjc rpeaix
it $m.)
Nug`ept djn }et}em aop ezujci}y utinf }he fenepjc'ruprote ezujci}y rpemidj}e ezq?.
(ezq?=0=0) 7> $}(ezq?=0$a) 7> $a
(ezq?=0=0.2) 7> $a
Hoveqep# ia you knov }hj} }he jpfugen}t }o `e dogrjpem jpe nug`ept# }he tredijc
nug`ep'ezujci}y rpemidj}e 7 it gope jr}.
(7=0=0) 7> $}
(7=0$a) ''>EPPOP***
(7=0=0.2) 7> $}
O}hep nug`ep dogrjpitont jccovem jpe 3# 37# ># >7.
(340) 7> $a(>7=.54) 7> $}
Jpi}hge}id rpodemupet +# '# ,# /# exr} hjqe }he exred}em ehjqiop 1('5.40) 7> 4.4
('50:) 7> 0(,:04) 7> 1(/14) 7> 0
(/006) 7> 00/6(exr}04) 7> 8
(exr}=:/0) 7> 0.2
Aop j tinfce jpfugen}# ' jnm / pe}upn }he nefj}ion jnm }he pedirpodjc petred}iqecy :/=
8/14/2019 Teach Yourself Scheme in Fixnum Days
11/120
]he rpodemupet gjx jnm gin pe}upn }he gjxigug jnm ginigug petred}iqecy oa }he
nug`ep jpfugen}t turrciem }o }heg. Jny nug`ep oa jpfugen}t djn `e to turrciem.
(gjx:4=04) 7> =(gin:4=04) 7> :
]he rpodemupe j`t pe}upnt }he j`tocu}e qjcue oa i}t jpfugen}.
(j`t 4) 7> 4
(j`t'=) 7> =
]hit it lut} }he }ir oa }he ide`epf. Tdhege rpoqimet j cjpfe jnm dogrpehentiqe tui}e oa
jpi}hge}id jnm }pifonoge}pid rpodemupet. Aop int}jnde# j}jn# exr# jnm tzp} petred}iqecy
pe}upn }he jpd}jnfen}# nj}upjc jn}icofjpi}hg# jnm tzujpe poo} oa }heip jpfugen}. Dontuc}
P5PT [04W aop gope me}jict.
0.:.4 Dhjpjd}ept
Tdhege dhjpjd}ep mj}j jpe perpeten}em `y rpeaixinf }he dhjpjd}ep vi}h $S. ]hut# $Sd it
}he dhjpjd}ep d. Toge non'fpjrhid dhjpjd}ept hjqe gope metdpir}iqe njget#
ef#$Snevcine# $S}j`. ]he dhjpjd}ep aop trjde djn `e vpi}}en $S # op gope
pejmj`cy# $Strjde.
]he dhjpjd}ep rpemidj}e it dhjp? $}(dhjp?:) 7> $a
(dhjp?$S;) 7> $}
No}e }hj} j tegidocon dhjpjd}ep mj}ug moet no} }piffep j doggen}.
]he dhjpjd}ep mj}j }yre hjt i}t te} oa dogrjpiton
rpemidj}et< dhjp7?# dhjp3?# dhjp37?# dhjp>?# dhjp>7?.
(dhjp7?$Sj$Sj) 7> $}
(dhjp3?$Sj$S`) 7> $}
(dhjp>7?$Sj$S`) 7> $a
]o gjke }he dogrjpitont djte'intenti}iqe# ute dhjp'di int}ejm oadhjp in }herpodemupe njge $}
]he djte donqeption rpodemupet jpe dhjp'movndjte jnm dhjp'urdjte
8/14/2019 Teach Yourself Scheme in Fixnum Days
12/120
(dhjp'movndjte$SJ) 7> $Sj(dhjp'urdjte$Sj) 7> $SJ
0.:.= Tyg`oct
]he tigrce mj}j }yret ve tjv j`oqe jpe teca'eqjcuj}inf. Ie# ia you }yrem jny o`led}
apog }hete mj}j }yret }o }he cit}enep# }he eqjcuj}em petuc} pe}upnem `y }he cit}enep vicc`e }he tjge jt vhj} you }yrem in.
$} 7> $}=0 7> =0
$Sd7> $Sd
Tyg`oct mon&} `ehjqe }he tjge vjy. ]hit it `edjute tyg`oct jpe utem `y Tdhege
rpofpjgt jt imen}iaiept aop qjpij`cet# jnm }hut vicc eqjcuj}e }o }he qjcue }hj} }he
qjpij`ce hocmt. Neqep}hecett# tyg`oct jpe j tigrce mj}j }yre# jnm tyg`oct jpe
cefi}igj}e qjcuet }hj} Tdhege djn }pjaaid in# jconf vi}h dhjpjd}ept# nug`ept# jnm }he
pet}.
]o trediay j tyg`oc vi}hou} gjkinf Tdhege }hink i} it j qjpij`ce# you
thoucm zuo}e }he tyg`oc xy|
Tinde }hit }yre oa zuo}inf it qepy doggon in Tdhege# j donqenien} j``peqij}ion it
rpoqimem. ]he exrpettion
&E
vicc `e }pej}em `y Tdhege jt ezuiqjcen} }o
(zuo}eE)
Tdhege tyg`oct jpe njgem `y j tezuende oa dhjpjd}ept. J`ou} }he oncy cigi}j}ion on
j tyg`oc&t njge it }hj} i} thoucmn&} `e git}jkj`ce aop toge o}hep mj}j# ef# dhjpjd}ept
op `oocejnt op nug`ept op dogrounm mj}j. ]hut# }hit'it'j'tyg`oc# i:8n# 37>#
jnm -*$, jpe jcc tyg`oct; :1# 'i (j dogrcex nug`ep*)# $}# "}hit'it'j't}pinf"# jnm(`jpa) (j
cit}) jpe no}. ]he rpemidj}e aop dhedkinf tyg`ocnett it djccem tyg`oc? $}
(tyg`oc?=0) 7> $a
Tdhege tyg`oct jpe nopgjccy djte'intenti}iqe. ]hut }he
tyg`oct Djcopie jnm djcopie jpe imen}idjc
8/14/2019 Teach Yourself Scheme in Fixnum Days
13/120
(ezq?&Djcopie&djcopie)
7> $}
Ve djn ute }he tyg`oc xy| jt j fco`jc qjpij`ce `y utinf }he aopg meaine $SH
Nev t}pinft djn `e dpej}em `y jrrenminf o}hep t}pinft "Hjcco"
0.0.0 Qed}opt
Qed}opt jpe tezuendet cike t}pinft# `u} }heip ecegen}t djn `e jny}hinf# no} lut}
dhjpjd}ept. Inmeem# }he ecegen}t djn `e qed}opt }hegtecqet# vhidh it j foom vjy }o
fenepj}e guc}imigentionjc qed}opt.
Hepe&t j vjy }o dpej}e j qed}op oa }he aipt} aiqe in}efept $(2:04=)
No}e Tdhege&t perpeten}j}ion oa j qed}op qjcue< j $ dhjpjd}ep aoccovem `y }he qed}op&t
don}en}t endcotem in rjpen}hetet.
8/14/2019 Teach Yourself Scheme in Fixnum Days
15/120
In jnjcofy vi}h gjke't}pinf# }he rpodemupe gjke'qed}op gjket j qed}op oa j trediaid
cenf}h :(cit}'peay4) 7> =
(cit}'}jicy:) 7> (04=)(cit}'}jicy4) 7> (=)
cit}'}jic pe}upnt }he }jic oa }he cit} t}jp}inf apog }he fiqen inmex.
]he rpemidj}et rjip?# cit}?# jnm nucc? dhedk ia }heip jpfugen} it j mo}}em rjip# cit}# op
}he egr}y cit}# petred}iqecy $}
(rjip?&(:0)) 7> $}(rjip?&()) 7> $a(cit}?&()) 7> $}
(nucc?&()) 7> $}
(cit}?&(:0)) 7> $}(cit}?&(: . 0)) 7> $a
(nucc?&(:0)) 7> $a(nucc?&(: . 0)) 7> $a
0.0.= Donqeptiont `e}veen mj}j }yret
Tdhege oaaept gjny rpodemupet aop donqep}inf jgonf }he mj}j }yret. Ve jcpejmy
knov hov }o donqep} `e}veen }he dhjpjd}ep djtet utinf dhjp'movndjte jnm dhjp'
urdjte. Dhjpjd}ept djn `e donqep}em in}o in}efept utinf dhjp'>in}efep# jnm in}efept
djn `e donqep}em in}o dhjpjd}ept utinf in}efep'>dhjp. (]he in}efep doppetronminf }o j
dhjpjd}ep it utujccy i}t jtdii dome.)
(dhjp'>in}efep$Sm) 7> :22
(in}efep'>dhjp52) 7> $S0
8/14/2019 Teach Yourself Scheme in Fixnum Days
18/120
T}pinft djn `e donqep}em in}o }he doppetronminf cit} oa dhjpjd}ept.
(t}pinf'>cit}"hecco") 7> ($Sh$Se$Sc$Sc$So)
O}hep donqeption rpodemupet in }he tjge qein jpe cit}'>t}pinf# qed}op'>cit}#
jnm cit}'>qed}op.
Nug`ept djn `e donqep}em }o t}pinftnug`ep":1")
7> :1
(t}pinf'>nug`ep"Jg I j ho} nug`ep?")
7> $a
t}pinf'>nug`ep }jket jn or}ionjc tedonm jpfugen}# }he pjmix.
(t}pinf'>nug`ep":1"8) 7> :=
`edjute :1 in `jte 8 it }he nug`ep aoup}een.
Tyg`oct djn `e donqep}em }o t}pinft# jnm qide qeptjtyg`oc"t}pinf")
7> t}pinf
0.4 O}hep mj}j }yret
Tdhege don}jint toge o}hep mj}j }yret. One it }herpodemupe. Ve hjqe jcpejmy teen
gjny rpodemupet# ef# mitrcjy# +# dont. In pejci}y# }hete jpe qjpij`cet hocminf }he
rpodemupe qjcuet# vhidh jpe }hegtecqet no} qiti`ce jt jpe nug`ept op dhjpjd}ept 3rpodemupe>
]he rpodemupet ve hjqe teen }hut ajp jperpigi}iqe rpodemupet# vi}h t}jnmjpm fco`jc
qjpij`cet hocminf }heg. Utept djn dpej}e jmmi}ionjc rpodemupe qjcuet.
8/14/2019 Teach Yourself Scheme in Fixnum Days
19/120
Ye} jno}hep mj}j }yre it }herop}. J rop} it }he donmui} }hpoufh vhidh inru} jnm ou}ru}
it repaopgem. Rop}t jpe utujccy jttodij}em vi}h aicet jnm dontocet.
In oup bbHecco# Vopcm*&& rpofpjg# ve utem }he rpodemupe mitrcjy }o vpi}e j t}pinf }o
}he dontoce. mitrcjy djn }jke }vo jpfugen}t# one }he qjcue }o `e mitrcjyem# jnm }he
o}hep }he ou}ru} rop} i} thoucm `e mitrcjyem on.
In oup rpofpjg# mitrcjy&t tedonm jpfugen} vjt igrcidi}. ]he meajuc} ou}ru} rop} utem
it }he t}jnmjpm ou}ru} rop}. Ve djn fe} }he duppen} t}jnmjpm ou}ru} rop} qij }he
rpodemupe'djcc (duppen}'ou}ru}'rop}). Ve doucm hjqe `een gope exrcidi} jnm vpi}}en
(mitrcjy"Hecco# Vopcm*" (duppen}'ou}ru}'rop}))
0.= T'exrpettiont
Jcc }he mj}j }yret mitduttem hepe djn `e cugrem }ofe}hep in}o j tinfce jcc'
endogrjttinf mj}j }yre djccem }he t'exrpettion (t aop tyg`ocid).
]hut =0# $Sd# (: . 0)# $(j`d)#"Hecco"# (zuo}exy|)# (t}pinf'>nug`ep":1")#
jnm (`efin (mitrcjy"Hecco# Vopcm*") (nevcine)) jpe jcc t'exrpettiont.
8/14/2019 Teach Yourself Scheme in Fixnum Days
20/120
Dhjr}ep 4
Aopgt
]he pejmep vicc hjqe no}em }hj} }he Tdhege exjgrce rpofpjgt rpoqimem }hut ajp jpe
jcto t'exrpettiont. ]hit it }pue oa jcc Tdhege rpofpjgt< Rpofpjgt jpe mj}j.
]hut# }he dhjpjd}ep mj}ug $Sd it j rpofpjg# op jaopg. Ve vicc ute }he gope fenepjc
}epgaopg int}ejm oarpofpjg# to }hj} ve djn mejc vi}h rpofpjg apjfgen}t }oo.
Tdhege eqjcuj}et }he aopg $Sd }o }he qjcue $Sd# `edjute $Sd it teca'eqjcuj}inf. No} jcct'exrpettiont jpe teca'eqjcuj}inf. Aop int}jnde }he tyg`oc t'exrpettion xy| eqjcuj}et
}o }he qjcue hecm `y }he qjpij`cexy|. ]he cit} t'exrpettion (t}pinf'
>nug`ep":1") eqjcuj}et }o }he nug`ep :1.
No} jcc t'exrpettiont jpe qjcim rpofpjgt. Ia you }yrem }he mo}}em'rjip t'
exrpettion (: . 0) j} }he Tdhege cit}enep# you vicc fe} jn eppop.
Tdhege eqjcuj}et j cit} aopg `y exjgininf }he aipt} ecegen}# op hejm# oa }he aopg. Ia
}he hejm eqjcuj}et }o j rpodemupe# }he pet} oa }he aopg it eqjcuj}em }o fe} }he
rpodemupe&t jpfugen}t# jnm }he rpodemupe it jrrciem}o }he jpfugen}t.
Ia }he hejm oa }he aopg it j tredijc aopg# }he eqjcuj}ion rpodeemt in j gjnnep
imiotyndpj}id }o }hj} aopg. Toge tredijc aopgt ve hjqe jcpejmy teen jpe `efin# meaine#
jnmte}*. `efin djutet i}t tu`aopgt }o `e eqjcuj}em in opmep# }he petuc} oa }he en}ipe aopg
`einf }he petuc} oa }he cjt} tu`aopg. meaine in}pomudet jnm ini}ijci|et j
qjpij`ce. te}*dhjnfet }he `inminf oa j qjpij`ce.
4.: Rpodemupet
Ve hjqe teen zui}e j aev rpigi}iqe Tdhege rpodemupet# ef# dont# t}pinf'>cit}# jnm}he cike. Utept djn dpej}e }heip ovn rpodemupet utinf }he tredijc aopg cjg`mj. Aop
exjgrce# }he aoccovinf meainet j rpodemupe }hj} jmmt 0 }o i}t jpfugen} 1
In fenepjc# jrrcy }jket j rpodemupe# aoccovem `y j qjpij`ce nug`ep oa o}hep
jpfugen}t# }he cjt} oa vhidh gut} `e j cit}. I} dont}pud}t }he jpfugen} cit} `y rpeaixinf
}he cjt} jpfugen} vi}h jcc }he o}hep (in}epqeninf) jpfugen}t. I} }hen pe}upnt }he petuc}
oa djccinf }he rpodemupe on }hit jpfugen} cit}. Ef#
(jrrcy+:04x)
7> :0
4.4 Tezuendinf
Ve utem }he `efin tredijc aopg }o `undh }ofe}hep j fpour oa tu`aopgt }hj} neem }o `e
eqjcuj}em in tezuende. Gjny Tdhege aopgt hjqe igrcidi}`efint. Aop exjgrce# ce}&t
meaine j 4'jpfugen} rpodemupe }hj} mitrcjyt i}t }hpee jpfugen}t# vi}h trjdet `e}veen
}heg. J rotti`ce meaini}ion it cov'rpettupe
Tdhege rpoqimet toge o}hep donmi}ionjc aopgt aop donqeniende. ]hey djn jcc `e
meainem jt gjdpot (dhjr 8) }hj} exrjnm in}o ia'exrpettiont.
=.: vhen jnm uncett
vhen jnm uncett jpe donqenien} donmi}ionjct }o ute vhen oncy one `pjndh (}he bb}hen&&
op }he bbecte&& `pjndh) oa }he `jtid donmi}ionjc it neemem.
(vhen (3 (rpettupe}u`e) 12)
(oren'qjcqe}u`e)
(j}}jdhacoop'rugr}u`e)(merpettacoop'rugr5)
(me}jdhacoop'rugr}u`e)
(dcote'qjcqe}u`e))
Jttuginf rpettupe oa}u`e it cett }hjn 12# }hit donmi}ionjc vicc j}}jdh acoop'
rugr }o }u`e jnm merpett i} 5 }iget. (j}}jdh jnm merpett jpe toge tui}j`ce
rpodemupet.)
8/14/2019 Teach Yourself Scheme in Fixnum Days
25/120
]he tjge rpofpjg utinf ia voucm `e 4
]he dcjute vhote hejm don}jint }he qjcue oad it dhoten.
=.= jnm jnm op
Tdhege rpoqimet tredijc aopgt aop `oocejn donlund}ion (bbjnm&&) jnm mitlund}ion(bbop&&). (Ve hjqe jcpejmy teen (ted 0.:.:) Tdhege&t oocejn nefj}ion no}# vhidh it j
rpodemupe.)
]he tredijc aopg jnm pe}upnt j }pue qjcue ia jcc i}t tu`aopgt jpe }pue. ]he jd}ujc qjcue
pe}upnem it }he qjcue oa }he ainjc tu`aopg. Ia jny oa }he tu`aopgt jpe
ajcte# jnm pe}upnt $a.
(jnm:0) 7> 0(jnm$a:) 7> $a
]he tredijc aopg op pe}upnt }he qjcue oa i}t aipt} }pue tu`aopg. Ia jcc }he tu`aopgt jpeajcte# op pe}upnt $a.
(op:0) 7> :(op$a:) 7> :
@o}h jnm jnm op eqjcuj}e }heip tu`aopgt cea}'}o'pifh}. Jt toon jt }he petuc} djn `e
me}epginem# jnm jnm op vicc ifnope }he pegjininf tu`aopgt.
(jnm:$aexrpettion'fujpjn}eem'}o'djute'eppop)
7> $a
(op:$aexrpettion'fujpjn}eem'}o'djute'eppop)
7> :
8/14/2019 Teach Yourself Scheme in Fixnum Days
27/120
Dhjr}ep 5
Cexidjc qjpij`cet
Tdhege&t qjpij`cet hjqe cexidjc tdore# ie# }hey jpe qiti`ce oncy }o aopgt vi}hin j
dep}jin don}ifuout t}pe}dh oa rpofpjg }ex}. ]he fco`jc qjpij`cet ve hjqe teen }hut ajp
jpe no exder}ion< ]heip tdore it jcc rpofpjg }ex}# vhidh it dep}jincy don}ifuout.
Ve hjqe jcto teen toge exjgrcet oacodjc qjpij`cet. ]hete vepe
}he cjg`mj rjpjge}ept# vhidh fe} `ounmejdh }ige }he rpodemupe it djccem# jnm vhote
tdore it }hj} rpodemupe&t `omy. Ef#
(meainex9)
(meainejmm0 (cjg`mj (x) (+x0)))
x 7> 9
(jmm04) 7> 5(jmm0x) 7> ::
x 7> 9
Hepe# }hepe it j fco`jc x# jnm }hepe it jcto j codjc x# }he cj}}ep in}pomudem `yrpodemupe jmm0. ]he fco`jc x it jcvjyt 9. ]he codjc x fe}t `ounm }o 4 in }he aipt} djcc
}o jmm0 jnm }o }he qjcue oa }he fco`jc x# ie# 9# in }he tedonm djcc }o jmm0. Vhen }he
rpodemupe djcct pe}upn# }he fco`jc x don}inuet }o `e 9.
]he aopg te}* gomiaiet }he cexidjc `inminf oa j qjpij`ce.
(te}*x02)
gomiaiet }he fco`jc `inminf oax apog 9 }o 02# `edjute }hj} it }he `inminf oax }hj} it
qiti`ce }o te}*. Ia }he te}* vjt intime jmm0&t `omy# i} voucm hjqe gomiaiem }he codjc x 02
No}e }hj} ve hjm jcc }hit mitduttion `edjute ve utem }he tjge imen}iaiep aop j codjc
qjpij`ce jnm j fco`jc qjpij`ce. In jny }ex}# jn imen}iaiep njgem x peaept }o }he cexidjccy
dcotet} qjpij`ce njgem x. ]hit vicc thjmov jny ou}ep op fco`jc x&t. Ef# in jmm0# }he
rjpjge}ep x thjmovt }he fco`jc x.
J rpodemupe&t `omy djn jddett jnm gomiay qjpij`cet in i}t tuppounminf tdore rpoqimem
}he rpodemupe&t rjpjge}ept mon&} thjmov }heg. ]hit djn fiqe toge in}epet}inf
rpofpjgt. Ef#
(meainedoun}ep2)
(meaine`ugr'doun}ep
(cjg`mj ()
(te}*doun}ep (+doun}ep:))doun}ep))
]he rpodemupe `ugr'doun}ep it j |epo'jpfugen} rpodemupe (jcto djccem j }hunk). I}
in}pomudet no codjc qjpij`cet# jnm }hut djnno} thjmov jny}hinf. Ejdh }ige i} it djccem#
i} gomiaiet }he fco`jc qjpij`ce doun}ep '' i} indpegen}t i} `y : '' jnm pe}upnt i}t duppen}
qjcue. Hepe jpe toge tuddettiqe djcct }o `ugr'doun}ep 0
(`ugr'doun}ep) 7> 4
5.: ce} jnm ce},
Codjc qjpij`cet djn `e in}pomudem vi}hou} exrcidi}cy dpej}inf j rpodemupe. ]he tredijc
aopg ce} in}pomudet j cit} oa codjc qjpij`cet aop ute vi}hin i}t `omy (:04)
Jt vi}h cjg`mj# vi}hin }he ce}'`omy# }he codjc x (`ounm }o :) thjmovt }he
fco`jc x (vhidh it `ounm }o 02).
]he codjc qjpij`ce ini}ijci|j}iont '' x }o :; y }o 0; | }o 4 '' jpe no} dontimepem rjp} oa
}he ce} `omy. ]hepeaope# j peaepende }o x in }he ini}ijci|j}ion vicc peaep }o }he fco`jc#
no} }he codjc x 0:
]hit it `edjute x it `ounm }o :# jnm y it `ounm }o }he fco`jcx# vhidh it 02.
Toge}iget# i} it donqenien} }o hjqe ce}&t cit} oa cexidjc qjpij`cet `e in}pomudem in
tezuende# to }hj} }he ini}ijci|j}ion oa j cj}ep qjpij`ce oddupt in }he cexidjc tdore oa
ejpciep qjpij`cet. ]he aopg ce}, moet }hit 0
]he x in y&t ini}ijci|j}ion peaept }o }he x lut} j`oqe. ]he exjgrce it en}ipecy ezuiqjcen}
}o '' jnm it in ajd} in}enmem }o `e j donqenien} j``peqij}ion aop '' }he aoccovinf
rpofpjg vi}h net}em ce}t 0
]he qjcuet `ounm }o cexidjc qjpij`cet djn `e rpodemupet 4
Intime }hit ce} `omy# }he cexidjc qjpij`ce dont jmmt i}t jpfugen}t.
Ou}time# dont don}inuet }o dpej}e mo}}em rjipt.
8/14/2019 Teach Yourself Scheme in Fixnum Days
30/120
5.0 acuim'ce}
J cexidjc qjpij`ce it qiti`ce }hpoufhou} i}t tdore# rpoqimem i} itn&} thjmovem.
Toge}iget# i} it hecrauc }o }egropjpicy te} j cexidjc qjpij`ce }o j dep}jin qjcue. Aop
}hit# ve ute }he aopg acuim'ce}.0
(acuim'ce} ((doun}ep99))
(mitrcjy (`ugr'doun}ep)) (nevcine)
(mitrcjy (`ugr'doun}ep)) (nevcine)
(mitrcjy (`ugr'doun}ep)) (nevcine))
]hit cookt tigicjp }o j ce}# `u} int}ejm oa thjmovinf }he fco`jc qjpij`ce doun}ep# i}
}egropjpicy te}t i} }o 99 `eaope don}inuinf vi}h }he acuim'ce} `omy. ]hut }he mitrcjyt
in }he `omy rpomude
:22
:2::20
Ja}ep }he acuim'ce} exrpettion hjt eqjcuj}em# }he fco`jc doun}ep peqep}t }o }he qjcue i}
hjm `eaope }he acuim'ce}.
doun}ep7> 4
No}e }hj} acuim'ce} hjt jn en}ipecy miaaepen} eaaed} apog ce}. acuim'ce} moet no}
in}pomude nev cexidjc qjpij`cet cike ce} moet. I} gomiaiet }he `inminft
oaexit}inf cexidjc qjpij`cet# jnm }he gomiaidj}ion dejtet jt toon jt }he acuim'
ce} moet.
]o mpiqe hoge }hit roin}# dontimep }he rpofpjg
(ce} ((doun}ep99))
(mitrcjy (`ugr'doun}ep)) (nevcine)
(mitrcjy (`ugr'doun}ep)) (nevcine)
(mitrcjy (`ugr'doun}ep)) (nevcine))
vhidh tu`t}i}u}et ce} aop acuim'ce} in }he rpeqiout exjgrce. ]he ou}ru} it nov
=
5
1
Ie# }he fco`jc doun}ep# vhidh it ini}ijccy 4# it urmj}em `y ejdh djcc }o `ugr'doun}ep.
]he nev cexidjc qjpij`ce doun}ep# vi}h i}t ini}ijci|j}ion oa99# hjt no igrjd} on }he
djcct }o`ugr'doun}ep# `edjute jc}houfh }he djcct }o `ugr'doun}ep jpe vi}hin }he tdore
8/14/2019 Teach Yourself Scheme in Fixnum Days
31/120
oa }hit codjc doun}ep# }he `omy oa`ugr'doun}ep itn&}. ]he cj}}ep don}inuet }o peaep }o
}hefco`jcdoun}ep# vhote ainjc qjcue it 1.
doun}ep7> 1
0acuim'ce} it j nont}jnmjpm tredijc aopg. Tee ted 8.4 aop j meaini}ion oaacuim'ce} in
Tdhege.
8/14/2019 Teach Yourself Scheme in Fixnum Days
32/120
Dhjr}ep 1
Peduption
J rpodemupe `omy djn don}jin djcct }o o}hep rpodemupet# no} cejt} i}teca ((: . :2) (0 . 02) (4 . 42))
(gjr+&(:04) &(:20242))
7> (::0044)
8/14/2019 Teach Yourself Scheme in Fixnum Days
36/120
Dhjr}ep 6
I/O
Tdhege hjt inru}/ou}ru} (I/O) rpodemupet }hj} vicc ce} you pejm apog jn inru} rop} op
vpi}e }o jn ou}ru} rop}. Rop}t djn `e jttodij}em vi}h }he dontoce# aicet op t}pinft.
6.: Pejminf
Tdhege&t pejmep rpodemupet }jke jn or}ionjc inru} rop} jpfugen}. Ia }he rop} it no}
trediaiem# }he duppen} inru} rop} (utujccy }he dontoce) it jttugem.
Pejminf djn `e dhjpjd}ep'# cine' op t'exrpettion'`jtem. Ejdh }ige j pejm it repaopgem#
}he rop}&t t}j}e dhjnfet to }hj} }he nex} pejm vicc pejm gj}epijc aoccovinf vhj} vjt
jcpejmy pejm. Ia }he rop} hjt no gope gj}epijc }o `e pejm# }he pejmep rpodemupe pe}upnt
j trediaid mj}ug djccem }he enm'oa'aice op eoa o`led}. ]hit mj}ug it }he oncy qjcue }hj}
tj}itaiet }he eoa'o`led}? rpemidj}e.
]he rpodemupe pejm'dhjp pejmt }he nex} dhjpjd}ep apog }he rop}. pejm'cine pejmt }he
nex} cine# pe}upninf i} jt j t}pinf (}he ainjc nevcine it no} indcumem). ]he
rpodemupe pejmpejmt }he nex} t'exrpettion.
6.0 Vpi}inf
Tdhege&t vpi}ep rpodemupet }jke }he o`led} }hj} it }o `e vpi}}en jnm jn or}ionjc ou}ru}
rop} jpfugen}. Ia }he rop} it no} trediaiem# }he duppen} ou}ru} rop} (utujccy }he dontoce)
it jttugem.
Vpi}inf djn e dhjpjd}ep' op t'exrpettion'`jtem.
]he rpodemupe vpi}e'dhjp vpi}et }he fiqen dhjpjd}ep (vi}hou} }he $S) }o }he ou}ru}rop}.
]he rpodemupet vpi}e jnm mitrcjy `o}h vpi}e }he fiqen t'exrpettion }o }he rop}# vi}h
one miaaepende< vpi}e j}}egr}t }o ute j gjdhine'pejmj`ce aopgj} jnm mitrcjy moetn&}.
Ef# vpi}e utet mou`ce zuo}et aop t}pinft jnm }he $S tyn}jx aop
dhjpjd}ept. mitrcjy moetn&}.
8/14/2019 Teach Yourself Scheme in Fixnum Days
37/120
]he rpodemupe nevcine t}jp}t j nev cine on }he ou}ru} rop}.
6.4 Aice rop}t
Tdhege&t I/O rpodemupet mo no} neem j rop} jpfugen} ia }he rop} hjrrent }o `e
t}jnmjpm inru} op t}jnmjpm ou}ru}. Hoveqep# ia you neem }hete rop}t exrcidi}cy# }he|epo'jpfugen} rpodemupet duppen}'inru}'rop} jnm duppen}'ou}ru}'rop} aupnith
}heg. ]hut#
(mitrcjy9)
(mitrcjy9 (duppen}'ou}ru}'rop}))
hjqe }he tjge `ehjqiop.
J rop} it jttodij}em vi}h j aice `y oreninf }he aice. ]he rpodemupe oren'inru}'
aice
}jket j aicenjge jpfugen} jnm pe}upnt j nev inru} rop} jttodij}em vi}h i}. ]herpodemupeoren'ou}ru}'aice }jket j aicenjge jpfugen} jnm pe}upnt j nev ou}ru} rop}
jttodij}em vi}h i}. I} it jn eppop }o oren jn inru} aice }hj} moetn&} exit}# op }o oren jn
ou}ru} aice }hj} jcpejmy exit}t.
Ja}ep you hjqe repaopgem I/O on j rop}# you thoucm dcote i} vi}h dcote'inru}'
rop} op dcote'ou}ru}'rop}.
In }he aoccovinf# jttuge }he aice hecco.}x} don}jint }he tinfce vopm hecco.
(meainei (oren'inru}'aice"hecco.}x}"))
(pejm'dhjpi)
7> $Sh
(meainel (pejmi))
l
7> ecco
Jttuge }he aice fpee}inf.}x} moet no} exit} `eaope }he aoccovinf rpofpjgt jpe aem }o
}he cit}enep ($Sh$Se$Sc)
]he rpodemupe djcc'vi}h'ou}ru}'aice moet }he jnjcofout tepqidet aop jn ou}ru} aice.
6.= T}pinf rop}t
I} it oa}en donqenien} }o jttodij}e rop}t vi}h t}pinft. ]hut# }he rpodemupe oren'inru}'
t}pinf jttodij}et j rop} vi}h j fiqen t}pinf. Pejmep rpodemupet on }hit rop} vicc pejm
oaa }he t}pinf 0
]hepe it j rpo`ceg vi}h }he gy'op gjdpo jt i} it vpi}}en. I} pe'eqjcuj}et }he aipt}
jpfugen} ia i} it }pue< onde in }he ia'}et}# jnm onde jfjin in }he bb}hen&& `pjndh. ]hit
djn djute unmetipem `ehjqiop ia }he aipt} jpfugen} vepe }o don}jin time'eaaed}t# ef#
(gy'op(`efin
(mitrcjy"moinf aipt} jpfugen}")
(nevcine)
$})
0)
mitrcjyt "moinf aipt} jpfugen}" }vide.
]hit djn `e jqoimem `y t}opinf }he ia'}et} petuc} in j codjc qjpij`ce aponm
(meainercjn}jin(gjke'}pee&heifh}6
&ceja'thjre&thee}))
(}pee.heifh}rcjn}jin)
7> 6
(}pee.ceja'thjrercjn}jin)
7> thee}
(}pee.ceja'docoprcjn}jin)
7> fpeen
9.0 meat}pud} meainem
]he meat}pud} gjdpo meaini}ion aoccovt
8/14/2019 Teach Yourself Scheme in Fixnum Days
49/120
(meaine'gjdpomeat}pud}(cjg`mj (t . aa)
(ce} ((t't (tyg`oc'>t}pinft)) (n (cenf}haa)))(ce}, ((n+: (+n:))
(qq (gjke'qed}opn+:)))
(ce}coor ((i:) (aaaa))(ia (37in)
(ce} ((a (djpaa)))
(qed}op'te}*qqi
(ia (rjip?a) (djmpa) &(ia$a$a)))
(coor (+i:) (dmpaa)))))
(ce} ((aa (gjr (cjg`mj (a) (ia (rjip?a) (djpa) a))
aa)))
b(`efin
(meaine#(t}pinf'>tyg`oc
(t}pinf'jrrenm"gjke'"t't))
(cjg`mjaqaq
(ce} ((t} (gjke'qed}op#n+:)) (aaaa))(qed}op'te}*t}2t)
#B(ce}coor ((i:) (p&()))
(ia (>7in+:) p(coor (+i:)
(dontb(qed}op'te}*t}#i
#(qed}op'peaqqi))
p))))
(ce}coor ((aqaqaqaq))(ia (no} (nucc?aqaq))
(`efin
(qed}op'te}*t}
(+ (cit}'roti}ion (djpaqaq) aa)
:)
(djmpaqaq))
(coor (dmmpaqaq)))))
t})))
#B(ce}coor ((i:) (rpodt&()))(ia (>7in+:) rpodt
(coor (+i:)
(ce} ((a (tyg`oc'>t}pinf
(cit}'peaaa ('i:)))))
(dont
b(meaine#(t}pinf'>tyg`oc
(t}pinf'jrrenm
t't"."a))
(cjg`mj (x) (qed}op'peax#i)))
(dont
b(meaine#(t}pinf'>tyg`oc
(t}pinf'jrrenm
"te}*"t't"."a))(cjg`mj (xq)
(qed}op'te}*x#iq)))
rpodt))))))
(meaine#(t}pinf'>tyg`oc (t}pinf'jrrenmt't"?"))
(cjg`mj (x)(jnm (qed}op?x)
(ezq? (qed}op'peax2) t))))))))))
8/14/2019 Teach Yourself Scheme in Fixnum Days
50/120
Dhjr}ep :2
Jcit}t jnm }j`cet
Jn jttodij}ion cit}# op jcit}# it j Tdhege cit} oa j tredijc aopgj}. Ejdh ecegen} oa }he
cit} it j dont decc# }he djp oa vhidh it djccem j key# }he dmp `einf }he qjcue jttodij}em
vi}h }he key. Ef#
((j . :) (` . 0) (d . 4))
]he rpodemupe djcc (jttqkjc) ainmt }he dont decc jttodij}em vi}h key k in jcit} jc.]he keyt oa }he jcit} jpe dogrjpem jfjint} }he fiqen k utinf }he ezujci}y
rpemidj}e ezq?. In fenepjc# }houfh ve gjy vjn} j miaaepen} rpemidj}e aop key
dogrjpiton. Aop int}jnde# ia }he keyt vepe djte'intenti}iqe t}pinft# }he
rpemidj}e ezq? it no} qepy uteauc.
Ve nov meaine j t}pud}upe djccem }j`ce# vhidh it j tourem'ur jcit} }hj} jccovt utep'
meainem rpemidj}et on i}t keyt. I}t aiecmt jpe ezu jnm jcit}.
(meat}pud}}j`ce (ezuezq?) (jcit}&()))
(]he meajuc} rpemidj}e it ezq? '' jt aop jn opminjpy jcit} '' jnm }he jcit} it ini}ijccy
egr}y.)
Ve vicc ute }he rpodemupe }j`ce'fe} }o fe} }he qjcue (jt orrotem }o }he dont decc)
jttodij}em vi}h j fiqen key. }j`ce'fe} }jket j }j`ce jnm key jpfugen}t# aoccovem `y
jn or}ionjc meajuc} qjcue }hj} it pe}upnem ia }he key vjt no} aounm in }he }j`ce "/hoge/mopji"
(fe}enq"THECC")
7> "/`in/`jth"
= G|Tdhege rpoqimet }he tyt}eg rpodemupe qij }he rpodett ci`pjpy.
Ute (pezuipe (ci`"rpodett.tt")) }o cojm }hit ci`pjpy.
8/14/2019 Teach Yourself Scheme in Fixnum Days
54/120
Dhjr}ep :0
O`led}t jnm dcjttet
J dcjtt metdpi`et j docced}ion oao`led}t }hj} thjpe `ehjqiop. ]he o`led}t metdpi`em `y
j dcjtt jpe djccem }he int}jndet oa }he dcjtt. ]he dcjtt trediaiet }he njget oa
}he tco}t}hj} }he int}jnde hjt# jc}houfh i} it ur }o }he int}jnde }o rorucj}e }hete tco}t
vi}h rjp}iducjp qjcuet. ]he dcjtt jcto trediaiet }he ge}homt }hj} djn `e jrrciem }o i}t
int}jndet. Tco} qjcuet djn `e jny}hinf# `u} ge}hom qjcuet gut} `e rpodemupet.
Dcjttet jpe hiepjpdhidjc. ]hut# j dcjtt djn `e j tu`dcjtt oa jno}hep dcjtt# vhidh itdjccem i}t turepdcjtt. J tu`dcjtt no} oncy hjt i}t ovn miped}tco}t jnm ge}homt# `u}
jcto inhepi}t jcc }he tco}t jnm ge}homt oa i}t turepdcjtt. Ia j dcjtt hjt j tco} op ge}hom
}hj} hjt }he tjge njge jt i}t turepdcjtt&t# }hen }he tu`dcjtt&t tco} op ge}hom it }he one
}hj} it pe}jinem.
:0.: J tigrce o`led} tyt}eg
Ce} ut nov igrcegen} j `jtid o`led} tyt}eg in Tdhege. Ve vicc jccov oncy one
turepdcjtt rep dcjtt (tinfce inhepi}jnde). Ia ve mon&} vjn} }o trediay j turepdcjtt# ve
vicc ute$} jt j bb|epo&& turepdcjtt# one }hj} hjt nei}hep tco}t nop ge}homt. ]heturepdcjtt oa$} it meegem }o `e i}teca.
Jt j aipt} jrrpoxigj}ion# i} it uteauc }o meaine dcjttet utinf j t}pud} djccem t}jnmjpm'
dcjtt# vi}h aiecmt aop }he tco} njget# }he turepdcjtt# jnm }he ge}homt. ]he aipt} }vo
aiecmt ve vicc djcc tco}t jnm turepdcjtt petred}iqecy. Ve vicc ute }vo aiecmt aop ge}homt#
j ge}hom'njget aiecm }hj} vicc hocm }he cit} oa njget oa }he dcjtt&t ge}homt# jnm
jge}hom'qed}op aiecm }hj} vicc hocm }he qed}op oa }he qjcuet oa }he dcjtt&t ge}homt.5 Hepe
it }he meaini}ion oa }he t}jnmjpm'dcjttdpogocy:8.5jciqio)
vhepe 3}piqijc'`ike'dcjtt> it j Tdhege mj}ug (jno}hep qed}op) }hj} it }he qjcue oa}piqijc'
`ike'dcjtt# jt meainem j`oqe.
]he rpodemupe dcjtt'oape}upnt }he dcjtt oa jn int}jnde $a
]he rupecy aund}ionjc jrrpojdh it }o acj}}en `o}h }peet jnm dhedk ia }he petuc}t gj}dh.
(meainetjge'apinfe?(cjg`mj (}pee:}pee0)
(ce}coor ((a}pee: (acj}}en}pee:))
(a}pee0 (acj}}en}pee0)))
(donm ((jnm (nucc?a}pee:) (nucc?a}pee0)) $})
((op (nucc?a}pee:) (nucc?a}pee0)) $a)
((ezq? (djpa}pee:) (djpa}pee0))
(coor (dmpa}pee:) (dmpa}pee0)))
(ecte$a)))))
(meaineacj}}en(cjg`mj (}pee)
(donm ((nucc?}pee) &())
((rjip? (djp}pee))(jrrenm (acj}}en (djp}pee))
(acj}}en (dmp}pee))))
(ecte
(dont (djp}pee)
(acj}}en (dmp}pee)))))))
Hoveqep# }hit }pjqeptet }he }peet dogrce}ecy }o acj}}en }heg# jnm }hen jfjin }icc i} ainmt
non'gj}dhinf ecegen}t. Aup}hepgope# eqen }he et} acj}}eninf jcfopi}hgt vicc
pezuipe dontet ezujc }o }he }o}jc nug`ep oa cejqet. (Met}pud}iqecy gomiayinf }he inru}
}peet it no} jn or}ion.)
Ve djn ute djcc/dd }o tocqe }he rpo`ceg vi}hou} neemcett }pjqeptjc jnm vi}hou}jny dontinf. Ejdh }pee it gjrrem }o j fenepj}op# j rpodemupe vi}h in}epnjc t}j}e }hj}
tuddettiqecy rpomudet }he cejqet oa }he }pee in }he cea}'}o'pifh} opmep }hj} }hey oddup in
}he }pee.
(meaine}pee'>fenepj}op(cjg`mj (}pee)
(ce} ((djccep&,))
(ce}ped
((fenepj}e'cejqet
(cjg`mj ()(ce}coor ((}pee}pee))
(donm ((nucc?}pee) &tkir)
((rjip?}pee)
(coor (djp}pee))
(coor (dmp}pee)))
(ecte
(djcc/dd
(cjg`mj (pet}'oa'}pee)(te}*fenepj}e'cejqet
(cjg`mj ()
8/14/2019 Teach Yourself Scheme in Fixnum Days
67/120
(pet}'oa'}pee&petuge)))
(djccep}pee))))))
(djccep&()))))(cjg`mj ()
(djcc/dd
(cjg`mj (k)(te}*djccepk)
(fenepj}e'cejqet))))))))
Vhen j fenepj}op dpej}em `y }pee'>fenepj}op it djccem# i} vicc t}ope }he don}inuj}ion
oa i}t djcc in djccep# to }hj} i} djn knov vho }o tenm }he ceja }o vhen i} ainmt i}. I} }hen
djcct jn in}epnjc rpodemupe djccem fenepj}e'cejqet vhidh punt j coor }pjqeptinf }he
}pee apog cea} }o pifh}. Vhen }he coor endoun}ept j ceja# i} vicc ute djccep }o pe}upn }he
ceja jt }he fenepj}op&t petuc}# `u} i} vicc pegeg`ep }o t}ope }he pet} oa }he coor
(djr}upem jt j djcc/dd don}inuj}ion) in }he fenepj}e'cejqet qjpij`ce. ]he nex} }ige
}he fenepj}op it djccem# }he coor it petugem vhepe i} cea} oaa to i} djn hun} aop }he nex}
ceja.
No}e }hj} }he cjt} }hinf fenepj}e'cejqet moet# ja}ep }he coor it mone# it }o pe}upn }he
egr}y cit} }o }he djccep. Tinde }he egr}y cit} it no} j qjcim ceja qjcue# ve djn ute i} }o
}ecc }hj} }he fenepj}op hjt no gope cejqet }o fenepj}e.
]he rpodemupe tjge'apinfe? gjrt ejdh oa i}t }pee jpfugen}t }o j fenepj}op# jnm }hen
djcct }hete }vo fenepj}opt jc}epnj}ecy. I} jnnoundet ajicupe jt toon jt }vo non'
gj}dhinf cejqet jpe aounmfenepj}op}pee:))
(fen0 (}pee'>fenepj}op}pee0)))
(ce}coor ()(ce} ((ceja: (fen:))
(ceja0 (fen0)))
(ia (ezq?ceja:ceja0)
(ia (nucc?ceja:) $} (coor))
$a))))))
I} it ejty }o tee }hj} }he }peet jpe }pjqeptem j} got} onde# jnm in djte oa gitgj}dh# }he
}pjqeptjct ex}enm oncy ur}o }he cea}got} gitgj}dh. dont it no} utem.
:4.= Dopou}inet
]he fenepj}opt utem j`oqe jpe in}epet}inf fenepjci|j}iont oa }he rpodemupe donder}.
Ejdh }ige }he fenepj}op it djccem# i} petuget i}t dogru}j}ion# jnm vhen i} hjt j petuc}
aop i}t djccep pe}upnt i}# `u} oncy ja}ep t}opinf i}t don}inuj}ion in jn in}epnjc qjpij`ce to
}he fenepj}op djn `e petugem jfjin. Ve djn fenepjci|e fenepj}opt aup}hep# to }hj} }hey
8/14/2019 Teach Yourself Scheme in Fixnum Days
68/120
djn gu}ujccy petuge ejdh o}hep# tenminf petuc}t `jdk jnm aop}h jgonft} }hegtecqet.
Tudh rpodemupet jpe djccem dopou}inet [:8W.
Ve vicc qiev j dopou}ine jt j unjpy rpodemupe# vhote `omy djn
don}jin petuge djcct. petuge it j }vo'jpfugen} rpodemupe utem `y j dopou}ine }o
petuge jno}hep dopou}ine vi}h j }pjntaep qjcue. ]he gjdpo dopou}ine meainet tudh jdopou}ine rpodemupe# fiqen j qjpij`ce njge aop }he dopou}ine&t ini}ijc jpfugen}# jnm
}he `omy oa }he dopou}ine.
(meaine'gjdpodopou}ine
(cjg`mj (x . `omy)
b(ce}ped ((+codjc'don}poc't}j}e(cjg`mj (#x) #B`omy))
(petuge
(cjg`mj (dq)
(djcc/dd
(cjg`mj (k)
(te}*+codjc'don}poc't}j}ek)(dq))))))
(cjg`mj (q)
(+codjc'don}poc't}j}eq)))))
J djcc oa }hit gjdpo dpej}et j dopou}ine rpodemupe (ce}&t djcc i}J) }hj} djn `e djccem
vi}h one jpfugen}.J hjt jn in}epnjc qjpij`ce djccem +codjc'don}poc't}j}e }hj} t}opet#
j} jny roin}# }he pegjininf dogru}j}ion oa }he dopou}ine. Ini}ijccy }hit it }he en}ipe
dopou}ine dogru}j}ion. Vhen petuge it djccem '' ie# inqokinf jno}hep dopou}ine@ ''
}he duppen} dopou}ine vicc urmj}e i}t +codjc'don}poc't}j}e qjcue }o }he pet} oa i}teca#
t}or i}teca# jnm }hen lugr }o }he petugem dopou}ine@. Vhen dopou}ineJ it
i}tecapetugem j} toge cj}ep roin}# i}t dogru}j}ion vicc rpodeem apog }he don}inuj}iont}opem in i}t +codjc'don}poc't}j}e.
:4.=.: ]pee'gj}dhinf vi}h dopou}inet
]pee'gj}dhinf it aup}hep tigrciaiem utinf dopou}inet. ]he gj}dhinf rpodett it domem
jt j dopou}ine }hj} merenmt on }vo o}hep dopou}inet }o turrcy }he cejqet oa }he
petred}iqe }peetEPPOP***jg`}peeexhjut}em
(Ve vicc exjgine }he vopminf oa }he eppop gettjfe cj}ep.)
In rjp}iducjp# jg` it pezuipem }o pe}upn j qjcue ia j} cejt} one i}t tu`exrpettiont
donqepfet# ie# moetn&} ajic. ]hut#
(jg`: (jg`))
8/14/2019 Teach Yourself Scheme in Fixnum Days
72/120
jnm
(jg` (jg`) :)
`o}h pe}upn :.
Dcejpcy# jg` djnno} tigrcy `e ezuj}em }o i}t aipt} tu`exrpettion# tinde i} hjt }o pe}upn
j non'ajicinf qjcue# ia }hit it j} jcc rotti`ce. Hoveqep# }hit it no} jcc< ]he `ijt aop
donqepfende it gope t}pinfen} }hjn j gepecy codjc dhoide oajg`&t
tu`exrpettiont. jg` thoucm aup}hepgope pe}upn }hj}donqepfen} qjcue }hj} gjket
}he en}ipe rpofpjgdonqepfe. In meno}j}ionjc rjpcjnde# jg` it jn jnfecid orepj}op.
Aop exjgrce#
(jg`$a$})
gjy pe}upn ei}hep $a op $}# `u} in }he rpofpjg
(ia (jg`$a$})
:
(jg`))
}he aipt} jg`'exrpettion gut}pe}upn $}. Ia i} pe}upnem $a# }he ia&t bbecte&& `pjndh voucm
`e dhoten# vhidh djutet }he en}ipe rpofpjg }o ajic.
:=.0 Igrcegen}inf jg` in Tdhege
In oup igrcegen}j}ion oajg`# ve vicc ajqop jg`&t tu`exrpettiont apog cea} }o pifh}. Ie#
}he aipt} tu`exrpettion it dhoten# jnm ia i} cejmt }o oqepjcc ajicupe# }he tedonm it ridkem#
jnm to on. jg`t odduppinf cj}ep in }he don}poc acov oa }he rpofpjg jpe tejpdhem aop
jc}epnj}et eaope jdk}pjdkinf }o rpeqiout jg`t. In o}hep vopmt# ve repaopg j mer}h'
aipt}tejpdh oa }he jg`dhoide }pee# jnm vheneqep ve `puth jfjint} ajicupe# ve
`jdk}pjdk }o }he got} peden} nome oa }he }pee }hj} oaaept j aup}hep dhoide. (]hit it
djccem dhponocofidjc jdk}pjdkinf.)
Ve aipt} meaine j gedhjnitg aop te}}inf }he `jte ajicupe don}inuj}ionihi) (jg`)
(jg`i (coor (+i:)))))))
]hut (nug`ep'`e}veen:1) vicc aipt} fenepj}e :. Thoucm }hj} ajic# }he coor i}epj}et#
rpomudinf 0. Thoucm }hj}ajic# ve fe} 4# jnm to on# un}ic 1. Ja}ep 1# coor it djccem vi}h
}he nug`ep 6# vhidh `einf gope }hjn 1# inqoket (jg`)# vhidh djutet ainjc ajicupe.
(Pedjcc }hj} (jg`) `y i}teca fujpjn}eet ajicupe.) J} }hit roin}# }he rpofpjg don}jininf
}he djcc }o(nug`ep'`e}veen:1) vicc jdk}pjdk }o }he dhponocofidjccy rpeqiout jg`'
djcc# jnm }py }o tj}itay }hj}djcc in jno}hep ajthion.
]he fujpjn}eem ajicupe oa(jg`) djn `e utem }o rpofpjg jttep}iont.
(meainejttep}(cjg`mj (rpem)
(ia (no}rpem) (jg`))))
]he djcc(jttep}rpem)
intit}t }hj}rpem
`e }pue. O}hepvite i} vicc djute }heduppen} jg` dhoide roin} }o ajic.6
Hepe it j rpodemupe utinf jttep} }hj} fenepj}et j rpige cett }hjn op ezujc }o i}t
jpfugen} hi4
]hit cejqet ye} jno}hep ajicupe don}inuj}ion# vhidh djn `e djccem jfjin aop ye} jno}hep
tocu}ion5
]he rpo`ceg vi}h }hit ge}hom it }hj} }he rpofpjg it ini}ijccy djccem j} }he Tdhege
rpogr}# jnm tuddettiqe tocu}iont jpe jcto o`}jinem `y djccinf jg` j} }he Tdhege
rpogr}. In eaaed}# ve jpe utinf miaaepen} rpofpjgt (ve djnno} rpemid} hov gjny*)#
djppyinf oqep inaopgj}ion apog j rpeqiout rpofpjg }o }he nex}. Int}ejm# ve voucm cike
}o `e j`ce }o fe} }hete tocu}iont jt }he pe}upn qjcue oa j aopg }hj} ve djn djcc in jny
don}ex}. ]o }hit enm# ve meaine }he `jf'oa gjdpo# vhidh pe}upnt jcc }he tuddettauc
int}jn}ij}iont oa i}t jpfugen}. (Ia }he jpfugen} neqep tuddeemt# `jf'oa pe}upnt }he
egr}y cit}.) ]hut# ve doucm tjy#
(`jf'oa
(fen'rpige02))
jnm i} voucm pe}upn
(0456:::4:6:9)
]he `jf'oa gjdpo it meainem jt aoccovt 2:04=51689
Ie# }he coor fe}t }o rpin} ur}o j dep}jin nug`ep (hepe 9) jnm }hen ajict `edjute oa }he
dcodk in}eppur}. Hoveqep# oupajicupe rpodemupe te}t j fco`jc qjpij`ce djccem ,gope, }o
}he ajicem enfine# vhidh ve djn ute }o petuge }he coor vhepe }he rpeqiout enfine cea}
oaa :2:::0:4:=:5:1:6:8:9
Ve vicc nov dont}pud} enfinet utinf djcc/dd }o djr}upe }he unainithem dogru}j}ion oa
j ajicinf enfine. Aipt} ve vicc dont}pud}acj}enfinet# op enfinet vhote dogru}j}ion
djnno} indcume }he punninf oa o}hep enfinet. Ve vicc cj}ep fenepjci|e }he dome }o }he
gope fenepjc net}j`ce enfinet op net}ept# vhidh djn djcc o}hep enfinet. @u} in `o}hdjtet# ve neem j }igep gedhjnitg# op j dcodk.
:5.: ]he dcodk
Oup enfinet jttuge }he rpetende oa j fco`jc dcodk op in}eppur}j`ce }igep }hj} gjpkt
}he rjttjfe oa }idkt jt j rpofpjg exedu}et. Ve vicc jttuge }he aoccovinf dcodk
in}epajde '' ia youp Tdhege rpoqimet jny kinm oa jcjpg gedhjnitg# i} thoucm `e jn
ejty gj}}ep }o pif ur j dcodk oa }he aoccovinf }yre. (Jrrenmix M meainet j dcodk aop
}he Fuice [:4W mijced} oa Tdhege.)
]he in}epnjc t}j}e oa oup dcodk rpodemupe dontit}t oa }vo i}egtcit}t)))
(cit}'>t}pinf
(ce}coor ((tt))(ia (nucc?t) &()
(ce} ((j (djpt)) (m (dmpt)))(djtej
(($S+) (dont$Strjde (coorm)))
(($S%) (dont (hex'>dhjp (djpm) (djmpm))
(coor (dmmpm))))
(ecte (dontj (coorm)))))))))))
b+
& it donqep}em in}o trjde. J }pici}epjc oa }he aopg b%xy
& it donqep}em# utinf }herpodemupe hex'>dhjp in}o }he dhjpjd}ep vhote jtdii endominf it }he hex nug`ep bxy&.
(meainehex'>dhjp(cjg`mj (xy)
(in}efep'>dhjp
(t}pinf'>nug`ep (t}pinfxy) :1))))
8/14/2019 Teach Yourself Scheme in Fixnum Days
99/120
Ve t}icc neem j aopg'mj}j rjptep aop }he djte vhepe }he pezuet} ge}hom it ROT]. ]he
juxicijpy rpodemupe rjpte'aopg'mj}j'utinf't}min moet }hit.
(meainerjpte'aopg'mj}j'utinf't}min(cjg`mj ()
(ce}, ((don}en}'cenf}h (fe}enq"DON]EN]_CENF]H"))
(don}en}'cenf}h
(iadon}en}'cenf}h
(t}pinf'>nug`epdon}en}'cenf}h) 2))
(i2))
(ce}rjp'coor ((rjp&()))(ce} ((d (pejm'dhjp)))
(te}*i (+i:))
(ia (op (>idon}en}'cenf}h)
(eoa'o`led}?d) (dhjp7?d$S7))
(ce}jpf'coor ((jpf&()))(ce} ((d (pejm'dhjp)))
(te}*i (+i:))
(ia (op (>idon}en}'cenf}h)
(eoa'o`led}?d) (dhjp7?d$S!))(ce} ((rjp (upc'medome
(cit}'>t}pinf
(peqepte*rjp))))
(jpf (upc'medome
(cit}'>t}pinf
(peqepte*jpf)))))
(}j`ce'ru}*,aopg'mj}j'}j`ce,rjp
(dontjpf (}j`ce'fe},aopg'mj}j'}j`ce,
rjp&())))(uncett (op (>idon}en}'cenf}h)
(eoa'o`led}?d))
(rjp'coor&())))
(jpf'coor (dontdjpf)))))
(rjp'coor (dontdrjp))))))))
]he ROT] ge}hom tenmt aopg mj}j qij }he tdpir}&t t}min. ]he nug`ep oa dhjpjd}ept ten}
it rcjdem in }he enqipongen} qjpij`ce DON]EN]_CENF]H. rjpte'aopg'mj}j'utinf'
t}min pejmt }he pezuipem nug`ep oa dhjpjd}ept apog t}min# jnm rorucj}et }he ,aopg'
mj}j'}j`ce, jt `eaope# gjkinf tupe }o medome }he rjpjge}ept& njget jnm qjcuet.
I} pegjint }o pe}pieqe }he qjcuet aop trediaid rjpjge}ept apog }he ,aopg'mj}j'}j`ce,.
No}e }hj} }he }j`ce jttodij}et j cit} vi}h ejdh rjpjge}ep# in opmep }o jddoggomj}e }he
rotti`ici}y oa guc}irce qjcuet aop j rjpjge}ep. aopg'mj}j'fe} pe}pieqet jcc }he qjcuet
jttifnem }o j rjpjge}ep. Ia }hepe it oncy one qjcue# i} pe}upnt j tinfce}on don}jininf}hj} qjcue.
(meaineaopg'mj}j'fe}(cjg`mj (k)
(}j`ce'fe},aopg'mj}j'}j`ce,k&())))
8/14/2019 Teach Yourself Scheme in Fixnum Days
100/120
aopg'mj}j'fe}/: pe}upnt }he aipt} (op got} tifniaidjn}) qjcue jttodij}em vi}h j
rjpjge}ep.
(meaineaopg'mj}j'fe}/:(cjg`mj (k . meajuc})
(ce} ((qq (aopg'mj}j'fe}k)))
(donm ((rjip?qq) (djpqq))
((rjip?meajuc}) (djpmeajuc}))
(ecte"")))))
In oup exjgrcet to ajp# }he DFI tdpir} hjt fenepj}em rcjin }ex}. Fenepjccy# }houfh# ve
vicc vjn} }o fenepj}e jn H]GC rjfe. I} it no} undoggon aop j dog`inj}ion oa H]GC
aopg jnm DFI tdpir} }o }piffep j tepiet oa H]GC rjfet vi}h aopgt. I} it jcto doggon
}o dome jcc }he jd}ion doppetronminf }o }hete qjpiout aopgt in j tinfce DFI tdpir}. In
jny djte# i} it hecrauc }o hjqe j u}ici}y rpodemupe }hj} vpi}et ou} t}pinft in H]GC
aopgj}# ie# vi}h }he H]GC tredijc dhjpjd}ept endomem jrrporpij}ecy7in)
(ce} ((d (t}pinf'peati)))
(mitrcjy
(djted
(($S3) "!c};")
(($S>) "!f};")
(($S") "!zuo};")
(($S!) "!jgr;")(ected)) o)
(coor (+i:)))))))))
:6.= J djcducj}op qij DFI
Hepe it jn DFI djcducj}op tdpir}# dfidjcd.tdg# }hj} exrcoi}t Tdhege&t jp`i}pjpy'
rpedition jpi}hge}id.
$*/`in/th
"
8/14/2019 Teach Yourself Scheme in Fixnum Days
101/120
(entupe'nug`epe))))
(meaineentupe'orepj}op(cjg`mj (e)
(djtee
((+) +)
((') ')
((,) ,)
((/) /)
((,,) exr})
(ecte (uhoh"unrepgi}}em orepj}op")))))
(meaineentupe'nug`ep(cjg`mj (e)
(ia (nug`ep?e) e
(uhoh"non'nug`ep"))))
(meainerpin}'aopg(cjg`mj ()
(mitrcjy"3aopg jd}ion7S"")
(mitrcjy (fe}enq"TDPIR]_NJGE"))(mitrcjy"S">
En}ep jpi}hge}id exrpettion
3inru} }yre7}ex}jpej njge7jpi}hexr>3r>
3inru} }yre7tu`gi} qjcue7S"Eqjcuj}eS">
3inru} }yre7pete} qjcue7S"DcejpS">
3/aopg>")))
(meainerpin}'rjfe'`efin
(cjg`mj ()
(mitrcjy"don}en}'}yre< }ex}/h}gc
3h}gc>
3hejm>
3}i}ce>J Tdhege Djcducj}op3/}i}ce>
3/hejm>
3`omy>")))
(meainerpin}'rjfe'enm
(cjg`mj ()
(mitrcjy"3/`omy>
3/h}gc>")))
(rjpte'aopg'mj}j)
(rpin}'rjfe'`efin)
(ce} ((e (aopg'mj}j'fe}"jpi}hexr")))(uncett (nucc?e)
(ce} ((e: (djpe)))
(mitrcjy'h}gce:)
(mitrcjy"3r>
7!f};!n`tr;!n`tr;")
(mitrcjy'h}gc
(djcc/dd
(cjg`mj (k)(te}*uhoh
8/14/2019 Teach Yourself Scheme in Fixnum Days
102/120
(cjg`mj (t)
(k (t}pinf'jrrenm"Eppop< "t))))
(nug`ep'>t}pinf
(djcd'eqjc (pejm (oren'inru}'t}pinf (djpe))))))))
(mitrcjy"3r>"))))
(rpin}'aopg)
(rpin}'rjfe'enm)
8/14/2019 Teach Yourself Scheme in Fixnum Days
103/120
Jrrenmix J
Tdhege mijced}t
Jcc gjlop Tdhege mijced}t igrcegen} }he P5PT trediaidj}ion [04W. @y utinf oncy }he
aej}upet modugen}em in }he P5PT# one djn vpi}e Tdhege dome }hj} it rop}j`ce jdpott
}he mijced}t. Hoveqep# }he P5PT# ei}hep aop vjn} oa dontentut op `edjute oa ineqi}j`ce
tyt}eg merenmendiet# pegjint ticen} on teqepjc gj}}ept }hj} non'}piqijc rpofpjgginf
djnno} ifnope. ]he qjpiout mijced}t hjqe }hepeaope hjm }o tocqe }hete gj}}ept in j non'
t}jnmjpm jnm imiotyndpj}id gjnnep.
]hit `ook utet }he G|Tdhege [9W mijced} oa Tdhege# jnm }hepe`y utet teqepjc
aej}upet }hj} jpe nont}jnmjpm. ]he dogrce}e cit} oa }he mijced}'merenmen} aej}upet utem
in }hit `ook it< }he doggjnm'cine (`o}h aop oreninf j cit}enep tettion jnm aop thecc
tdpir}t)# meaine'gjdpo# mece}e'aice# aice'exit}t?# aice'op'miped}opy'gomiay'
tedonmt# acuim'ce}# fentyg# fe}enq# fe}'ou}ru}'t}pinf# cojm'pecj}iqe# oren'inru}'
t}pinf# oren'ou}ru}'t}pinf# pejm'cine# peqepte*# tyt}eg#uncett jnm vhen.
Jcc `u} }vo oa }hete jpe rpeten} in }he meajuc} enqipongen} oa G|Tdhege. ]he gittinf
}vo# meaine'gjdpo jnm tyt}eg# jpe rpoqimem in t}jnmjpm G|Tdhege ci`pjpiet# vhidh
djn `e exrcidi}cy cojmem in}o G|Tdhege utinf }he aopgtn2)(ce} ((d2 (t}pinf'peaa2)))
(op (dhjp7?d2$S/)
(dhjp7?d2$S~))))))
(iaaucc'rj}hnjge?a(t}pinf'jrrenm
(mipnjge,cojm'rj}hnjge,)
"/"a))))))
(t}k%cojm,cojm'rj}hnjge,))))
(meainecojm
(cjg`mj (a)
(eppop"Mon&} ute cojm. Ute cojm'pecj}iqe int}ejm.")))
:: Ve vicc ute ~/aicenjge }o meno}e }he aice djccem aicenjge in }he utep&t hoge
miped}opy.
8/14/2019 Teach Yourself Scheme in Fixnum Days
108/120
Jrrenmix @
MOT `j}dh aicet in Tdhege
MOT thecc tdpir}t jpe knovn jt `j}dh aicet. J donqen}ionjc MOT `j}dh aice }hj}
ou}ru}t bbHecco# Vopcm*&& hjt }he aoccovinf don}en}t 2# (n) it meainem jt }he
aoccovinf in}efpjc vi}h un`ounmem urrep cigi} 2# (n + :) 7 n (n). ]hit igrciet
}hj} ia ve knov }he qjcue oa in }he in}epqjc (:# 0)# ve djn ainm (n) aop jny pejcn >
2. Inmeem# ia ve pecjx }he donmi}ion n > 2# ve djn ute petuc} (`) }o ex}enm }he mogjin
oa (n) }o indcume n 3 2# vi}h }he unmept}jnminf }hj} }he aund}ion vicc miqepfe
aop in}efepn 32.:1
Ve aipt} igrcegen} j Tdhege rpodemupe fjggj':'}o'0 }hj} pezuipet i}t jpfugen} n }o
`e vi}hin }he in}epqjc (:# 0). fjggj':'}o'0 }jket j tedonm jpfugen} e aop }he }ocepjnde.
(meainefjggj':'}o'0(cjg`mj (ne)
(uncett (3:n0)(eppop&fjggj':'}o'0"jpfugen} ou}time (:# 0)"))
;...
Ve in}pomude j codjc qjpij`ce fjggj'in}efpjnm }o hocm }he 'in}efpjnm f(x) 7xn':ex 2 it i}teca jn ex}ention oa }he bbmedpegen}'}hen'ajd}opijc&& aund}ion
}hj} gjrt in}efepn > 2 }o (n' :)*.
8/14/2019 Teach Yourself Scheme in Fixnum Days
118/120
Jrrenmix M
J dcodk aop inaini}y
]he Fuice [:4W rpodemupe jcjpg rpoqimet jn in}eppur}j`ce }igep gedhjnitg. ]he utep
djn te} op pete} }he jcjpg aop toge }ige uni}t# op t}or i}. Vhen }he jcjpg&t }igep punt
ou} oa }hit }ige# i} vicc te} oaa jn jcjpg# vhote dontezuendet jpe utep'te}}j`ce.
Fuice&t jcjpg it no} zui}e }he dcodk oa ted :5.:# `u} ve djn gomiay i} ejticy enoufh.
]he jcjpg&t }igep it ini}ijccy t}orremop zuietden}# ie# i} vicc no} te} oaa jn jcjpg eqen
jt }ige foet `y. ]o te} }he jcjpg&t }ige'}o'jcjpg }o `e n tedonmt# vhepe n it no} 2#pun(jcjpgn). Ia }he }igep vjt jcpejmy te} (`u} hjt no} ye} te} oaa jn jcjpg)#
}he (jcjpgn) rpodemupe djcc vicc pe}upn }he nug`ep oa tedonmt pegjininf apog }he
rpeqiout jcjpg te}}inf. Ia }hepe it no rpeqiout jcjpg te}}inf# (jcjpgn) pe}upnt 2.
]he rpodemupe djcc (jcjpg2)t}ort }he jcjpg&t }igep# ie# }he doun}movn oa }ige it
t}orrem# }he }igep `edoget zuietden} jnm no jcjpg vicc fo oaa. (jcjpg2) jcto pe}upnt
}he tedonmt pegjininf apog j rpeqiout jcjpg te}}inf# ia jny.
@y meajuc}# vhen }he jcjpg&t doun}movn pejdhet 2# Fuice vicc mitrcjy j gettjfe on
}he dontoce jnm exi}. Gope uteauc `ehjqiop djn `e o`}jinem `y utinf }herpodemupetifjd}ion# jt aoccovt