Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table

This commit is contained in:
venomade committed 2026-11-22 11:15:35 +00:00
1 parent 77843402fa
commit 4675bd1106
76 files changed
+2505 -14

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
;;; CLOS 7: PRINT-OBJECT AND DEFAULT-INITARGS
;;;
;;; DEFSTRUCT (chapter 12) writes the constructor, the readers and
;;; the predicate for you. DEFCLASS spells them out by hand - and
;;; buys methods, inheritance, and defaults:
;;;
;;; :INITFORM fills one slot when nothing else does.
;;; :DEFAULT-INITARGS feeds an :INITARG its default, so
;;; MAKE-INSTANCE can still override it.
;;;
;;; PRINT-OBJECT is the method the printer calls: define it, and
;;; PRINC shows your objects your way. PRINT-UNREADABLE-OBJECT
;;; builds the #<...> frame around your text.
(defstruct candy filling size)
;; TODO: POINT starts at the origin unless you say otherwise.
(defclass point ()
((x :initarg :x :accessor point-x)
(y :initarg :y :accessor point-y)))
;; TODO: A point prints as #<POINT x=3 y=4>.
(defmethod print-object ((p point) stream)
(format stream "point"))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal 'swirl (candy-filling (make-candy :filling 'swirl)))
(check-equal 0 (point-x (make-instance 'point)))
(check-equal 7 (point-x (make-instance 'point :x 7)))
(check-equal "#<POINT x=3 y=4>"
(with-output-to-string (s)
(princ (make-instance 'point :x 3 :y 4) s)))