MACROEXPAND, MACROEXPAND-1, DEFMACRO 
Author Message
 MACROEXPAND, MACROEXPAND-1, DEFMACRO

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 ?

--



Wed, 14 Jul 2004 22:53:38 GMT  
 MACROEXPAND, MACROEXPAND-1, DEFMACRO


Quote:
>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.

Quote:
>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))

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

Tim



Thu, 15 Jul 2004 01:40:11 GMT  
 MACROEXPAND, MACROEXPAND-1, DEFMACRO

Quote:

> (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))

> (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 ?

--



Thu, 15 Jul 2004 17:02:25 GMT  
 MACROEXPAND, MACROEXPAND-1, DEFMACRO


Quote:

>> (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))

>> (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.

Quote:

>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



Thu, 15 Jul 2004 17:48:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. macroexpand vs. macroexpand-1 vs. ELI's recursive-macroexpand

2. More readable macroexpand-1 output

3. Macroexpand and symbol-macrolet

4. Macroexpand local macros

5. Macroexpanding

6. Does anyone have a MACROEXPAND-ALL function?

7. Any implementation of "macroexpand-all"?

8. explicit macroexpand

9. macroexpanding macrolets

10. MacGambit, SLIB and defmacro

11. Slib defmacro

12. R4RS Macros implemented in defmacro (or for Elk)?

 

 
Powered by phpBB® Forum Software