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

(standard version)

Date:04/20/05
Author:Rebecca Walpole
URL:n/a
Comments:5
Info:n/a
Score: (3.02 in 170 votes)
;; Bottles by Rebecca Walpole (walpolr@cs.orst.edu)
;; tested in Austin Kyoto Common Lisp version 1.615
;; Note: the ~p takes care of plurals.
;;
(defun bottles (n)
 "Prints the lyrics to '99 Bottles of Beer'"
(if (< n 1)
    (format t "~%Time to go to the store.~%")
    (progn (format t "~% ~a bottle~:p of beer on the wall." n)
           (format t "~% ~a bottle~:p of beer." n)
           (format t "~% Take one down, pass it around.")
           (format t "~% ~a bottle~:p of beer on the wall.~%" (- n 1))
           (bottles (- n 1))
	   )
  )
)

(bottles 99)

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
format stringGeoff Summerhayes04/20/052

Comments

>>  Stefan Scholl said on 08/14/05 21:26:21

Stefan Scholl Minor code cleanup:

(defun bottles (n)
  "Prints the lyrics to '99 Bottles of Beer'"
  (cond ((< n 1) (format t "~%Time to go to the store.~%"))
        (t (format t "~% ~a bottle~:p of beer on the wall." n)
           (format t "~% ~a bottle~:p of beer." n)
           (format t "~% Take one down, pass it around.")
           (format t "~% ~a bottle~:p of beer on the wall.~%" (1- n))
           (bottles (1- n)))))

(bottles 99)

>>  Chris said on 03/07/06 09:15:38

Chris Seeing as Common Lisp supports object orientation, I was surprised that this was procedural. I don't know any Lisp, but I DO know Common Lisp has OOP. Allegro CL is a good example. Well, their documentation is. The IDE, however, is a crash addict.

>>  Tel said on 04/23/06 04:45:51

Tel Chris,

Common Lisp does indeed support object orientation; however, it is only one of many abstrations CL supports. In this case, it is much easier to use recursive abstraction than to invoke the overhead of defining objects using CLOS, the Common Lisp Object System, though it is native to all major implementations of CL.

>>  blink said on 09/27/07 20:41:21

blink clisp --- Nice and simple. Elegant.

>>  mr said on 09/28/07 06:37:10

mr I'm interested in seeing a non-recursive (i.e. DO or LOOP-based) version, with sane FORMAT strings (unlike the one already on the site). I'd try to code one up now, but I don't have access to a CL implementation at the moment.

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: