Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Anonymous Macro - Is there such a thing?
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).


Report this thread to moderator Post Follow-up to this message
Old Post
rocco.rossi@gmail.com
04-02-08 09:47 AM


Re: Anonymous Macro - Is there such a thing?
rocco.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

Report this thread to moderator Post Follow-up to this message
Old Post
Frank Buss
04-02-08 09:47 AM


Re: Anonymous Macro - Is there such a thing?
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Tayssir John Gabbour
04-02-08 09:47 AM


Re: Anonymous Macro - Is there such a thing?
On 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Thomas F. Burdick
04-02-08 01:30 PM


Re: Anonymous Macro - Is there such a thing?
On 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Tim Bradshaw
04-02-08 01:30 PM


Re: Anonymous Macro - Is there such a thing?
rocco.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/

Report this thread to moderator Post Follow-up to this message
Old Post
Pascal Costanza
04-03-08 12:44 AM


Re: Anonymous Macro - Is there such a thing?
** Warning, Emacs Lisp! **

((macro . (lambda (x) `',x))
a)
=> a

Report this thread to moderator Post Follow-up to this message
Old Post
Johan Bockgård
04-03-08 12:44 AM


Re: Anonymous Macro - Is there such a thing?
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



Report this thread to moderator Post Follow-up to this message
Old Post
Alex Mizrahi
04-03-08 01:43 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Lisp archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:17 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.