Bugs item #1602849, was opened at 2006-11-25 23:09
Message generated for change (Comment added) made by crategus
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1602849&group_id=4933
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Lisp Core
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Barton Willis (willisbl)
Assigned to: Nobody/Anonymous (nobody)
Summary: apropos
Initial Comment:
The use documentation for 'apropos' says the input
should be a string. That's not right:
(%i20) apropos("rat");
(%o20) [rat]
(%i21) apropos(rat);
(%o21) [rat, ...,ratwtlvl]
Alos, apropos should quote its argument:
(%i22) apropos(float)
(%o22) [false,nill,punt-nil,punt-nil-warnp] <-- not expected
(%i23) apropos('float);
(%o23)[float,...,dconv-$float] <-- expected
Finally, when the input to apropos isn't a Maxima
function or option variable, we get sillyness such
as
(%i28) apropos('larry);
(%o28) [larry] <-- There isn't a function "larry"
apropos(42);
(%o35) [*,**, ... ] <-- might be useful, but...
Barton
----------------------------------------------------------------------
>Comment By: Dieter Kaiser (crategus)
Date: 2009-06-11 18:45
Message:
The proposed code in this thread has some problems.
1.
When the argument is a symbol 'EXP, apropos finds only names with $EXP in
it. Therefore the code does not find symbols which have EXP as a part of
the name, but only symbols which have EXP at the beginning of the name.
2.
Every symbol which is an argument to apropos and is not known by Maxima is
interned as a symbol. We allways get a result, in a second call we will
find symbols which are wrong input to apropos.
The following code does exactly what is described in the manual:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Utility function to filter a list LST with a function FN
;;; e.g. (filter #'(lambda(x) (if (oddp x) x)) '(1 2 3 4 5 6 7)) --> (1 3
5 7)
(defun filter (fn lst)
(let ((acc nil))
(dolist (x lst)
(let ((val (funcall fn x)))
(if val (push val acc))))
(nreverse acc)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmspec $apropos (s)
(let ((acc nil))
(setq s (car (margs s)))
(cond ((stringp s)
;; A list of all Maxima names which contain the string S.
(setq acc (append acc (apropos-list (stripdollar s) :maxima)))
;; Filter the names which are Maxima User symbols starting
;; with % or $ and remove duplicates.
($listify
($setify
(cons '(mlist)
(filter #'(lambda (x)
(if (member (getcharn x 1) '(#\$ #\%))
x))
acc)))))
(t
(merror
(intl:gettext "apropos: The argument has to be a
string."))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1. The argument is a string to prevent that the argument is interned.
2. Only Maxima names including user defined names are part of the output.
3. We do not add new names to the namespace with a call to apropos.
FILTER is a utility function to get only the Maxima names of a list. The
function can generally be used to filter lists with a condition.
This code ignores more than one argument. When the first argument is not a
string, a Maxima error is thrown. When we call apropos with an empty string
"", we get a list of all Maxima names. When no Maxima name is found, an
empty list is returned.
I think this function can be useful and the description should be moved
from the file Miscelanous.texi to the file Help.texi.
Dieter Kaiser
----------------------------------------------------------------------
Comment By: Robert Dodier (robert_dodier)
Date: 2006-12-26 23:42
Message:
Logged In: YES
user_id=501686
Originator: NO
I'm not all that crazy about apropos -- I wouldn't mind if we just cut it
-- but if we do keep it I think it should give some indication of the type
of an object. E.g. function vs variable, Lisp vs Maxima, built-in vs
user-defined, maybe other categorizations.
----------------------------------------------------------------------
Comment By: Barton Willis (willisbl)
Date: 2006-11-26 07:53
Message:
Logged In: YES
user_id=895922
Originator: YES
The first version gives lisp error for apropos(a+b). Let's try:
(defmspec $apropos (s)
(let ((acc nil))
(setq s (margs s))
(dolist (si s ($listify ($setify (cons '(mlist) acc))))
(setq si (if (op-equalp si 'mquote) (second si) si))
(if (symbolp si) (setq acc (append acc (apropos-list (amperchk si)
:maxima)))))))
----------------------------------------------------------------------
Comment By: Barton Willis (willisbl)
Date: 2006-11-26 03:40
Message:
Logged In: YES
user_id=895922
Originator: YES
Proposed replacement:
(defmspec $apropos (s)
(let ((acc nil))
(setq s (margs s))
(dolist (si s ($listify ($setify (cons '(mlist) acc))))
(setq si (amperchk (if (op-equalp si 'mquote) (second si) si)))
(if (symbolp si) (setq acc (append acc (apropos-list si
:maxima)))))))
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1602849&group_id=4933