birthday

I felt a little silly today, and just learned about SRFI 42 (Eager Comprehensions), so I thought I might play with it on a trivial example.


(module happy-birthday-song mzscheme
  (require (lib "etc.ss")
           (lib "42.ss" "srfi"))

  (provide sing)

  ;; sing: string -> void
  ;; Prints out the popular happy birthday stanza.
  (define (sing person)
    (local ((define (trailer i)
              (cond [(= i 2)
                     (format "dear ~a" person)]
                    [else
                     "to you"])))
      (do-ec (: i 4)
             (begin
               (display "Happy birthday ")
               (display (trailer i))
               (newline))))))