From: ···········@gmail.com
Subject: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <c363b8a6-086e-4605-9a9b-9f713879912b@m3g2000hsc.googlegroups.com>
Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
instance, a back-quoted list (I know a back-quoted list is not a
macro, but just to get my point across) whose code is to be expanded
at compile-time, but without necessarily creating a full-blown, named
macro. In short, something like LAMBDA but for macros instead of
functions. Is this possible?

I realize I could pass the list to EVAL, but I don't want to do that
because the evaluation occurs during runtime (and for other reasons
regarding lexical scoping).

From: Tayssir John Gabbour
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <187247e9-c253-41aa-b7e4-e84d5d00d66a@p25g2000hsf.googlegroups.com>
On Apr 2, 11:24 am, ···········@gmail.com wrote:
> Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
> instance, a back-quoted list (I know a back-quoted list is not a
> macro, but just to get my point across) whose code is to be expanded
> at compile-time, but without necessarily creating a full-blown, named
> macro. In short, something like LAMBDA but for macros instead of
> functions. Is this possible?

Would MACROLET be a good compromise?

More discussion here:
http://groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?dmode=source


Tayssir
From: Tim Bradshaw
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <787e8249-12f2-45a0-a1d2-2a2bda6edf0a@e6g2000prf.googlegroups.com>
On Apr 2, 10:36 am, Tayssir John Gabbour <············@googlemail.com>
wrote:

>
> Would MACROLET be a good compromise?

I was going to ask if

(macrolet ((x ...))
  (x ...))

Does the right thing by toplevlness and so on, but I think the
hyperspec says it does, so this would be a good answer.
From: Frank Buss
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <7rrh7u2spqj2.1o2f3dg3npv3k$.dlg@40tude.net>
···········@gmail.com wrote:

> Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
> instance, a back-quoted list (I know a back-quoted list is not a
> macro, but just to get my point across) whose code is to be expanded
> at compile-time, but without necessarily creating a full-blown, named
> macro. In short, something like LAMBDA but for macros instead of
> functions. Is this possible?

If you want to use the macro once, why using a macro at all? Inside of
functions you could use macrolet to define a local macro, which you can use
multiple times.

-- 
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: Thomas F. Burdick
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <98debb5f-6168-4bcb-be3a-7b3473e81acc@c19g2000prf.googlegroups.com>
On Apr 2, 11:33 am, Frank Buss <····@frank-buss.de> wrote:
> ···········@gmail.com wrote:
> > Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
> > instance, a back-quoted list (I know a back-quoted list is not a
> > macro, but just to get my point across) whose code is to be expanded
> > at compile-time, but without necessarily creating a full-blown, named
> > macro. In short, something like LAMBDA but for macros instead of
> > functions. Is this possible?
>
> If you want to use the macro once, why using a macro at all? Inside of
> functions you could use macrolet to define a local macro, which you can use
> multiple times.

Because sometimes it's easier and safer to write the code to write
some code, rather than writing the desired code directly.  For
example, would you rather write out the definitions to the functions
c[ad]{2-4}r or write a macro that expands into their definitions?

Whoops, now you need to define the setf functions, too.
From: Pascal Costanza
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <65hujgF2fmnjnU2@mid.individual.net>
···········@gmail.com wrote:
> Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
> instance, a back-quoted list (I know a back-quoted list is not a
> macro, but just to get my point across) whose code is to be expanded
> at compile-time, but without necessarily creating a full-blown, named
> macro. In short, something like LAMBDA but for macros instead of
> functions. Is this possible?
> 
> I realize I could pass the list to EVAL, but I don't want to do that
> because the evaluation occurs during runtime (and for other reasons
> regarding lexical scoping).

Try to implement it.

Here is a suggestion for the use of anonymous macros:

(amacro ((a b &body body) `(prog2 a b ,@body))
   (print 1)
   (print 2)
   (print 3))

Here is the beginning of the macro definition:

(defmacro amacro ((lambda-list expression) &body body)
   ...)


(Don't make the mistake and try to define first-class macros. That 
doesn't work.)



Pascal

-- 
1st European Lisp Symposium (ELS'08)
http://prog.vub.ac.be/~pcostanza/els08/

My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: D Herring
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <BvudncIQOeOgAWjanZ2dnUVZ_rKtnZ2d@comcast.com>
Pascal Costanza wrote:

> (Don't make the mistake and try to define first-class macros. That 
> doesn't work.)

Sure it does.  ;-)  We just have to take your quote out of context.

;; "first-class" macros

(defmacro mapmacro (macro list)
   (cond
     ((symbolp macro)
      (cons 'progn
            (loop for l in list
               collect (list macro l))))
     ((listp macro)
      (let ((m (gensym)))
        (append
         `(macrolet (,(cons m macro)))
         (loop for l in list
            collect (list m l)))))))

(defmacro m1 (x)
   `(+ ,x 3))

(mapmacro m1 (1 2 3))
(mapmacro ((x) (+ x 3)) (1 2 3))


;; or

(defmacro mapmacro (macro list)
   (cond
     ((symbolp macro)
      (cons 'progn
            (loop for l in list
               collect (list macro l))))
     ((and (listp macro)
           (equal (car macro) 'mambda))
      (let ((m (gensym)))
        (append
         `(macrolet (,(cons m (cdr macro))))
         (loop for l in list
            collect (list m l)))))))

(mapmacro (mambda (x) (+ x 3)) (1 2 3))

- Daniel
From: Johan Bockgård
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <yoijve303zk9.fsf@remote2.student.chalmers.se>
** Warning, Emacs Lisp! **

  ((macro . (lambda (x) `',x))
   a)
 => a
From: Alex Mizrahi
Subject: Re: Anonymous Macro - Is there such a thing?
Date: 
Message-ID: <47f4c7d7$0$90272$14726298@news.sunsite.dk>
 rr> Suppose I wanted to create a sort of "anonymous" (one-shot) macro. For
 rr> instance, a back-quoted list (I know a back-quoted list is not a
 rr> macro, but just to get my point across) whose code is to be expanded
 rr> at compile-time,

you can expand code at read-time via "#.". that should be fine for most 
purposes