11-752: week 3 exercises hints

  1. You will need to add a new definition for token_to_words by convention save the existing one and call that for things that don't match what you are looking for. Thus your file will look something like
    (set! previous_token_to_words token_to_words)
    
    (define (token_to_words token name)
       (cond
         ;; condition to recognize money tokens
         ;; return list of words 
        (t
         (previous_token_to_words token name))))
    
    The actual condition and return list of words is similar to the treatment of email addresses described above.

    The regular expression for money is probably "\\$[0-9]+\\.[0-9][0-9]"

  2. Take the above and add to it. The rule is probably: if the token is a two digit number and the succeeding token's name is a month name (or abbreviation of a month name) then return the word, first, second etc.

    You will need a new function to relate the digits to the pronunciation. If you don't know how to do that in Scheme the following will work

    (define (num-to-ordinal num)
    "Returns the ordinal in words for num (up to 40)."
    (car    
     (cdr 
      (assoc (parse-number num)
       '((1 first) (2 second) (3 third) ...
         (39 thirty-ninth) (40 fortieth))))))
    
    Once you decide on the condition, remember that you need to return a list of words.