CL-USER
CL-USER

Reputation: 786

Invoking print-object on a list of symbols

I have a global list of symbols, CLOS objects, and a corresponding print-object method defined that gives them succinct summaries. I'd like to provide the user with a show-all method that loops over them and prints the same output that I get at the REPL, using print-object. An earlier question suggested method-function to look up the specific method and then funcall it, but using closer-mop isn't an option.

I can get a specific object to print in the loop, but not looping over the list, e.g.:

(defun show-all (&optional (stream *standard-output*))
  "Print summaries for all objects in the current environment"
  (dolist (o *master-list*)
    (format t "~A~%" o) ; prints symbol name as text
    (print-object foo::my-object *standard-output*) ;prints my-object using print-object, this is what I want
    (print-object o *standard-output*))) ; same as format, prints symbol-name as text

Anyone have any ideas of what's going on here? If I can print a specific object in the environment using print-object, I should be able to print all of them looping over the list of symbols.

Upvotes: 1

Views: 196

Answers (1)

Svante
Svante

Reputation: 51501

A symbol is not the same as a thing that it names.

Since print-object is a (generic) function, normal evaluation applies. It gets the value of foo::my-object as an argument. It never sees the symbol foo::my-object. If you iterate over a list of symbols, you still need to lookup whatever values you want, e. g. using symbol-value if they name global values.

You have specialized your print-object method on some class, right? Not on an eql specializer for each symbol?

Upvotes: 3

Related Questions