Sha256: 1f73684e881d9a23219c121c143f58b1a4f6fb1644aa4d471f6853d0d897bef9

Contents?: true

Size: 1.11 KB

Versions: 396

Compression:

Stored size: 1.11 KB

Contents

(defpackage #:beer
  (:use #:common-lisp)
  (:export #:verse #:sing))

(in-package #:beer)

(defgeneric bottles (n))
(defmethod bottles (n) (format nil "~A bottle~:P" n))
(defmethod bottles ((n (eql 0))) (bottles "no more"))

(defgeneric left (n))
(defmethod left ((n integer)) (1- n))
(defmethod left ((n (eql 0))) 99)

(defgeneric pronoun (n))
(defmethod pronoun ((n integer)) "one")
(defmethod pronoun ((n (eql 1))) "it")

(defmethod action (n))
(defmethod action ((n integer))
  (format nil "Take ~A down and pass it around" (pronoun n)))
(defmethod action ((n (eql 0)))
  "Go to the store and buy some more")

(defun capitalize-first-word (str)
  (progn
    (setf (char str 0)
          (char-upcase (char str 0)))
    str))

(defun verse (n)
  (format nil
          "~A of beer on the wall, ~A of beer.~%~
           ~A, ~A of beer on the wall.~%"
          (capitalize-first-word (bottles n))
          (bottles n)
          (action n)
          (bottles (left n))))

(defun sing (start &optional (end 0))
  (format nil
          "~{~A~^~%~}~%"
          (loop for n from start downto end
             collecting (verse n))))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.179 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.178 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.177 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.176 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.175 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.174 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.173 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.172 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.171 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.170 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.169 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.167 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.166 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.165 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.164 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.163 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.162 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.161 tracks/common-lisp/exercises/beer-song/example.lisp
trackler-2.2.1.160 tracks/common-lisp/exercises/beer-song/example.lisp