1 | ;;; package.lisp |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 2008 Erik Huelsmann |
---|
4 | ;;; $Id: package.lisp 11299 2008-08-31 20:19:05Z ehuelsmann $ |
---|
5 | ;;; |
---|
6 | ;;; This program is free software; you can redistribute it and/or |
---|
7 | ;;; modify it under the terms of the GNU General Public License |
---|
8 | ;;; as published by the Free Software Foundation; either version 2 |
---|
9 | ;;; of the License, or (at your option) any later version. |
---|
10 | ;;; |
---|
11 | ;;; This program is distributed in the hope that it will be useful, |
---|
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | ;;; GNU General Public License for more details. |
---|
15 | ;;; |
---|
16 | ;;; You should have received a copy of the GNU General Public License |
---|
17 | ;;; along with this program; if not, write to the Free Software |
---|
18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | (in-package "SYSTEM") |
---|
21 | |
---|
22 | ;; Redefines make-package from boot.lisp |
---|
23 | |
---|
24 | (defun make-package (name &key nicknames use) |
---|
25 | (restart-case |
---|
26 | (progn |
---|
27 | (when (find-package name) |
---|
28 | (error 'simple-error "Package ~A already exists." name)) |
---|
29 | (dolist (nick nicknames) |
---|
30 | (when (find-package nick) |
---|
31 | (error 'package-error :package nick))) |
---|
32 | (%make-package name nicknames use)) |
---|
33 | (use-existing-package () |
---|
34 | :report "Use existing package" |
---|
35 | (return-from make-package (find-package name))))) |
---|
36 | |
---|
37 | ;; Redefines function from defpackage.lisp, because there it's lacking restart-case |
---|
38 | |
---|
39 | (defun ensure-available-symbols (imports) |
---|
40 | (remove nil |
---|
41 | (mapcar #'(lambda (package-and-symbols) |
---|
42 | (let* ((package (find-package (designated-package-name (car package-and-symbols)))) |
---|
43 | (new-symbols |
---|
44 | (remove nil |
---|
45 | (mapcar #'(lambda (sym) |
---|
46 | (restart-case |
---|
47 | (progn |
---|
48 | (unless (find-symbol sym package) |
---|
49 | (error 'package-error |
---|
50 | "The symbol ~A is not present in package ~A." sym (package-name package))) |
---|
51 | sym) |
---|
52 | (skip () |
---|
53 | :report "Skip this symbol." |
---|
54 | nil))) |
---|
55 | (cdr package-and-symbols))))) |
---|
56 | (when new-symbols |
---|
57 | (cons package new-symbols)))) |
---|
58 | imports))) |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | (defun import (symbols &optional (package *package* package-supplied-p)) |
---|
64 | (dolist (symbol (if (listp symbols) symbols (list symbols))) |
---|
65 | (let* ((sym-name (string symbol)) |
---|
66 | (local-sym (find-symbol sym-name package))) |
---|
67 | (restart-case |
---|
68 | (progn |
---|
69 | (when (and local-sym (not (eql symbol local-sym))) |
---|
70 | (error 'package-error |
---|
71 | "Different symbol (~A) with the same name already accessible in package ~A." |
---|
72 | local-sym (package-name package))) |
---|
73 | (if package-supplied-p |
---|
74 | (%import symbol package) |
---|
75 | (%import symbol))) |
---|
76 | (unintern-existing () |
---|
77 | :report (lambda (s) (format s "Unintern ~S and continue" local-sym)) |
---|
78 | (unintern local-sym) |
---|
79 | (%import symbol)) |
---|
80 | (skip () |
---|
81 | :report "Skip symbol")))) |
---|
82 | T) |
---|