User Tools


Function SYMBOL-PACKAGE

Syntax

  • symbol-package symbolcontents

Arguments and Values

Description

Returns the home package of symbol.

Examples

(in-package "CL-USER")

#<PACKAGE "COMMON-LISP-USER">

(symbol-package 'car)

#<PACKAGE "COMMON-LISP">

(symbol-package 'bus)

#<PACKAGE "COMMON-LISP-USER">

(symbol-package :optional)

#<PACKAGE "KEYWORD">

(symbol-package (gensym))

NIL ; gensyms are uninterned, so have no home package

(make-package 'pk1)

#<PACKAGE "PK1">

(intern "SAMPLE1" "PK1")

PK1::SAMPLE1 NIL

(export (find-symbol "SAMPLE1" "PK1") "PK1")

T

(make-package 'pk2 :use '(pk1))

#<PACKAGE "PK2">

(find-symbol "SAMPLE1" "PK2")

PK1:SAMPLE1 :INHERITED

(symbol-package 'pk1::sample1)

#<PACKAGE "PK1">

(symbol-package 'pk2::sample1)

#<PACKAGE "PK1">

(symbol-package 'pk1::sample2)

#<PACKAGE "PK1">

(symbol-package 'pk2::sample2)

#<PACKAGE "PK2">

The next several forms create a scenario in which a symbol is not really uninterned, but is "apparently uninterned", and so symbol-package still returns nil.

;;; TODO separate this example from the above one (defparameter *my-symbol* 'pk1::sample3)

*MY-SYMBOL*

*my-symbol* → PK1::SAMPLE3 (import *my-symbol* 'pk2) → T (unintern *my-symbol* 'pk1) → T (symbol-package *my-symbol*) → NIL (eq *my-symbol* 'pk2::sample3) → T

Side Effects

None.

Affected By

Exceptional Situations

Should signal an error of type type-error if symbol is not a symbol.

See Also

Notes

None.