home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / sing.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  100 lines

  1. ############################################################################
  2. #
  3. #    File:     sing.icn
  4. #
  5. #    Subject:  Program to sing The Twelve Days of Christmas
  6. #
  7. #    Author:   Frank J. Lhota
  8. #
  9. #    Date:     September 14, 1990
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #  
  17. #     This program is an Icon adaptation of a SNOBOL program by Mike
  18. #  Shapiro in the book The SNOBOL4 Programming Language.  The procedure
  19. #  sing writes the lyrics to the song, "The Twelve Days of Christmas"
  20. #  to the singer parameter.  "singer" can be any file open for output,
  21. #  but it would be especially nice to send the lyrics to a speech
  22. #  synthesiser (perhaps via a pipe).  
  23. #
  24. #     The algorithm used can be adapted to other popular songs, such as
  25. #  "Old McDonald had a Farm".
  26. #
  27. #  Reference:
  28. #
  29. #     "The SNOBOL 4 Programming Language" by Griswold, Poage, and
  30. #  Polonsky, 2nd ed. Englewood Cliffs, N.J. Prentiss-Hall, Inc. 1971.
  31. #
  32. ############################################################################
  33.  
  34. procedure sing(singer)
  35.  
  36.     local which, and
  37.     static day, gift
  38.  
  39.     initial {
  40.     day := [
  41.         "first",
  42.         "second",
  43.         "third",
  44.         "fourth",
  45.         "fifth",
  46.         "sixth",
  47.         "seventh",
  48.         "eighth",
  49.         "ninth",
  50.         "tenth",
  51.         "eleventh",
  52.         "twelfth"]
  53.  
  54.     gift := [
  55.         "twelve lords a'leaping,",
  56.         "eleven ladies dancing,",
  57.         "ten pipers piping,",
  58.         "nine drummers drumming,",
  59.         "eight maids a'milking,",
  60.         "seven swans a'swimming,",
  61.         "six geese a'laying,",
  62.         "five golden rings,",
  63.         "four colly birds,",
  64.         "three french hens,",
  65.         "two turtle doves,",
  66.         "a partridge in a pear tree."]
  67.     }
  68.  
  69.     every which := 1 to 12 do {
  70.     write (singer)    # Take a breath
  71.     write (singer, "On the ", day [which], " day of Christmas,")
  72.     write (singer, "my true love gave to me,")
  73.     every write (singer, !(gift[-which : 0]))
  74.  
  75.     if (/and := "and ") then gift[-1] := and || gift[-1]
  76.     }
  77.  
  78.     #
  79.     # Reset gift[-1] in case sing is called again.
  80.     #
  81.  
  82.     gift[-1] ?:= (=and & tab (0))
  83.  
  84.     return
  85.     
  86. end
  87.  
  88. ############################################################################
  89.  
  90. procedure main ()
  91.  
  92.     #
  93.     # Try out sing procedure with standard output.
  94.     #
  95.     
  96.     sing(&output)
  97.  
  98. end
  99.