dsharma@kaffa.anu.oz.au (Dharmendra Sharma) (03/15/91)
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? Thanx. -- * Dharmendra Sharma-email:dsharma@anucsd.anu.edu.AU-post: * *Computer Science Department, ANU, GPO Box 4, Canberra ACT 2601, Australia * *From down under | Live to study and not study to live * ******************************************************************************
rkf@INEL.GOV (Raymond K. Fink) (03/16/91)
In article <dsharma.669010518@kaffa>, 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? >Thanx. 0- Presuming that the :print-function takes a stream argument...... 1- First create a stream to the file 2- use (make-broadcast-stream <file-stream> *standard-output*) to create a stream that will broadcast stuff to multiple streams. Ray Fink -- Idaho National Engineering Laboratory -- Idaho Falls ID rkf@inel.gov 208-526-9323 ========== long legal disclaimer follows, press n to skip =========== Neither the United States Government or the Idaho National Engineering Laboratory or any of their employees, makes any warranty, whatsoever, implied, or assumes any legal liability or responsibility regarding any information, disclosed, or represents that its use would not infringe privately owned rights. No specific reference constitutes or implies endorsement, recommendation, or favoring by the United States Government or the Idaho National Engineering Laboratory. The views and opinions expressed herein do not necessarily reflect those of the United States Government or the Idaho National Engineering Laboratory, and shall not be used for advertising or product endorsement purposes.
barmar@think.com (Barry Margolin) (03/16/91)
In article <dsharma.669010518@kaffa> 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