From: Vladimir Zolotykh
Subject: MACROEXPAND, MACROEXPAND-1, DEFMACRO
Date: 
Message-ID: <3C52C2F2.754B986@eurocom.od.ua>
MACROEXPAND, MACROEXPAND-1, DEFMACRO.

These above use &environment parameter. Most others CL functions,
operators, macros etc do not. In other words,they made explicit
distinction between environments e.g. between global environment and
lexical environment for example. Should be important reason for that I
suppose. This is it I'd like to know better. Could you help me a bit
with explanation ?

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua

From: Tim Moore
Subject: Re: MACROEXPAND, MACROEXPAND-1, DEFMACRO
Date: 
Message-ID: <a2uplr$es$0@216.39.145.192>
On Sat, 26 Jan 2002 16:53:38 +0200, Vladimir Zolotykh <······@eurocom.od.ua> 
wrote:
>MACROEXPAND, MACROEXPAND-1, DEFMACRO.
>
>These above use &environment parameter. Most others CL functions,
>operators, macros etc do not. In other words,they made explicit

Strictly speaking they don't take an "&environment" parameter; only
macros have &environment parameters.  These function take an
"environment" as a parameter.

Actually, any macro can take an &environment parameter even though it
isn't explicit in the "published" interface to the macro.

>distinction between environments e.g. between global environment and
>lexical environment for example. Should be important reason for that I
>suppose. This is it I'd like to know better. Could you help me a bit
>with explanation ?
>

Macros can be defined in the local lexical environment, so these
functions need access to that environment in order to work correctly.
Obviously this is required for an implementation's interpreter and
compiler -- assuming it uses macroexpand internally -- but it is also
needed by many macros that macroexpand their arguments.

Here's a slightly silly example:

(defmacro .lookup-cache. () nil)

(defmacro with-cached-lookup (&body body)
  (let ((lookup-table (gensym)))
    `(let ((,lookup-table) (make-lookup-table))
       (macrolet ((.lookup-cache. () ',lookup-table))
	 ,@body))))

(defmacro lookup (foo &environment env)
  (let ((lookup-table (macroexpand '(.lookup-cache.) env)))
    (if lookup-table
	`(fast-lookup ,foo ,lookup-table)
      `(slow-lookup foo))))

Tim
From: Vladimir Zolotykh
Subject: Re: MACROEXPAND, MACROEXPAND-1, DEFMACRO
Date: 
Message-ID: <3C53C221.F9991162@eurocom.od.ua>
Tim Moore wrote:
> 
> (defmacro .lookup-cache. () nil)
> 
> (defmacro with-cached-lookup (&body body)
>   (let ((lookup-table (gensym)))
>     `(let ((,lookup-table) (make-lookup-table))
>        (macrolet ((.lookup-cache. () ',lookup-table))
>          ,@body))))
> 
> (defmacro lookup (foo &environment env)
>   (let ((lookup-table (macroexpand '(.lookup-cache.) env)))
>     (if lookup-table
>         `(fast-lookup ,foo ,lookup-table)
>       `(slow-lookup foo))))
> 

Thank you, I understood this (more or less). But I also interested
which cases in I wouldn't want to use lexical environment, just global.

What is the conventions on using names surrounded by dots , e.g.
.lookup-cache. in your example ?

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua
From: Tim Moore
Subject: Re: MACROEXPAND, MACROEXPAND-1, DEFMACRO
Date: 
Message-ID: <a30idi$h59$0@216.39.145.192>
On Sun, 27 Jan 2002 11:02:25 +0200, Vladimir Zolotykh <······@eurocom.od.ua> 
wrote:
>Tim Moore wrote:
>> 
>> (defmacro .lookup-cache. () nil)
>> 
>> (defmacro with-cached-lookup (&body body)
>>   (let ((lookup-table (gensym)))
>>     `(let ((,lookup-table) (make-lookup-table))
>>        (macrolet ((.lookup-cache. () ',lookup-table))
>>          ,@body))))
>> 
>> (defmacro lookup (foo &environment env)
>>   (let ((lookup-table (macroexpand '(.lookup-cache.) env)))
>>     (if lookup-table
>>         `(fast-lookup ,foo ,lookup-table)
>>       `(slow-lookup foo))))
>> 
>
>Thank you, I understood this (more or less). But I also interested
>which cases in I wouldn't want to use lexical environment, just global.

I'm not sure, but the whole point of &environment arguments is to use
information in the local lexical environment.
>
>What is the conventions on using names surrounded by dots , e.g.
>.lookup-cache. in your example ?

It indicates "magic is afoot" i.e., this is an internal macro that no
one should ever call.  I don't know how widespread this convention is;
you often see variable names in macros named that way.

Tim