Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Problem with defstruct printing in Common Lisp Message-ID: <1991Mar15.183935.16362@Think.COM> Date: 15 Mar 91 18:39:35 GMT References: Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 36 In article dsharma@kaffa.anu.oz.au (Dharmendra Sharma) writes: >I would like to be able to print a defstruct object on more than 1 >stream i.e. on the screen and to a file. How can I do it with a >predefined :print-function? I have a feeling you're not describing your problem correctly, or you're very confused. To print something on more than one stream, you can call PRINT multiple times, e.g.: (progn (print my-object *standard-output*) (print my-object file-stream)) If you want to print lots of stuff to both streams without having to double all your PRINT forms, you can use a broadcast stream: (with-open-stream (bs (make-broadcast-stream *standard-output* file-stream)) (print my-object bs) ...) The fact that a defstruct type has a :PRINT-FUNCTION is immaterial. The :PRINT-FUNCTION specifies what the output looks like, but not where it goes; the stream is a parameter to this function, and that's the only stream it should perform any output to. It's probably also a bad idea for a :PRINT-FUNCTION to have *any* side effects other than output to the given stream; however, CLtL doesn't specifically mention such a restriction (at least not in the descriptions of :PRINT-FUNCTION and PRINT-OBJECT). -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar