From: Peter Berck
Subject: Structure question
Date: 
Message-ID: <1991Jan25.115153.2864@kub.nl>
Hi,

I have this structure which I save and load from disc. I recently
added a :print-function to it, but now (after I printed it to disc)
I can't read it back in again... I guess the reader doesn't like my
string-output generated with the :print-function.

Is there a way around it - like forcing LISP to still print out my
structure using the #S(.. syntax?

I use something like (but this is probably irrelevant):

(defun save-network (filename)
  (with-open-file (my-stream filename
                             :direction :output)
    (print *patterns* my-stream)
    (print *targets* my-stream)
	...))

and 

(defun load-network (filename)
  (with-open-file (my-stream filename
                             :direction :input)
    (setf *patterns* (read my-stream nil))
    (setf *targets* (read my-stream nil))
	..))

The *patterns* &c. variables are a list with structures...

thanx,
-peter

-- 
······@kub.nl     -     kubvx1::pberck

From: lou
Subject: Re: Structure question
Date: 
Message-ID: <LOU.91Jan25134632@atanasoff.rutgers.edu>
Peter Berck writes:

    I have this structure which I save and load from disc. I recently
    added a :print-function to it, but now (after I printed it to disc)
    I can't read it back in again

There are two solutions to this problem:

1) Revise your print function so that under some circumstance it
prints the structure in the #S( ... ) form.  E.g. it might check the
global variable *print-pretty*, and if it is NIL print the #S form.
Then just make sure that you are not pretty-printing when you dump
your network to disk.  Off hand, though, I do not know of any clean
and portable way to both have your own print-function and at the same
time get access to the print code that would be used if you did not
have one.  So, you probably have to write your own code to print the
#S form (or find a non-portable method that works in your implementation
of CL).

2) Revise your print function to start with some special character
or character sequence and write a read-macro for that character
or sequence that reads in your new printed format for the structures.


--
					Lou Steinberg

uucp:   {pretty much any major site}!rutgers!aramis.rutgers.edu!lou 
internet:   ···@cs.rutgers.edu
From: Barry Margolin
Subject: Re: Structure question
Date: 
Message-ID: <1991Jan25.203223.25843@Think.COM>
In article <·················@atanasoff.rutgers.edu> ···@cs.rutgers.edu writes:
>1) Revise your print function so that under some circumstance it
>prints the structure in the #S( ... ) form.  E.g. it might check the
>global variable *print-pretty*, and if it is NIL print the #S form.

Actually, *PRINT-ESCAPE* is supposed to be used for this purpose.  When it
is true the implication is that computer-parsable formatting should be used
when it is available; when it is NIL the implication is that the output is
only intended for human consumption.

*PRINT-PRETTY* is only supposed to affect whitespace.  This generally means
that when it is true spaces should be turned into newlines followed by
whitespace in order to make the nesting structure more obvious.
Pretty-printing can be done with both escaped and unescaped output.

By the way, ANSI CL is adding another variable, *PRINT-READABLY*, which is
even stronger than *PRINT-ESCAPE*.  See pp.557-8 of CLtL2 for a
description, but basically it is used to specify that an error should be
signalled if there is no computer-parsable printed representation for an
object being printed (*PRINT-ESCAPE* specifies a preference, while
*PRINT-READABLY* specifies a requirement).
--
Barry Margolin, Thinking Machines Corp.

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