25 lines
450 B
Plaintext
25 lines
450 B
Plaintext
(defstruct shape ()
|
|
cached-area
|
|
|
|
(:init (self)
|
|
(put-line `@self is born!`))
|
|
|
|
(:fini (self)
|
|
(put-line `@self says goodbye!`))
|
|
|
|
(:method area (self)
|
|
(or self.cached-area
|
|
(set self.cached-area self.(calc-area)))))
|
|
|
|
(defstruct circle shape
|
|
(radius 1.0)
|
|
|
|
(:method calc-area (self)
|
|
(* %pi% self.radius self.radius)))
|
|
|
|
(defstruct square shape
|
|
(length 1.0)
|
|
|
|
(:method calc-area (self)
|
|
(* self.length self.length)))
|