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

+26
View File
@@ -0,0 +1,26 @@
;;; CLOS 5: WITH-SLOTS AND WITH-ACCESSORS (solution)
(defclass point ()
((x :initarg :x :accessor point-x)
(y :initarg :y :accessor point-y)))
(defun double-point (p)
(with-slots (x y) p
(make-instance 'point :x (* x 2) :y (* y 2))))
(defun shift-x (p)
(with-accessors ((x point-x)) p
(setf x (1+ x)))
p)
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check (let ((q (double-point (make-instance 'point :x 3 :y 4))))
(and (eql 6 (point-x q)) (eql 8 (point-y q)))))
(check (let ((p (shift-x (make-instance 'point :x 1))))
(eql 2 (point-x p))))
(check (let ((p (shift-x (make-instance 'point :x 10))))
(eql 11 (point-x p))))