magic car and cdr

Chapter: Magic numbers
...Section: magic car and cdr

In Scheme programming, there is a functional analog of the magic number. If your code is full of
t car cdr cadr caddr cddar etc then it is heavily dependent on the form in which you maintain your data. Code that expects phone books of the form (nick 775-0912 valerie 775-9043) will break horribly when you upgrade to data in the form ((nick 775-0912) (valerie 775-9043)) and again when you switch to a format like ((valerie 775-9043 9-1-71) (nick 775-0912 3-5-22) (valerie 774-9966 9-1-71) (valerie 774-5432 9-1-71))

Q. 28
So what's the fix?



Exercise 12

Do Exercise 11 again. But this time you are only allowed to use the built-in list deconstructors car cdr cadr etc. in the bodies of newly defined functions with names like namePart numberPart etc. Define these new accessor functions at the top of your file. The code for phone-number and any help functions should come after them and I repeat may not use the built-in list deconstructors.


rhypj@gwu.edu