From: Vassil Nikolov
Subject: Re: printing objects readable
Date: 
Message-ID: <l03130300b3e47e5fee30@195.138.129.104>
kp gores wrote:                [1999-08-21 15:35 +0200]

  > hello,
  > 
  > it seems that cmucl and probably other lisp's conforming to clos canT
  > print an object (class instance) such that it is readable.

More precisely, the Common Lisp specification indeed does not define
a standard syntax for instances (like it does for structures etc.).

  > what is the recommended way for temporarily printing such objects to a
  > file and reading back later?

There are at least three choices (well, I don't know which is _the_
recommended one...):

(1) design your own syntax for the class(es) of interest to you, write your
    own PRINT-OBJECT method(s) and your own reader macros;

(2) write your PRINT-OBJECT method(s) that produce(s) a call to the class
    constructor (or to MAKE-INSTANCE) preceded by a ``#.'' (hash-dot);

(3) use the trick of writing something like "(SETQ *FOO* #.*FOO*)" to a
    lisp source file and then compile that file (where the value of *FOO*
    at file-compile time is the object you want to write to a file); load
    the compiled file to set *FOO* to the value of the instance.

Sorting out the issues related to (in no particular order):
* externalisation of objects;
* handling shared (sub)structure;
* `interning' of objects;
is left as an exercise for the reader (i.e. I don't have time for a multi-line
treatise of all those issues in general; if you have any *specific* problems,
it might be fruitful to discuss them in the group).


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.





 Sent via Deja.com http://www.deja.com/
 Share what you know. Learn what you don't.

From: Rainer Joswig
Subject: Re: printing objects readable
Date: 
Message-ID: <joswig-2208991616490001@194.163.195.67>
In article <·····················@195.138.129.104>, Vassil Nikolov <···@einet.bg> wrote:

> kp gores wrote:                [1999-08-21 15:35 +0200]
> 
>   > hello,
>   > 
>   > it seems that cmucl and probably other lisp's conforming to clos canT
>   > print an object (class instance) such that it is readable.
> 
> More precisely, the Common Lisp specification indeed does not define
> a standard syntax for instances (like it does for structures etc.).

There was once a portable library for that: save-object.lisp

From the doc:

SAVE-OBJECT is a recursive function which writes an ASCII representation of
a LISP object to a designated file. 

Objects which may be saved include:

      ---- symbols, keywords, numbers, characters, strings, and  pathnames.
      ---- vectors and multi-dimensional arrays.
      ---- objects produced by defstruct.
      ---- CLOS (PCL) instances.
      ---- hash-tables.
      ---- compiled functions (represented as (FUNCTION <function-name>). )
           (not supported [in MAC version] - AMK)

      ---- generic-functions, method objects, and class objects.
           (New since version 1)

      ---- conses.
      ---- lists.

      ---- user defined methods may be defined for arbitrary objects,
           such as images.
           (not supported [in MAC version] - AMK)


      ---- readtables (note: kludge for now, no MAC version....)
           can be got at on the Symbolics....
From: Larry Hunter
Subject: Re: printing objects readable
Date: 
Message-ID: <3isvha6fw2a.fsf@work.nci.nih.gov>
    it seems that cmucl and probably other lisp's conforming to clos canT
    print an object (class instance) such that it is readable.
 
  More precisely, the Common Lisp specification indeed does not define a
  standard syntax for instances (like it does for structures etc.).

 There was once a portable library for that: save-object.lisp

And there's PLOB, Persistent Lisp OBjects, a really very useful MOP package
that easily allows any CL entity (including CLOS objects) to be made
persistent.  I find it is often the case that when people say they want to
save instances to a file, what they really mean is that they need tools to
manage persistency.  PLOB is a whole lot lisp-ier and more appropriate than
the file system for persistency....

It's easy to use (simplest interface allows you to just add a :metaclass
:persistent-metaclass clause to defclass), has fairly sophisticated controls
for things like transactions, indices and locking, and is mostly free (in
both senses, although it's not GPL'd; see the license details if you care
about that sort of thing).  I've been using it happily for several years
now, including on some large projects. It works and plays particularly well
with CL-HTTP.

 http://www.lisp.de/software/plob/

PLOB's main drawback is that it hasn't been ported very widely.  It works
out of the box on Franz ACL/Unix and NT systems.  I imagine that it could be
ported with moderate effort to other parts of the lisp universe. Given my
positive experiences with the author (Heiko Kirschke) on my own porting
issues, I also imagine that if someone wanted to take on the work of a port
to other vendors/platforms, he would be quite supportive.

Larry

-- 
Lawrence Hunter, Ph.D.        Chief, Molecular Statistics and Bioinformatics
National Cancer Institute                             email: ·······@nih.gov
Federal Building, Room 3C06                         phone: +1 (301) 402-0389
7550 Wisconsin Ave.                                   fax: +1 (301) 480-0223
Bethesda, MD 20892  USA
From: Rainer Joswig
Subject: Re: printing objects readable
Date: 
Message-ID: <joswig-2308991656400001@pbg3.lavielle.com>
In article <···············@work.nci.nih.gov>, Larry Hunter <·······@nih.gov> wrote:

>     it seems that cmucl and probably other lisp's conforming to clos canT
>     print an object (class instance) such that it is readable.
>  
>   More precisely, the Common Lisp specification indeed does not define a
>   standard syntax for instances (like it does for structures etc.).
> 
>  There was once a portable library for that: save-object.lisp

> PLOB's main drawback is that it hasn't been ported very widely.

Btw.: Macintosh Common Lisp has a similar package: WOOD.
It has been in a number of projects (including CL-HTTP
sites) and has been written by Bill St.Clair.
From: Pierre R. Mai
Subject: Re: printing objects readable
Date: 
Message-ID: <87wvumi4rq.fsf@orion.dent.isdn.cs.tu-berlin.de>
Larry Hunter <·······@nih.gov> writes:

> for things like transactions, indices and locking, and is mostly free (in
> both senses, although it's not GPL'd; see the license details if you care
> about that sort of thing).  I've been using it happily for several years

Do you know where to find the licensing terms of the POSTORE backend
used by PLOB? I've not been able to find the exact terms for this, not
at PLOB's site nor at the home site of POSTORE...

> now, including on some large projects. It works and plays particularly well
> with CL-HTTP.
> 
>  http://www.lisp.de/software/plob/
> 
> PLOB's main drawback is that it hasn't been ported very widely.  It works
> out of the box on Franz ACL/Unix and NT systems.  I imagine that it could be
> ported with moderate effort to other parts of the lisp universe. Given my

IIRC it works on Harlequin's Lispworks, too.

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Vassil Nikolov
Subject: Re: printing objects readable
Date: 
Message-ID: <l03130302b3e5d7e55b29@195.138.129.116>
Rainer Joswig wrote:                [1999-08-22 16:16 +0200]

  [...]
  > SAVE-OBJECT is a recursive function which writes an ASCII representation of
  > a LISP object to a designated file. 
  > 
  > Objects which may be saved include:
  > 
  >       ---- symbols, keywords, numbers, characters, strings, and  pathnames.
  >       ---- vectors and multi-dimensional arrays.
  >       ---- objects produced by defstruct.
  >       ---- CLOS (PCL) instances.
  >       ---- hash-tables.
  >       ---- compiled functions (represented as (FUNCTION <function-name>). )
  >            (not supported [in MAC version] - AMK)
  > 
  >       ---- generic-functions, method objects, and class objects.
  >            (New since version 1)
  > 
  >       ---- conses.
  >       ---- lists.
  > 
  >       ---- user defined methods may be defined for arbitrary objects,
  >            such as images.
  >            (not supported [in MAC version] - AMK)
  > 
  > 
  >       ---- readtables (note: kludge for now, no MAC version....)
  >            can be got at on the Symbolics....

Thanks for this.  I admit I didn't know about this (or knew only very little
and had forgotten, which is the same).

Maybe you wouldn't want to bother; in any case, some obvious
questions are:

Did it produce standard syntax (one that the reader understands) for
those objects that have one (like symbols, lists, arrays, etc.)?

Or, for arrays for example, did it write fill-pointer information?

Alternatively, is there a URL where one can find answers to questions
like these?

And finally, I wonder if people who actually used it (for real tasks, not
for playing with it) were happy with it (I expect they had mixed feelings
about it, but that's just a guess).


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.





 Sent via Deja.com http://www.deja.com/
 Share what you know. Learn what you don't.