From d185dba5caad19127c443d847b6214e4aebcad08 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 6 Aug 2019 12:58:23 +0100 Subject: [PATCH] doc/list-exports.lisp (best-package-name: Don't sort the whole list. Just pick the shortest one. --- doc/list-exports.lisp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/list-exports.lisp b/doc/list-exports.lisp index f4117df..c47a500 100755 --- a/doc/list-exports.lisp +++ b/doc/list-exports.lisp @@ -200,9 +200,17 @@ (find-symbol-homes paths package))) (defun best-package-name (package) - (car (sort (cons (package-name package) - (copy-list (package-nicknames package))) - #'< :key #'length))) + + ;; We pick the shortest one. Strangely, there's no `find minimal thing + ;; according to this valuation' function in Common Lisp. + (loop with best = (package-name package) + with best-length = (length best) + for name in (package-nicknames package) + for name-length = (length name) + when (< name-length best-length) + do (setf best name + best-length name-length) + finally (return best))) (defvar charbuf-size 0) -- 2.11.0