From: piscesboy on
On Mar 20, 12:19 am, Raffael Cavallaro
<raffaelcavall...(a)pas.espam.s.il.vous.plait.mac.com> wrote:
> On 2010-03-19 23:06:46 -0400, piscesboy said:
>
> > I've been working on a library to parse CLOS classes into XML output
> > format and read them back again into CLOS structures.
>
> I'm starting to sound like a broken record, but did you realize that
> the s-serialization library which is associated with/part of
> cl-prevalence already does this?
>
> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro

No, I didn't. I've been coding Lisp for a little over four months now,
so I'm a bit of a newbie myself. But anyway, I've been doing the xml
library as an exercise. The library you mentioned requires asdf to
install or the installation of SBCL which has the package installed by
default. I have CLisp and CCL installed, so I have to install those
libraries before I can use them.
From: Raffael Cavallaro on
On 2010-03-20 01:45:30 -0400, piscesboy said:

> I have CLisp and CCL installed, so I have to install those
> libraries before I can use them.

with CCL you can get asdf with require:

rafbookpro13:ccl raffaelc$ ./dx86cl64 -n ;; i.e., no init file loaded
Welcome to Clozure Common Lisp Version 1.5-dev-r13539M-trunk (DarwinX8664)!
? (require 'asdf)
ASDF
("ASDF")
?

--
Raffael Cavallaro

From: Pascal J. Bourguignon on
Krzysztof Drewniak <krzysdrewniakNOSPAM(a)gmail.com> writes:
> I am going to try and write a roguelike in CL. To implement
> saving/loading, I would like to implement saves by 'print'ing and
> 'read'ing from a file. However, I will be using CLOS, and the
> standard 'print-object' is useless in this situation. Could someone
> please provide code or pointers to code that lets you print an object
> (and all of its slots) and read it back in, without losing any values.


It's not so much that they're useless in this situation, than rather
you really do not want to do that.

You _could_ use print-object to print objects "readably". For example,
you could implement a print-object method writing something like:

#.(make-instance '<the-class> :field1 value-of-field1 ...)

However, there are two problems:

1- this wouldn't work very well in case of circular relationships
(or you would have to implement the de-circularization yourself).

2- print-object is actually used by the debugger, and you definitely
don't want to serialize your whole object graph when debugging a
little method.


So print-object has a purpose, and serializing application data is not
really it. For this, you should write your own methods. You can
however easily reuse print-object for "simple" objects. Something like:

(defmethod serialize ((lisp-object t) stream)
(print-object lisp-object t))

(defmethod serialize ((appl-object world-object) stream)
(multiple-value-bind (instances associations)
(analyze-object-graph appl-object)
(with-references (mapc (function serialize-instance) instances)
(mapc (function serialize-associations) associations))))

--
__Pascal Bourguignon__
From: Krzysztof Drewniak on
On 2010-03-20, Raffael Cavallaro <raffaelcavallaro(a)pas.espam.s.il.vous.plait.mac.com> wrote:
> On 2010-03-20 00:19:26 -0400, Raffael Cavallaro said:
>
>> I'm starting to sound like a broken record, but did you realize that
>> the s-serialization library which is associated with/part of
>> cl-prevalence already does this?
>
> Sorry, forgot the obligatory minimal examples:
>
> sexp:
>
> ? (serialize-sexp (progn (defclass foo () ((bar :accessor bar :initarg
>:bar) (quux :accessor quux :initarg :quux))) (make-instance 'foo :bar 3
>:quux 28)) *standard-output*)
[snip]
> warmest regards,
>
> Ralph
>
Thank you for the tip. This library seems to meet my needs quite fine.
These responses were very helpful. Great group!

Krzysztof Drewniak

--
X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com
pgp key on keyserver.ubuntu.com and maybe some other place too
From: game_designer on
On Mar 20, 7:13 am, Krzysztof Drewniak <krzysdrewniakNOS...(a)gmail.com>
wrote:
> On 2010-03-20, Raffael Cavallaro <raffaelcavall...(a)pas.espam.s.il.vous.plait.mac.com> wrote:
>
>
>
> > On 2010-03-20 00:19:26 -0400, Raffael Cavallaro said:
>
> >> I'm starting to sound like a broken record, but did you realize that
> >> the s-serialization library which is associated with/part of
> >> cl-prevalence already does this?
>
> > Sorry, forgot the obligatory minimal examples:
>
> > sexp:
>
> > ? (serialize-sexp (progn (defclass foo () ((bar :accessor bar :initarg
> >:bar) (quux :accessor quux :initarg :quux))) (make-instance 'foo :bar 3
> >:quux 28)) *standard-output*)
> [snip]
> > warmest regards,
>
> > Ralph
>
> Thank you for the tip. This library seems to meet my needs quite fine.
> These responses were very helpful. Great group!
>
> Krzysztof Drewniak
>
> --
> X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com
> pgp key on keyserver.ubuntu.com and maybe some other place too


if you don't mind XML try XMLisp:
http://code.google.com/p/xmlisp/source/browse/trunk/XMLisp/sources/XMLisp/XMLisp.lisp


It uses the MOP to serialize/de-serialize CLOS instances

alex