Quiz 2, CS 257

  1. Respectable plant-people of the planet Blorg have their names inscribed upon their trunks shortly after germination. When a purple Blorgian speaks someone's name, it adds a suffix "-OOK-OOK" to the name inscribed on their trunk. When a green Blorgian addresses someone, it adds a prefix "BLIP-" to their name if it starts with a "Z", adds the prefix "BLOP-" to their name if it starts with a "Q", and adds the honorific suffix "-ICHOR" if it ends with an "S".

    Define a function (BLORG-SPOKEN-NAME COLOR-OF-SPEAKER NAME-ON-TRUNK) which, given the color of the speaking Blorgian and the name inscribed on the trunk of the Blorgian being addressed, returns the name to be spoken.

    For example:
    Color of Speaking Blorgian Name on Trunk of Blorgian Being Addressed Name to be Spoken
    PURPLE ZACH ZACH-OOK-OOK
    GREEN ZACH BLIP-ZACH
    GREEN ZAQS BLIP-ZAQS-ICHOR
    GREEN QUUX BLOP-QUUX
    GREEN QUIS BLOP-QUIS-ICHOR
    GREEN JIMMY JIMMY
    PURPLE JIMMY JIMMY-OOK-OOK

    
    
    
    
    
    
    
    
    
    
    
    
    

  2. Define a function (ADD-UP SEN) that, given a sentence of numbers, returns the sum of all the numbers in the sentence. For instance, (ADD-UP '(93)) = 93, (ADD-UP '(1 3 5)) = 9, and (ADD-UP '()) = 0.
    
    
    
    
    
    
    
    
    
    

  3. What values are printed when you type each of the following to Scheme?
    expressionresult
    (or #f #f 'aye 'bee) 
    (and #t #t 'aye 'bee) 
    (sentence 1 2) 
    '(sentence 1 2) 
    (word 12 13) 
    (first 98765) 
    (first '(98 76 5)) 
    (butfirst '(98 76 5)) 
    (quote (and 1 2)) 
    (not 'false) 

  4. Rewrite the following using IF rather than COND.
    (define (utensil cuisine)
       (cond ((equal? cuisine 'chinese) 'chopsticks)
             ((equal? cuisine 'ethiopian) 'fingers)
             (else 'fork)))