Skip to content

Instantly share code, notes, and snippets.

@takano32 takano32/beer.lisp forked from sbwhitecap/beer.lisp
Created Sep 23, 2018

What would you like to do?
(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)
(if (= 0 n) "no more" 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."
(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)
(defun verse (n)
(format nil
(generate-1st-line n)
(generate-2nd-line n)))
(defun sing (&optional (start *endpoint-max*) (end *endpoint-min*))
(format nil
(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
You can’t perform that action at this time.