;;; HASH TABLES 2: IS THE KEY THERE? (solution) (defun has-key-p (key table) (nth-value 1 (gethash key table))) (defun lookup (key table default) (multiple-value-bind (value present) (gethash key table) (if present value default))) ;;; ------------------------------------------------------------------ ;;; Checks. Read them - they tell you what to aim for - but leave ;;; them unchanged. ;;; ------------------------------------------------------------------ (check (let ((table (make-hash-table))) (setf (gethash 'a table) 1 (gethash 'b table) nil) (and (has-key-p 'a table) (has-key-p 'b table) (not (has-key-p 'c table))))) (check (let ((table (make-hash-table))) (setf (gethash 'a table) 1) (and (eql 1 (lookup 'a table 0)) (eql 99 (lookup 'c table 99)))))