Files
lisplings/exercises/02_functions/functions4.lisp
T
venomade 4df60ead93 Lisplings: Rustlings-style exercises for Common Lisp
70 exercises in 20 chapters, from first s-expressions to restarts,
macros, CLOS, and a tiny Lisp interpreter. Each exercise ships
broken with a solved twin and a hint. Includes a watch-mode runner,
a plain-CL check harness, a nix flake, and verification tooling.
All plain SBCL, no dependencies.
2026-11-22 03:30:19 +00:00

25 lines
898 B
Common Lisp

;;; FUNCTIONS 4: MULTIPLE VALUES
;;;
;;; A function may return several values at once:
;;; (values 1 2) => 1 and 2
;;; Everything except the first value rides along, waiting for
;;; MULTIPLE-VALUE-BIND or NTH-VALUE to pick it up. FLOOR is a
;;; classic: (floor 10 3) returns 3 AND 1.
;; TODO: Return TWO values: the whole part of A/B and the rest.
(defun divide (a b)
(/ a b))
;; TODO: Return TWO values: whole minutes, and leftover seconds.
(defun split-seconds (seconds)
seconds)
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal '(3 1) (multiple-value-list (divide 10 3)))
(check-equal '(3 1) (multiple-value-list (divide 7 2)))
(check-equal '(2 5) (multiple-value-list (split-seconds 125)))