aboutsummaryrefslogtreecommitdiff
path: root/class.lisp
blob: 526418cb1fd5f3d34843370cdedc5024836bd1ab (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
    :solar-short/class
    (:export #:book #:display-haiku #:next-haiku)
    (:import-from :asdf))

(in-package :solar-short/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))))