Language LISP
Date: | 04/20/05 |
Author: | Anonymous |
URL: | n/a |
Comments: | 3 |
Info: | http://www.sover.net/~nichael/lisp99.html |
Score: | (3.01 in 164 votes) |
;;; Lisp example of "99 Bottles of beer on the wall" ;;; ;;; NOTE: Although my mailer insists on inserting ;;; (at least) one, there is no line break in the ;;; string beginning "~~ (i.e. it should all be on one line). ;;; ;;; In particular, if it breaks so that the first line ;;; ends with "...~~R" and the second line starts "~0@..." ;;; they should be put back together with a space between ;;; them. That is, it should read "...~~R ~0@...". ;;; Or just see it here: ;;; http://www.sover.net/~nichael/lisp99.html (labels ((foo (x) (and (<= 0 x) (cons x (foo (1- x)))))) (format t (format nil "~~{~~&~~@(~~%~~R ~A ~A!~~)~~:*~~&~~@(~~R ~0@*~A!~~)~~&~~@(~2@*~A!~~)~~&~~@(~~[~A~~:;~~:*~~R~~:*~~] ~0@*~A!~~)~~}" "bottles of beer" "on the wall" "take one down, pass it around" "no more" ) (foo 99)))
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Sascha Wilde said on 05/16/05 22:54:52
This one could be really nice, if only it would handle the plurals right -- but the last verse prints
"One bottles of beer on the wall!
One bottles of beer!"
what a pity...
metacog said on 11/15/06 13:28:38
Should have used this one:
(defun bottle-song (&optional (in-stock 99) (stream *standard-output*))
;; Original idea and primary coding by Geoff Summerhayes
;; <sumrnot @hotmail.com>
;; Formatting idea by Fred Gilham <gilham @snapdragon.csl.sri.com>
;; Actual formatting & minor recoding by Kent M Pitman
;; <pitman @world.std.com>
(format
stream
"-----~2%~
~{~&~1&~
~[~^~:;~
~1:*~@(~
~R~) bo~
ttle~:P o~
f beer on t~
he wall~01:*~[.~
~:;,~%~1:*~@(~R~
~) bottle~:*~P ~
of beer.~%You t~
ake one down, p~
ass it around, ~
~01%~[*No* more~
~:;~01:*~@(~R~)~
~] bottle~:*~P ~
of beer on the ~
wall.~2&-----~%~
~1%~:*~]~]~}~0%"
(loop for bottle from in-stock downto 0 collect bottle)))
Jimka said on 04/22/07 01:14:47
This one does not implement the proper indentation, but it does
imlement the correct grammar.
(defun bottles-of-bier (n)
(case n
(0
'(No more bottles of beer on the wall no more bottles of beer.
Go to the store and buy some more 99 bottles of beer on the wall.))
(1
`(1 bottle of beer on the wall 1 bottle of beer.
Take one down and pass it around no more bottles of beer on the wall.
,@(bottles-of-bier 0)))
(2
`(2 bottles of beer on the wall 2 bottles of beer.
Take one down and pass it around 1 bottle of beer on the wall.
,@(bottles-of-bier 1)))
(t
`(,n bottles of beer on the wall ,n bottles of beer.
Take one down and pass it around
,(1- n) bottles of beer on the wall.
,@(bottles-of-bier (1- n))))))
(bottles-of-bier 99)