Skip to content

Instantly share code, notes, and snippets.

@mtimkovich
Last active February 17, 2016 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtimkovich/3545681 to your computer and use it in GitHub Desktop.
Save mtimkovich/3545681 to your computer and use it in GitHub Desktop.
Beer song in Lisp
(defun plural (n)
(if (> n 1) "s" ""))
(defun beer-song (n)
(format t "~a bottle~a of beer on the wall.~%" n (plural n))
(format t "~a bottle~a of beer.~%" n (plural n))
(format t "Take one down.~%")
(format t "Pass it around.~%")
(decf n)
(if (> n 0)
(progn
(format t "~a bottle~a of beer on the wall.~%" n (plural n))
(beer-song n))
(format t "No more bottles of beer on the wall.~%")))
(beer-song 99)
@fchurca
Copy link

fchurca commented Feb 17, 2016

A more elegant way of expressing plurals can be to make use of format's builtin ~p directive. See this as an example:
https://gist.github.com/fchurca/d788c9df76d4491fb625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment