Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Common Lisp

(format string)

Date:04/20/05
Author:Geoff Summerhayes
URL:n/a
Comments:2
Info:n/a
Score: (3.03 in 263 votes)
;;; 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

Alternative Versions

VersionAuthorDateCommentsRate
standard versionRebecca Walpole04/20/055

Comments

>>  Geoffrey Summerhayes said on 09/26/05 21:43:59

Geoffrey Summerhayes Minor correction, the line
~:;~:01*~@(~R~)~
should read
~:;~01:*~@(~R~)~

>>  Hateras said on 03/17/10 23:20:45

Hateras Woooow. Imba formatting.
#cheers#

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!

Name:

eMail:

URL:

Security Code:
  
Comment: