MASSACHVSETTS INSTITVTE OF TECHNOLOGY Depart ment of Electrical Engineering and Computer Science 01-Structure and Interpret at ion of Computer Programs Spring semester, 2005 Quiz i Closed book- one sheet of notes hroug hout this quiz, we have set aside space in which you should write your answers. Please try to put all of answers in the designated spaces, as we will look only in this spaces when grading Note that any procedures or code fragment s that you write will be judged not only on correct function, but also on clarity and good programming practice. NAME Sect ion number Tutor’ s Name: PART Value Grade grader 2345 叼56 Tot a 100
!"##$ %& &' (##) * * *& + ,' - *. & & & -** / &* - / &-&" %& / / &-& * & &&' & - - 0 / *& && -* " * / & & * / - - 1 2 / ' 1 & / " 3 13 4& 3 %5 (# ( 6 7 (# 8 ( ) ) ! ! ##
6.001, Spring Semester, 2005-Quiz I Part 1:(20 points) kor fach of thf following fxprfssions or sfqufncfs of fxprfssions, st atf thf valuf rft urnfd as thf rfsult of fvaluat ing thf final fxprfssion in fach sft, or indicate that thf fvaluat ion rfsults in an frror. Ef thf rfsult is an frror, st atf in gfnfral terms w hat kind of frror (f g. you might writf frror: wrong typf of argument to procfdurf"). ef thf fvaluat ion rft urns a built-in pro cfdur writf primitive pr ocedure. ef thf fvaluation returns a usfr-crfat fd procfdurf, writf compound pr oce Ef thf fxprfssion dofs not rfsult in an frror, also st atf thf "typf" of thf rfturnfd fxprfssion, using thf notat ion introduced in lfct urf hou may assumf that fvaluation of fach sfqufncf takfs placf in a nf wly init ializfd zchfmf syst fm Question 1. I aluf ypf Question (define + - (*12(+62) I aluf s ypf Question 3. ((lamb da(a b)(+ b a)) I aluf
( * * - >&&& &+ & >&&&' & * . & * & . * ? >&& * &' * * . & & " * & & ' & & -* 0 @"" / * - A3 - / BC" * . & 1 9 ' - " * . & &9 ' - " * >&& & & ' & & * A/B * >&&' & * " / && * . * &+ 0& -/ , * &/&" 3 /3 3 /3 3 /3
6.001, Spring Semester, 2005--Quiz I Question 4. ((lamb da (a) (+(sart a)(sart b)))) Question 5. e arg (defil (define (proc arg) (let ((local-arg 2)) (list arg local-arg))) (pr oc 1) Valu ype
7 3 /3 3 /3
6.001, Spring Semester, 2005--Quiz I Cons. 4er the follow ng S mple database of personnel nformat on. s he ent.re 4at abase. s represented as a liit of entr es. oach entry .s made 5s. ng the follow ng constr5ctor 01, SpI.-5k le lptry p Irzop z 5251 St So 2szt p Irzop z525r s he pn(10- part of an entry . s created 5s. ng the constr 5ctor Note that vales for names an4 pos t ons are represent e4 5s. ng str ngs, wh. le salar. es are represented 5s. ng n5mbers. Here s an example 4at abase 01,Sp1z5-p2105t5 2zt .-5k le lptry . -5k lep Irzopz-Sth""johphlpry"n 30000"pr lz solpt"n -5klelptry, ok ep rop"z-Sth m ppI"-fr SIm"h15thIr"n toooo"hick Ir"n 5k le lp 5k lep Ir r 10"n 55000"hack Ir"n -5k le lptry . -5k lep Irzop"Oo 1""j5pl""12Sz5(lth"n 38000"5zz Szt5pt Irzop"rol-5rSij5pl"n s9000"v Sc lepr 1z solpt Note that the fam. ly"name. s always the first element of the person abstract. on, b5t there can be arb. trar.ly many"g.ven"names Queltion 6: t raw a box-an4-po nter 4. agram for the str5ct5re correspond ng to fn1f, where 01, SpI t lzt.-5k le lptry -sk lep Irzop "z-Sth""johp'hlpry"n 30000 "pr Iz solpt"nm
8 & * - & 1& & " * 1& & & & &" * / & & * - & 3 * / & & * & 3 * . & & && & & &&' -* && & & 1&" & > 1&3 !"! !#"! !" ! $$$$ !! !#! !! !! !""! $$$$ !"! !"! !! $$$ !"! !! !#! !%"! &$$$ !! !! !! !#! '$$$ !(! * * B/B & -/& * ?& * & 1&' 1 * 1 1/ / B.B &" ! " - 1>99 * & & ' -* !"! !#"! !" ! $$$$ !!
6.001, Spring Semester, 2005--Quiz I Question 7mt omplete the n-f(2 abstraction by providing selectors for >n(1*-, for 1616(2 and for >*1dfd*-. For example (person test Value: ("smith""john"henry ") Question 8t omplete the >n(1*-abstract ion by providing selectors for a6ed12m-6en and bdin-m-6en1 (given-names (make-person "jones""anne""marie""heather")) value: ("anne ""marie""heather " (family-name (make-person "jones""anne""marie""heather ") Jones c hus the family name is always the first name in the entry, the given names are any names after
) ! * 1& 1/ . && ' " >3 )*+, !"! !#"! !" ! # * 1& 1/ . && ' "" ( !#! !! !! !""! )*+, !! !! !""! !#! !! !! !""! )*+, !#! * & * / & -/& * ?& * /' * . & / & *&"