Skip to content

do-internal-symbols #39

Description

@vindarel

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions