Is there a way to save all data associated with a given package
(including closures, objects, and so on), so it could be then restored
at runtime? Something like a small core dump. I'm writing a library for
writing Interactive Fiction (text adventures) in Lisp and I wonder how
savegames and undo could be implemented. Since everything could change
at runtime, this seems almost impossible. Any ideas?
--
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru http://grue3.tripod.com |
| k || PWNZ J00 || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]
····@mail.ru (Timofei Shatrov) writes:
> Is there a way to save all data associated with a given package
> (including closures, objects, and so on),
closures, objects and so on are not associated with a given package.
Only symbols are somewhat associated with a given package.
Symbols can have a given package as home package, or be imported into
the given package.
> so it could be then restored
> at runtime? Something like a small core dump. I'm writing a library for
> writing Interactive Fiction (text adventures) in Lisp and I wonder how
> savegames and undo could be implemented. Since everything could change
> at runtime, this seems almost impossible. Any ideas?
Either save the whole image, or write your own read/write
functions. (You get enough help from CL already to implement them!)
--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
On Thu, 27 Oct 2005 12:33:33 +0200, Pascal Bourguignon
<····@mouse-potato.com> tried to confuse everyone with this message:
>····@mail.ru (Timofei Shatrov) writes:
>
>> Is there a way to save all data associated with a given package
>> (including closures, objects, and so on),
>
>closures, objects and so on are not associated with a given package.
>
>Only symbols are somewhat associated with a given package.
>
>Symbols can have a given package as home package, or be imported into
>the given package.
That depends on the meaning of "associated". I meant it in a recursive
sense: symbols in package point to objects which point to other objects
and so on (the recursion stops at the symbol from the wrong package). In
the end everything related to the package must be saved into the file.
As for saving functions with the help of CL, the only way I see is the
following:
[1]> (defun fun (x y) (+ x y 1))
FUN
[2]> #'fun
#<CLOSURE FUN (X Y) (DECLARE (SYSTEM::IN-DEFUN FUN))
(BLOCK FUN (+ X Y 1))>
Now the last result can be transformed back into the definition of the
function. Of course that works only in CLISP and only if the function is
uncompiled.
--
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru http://grue3.tripod.com |
| k || PWNZ J00 || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]
····@mail.ru (Timofei Shatrov) writes:
>>closures, objects and so on are not associated with a given package.
>>
>>Only symbols are somewhat associated with a given package.
>>
>>Symbols can have a given package as home package, or be imported into
>>the given package.
>
> That depends on the meaning of "associated". I meant it in a recursive
> sense: symbols in package point to objects which point to other objects
> and so on (the recursion stops at the symbol from the wrong package). In
> the end everything related to the package must be saved into the file.
What package is the this closure:
(cl:let ((p3:y 2))
(cl:lambda (cl-user:x)
(p1:f cl-user:x (p2:f cl-user:x p3:ye))))
associated to?
> As for saving functions with the help of CL, the only way I see is the
> following:
>
> [1]> (defun fun (x y) (+ x y 1))
> FUN
> [2]> #'fun
> #<CLOSURE FUN (X Y) (DECLARE (SYSTEM::IN-DEFUN FUN))
> (BLOCK FUN (+ X Y 1))>
>
> Now the last result can be transformed back into the definition of the
> function. Of course that works only in CLISP and only if the function is
> uncompiled.
This is implementation dependant. On some implementations, while you
don't compile the function, you can recover the source s-expression
with FUNCTION-LAMBDA-EXPRESSION. But this is implementation dependant
whether you get a useful result or not.
The correct way to collect definitions is to define your own defun,
defvar, defmacro, etc, macros:
(defpackage :rcl (:use :cl) (:shadow :defun :defvar #|...|#))
(in-package :rcl)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter *definitions* '()))
(cl:defmacro defun (&whole form)
(push form *definitions*)
`(cl:defun ,@(cdr form)))
(cl:defmacro defvar (&whole form)
(push form *definitions*)
`(cl:defvar ,@(cdr form)))
#|...|#
(defpackage :rcl-user (:use :rcl))
(in-package :rcl-user)
(defun f (x) (1+ x))
(defun g (x) (1- x))
(defvar x (let ((z 0)) (lambda (&optional v) (if v (setf z v) z))))
(print rcl::*definitions*)
--
"Klingon function calls do not have "parameters" -- they have
"arguments" and they ALWAYS WIN THEM."
Pascal Bourguignon wrote:
> ····@mail.ru (Timofei Shatrov) writes:
>
>> Is there a way to save all data associated with a given package
>> (including closures, objects, and so on),
>
> closures, objects and so on are not associated with a given package.
>
> Only symbols are somewhat associated with a given package.
>
> Symbols can have a given package as home package, or be imported into
> the given package.
Well, but it would be cool to be able to serialize values (like
functions and objects). Then you could get the function object and
write it out as a binary blob (for all wanted functions).
--
The road to hell is paved with good intentions.
Ulrich Hobelmann <···········@web.de> writes:
> Pascal Bourguignon wrote:
>> ····@mail.ru (Timofei Shatrov) writes:
>>
>>> Is there a way to save all data associated with a given package
>>> (including closures, objects, and so on),
>> closures, objects and so on are not associated with a given package.
>> Only symbols are somewhat associated with a given package.
>> Symbols can have a given package as home package, or be imported
>> into
>> the given package.
>
> Well, but it would be cool to be able to serialize values (like
> functions and objects). Then you could get the function object and
> write it out as a binary blob (for all wanted functions).
There may be implementation specific API, but the only one that allow
you to serialize functions and closures and most data types, is
COMPILE-FILE. So you need to generate a lisp source in the first
place. Therefore you can as well load the lisp source.
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
In article <··············@thalassa.informatimago.com>,
Pascal Bourguignon <····@mouse-potato.com> wrote:
> ····@mail.ru (Timofei Shatrov) writes:
>
> > Is there a way to save all data associated with a given package
> > (including closures, objects, and so on),
>
> closures, objects and so on are not associated with a given package.
>
> Only symbols are somewhat associated with a given package.
In suspect he meant package in the "packaging an application" sense, not
the Lisp sense.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
This can help too :
http://plob.sourceforge.net/
--
Fabrice Popineau
------------------------
e-mail: ················@supelec.fr | The difference between theory
voice-mail: +33 (0) 387764715 | and practice, is that
surface-mail: Supelec, 2 rue E. Belin, | theoretically,
F-57070 Metz | there is no difference !
Hi
there are a couple of packages out there that do this full blown
serialization. One is the venerable "save-object" library. There is
another newer one on common-lisp.net called "cl-store".
YMMV.
Cheers
--
Marco
Timofei Shatrov wrote:
> Is there a way to save all data associated with a given package
> (including closures, objects, and so on), so it could be then restored
> at runtime? Something like a small core dump. I'm writing a library for
> writing Interactive Fiction (text adventures) in Lisp and I wonder how
> savegames and undo could be implemented. Since everything could change
> at runtime, this seems almost impossible. Any ideas?
>