From: Tushar Saxena
Subject: Printing an inctance of a Class
Date: 
Message-ID: <1992Jul6.151622.2722@cs.albany.edu>
I am working on a big piece of software written on PCL. Now, for various
arithmetics, it has various classes. For a particular kind of arithmetic
I had defined a pretty complex class (not in absolute terms, but as compared
to what I later found could suffice). My job on that class is such that
the time taken to print any instance of this class is unimportant. What
is important is the time taken in doing computations on the instances of
this class. But, ironically, even though the printing time is not important,
I have to do a great amount of processing before I can print that instance.
Hence the print function for that class was very complex. This is not to say
that I want to get rid of this complex processing. This is important and I
would need this if I want to print anything meaningful.

Now I once decided to care only about reducing the time taken in doing all
the computations on the instances of that class. So after some thought, I
decided to use the built in list class. After I wrote down all the functions
for this class, I ran the program, and to my surprise, it took 1/50th of the
time it was taking previously with the more complex class. Moral : the builder
function for the user made classes takes much more time than by the predefined
(built-in) classes. That's okay, I was happy. But the problem now is that I
have lost all hold on printing. It prints all the output as a list. That might
make sense to me after an hour of figuring out, but I have to process the
output and print in concise form if it has to make sense to anyone else.

Hence arises my problem. How can I get a hold on printing without raising the
time taken in the computations.

Any help/advise would be greatly appreciated.

	-Tushar

--------------------------------------------------------------------------------
And any fool knows a dog needs a home, A shelter from pigs on the wing.
        -Roger Waters
--------------------------------------------------------------------------------
email : ······@cs.albany.edu                        Computer Science Department
Phone : 518-442-3388				    SUNY Albany
Tushar Saxena					    Albany NY 12222 (USA)
--------------------------------------------------------------------------------
From: Barry Margolin
Subject: Re: Printing an inctance of a Class
Date: 
Message-ID: <13a40sINNsui@early-bird.think.com>
In article <····················@cs.albany.edu> ······@cs.albany.edu (Tushar Saxena) writes:
>Hence arises my problem. How can I get a hold on printing without raising the
>time taken in the computations.

I'm going to summarize your original message, as I had trouble
understanding it and want to make sure I finally figured it out.

You originally defined your data structure using user-defined classes,
which allowed you to customize the way the objects printed, but found the
performance of processing the objects unacceptable.  You redesigned your
program to use lists instead of user-defined classes, but now you no longer
have control over the way the objects print (because they're just lists).

One solution may be to use structures rather than CLOS classes.  These tend
to have better performance than classes, but still allow you to customize
printing.

Another solution would be to use Dick Waters' XP pretty-printer.  This is
the pretty-printer that served as the prototype for the pretty-printing
enhancements in draft ANSI CL, as described in chapter 27 of CLtL2.  This
facility allows you to customize the way the pretty-printer prints objects,
using type specifiers rather than classes as keys, which permits finer
recognition.  For instance, if your lists all begin with the symbol
MY-OBJECT, you could use

(set-pprint-dispatch '(cons (member my-object)) #'pprint-my-object)

to specify that the pretty-printer should use PPRINT-MY-OBJECT when
displaying your lists.

Note that this solution only works when you're using the pretty-printer
(i.e. when *PRINT-PRETTY* is not NIL), and requires you to make your list
objects distinguishable from other lists (e.g. by putting a special object
in the car).  If that's not appropriate for your needs, you may have to
give up on using PRINT to print your objects, and always print them with a
function of your own that formats them as you want.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar