From: David Bakhash
Subject: couple of questions...
Date: 
Message-ID: <cxjg13jufc3.fsf@acs5.bu.edu>
I have several short questions (answers might not all be that short, though).
Figured I'd ask in a single post.

1) I tried to write a defmethod for vector:

(defmethod make-load-form ((self vector) &optional env)
  (declare (ignore env))
  ...)

and got a compiler warning, and that MAKE-LOAD-FORM on VECTOR would render the
code non-portable.  Why?  This is not obvious to me.

2) In (1), is it wise for me to (ignore env)?  What is `env' for anyway?
   Does anyone ever use it?
	
dave

From: Barry Margolin
Subject: Re: couple of questions...
Date: 
Message-ID: <Lr7c3.825$KM3.210801@burlma1-snr2>
In article <···············@acs5.bu.edu>,
David Bakhash  <·····@acs.bu.edu> wrote:
>I have several short questions (answers might not all be that short, though).
>Figured I'd ask in a single post.
>
>1) I tried to write a defmethod for vector:
>
>(defmethod make-load-form ((self vector) &optional env)
>  (declare (ignore env))
>  ...)
>
>and got a compiler warning, and that MAKE-LOAD-FORM on VECTOR would render the
>code non-portable.  Why?  This is not obvious to me.

See Section 11.1.2.1.2 "Constraints on the COMMON-LISP Package for
Conforming Programs" of the CLHS:
<http://www.harlequin.com/education/books/HyperSpec/Body/sec_11-1-2-1-2.html>

The spec doesn't give the reason, but consider that the implementation
already has to have a way to write vectors to object files.  If you define
your own method for this, it will probably break the implementation's
internal mechanism.

>2) In (1), is it wise for me to (ignore env)?  What is `env' for anyway?
>   Does anyone ever use it?

I'm not sure.  I notice that all the examples in the CLHS either ignore the
environment or simply pass it along to MAKE-LOAD-FORM-SAVING-SLOTS.

This argument wasn't in the original MAKE-LOAD-FORM specification, but was
added in cleanup proposal MAKE-LOAD-FORM-CONFUSION:REWRITE.  The rationale
given was:

 Adding optional environment arguments to these functions provides them with
 access to the environment in which the forms to be returned will be processed
 by COMPILE-FILE.

And there's a comment by Dave Moon:

  As I keep saying over and over (although I guess I must not have been
  listening to myself when I first proposed make-load-form!), no form has any
  meaning without an accompanying environment.

However, as far as I can tell, this function doesn't process forms in any
way that could make use of the environment.  Environments are opaque
objects that can be passed to things like MACROEXPAND (so that they'll take
things like MACROLET into account), but MAKE-LOAD-FORM shouldn't need to do
anything like this.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Pekka P. Pirinen
Subject: Re: couple of questions...
Date: 
Message-ID: <ixpv2bknkk.fsf@gaspode.cam.harlequin.co.uk>
Barry Margolin <······@bbnplanet.com> writes:
> In article <···············@acs5.bu.edu>,
> David Bakhash  <·····@acs.bu.edu> wrote:
> >(defmethod make-load-form ((self vector) &optional env)
> >  (declare (ignore env))
> >  ...)
> >2) In (1), is it wise for me to (ignore env)?  What is `env' for anyway?
> >   Does anyone ever use it?

If you don't do any environment lookups, you can probably ignore it.
I've never seen a user MAKE-LOAD-FORM method that used it.

> This argument wasn't in the original MAKE-LOAD-FORM specification, but was
> added in cleanup proposal MAKE-LOAD-FORM-CONFUSION:REWRITE.  The
> rationale given was:
> 
>  Adding optional environment arguments to these functions provides
>  them with access to the environment in which the forms to be
>  returned will be processed by COMPILE-FILE.

> 
> And there's a comment by Dave Moon:
> 
>   As I keep saying over and over (although I guess I must not have
>   been listening to myself when I first proposed make-load-form!),
>   no form has any meaning without an accompanying environment.
>
> However, as far as I can tell, this function doesn't process forms in any
> way that could make use of the environment.

It's hard to be 100% sure that no user method will never need to use
it.  Theoretically, Moon is right: the returned form will only have
meaning relative to the environment is executed in.  That environment
is determined by the compiler, so it needs to be passed down to
MAKE-LOAD-FORM methods, if they need to worry about the meaning.  In
practice, the programmer knows what the environment is going to be
like, so they can just write
  (defmethod make-load-form ((self foo) &optional env)
    (declare (ignore env))
    `(make-foo ',(foo-key self)))
without worrying about what MAKE-FOO will refer to.

FWIW, it is used in the LispWorks implementation of
MAKE-LOAD-FORM-SAVING-SLOTS, to check that (CLASS-NAME (CLASS-OF
self)) actually refers to (CLASS-OF self) in that environment.
-- 
Pekka P. Pirinen
Harlequin Group plc
"Unix is the answer, but only if you phrase the question very carefully."