From: Thomas Kolbe
Subject: ADVICE NEEDED: avoiding the :PRINT-FUNCTION ?
Date: 
Message-ID: <2j87qo$gp2@rs18.hrz.th-darmstadt.de>
I have a problem which is not covered by the FAQ:

How can I PRINT a data structure object such that
the printed representation is readable by READ, i.e.
avoiding the use of the optional :PRINT-FUNCTION ?

Consider the following code:

(defstruct (var  (:print-function pv)) name index)
(defun pv (var stream depth) (FORMAT stream "~A" (var-name var)))
(setq v (make-var :name "u" :index 2))  

Now (PRINT v) yields (using the PRINT-FUNCTION pv)
        u
instead of yielding
        #S(VAR NAME "u" INDEX 2)
as without the PRINT-FUNCTION.

How can I get the #S-syntax for v without changing the code above ?
In Steele/"Common Lisp", p.557 a global variable *PRINT-READABLY*
is mentioned that seems to be suitable but which is not defined in
the SUN COMMON LISP 4.0 version I'm using.
Any help for solving my problem is highly appreciated.

Thomas Kolbe
·····@inferenzsysteme.informatik.th-darmstadt.de
From: David Gadbois
Subject: Re: ADVICE NEEDED: avoiding the :PRINT-FUNCTION ?
Date: 
Message-ID: <2j8nmu$bsc@peaches.cs.utexas.edu>
In article <··········@rs18.hrz.th-darmstadt.de>,
Thomas Kolbe <·····@kiebitz.intellektik.informatik.th-darmstadt.de> wrote:
>
>How can I PRINT a data structure object such that
>the printed representation is readable by READ, i.e.
>avoiding the use of the optional :PRINT-FUNCTION ?

In ANSish Common Lisps, you can do:

   (defmethod print-object ((var var) stream)
     (if *print-readably*
	 (call-next-method)
	 (princ (var-name var) stream)))

In older CLs without PRINT-OBJECT, there is no way of doing this
portably short of writing your own #S printer for each structure type.

--David Gadbois