[Ecls-list] APROPOS issues, proposed enhancement
Matthew Mondor
mm_lists at pulsar-zone.net
Thu Jun 28 06:50:31 UTC 2012
On Wed, 27 Jun 2012 05:29:11 -0400
Matthew Mondor <mm_lists at pulsar-zone.net> wrote:
> > (defun apropos (string &optional package)
>
> Alternate implementation:
Yet another easy solution which instead returns sorted unique symbols in APROPOS-LIST (SBCL and CLISP do this):
;;; Original function renamed and documentation moved below
(defun %apropos-list (string &optional package)
(let* ((list '())
(string (string string)))
(cond (package
(dolist (p (package-use-list package))
(setf list (nconc (apropos-list string p) list)))
(do-symbols (symbol package)
(when (search string (string symbol) :test #'char-equal)
(setq list (cons symbol list)))))
(t
(do-all-symbols (symbol)
(when (search string (string symbol) :test #'char-equal)
(setq list (cons symbol list))))))
list))
(defun apropos-list (symbol &optional package)
"Args: (string &optional (package nil))
Returns a list of all symbols whose print-names contain STRING as substring.
If PACKAGE is non-NIL, then only the specified PACKAGE is searched."
(loop
with dupes = (sort (%apropos-list symbol package)
#'(lambda (a b)
(string-lessp (prin1-to-string a)
(prin1-to-string b))))
for prec = nil then item
for item in dupes
unless (and prec (eq prec item)) collect item))
;;; Original unmodified function
(defun apropos (string &optional package)
"Args: (string &optional (package nil))
Prints those symbols whose print-names contain STRING as substring. If
PACKAGE is non-NIL, then only the specified PACKAGE is searched."
(setq string (string string))
(mapc #'print-symbol-apropos (apropos-list string package))
(values))
--
Matt
More information about the ecl-devel
mailing list