;; You should have received a copy of the GNU General Public License
;; along with JSCL. If not, see <http://www.gnu.org/licenses/>.
+(/debug "loading package.lisp!")
+
(defvar *package-list* nil)
(defun list-all-packages ()
(defun make-package (name &key use)
(let ((package (new))
(use (mapcar #'find-package-or-fail use)))
- (setf (oget package "packageName") name)
+ (setf (oget package "packageName") (string name))
(setf (oget package "symbols") (new))
(setf (oget package "exports") (new))
(setf (oget package "use") use)
(defvar *package* *common-lisp-package*)
(defmacro in-package (string-designator)
- `(eval-when-compile
+ `(eval-when (:compile-toplevel :load-toplevel :execute)
(setq *package* (find-package-or-fail ',string-designator))))
;; This function is used internally to initialize the CL package
(dolist (package *package-list*)
(map-for-in function (%package-symbols package))))
+(defun %map-all-external-symbols (function)
+ (dolist (package *package-list*)
+ (map-for-in function (%package-external-symbols package))))
+
(defmacro do-symbols ((var &optional (package '*package*) result-form)
&body body)
`(block nil
(defmacro do-all-symbols ((var &optional result-form) &body body)
`(block nil (%map-all-symbols (lambda (,var) ,@body)) ,result-form))
-(defun find-all-symbols (string)
+(defmacro do-all-external-symbols ((var &optional result-form) &body body)
+ `(block nil (%map-all-external-symbols (lambda (,var) ,@body)) ,result-form))
+
+(defun find-all-symbols (string &optional external-only)
(let (symbols)
(dolist (package *package-list* symbols)
(multiple-value-bind (symbol status) (find-symbol string package)
- (when status
+ (when (if external-only (eq status :external) status)
(pushnew symbol symbols :test #'eq))))))