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,29 @@
|
||||
;;; LISTS 6: DESTRUCTURING-BIND
|
||||
;;;
|
||||
;;; LET binds one name; DESTRUCTURING-BIND binds a whole lambda
|
||||
;;; list of names at once, pulling them out of a list:
|
||||
;;;
|
||||
;;; (destructuring-bind (w h d) dims
|
||||
;;; (* w h d))
|
||||
;;;
|
||||
;;; The dotted template (x . rest) splits the head from the tail,
|
||||
;;; like CAR and CDR in one go.
|
||||
|
||||
;; TODO: The volume of a box given as (width height depth).
|
||||
(defun dimensions (dims)
|
||||
(destructuring-bind (w h d) dims
|
||||
(* w d)))
|
||||
|
||||
;; TODO: XS as two values: the first element, and the rest.
|
||||
(defun first-and-rest (xs)
|
||||
(list (car xs) (cdr xs)))
|
||||
|
||||
;;; ------------------------------------------------------------------
|
||||
;;; Checks. Read them - they tell you what to aim for - but leave
|
||||
;;; them unchanged.
|
||||
;;; ------------------------------------------------------------------
|
||||
|
||||
(check-equal 60 (dimensions '(3 4 5)))
|
||||
(check-equal 0 (dimensions '(0 10 2)))
|
||||
(check-equal '(1 (2 3)) (multiple-value-list (first-and-rest '(1 2 3))))
|
||||
(check-equal '(a ()) (multiple-value-list (first-and-rest '(a))))
|
||||
Reference in new issue
Block a user