20 lines
653 B
Common Lisp
20 lines
653 B
Common Lisp
;;; LISTS 6: DESTRUCTURING-BIND (solution)
|
|
|
|
(defun dimensions (dims)
|
|
(destructuring-bind (w h d) dims
|
|
(* w h d)))
|
|
|
|
(defun first-and-rest (xs)
|
|
(destructuring-bind (x . rest) xs
|
|
(values x rest)))
|
|
|
|
;;; ------------------------------------------------------------------
|
|
;;; 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))))
|