(defun find-second-smallest-number (list)
  (loop for n in list
        for second = n then (if (< first n second) n second)
        minimize n into first
        finally (return (if (> second first) second nil))))

(defun test (fn)
  (loop for (arg expected) in '(((4 5 1 7 1 2 8 9 2 7) 2)
                                ((2 2 2 2 2 2 2 2 2 2) nil)
                                ((1) nil)
                                ((2 1) 2)
                                ((1 2) 2)
                                ((3 2 1) 2)
                                (() nil))
        for result = (handler-case (funcall fn arg)
                       (error (cond) cond))
        do (format t "~:[❌~;✓~] ~:S → ~S~%"
                   (eql result expected)
                   arg
                   result)))

(test #'find-second-smallest-number)
