From: Joel Ray Holveck
Subject: Autoloading
Date: 
Message-ID: <y7cy9c8bnfq.fsf@sindri.juniper.net>
Is this guaranteed to do the right thing?

(defmacro foo (&body body)
  (require 'foo) ;Loads a new defmacro foo
  `(foo ,@body))

Thanks,
joelh

From: Nils Goesche
Subject: Re: Autoloading
Date: 
Message-ID: <lkheiwnehr.fsf@pc022.bln.elmeg.de>
Joel Ray Holveck <·····@juniper.net> writes:

> Is this guaranteed to do the right thing?
> 
> (defmacro foo (&body body)
>   (require 'foo) ;Loads a new defmacro foo
>   `(foo ,@body))

What do you want it to do?

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Christophe Rhodes
Subject: Re: Autoloading
Date: 
Message-ID: <sq8z48vt54.fsf@lambda.jcn.srcf.net>
Nils Goesche <······@cartan.de> writes:

> Joel Ray Holveck <·····@juniper.net> writes:
> 
> > Is this guaranteed to do the right thing?
> > 
> > (defmacro foo (&body body)
> >   (require 'foo) ;Loads a new defmacro foo
> >   `(foo ,@body))
> 
> What do you want it to do?

Here's my guess.

(defmacro foo (&body body)
  (require 'foo)
  `(foo ,@body))

--- inside foo.lisp ---
(defmacro foo (&body body)
  (with-some-frobnicator ()
    ,@body))

(provide 'foo)
--- end of foo.lisp ---

* (foo (baz))

calls the currently available macro function for FOO as part of
evaluation of the form, probably somewhere inside MACROEXPAND.  This
function ensures that foo.lisp is loaded (well, if REQUIRE does what
you want it to, anyway) and then returns the form (foo (baz)).
MACROEXPAND detects that the CAR of this form has a macro-function
associated with it, calling that (new) macro-function, resulting in
the eventual evaluation of (with-some-frobnicator () (baz)).

Now, as to the question of whether it's specified that the above forms
actually do this, I'm afraid I'm going to pass; I have a vague worry
about compilation environments and the like, and I can't honestly say
that I know what is specified about which environments LOAD and
friends affect. Sorry. :-/

Cheers,

Christophe
-- 
Jesus College, Cambridge, CB5 8BL                           +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/                  (defun pling-dollar 
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)
From: Thomas F. Burdick
Subject: Re: Autoloading
Date: 
Message-ID: <xcv3cuftt2n.fsf@blizzard.OCF.Berkeley.EDU>
Christophe Rhodes <·····@cam.ac.uk> writes:

> Now, as to the question of whether it's specified that the above forms
> actually do this, I'm afraid I'm going to pass; I have a vague worry
> about compilation environments and the like, and I can't honestly say
> that I know what is specified about which environments LOAD and
> friends affect. Sorry. :-/

I'm pretty sure this would have to work in any conforming
implementation.  I can't find any justification in the spec for a
compile-time LOAD call to evaluate the file's forms in any environment
but the compile-time one.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Pekka P. Pirinen
Subject: Re: Autoloading
Date: 
Message-ID: <ud6t24kn9.fsf@globalgraphics.com>
···@blizzard.OCF.Berkeley.EDU (Thomas F. Burdick) writes:
> Christophe Rhodes <·····@cam.ac.uk> writes:
> > Now, as to the question of whether it's specified that the above forms
> > actually do this, I'm afraid I'm going to pass; I have a vague worry
> > about compilation environments and the like, and I can't honestly say
> > that I know what is specified about which environments LOAD and
> > friends affect. Sorry. :-/

You're right to worry, but it's actually good enough.

ANS 3.2.1 specifies the compiler's environments in terms of the
"startup", "evaluation", and "compilation" environments.  An
implementation is not required to maintain three different
environments, they can be identical.  The compilation environment gets
updated when the compiler sees something that it needs to remember.
All evaluations initiated by the compiler take place in the evaluation
environment, and the compilation environment inherits from it.

Applying that specification, I'd say that executing a DEFMACRO inside
the compiler would probably affect the evaluation environment.
However, the name could be shadowed by a macro definition the compiler
has seen and remembered in the compilation environment.  If the
environment are identical, there's only one definition, but typical
Lisp implementations do have a separate compilation environment.

> I'm pretty sure this would have to work in any conforming
> implementation.  I can't find any justification in the spec for a
> compile-time LOAD call to evaluate the file's forms in any environment
> but the compile-time one.

I'm sure it doesn't have to work.  You were probably looking for the
wrong thing.  However, the case where it doesn't work is where the
macro is invoked in the same file (compilation unit) as the autoload
definition, since the compiler's environments only survive until the
end of the compilation unit.  This is not worth worrying about in
practice, so Holveck should worry about error checking or something
else instead.
-- 
Pekka P. Pirinen
The great problem with Lisp is that it is just good enough to keep us
from developing something really good.  - Alan Kay
From: Joel Ray Holveck
Subject: Re: Autoloading
Date: 
Message-ID: <y7cu1mvtjuh.fsf@sindri.juniper.net>
>>  What do you want it to do?
> Here's my guess.
[snip]

Yes, that's precisely what I meant.  Thanks; sorry if I was unclear.

joelh