Skip to content

Instantly share code, notes, and snippets.

@takano32
Forked from elderica/beer.lisp
Created September 23, 2018 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takano32/ab0da13aa1a272bac6471c9f07cab867 to your computer and use it in GitHub Desktop.
Save takano32/ab0da13aa1a272bac6471c9f07cab867 to your computer and use it in GitHub Desktop.
(in-package #:cl-user)
(defpackage #:beer
(:use #:common-lisp)
(:export #:verse #:sing))
(in-package #:beer)
;; [*endpoint-min*, *endpoint-max*] in notations for intervals.
(defparameter *endpoint-max* 99)
(defparameter *endpoint-min* 0)
(defun generate-1st-line (n)
(format nil
"~a bottle~p of beer on the wall, ~a bottle~p of beer."
(if (= 0 n) "No more" n)
n
(if (= 0 n) "no more" n)
n))
(defun generate-2nd-line (n)
(if (= *endpoint-min* n)
(format nil
"Go to the store and buy some more, ~a bottle~p of beer on the wall."
*endpoint-max*
*endpoint-max*)
(let ((n-1 (1- n)))
(format nil
"Take ~a down and pass it around, ~a bottle~p of beer on the wall."
(if (= *endpoint-min* n-1) "it" "one")
(if (= *endpoint-min* n-1) "no more" n-1)
n-1))))
(defun verse (n)
(format nil
"~a~&~a~&"
(generate-1st-line n)
(generate-2nd-line n)))
(defun sing (&optional (start *endpoint-max*) (end *endpoint-min*))
(format nil
"~{~a~%~}"
(loop for i from start downto end
collect (verse i))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment