Hi,
Is there any access to MOP-like functionality in swank? I've not found it so I create a simple interface, similar to the xref one.
swank.lisp: ;;; MOP (defslimefun mop (type symbol-name) (let ((symbol (parse-symbol-or-lose symbol-name *buffer-package*))) (ecase type (:subclasses (class-direct-subclasses symbol)) (:superclasses (class-direct-superclasses symbol)))))
Maybe 'mop' isn't the best name.
swank-backend.lisp: ;;; MOP (definterface class-direct-subclasses (class-name) "Return the list of subclasses of class.")
(definterface class-direct-superclasses (class-name) "Return the list of superclasses of class.")
swank-cmucl.lisp: ;;; CLOS MOP (defimplementation class-direct-subclasses (class-name) (handler-bind ((simple-error (lambda (c) (declare (ignore c)) (return-from class-direct-subclasses nil)))) (let* ((class (find-class class-name)) (subclasses (pcl:class-direct-subclasses class))) (mapcar #'(lambda (x) (symbol-name (pcl:class-name x))) subclasses))))
(defimplementation class-direct-superclasses (class-name) (handler-bind ((simple-error (lambda (c) (declare (ignore c)) (return-from class-direct-superclasses nil)))) (let* ((class (find-class class-name)) (superclasses (pcl:class-direct-superclasses class))) (mapcar #'(lambda (x) (symbol-name (pcl:class-name x))) superclasses))))
The handler is to catch the errors of find-class with a class that doesn't exist. Maybe there's a better behaviour in that situation.
I have a generic browser in emacs that can be used to see the stuff above, xrefs,etc. I'll release the code soon.
Rui Patrocínio
Rui Patrocínio rui.patrocinio@netvisao.pt writes:
Hi,
Is there any access to MOP-like functionality in swank? I've not found it so I create a simple interface, similar to the xref one.
No, there is no such thing.
swank.lisp: ;;; MOP (defslimefun mop (type symbol-name) (let ((symbol (parse-symbol-or-lose symbol-name *buffer-package*))) (ecase type (:subclasses (class-direct-subclasses symbol)) (:superclasses (class-direct-superclasses symbol)))))
Maybe 'mop' isn't the best name.
It is a least short :-) If you add a docstrings, things should be fine.
swank-cmucl.lisp: ;;; CLOS MOP (defimplementation class-direct-subclasses (class-name) (handler-bind ((simple-error (lambda (c) (declare (ignore c)) (return-from class-direct-subclasses nil)))) (let* ((class (find-class class-name)) (subclasses (pcl:class-direct-subclasses class))) (mapcar #'(lambda (x) (symbol-name (pcl:class-name x))) subclasses))))
[...]
The handler is to catch the errors of find-class with a class that doesn't exist. Maybe there's a better behaviour in that situation.
It might be simpler to export the MOP functions directly from the swank-backend, e.g., just adding
(export 'pcl:class-direct-subclasses)
in swank-cmucl and the analog in the other backends. This could save us the work for inventing a new interface and the AMOP specification is probably not that bad. Whether the implementations agree with AMOP specification is, of course, a different question.
We can probably also save some code duplication if we move the error handling and class->name translation to swank.lisp.
Helmut.