aboutsummaryrefslogtreecommitdiff
path: root/class.lisp
blob: ef581b2470fb275e25f1c1c2387f65b4d2f378bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(uiop:define-package
    :haiku-book/class
    (:export #:book #:display-haiku #:next-haiku)
    (:import-from :asdf))

(in-package :haiku-book/class)

(defclass book ()
  ((haikus
    :initform (list "Old brackets~%laying forgotten~%spring anew."
		    "The water drop~%falling on the cracked ground~%bounces away."
		    "Striving for more~%time for contentment~%is gone."))
   (current :initform 0)))

(defmethod display-haiku ((obj book) stream)
  (with-slots (haikus current) obj
    (format *error-output* "Refreshing display, current is ~a" current)
    (format stream (nth current haikus))))

(defmethod next-haiku ((obj book))
  (with-slots (haikus current) obj
    (if (= current (- (length haikus) 1))
	(setf current 0)
	(incf current))))