Wave 4: add sequences/vectors/files chapters, 23 exercises, quiz3, finish ceremony, PCL table
This commit is contained in:
1 parent
77843402fa
commit
4675bd1106
76 files changed
+2505
-14
No files matched your search
@@ -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))))
|
||||
Reference in new issue
Block a user