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 scheme

(slightly shorter, efficient, featureful)

Date:08/29/05
Author:Ricardo Malafaia
URL:n/a
Comments:0
Info:http://www.schemers.org
Score: (3.06 in 18 votes)
;; rmalafaia@gmail.com, 2005-08-29
;; slightly shorter and more efficient
;; some more language features shown as well

(let ((str+ string-append)
      (n->s number->string))
  (define (bottles n)
    (str+ (case n
	    ((0) "No more bottles")
	    ((1) "One bottle")
	    (else (str+ (n->s n)
			" bottles")))
	  " of beer"))
  (define (beer n)
    (if (> n 0)
	(let ((bn (bottles n))
	      (msg (lambda (b cmp)
		     (display (str+ b cmp))
		     (newline))))
	  (msg bn " on the wall")
	  (msg bn "")
	  (msg "Take one down, pass it around" "")
	  (msg (bottles (- n 1)) " on the wall")
	  (newline)
	  (beer (- n 1)))))
  (beer 99))

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
original versionTim Goodwin04/20/050
uses the hygenic macro systemEvan Farrer08/11/052
Cleanly factored MAP-based versionGnomon04/18/082

Comments

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: