Problem Set Two, CS257, Spring 1999 Due 7pm Tue Feb 2 (the short time allowed is to honor valiant programmers turn in via worldwide struggling before ~cslab/bin/cs257-handin ps2.scm the Jan 1, 2000 deadline) ---------------------------------------------------------------- PROBLEM 1 No matter what happens, the U.S. Navy is not going to be caught napping. -Secretary of the Navy Frank Knox, December 5, 1941 Define the predicate DATE-OKAY? which takes three arguments: a year, a month (as a number), and a day of the month. It returns true iff the three arguments correspond to a valid date - including months with only 30 days, leap years, etc. Also if any of the arguments are inappropriate the routine should return #f rather than getting an error. Your function should assume that the current Gregorian calendar extends forward and backward in time forever - don't worry about the 10 missing days of Pope Pious or things like that. Examples: (date-okay? 1963 9 17) -> #t (17-Sep-1963 is okay) (date-okay? 1963 2 29) -> #f because '63 wasn't a leap year (date-okay? 1963 13 2) -> #f 13 isn't a valid month (date-okay? 1963 9 17.5) -> #f 17.5 isn't a valid day Hint1: your code had better be clear rather than a big mess, because if it's a big mess it'll ooze small bugs. It is vain to do with more what can be done with fewer. -- William of Occam, 14th-century Hint2: break things up into pieces ... but be sure to choose the right pieces. Hint3: liberal use of AND and OR, and avoiding explicit #f or #t, tends to clarify the logic of this kind of code. Hint4: You may need to look up the rule for what constitutes a leap year in the library. If you don't know how, ask a librarian! ---------------------------------------------------------------- PROBLEM 2 Indent this nicely: (+ (* (+ (* a u u u) (* b u u) (* c u) d) (+ (* a v v v) (* b v v) (* c v) d)) (* (+ (* a w w w) (* b w w) (* c w) d) (+ (* a x x x) (* b x x) (* c x) d)) (* (+ (* a y y y) (* b y y) (* c y) d) (+ (* a z z z) (* b z z) (* c z) d))) ---------------------------------------------------------------- Extra Credit Goof around with Scheme, and write a short description of something unexpected but cool you found by playing, rather than by reading the documentation. Be sure to explain why it's cool, and how you bumped into it. Eg: (+) evaluates to 0, which is the identity element for addition.