Lecture overview -- Keyboard shortcut: 'u'  Previous page: Example with <kbd>cond</kbd>: <kbd>leap-year?</kbd> -- Keyboard shortcut: 'p'  Next page: Example with <kbd>cond</kbd>: <kbd>as-string</kbd> -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home    Lecture 3 - Page 13 : 42
Functional Programming in Scheme
Name binding, Recursion, Iteration, and Continuations
Example with cond: american-time

(define (american-time h m s)
  (cond ((< h 0)
           (laml-error "Cannot handle this hour:" h))

        ((and (= h 12) (= m 0) (= s 0))
             "noon")

        ((< h 12)
           (string-append
             (format-hour-minutes-seconds h m s) 
             " " "am"))

        ((= h 12)  
           (string-append
             (format-hour-minutes-seconds h m s) 
             " " "pm"))

        ((and (= h 24) (= m 0) (= s 0))
             "midnight")

        ((<= h 24)
           (string-append 
             (format-hour-minutes-seconds (- h 12) m s) 
             " " "pm"))

        (else
           (laml-error "Cannot handle this hour:" h))))

The function american-time. The function returns a string displaying the 'am/pm/noon' time given hour h, minute m, and seconds s.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/american-time.scmThe function american-time with helping functions.