From: Randy Coulman
Subject: make-load-form
Date: 
Message-ID: <1991Nov7.182629.18893@access.usask.ca>
I've just been playing with make-load-form.  I've managed to
get it to "automatically" copy a structure (using the example
on p. 662 of CLtL2).  What I'd really like to be able to do 
with it is the following:

-build up a structure in the current Lisp session
-use make-load-form to generate a set of forms which will recreate
 the structure when necessary
-somehow save these forms in a file
-reload the forms in another Lisp session to recreate the original 
 structure

The structures are defined using classes and instances in CLOS.  In order
to fill some of the slots in the structures, a lot of processing is required
to re-create sub-structures, so if I can do it automatically, it will 
save a lot of time.

Is it possible to use make-load-form for this, or am I dreaming?  If it's 
possible, how do I do it?  Also, in CLtL2, it appears as though the normal
thing to do is to put a call to make-load-form in a file that is being compiled.
What is the purpose of this?  I guess what I'm saying is that I'm not totally 
clear about what the purpose of make-load-form really is.  Any explanations?

Randy

P.S. If it matters, I'm using Allegro CL 4.1.beta.0 with its native CLOS.
-- 
Randy A. Coulman                    |
Department of Computational Science | 
University of Saskatchewan          | ·······@cs.Usask.ca         
Saskatoon, SK   S7N 0W0             | ·······@skaries.Usask.ca

From: Barry Margolin
Subject: Re: make-load-form
Date: 
Message-ID: <khjl5dINNll7@early-bird.think.com>
In article <·····················@access.usask.ca> ·······@cs.Usask.CA writes:
>Is it possible to use make-load-form for this, or am I dreaming?  If it's 
>possible, how do I do it?  Also, in CLtL2, it appears as though the normal
>thing to do is to put a call to make-load-form in a file that is being compiled.
>What is the purpose of this?  I guess what I'm saying is that I'm not totally 
>clear about what the purpose of make-load-form really is.  Any explanations?

MAKE-LOAD-FORM is not normally called by user programs.  Rather, users are
expected to define MAKE-LOAD-FORM methods for the classes they define.  The
compiler will automatically call MAKE-LOAD-FORM on any objects that appear
as a quoted constant or self-evaluating form in a file being compiled.
This could occur by using #S syntax for a structure type that has a
MAKE-LOAD-FORM method, by using a user-defined read-macro that produces
objects of a CLOS class, or by writing #.(make-instance ...).  For
instance, if a file contains:

(defconstant *my-object* #.(make-instance 'my-class ...))

the compiler will call MAKE-LOAD-FORM on the instance, which should return
a creation form and an initialization form.  The compiler will then act as
if the following had actually been in the file being compiled:

(defconstant *my-object* (let ((temp <creation form>))
			   <initialization form>
			   temp))

In the implementation of a MAKE-LOAD-FORM method you simply reference the
object itself in the form you return, and the compiler takes care of
turning these into references to TEMP in the binary.
-- 
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar
From: Jeff Dalton
Subject: Re: make-load-form
Date: 
Message-ID: <5581@skye.ed.ac.uk>
In article <············@early-bird.think.com> ······@think.com (Barry Margolin) writes:
>(defconstant *my-object* #.(make-instance 'my-class ...))
>
>the compiler will call MAKE-LOAD-FORM on the instance, which should return
>a creation form and an initialization form.  The compiler will then act as
>if the following had actually been in the file being compiled:
>
>(defconstant *my-object* (let ((temp <creation form>))
>			   <initialization form>
>			   temp))

I'm not sure using defconstant this way will work very well,
expecially if the file containing it is ever reloaded, because
a different, non-EQL, object will be constructed each time.
From: Paul Krueger
Subject: Re: make-load-form
Date: 
Message-ID: <1991Nov8.112431.20938@hemlock.cray.com>
In article <·····················@access.usask.ca>, ·······@cs.Usask.CA (Randy Coulman) writes:
> I've just been playing with make-load-form.  I've managed to
> get it to "automatically" copy a structure (using the example
> on p. 662 of CLtL2).  What I'd really like to be able to do 
> with it is the following:
> 
> -build up a structure in the current Lisp session
> -use make-load-form to generate a set of forms which will recreate
>  the structure when necessary
> -somehow save these forms in a file
> -reload the forms in another Lisp session to recreate the original 
>  structure
> 
> The structures are defined using classes and instances in CLOS.  In order
> to fill some of the slots in the structures, a lot of processing is required
> to re-create sub-structures, so if I can do it automatically, it will 
> save a lot of time.
> 
> Is it possible to use make-load-form for this, or am I dreaming?  If it's 
> possible, how do I do it?  Also, in CLtL2, it appears as though the normal
> thing to do is to put a call to make-load-form in a file that is being compiled.
> What is the purpose of this?  I guess what I'm saying is that I'm not totally 
> clear about what the purpose of make-load-form really is.  Any explanations?> 
> Randy
> 
Barry Margolin gave a good response regarding make-load-form but left out an example that might help with your specific problem.  All Common Lisp data objects other than symbols and lists are self-evaluating objects.  This means that you
can do something like the following:

During one lisp session make all the class instances or structures that you want and, for example, put them into a list bound to the variable foo.  Then create
a file with the text line (defvar reconstructed-foo #.foo) and compile it.  The #. construct causes read-time evaluation (namely when the compiler reads the file) and what is returned is a list of self-evaluating objects (namely your instances or structures).  The compiler knows how to deal with lists and will call make-load-form on each of its objects.  It will take the forms returned by the make-load-form calls and do its thing to assure that when the compiled file is re-loaded the objects will be recons





tructed properly and bound to the variable reconstructed-foo (obviously you can do whatever you want with them).

Note that I haven't been able to verify that this all works since the Allegro 4.0 compiler does not implement this functionality and I do not yet have access to 4.1 to try it out.  I believe it will work, however, because the 4.0 compiler at least recognizes what you are trying to do and tells you that evaluation of these objects is not yet implemented.  If you have success with 4.1 let me know.
--
     Paul Krueger                                    Cray Research Park
     ········@cray.com                               655F Lone Oak Drive
     (612) 683-5243  Fax: (612) 683-5889             Eagan, MN 55121 USA