Language Common Lisp
(format string)
| Date: | 04/20/05 |
| Author: | Geoff Summerhayes |
| URL: | n/a |
| Comments: | 1 |
| Info: | n/a |
| Score: |
;;; The format string in Common Lisp is almost a
;;; language on its own. Here's a Lisp version
;;; that shows its power. Hope you find it
;;; entertaining.
(in-package "CL-USER")
(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)))
(bottle-song)
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
~:;~:01*~@(~R~)~
should read
~:;~01:*~@(~R~)~