Problem 5
For the following Scheme expressions, write the value that the STk
would output if you were to type it in. If an expression produces an error,
then just write ERROR.
- (first '(things first))
- (first (bf (item 3 '(thom colin johnny ed phil)))
(if (equal? 'that (or 'this 'that '(the other)))
(se (word) (quote (to say)))
(se (quote (+ 2 2)) 'always 'makes (se (word (word) 'a) '5)))
- (and (not '(hello)) (or (and (/ 5 0)) #t))
- (se ('tell 'me 'why))
Problem 6
For this function:
(define (mystery x)
(or (and (zero? x) '(+ x 5))
(and (= x 3) 5)
(se 'o (mystery (- x 2)))))
Give the results of the following calls. If a call results in an error,
write ERROR. If it results in an infinite recursion,
write INFLOOP
- (mystery 1)
- (mystery 2)
- (mystery 3)
- (mystery 8)
- (mystery 7)
Problem 7
Write a procedure called bunch-words, which takes in a sentence.
If the last letter of one word is the
same as the first letter of the following word, then the two words
should be joined together with the common letter removed from one of
them. See the examples:
- (bunch-words '(palo alto)) ==> (palo alto)
- (bunch-words '(planet telex)) ==> (planetelex)
- (bunch-words '(high and dry)) ==> (high andry)
- (bunch-words '(oh hello there)) ==> (ohello there)
- (bunch-world '(oh hello once more)) ==> (ohellonce more)
Problem 8
You and your partner have just expanded your day-span procedure
to work with any two dates in any years, even years before zero which are
currently represented as negative numbers (the year -1 refers to 1 BCE).
Your partner suggests that you switch to the more conventional
representation with CE and BCE. For example, instead of (may 1
1984) you
would use (may 1 1984 ce), and instead of (august 3 -50)
you would use
(august 3 50 bce).
Part A: How would you change the following accessors
to
accomodate this change?
(define (year date)
(item 3 date))
(define (month-name date)
(item 2 date))
(define (day-of-month date)
(first date))
Part B: Is it necessary to change anything else in the case study?
Why or why not?