Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

symbols, internal or external?

已查看 20 次
跳至第一个未读帖子

Erik Naggum

未读,
1997年4月22日 03:00:001997/4/22
收件人

I have been looking for a function to learn whether a symbol is internal,
external, or inherited in a given package, but find that both `find-symbol'
and `intern' only take arguments of type _string_, not _string designator_
ever since CLtL2. right now, I can find what I'm looking for with

(defun symbol-information (symbol)
(let* ((name (symbol-name symbol))
(package (symbol-package symbol))
(status (nth-value 1 (find-symbol name package))))
(values status name package)))

but this seems like such a waste.

since the Lisp printer must determine whether a symbol is accessible in the
default package or internal or external in some package all the time, I'd
thought I could have access to that information, too. suggestions?

(I'm aware of the `with-package-iterator' macro, which uses a lot of
internal functions in all the implementations I have that support it.)

#\Erik
--
Bastard Sex Therapist from Hell: "Read the F*cking Manual!"

Barry Margolin

未读,
1997年4月22日 03:00:001997/4/22
收件人

In article <30707034...@naggum.no>, Erik Naggum <er...@naggum.no> wrote:
>I have been looking for a function to learn whether a symbol is internal,
>external, or inherited in a given package, but find that both `find-symbol'
>and `intern' only take arguments of type _string_, not _string designator_
>ever since CLtL2. right now, I can find what I'm looking for with
>
>(defun symbol-information (symbol)
> (let* ((name (symbol-name symbol))
> (package (symbol-package symbol))
> (status (nth-value 1 (find-symbol name package))))
> (values status name package)))
>
>but this seems like such a waste.

Your function doesn't do what you described above. You said you wanted to
find out the symbol's status with respect to a given package, but the above
function only returns its status w/r/t its home package. The function you
asked for would be more like:

(defun symbol-information (symbol &optional (package (symbol-package symbol)))
(nth-value 1 (find-symbol (symbol-name symbol) package)))

>since the Lisp printer must determine whether a symbol is accessible in the
>default package or internal or external in some package all the time, I'd
>thought I could have access to that information, too. suggestions?

The printer also has to call SYMBOL-NAME so it will know what to print, so
it's not so much of a waste for it to pass this to FIND-SYMBOL. I expect
the printer's code looks something like this (ignoring uninterned and
keyword symbols, for simplicity):

(defun print-symbol (symbol)
(let ((name (symbol-name symbol)))
(if (eq symbol (find-symbol name *package*))
(write-with-escapes name)
(let* ((package (symbol-package symbol))


(status (nth-value 1 (find-symbol name package))))

(write-with-escapes (package-name package))
(write-char #\:)
(unless (eq status :external)
(write-char #\:))
(write-with-escapes name)))))
--
Barry Margolin
BBN Corporation, Cambridge, MA
bar...@bbnplanet.com
(BBN customers, call (800) 632-7638 option 1 for support)

0 个新帖子