aboutsummaryrefslogtreecommitdiff
path: root/class.lisp
blob: 93fc4d9b89618469676717d61de1661be464577b (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
25
26
27
28
(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 "haiku 1"
		    "haiku 2"
		    "haiku 3"))
   (current :initform 0)))

(defmethod display-haiku ((obj book) stream)
  (with-slots (haikus current) obj
    (format *standard-output* "haiku num: ~a" current)
    (princ (nth current haikus) stream)))

(defmethod next-haiku ((obj book))
  (with-slots (haikus current) obj
    (format *standard-output* "increasing current")
    (let ((factor (if (= current (length haikus)) 0 1)))
      (format *standard-output* "increment factor: ~a" factor)
      (finish-output *standard-output*)
      (setf current
	    (+ factor
	       current)))))