| SketchyLISP Stuff | Copyright (C) 2007 Nils M Holm |
| [ More Sketchy LISP Stuff ] |
Language: R5RS Scheme
Purpose: Print the lyrics of "99 bottles of beer on the wall".
Arguments:
N - number of bottles
Implementation:
(define (bottles . n)
(letrec
((bottles
(lambda (n suffix)
(begin
(display n)
(display (if (= n 1) " bottle" " bottles"))
(display suffix)
(newline))))
(verse
(lambda (n)
(begin
(bottles n " of beer on the wall,")
(bottles n " of beer.")
(display "Take one down and pass it around,")
(newline)
(bottles (- n 1) " of beer on the wall."))))
(count-bottles
(lambda (n)
(or (zero? n)
(begin (verse n)
(newline)
(count-bottles (- n 1)))))))
(cond ((null? n)
(count-bottles 99))
(else (count-bottles (car n))))))
Example:
(bottles 99) => #t
| [ More Sketchy LISP Stuff ] |