From: JP Massar
Subject: Re: help with nested macros
Date: 
Message-ID: <3be81481.83113051@news>
On 06 Nov 2001 11:07:02 -0500, Myriam Abramson <········@osf1.gmu.edu>
wrote:

>
>Hi!
>
>I'm back into lisp after being away for more than 2 years, yeah!
>
>Anyway, enough excuses, I want to write a macro such as 
>
>(defmacro defcom (fn args &rest rules)
>  `(defun ,fn (&key ,@args &allow-other-keys)
>       (with-appropriate-vars (var ',fn)
>          ,@rules)))
>
>(defmacro with-appropriate-vars ((var fn) &body body)
>   `(let ((,var '(0 0 0 0)))
>       (when (appropriate-p ,fn)
>           (setf ,var (set-var)))
>        ,@body))
>
>
>When expanded, the function created does not have
>with-appropriate-vars expanded to the let clause so I'm obviously
>doing something wrong. What's the best way to write defcom? 
>
 
In fact, you aren't doing anything wrote wrt with-appropriate-vars.

When you macroexpand a DEFCOM form, you are probably calling 
(explicitly or implicitly) the function MACROEXPAND-1 or MACROEXPAND
on the DEFCOM for.

These functions only macroexpand the toplevel macro call.  They
don't go into the 'body' of what has been generated and keep trying
to macroexpand.

E.g.

(defmacro foo (x) `(+ (or ,x 0) 1))

If you macroexpand (foo 3) you get the form (+ (or 3 0) 1).

But OR is also defined as being a macro in CLtL.  You are suggesting
that you should also be seeing the macroexpansion or OR when you do
your toplevel macroexpansion.  But you do not, even though the code
is fine.

When the code is compiled and/or executed, all macro's are 
indeed expanded.  When the compiler compiles the defun generated
by your defcom macro above, it will expand the with-appropriate-vars
macro invocation.   

Sometimes it is, indeed, useful to do a macroexpansion whereby the
form is traversed in its entirety, and all macros expanded until
the only thing left in the form is special forms and functions.
One might call it MACROEXPAND-ALL.

I don't know of any function that does this in Allegro; other
implementations may have one.  I think Lisp Machines used to have
this functionality.





 

From: Thomas F. Burdick
Subject: Re: help with nested macros
Date: 
Message-ID: <xcvelnb8ta4.fsf@conquest.OCF.Berkeley.EDU>
Myriam Abramson <········@osf1.gmu.edu> writes:

> Okay, I was under the impression that macroexpand will expand
> everything and macroexpand-1 only the top level. My bad :)

MACROEXPAND will fully expand the form, and MACROEXPAND-1 will only
expand one level.  Neither expands the whole tree:

  * (defmacro foo (a b) `(bar ,a ,b))
  foo
  * (defmacro bar (a b) `(cons ,a ,b))
  bar
  * (macroexpand-1 '(foo (foo 'a 1) (foo 'b 2)))
  (bar (foo 'a 1) (foo 'b 2))
  t
  * (macroexpand '(foo (foo 'a 1) (foo 'b 2)))
  (cons (foo 'a 1) (foo 'b 2))
  t

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Francis Leboutte
Subject: Re: help with nested macros
Date: 
Message-ID: <kouhut459pp8qaiqfvdl0ku3ipc8vmuab5@4ax.com>
······@alum.mit.edu (JP Massar) wrote:

>...
>I don't know of any function that does this in Allegro; other
>implementations may have one.  I think Lisp Machines used to have
>this functionality.

There is aclwin302:macroexpand-all (aclwin302 is the ACLwin compatibility
package, I think it's also available in ACL on Unix).

--
www.algo.be
Logo programming : www.algo.be/logo.html
From: JP Massar
Subject: Re: help with nested macros
Date: 
Message-ID: <3bf298b1.292115803@news>
On Wed, 07 Nov 2001 10:28:44 +0100, Francis Leboutte
<··········@algo.be> wrote:

>······@alum.mit.edu (JP Massar) wrote:
>
>>...
>>I don't know of any function that does this in Allegro; other
>>implementations may have one.  I think Lisp Machines used to have
>>this functionality.
>
>There is aclwin302:macroexpand-all (aclwin302 is the ACLwin compatibility
>package, I think it's also available in ACL on Unix).
>
 
I couldn't find any macroexpand-all under Allegro 6.0 running on Unix.

aclwin302:macroexpand-all simply calls clos::walk-form; maybe that's
available on Unix but I don't have a Unix version available where I am
now to check.
From: Tim Moore
Subject: Re: help with nested macros
Date: 
Message-ID: <9sugp9$8ug$0@216.39.145.192>
In article <··················@news>, "JP Massar" <······@alum.mit.edu>
wrote:


> On Wed, 07 Nov 2001 10:28:44 +0100, Francis Leboutte
> <··········@algo.be> wrote:
> 
>>······@alum.mit.edu (JP Massar) wrote:
>>>...
>>>I don't know of any function that does this in Allegro; other
>>>implementations may have one.  I think Lisp Machines used to have this
>>>functionality.
>>There is aclwin302:macroexpand-all (aclwin302 is the ACLwin
>>compatibility package, I think it's also available in ACL on Unix).
>  
> I couldn't find any macroexpand-all under Allegro 6.0 running on Unix. 
> aclwin302:macroexpand-all simply calls clos::walk-form; maybe that's
> available on Unix but I don't have a Unix version available where I am
> now to check.
In 6.0 it's excl::walk-form.  It's bound to C-c C-w in the Emacs
interface.  Very handy.

Tim
From: Francis Leboutte
Subject: Re: help with nested macros
Date: 
Message-ID: <6q37vtollma4q32jhotsagutr77tqk7qtg@4ax.com>
"Tim Moore" <·····@bricoworks.com> wrote:

>In 6.0 it's excl::walk-form.  It's bound to C-c C-w in the Emacs
>interface.  Very handy.

Right. There is also excl::compiler-walk, at least in ACL6.1 which I just start
to use. Both are available from the Edit menu (IDE - MS Windows).
--
www.algo.be
Logo programming : www.algo.be/logo.html