I wanted to print the symbols of a package that are not exported: the internal symbols.
(defun internal-symbol-p (symbol)
(equal :internal
(nth-value 1 (find-symbol (string symbol)))))
indeed, find-symbol returns two values: the symbol, its status: :internal, :inherited, :external.
We can use it like this:
(do-symbols (sym *package*)
(when (internal-symbol-p sym)
(format t "Symbol ~a is internal to ~a~&"
sym
*package*)))
So, a helper macro:
(defmacro do-internal-symbol ((sym &optional (package *package*)) &body body)
`(do-symbols (sym ,package)
(when (internal-symbol-p ,sym)
,@body)))
(do-internal-symbol (sym)
(print sym))
With loop, we can loop over external symbols:
(loop for sym being the :external-symbol of *package*
count sym))
loop is hardly extensible, so I didn't try to add a keyword.
Happy to receive improvements or corrections.
I wanted to print the symbols of a package that are not exported: the internal symbols.
indeed,
find-symbolreturns two values: the symbol, its status::internal,:inherited,:external.We can use it like this:
So, a helper macro:
With
loop, we can loop over external symbols:loop is hardly extensible, so I didn't try to add a keyword.
Happy to receive improvements or corrections.