Code Comments
Programming Forum and web based access to our favorite programming groups.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).
Post Follow-up to this messagerocco.rossi@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, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
Post Follow-up to this messageOn Apr 2, 11:24 am, rocco.ro...@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: [url]http://groups.google.com/group/comp.lang.lisp/msg/4da9387c1b81573e?dmode=source[/u rl] Tayssir
Post Follow-up to this messageOn Apr 2, 11:33=A0am, Frank Buss <f...@frank-buss.de> wrote:
> rocco.ro...@gmail.com wrote:
>
> 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 us=[/color
]
e
> 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.
Post Follow-up to this messageOn Apr 2, 10:36 am, Tayssir John Gabbour <tayssir.j...@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.
Post Follow-up to this messagerocco.rossi@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/
Post Follow-up to this message** Warning, Emacs Lisp! ** ((macro . (lambda (x) `',x)) a) => a
Post Follow-up to this messagerr> 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.